diff --git a/lib/src/front_end/sequence_builder.dart b/lib/src/front_end/sequence_builder.dart index 3c7cf39d..ce51a298 100644 --- a/lib/src/front_end/sequence_builder.dart +++ b/lib/src/front_end/sequence_builder.dart @@ -53,11 +53,13 @@ class SequenceBuilder { // BlockPiece. if (_elements.isEmpty) { return _visitor.pieces.build(() { - _visitor.pieces.add(_leftBracket!); - if (forceSplit) { + if (_leftBracket case var bracket?) _visitor.pieces.add(bracket); + + if (forceSplit || _leftBracket == null) { _visitor.pieces.add(NewlinePiece()); } - _visitor.pieces.add(_rightBracket!); + + if (_rightBracket case var bracket?) _visitor.pieces.add(bracket); }); } diff --git a/test/tall/top_level/whitespace.unit b/test/tall/top_level/whitespace.unit index 42b1930b..b51b54f0 100644 --- a/test/tall/top_level/whitespace.unit +++ b/test/tall/top_level/whitespace.unit @@ -1,4 +1,10 @@ 40 columns | +>>> Empty compilation unit. + + + +<<< + >>> Force at least one newline between directives. import 'a.dart';import 'b.dart';export 'c.dart'; <<<