From 89c704f2308e2a2c41f7052c8e0176c85d3121e1 Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Thu, 19 Mar 2020 14:56:42 -0700 Subject: [PATCH 1/2] Always insert a blank line after script tags. This makes the behavior consistent across script tags that precede library tags, imports, classes, variables, doc comments, and regular comments. Fix #782. --- lib/src/source_visitor.dart | 2 +- test/regression/0000/0089.unit | 1 + test/regression/0500/0513.unit | 2 ++ test/regression/0700/0782.unit | 48 ++++++++++++++++++++++++++++++++++ test/whitespace/script.unit | 44 ++++++++++++++++++++++++++++++- 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 test/regression/0700/0782.unit diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart index ffd7a0f0..73be3a99 100644 --- a/lib/src/source_visitor.dart +++ b/lib/src/source_visitor.dart @@ -2413,7 +2413,7 @@ class SourceVisitor extends ThrowingAstVisitor { // come at the top of the file, we don't have to worry about preceding // comments or whitespace. _writeText(node.scriptTag.lexeme.trim(), node.offset); - newline(); + twoNewlines(); } @override diff --git a/test/regression/0000/0089.unit b/test/regression/0000/0089.unit index 512d57e6..ac8f80f5 100644 --- a/test/regression/0000/0089.unit +++ b/test/regression/0000/0089.unit @@ -5,6 +5,7 @@ // BSD-style license that can be found in the LICENSE file. <<< #!/usr/bin/env dart + // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. \ No newline at end of file diff --git a/test/regression/0500/0513.unit b/test/regression/0500/0513.unit index 2aaa4a9d..4f5874fc 100644 --- a/test/regression/0500/0513.unit +++ b/test/regression/0500/0513.unit @@ -5,6 +5,7 @@ library x; <<< #!script + library x; >>> #!script @@ -12,4 +13,5 @@ library x; library x; <<< #!script + library x; \ No newline at end of file diff --git a/test/regression/0700/0782.unit b/test/regression/0700/0782.unit new file mode 100644 index 00000000..b4f2262b --- /dev/null +++ b/test/regression/0700/0782.unit @@ -0,0 +1,48 @@ +>>> +#!/usr/bin/env dart + +import 'dart:io'; +// More code... +<<< +#!/usr/bin/env dart + +import 'dart:io'; +// More code... +>>> +#!/usr/bin/env dart + +void main() {} +<<< +#!/usr/bin/env dart + +void main() {} +>>> +#!/usr/bin/env dart + +/// dartdoc comment. +<<< +#!/usr/bin/env dart + +/// dartdoc comment. +>>> +#!/usr/bin/env dart + +var someGlobal = 0; +<<< +#!/usr/bin/env dart + +var someGlobal = 0; +>>> +#!/usr/bin/env dart +import 'dart:io'; +<<< +#!/usr/bin/env dart + +import 'dart:io'; +>>> +#!/usr/bin/env dart +// Normal comment. +<<< +#!/usr/bin/env dart + +// Normal comment. \ No newline at end of file diff --git a/test/whitespace/script.unit b/test/whitespace/script.unit index cd84ba1c..cf0f9c6a 100644 --- a/test/whitespace/script.unit +++ b/test/whitespace/script.unit @@ -4,6 +4,7 @@ library foo; <<< #!script + library foo; >>> multiple lines between script and library #!script @@ -13,12 +14,14 @@ library foo; library foo; <<< #!script + library foo; >>> one line between script and import #!script import 'foo'; <<< #!script + import 'foo'; >>> multiple lines between script and import #!script @@ -28,12 +31,14 @@ import 'foo'; import 'foo'; <<< #!script + import 'foo'; >>> one line between script and line comment #!script // comment <<< #!script + // comment >>> multiple lines between script and line comment #!script @@ -43,12 +48,14 @@ import 'foo'; // comment <<< #!script + // comment >>> one line between script and block comment #!script /* comment */ <<< #!script + /* comment */ >>> multiple lines between script and block comment #!script @@ -58,4 +65,39 @@ import 'foo'; /* comment */ <<< #!script -/* comment */ \ No newline at end of file + +/* comment */ +>>> one line between script and class +#!script +class C {} +<<< +#!script + +class C {} +>>> multiple lines between script and class +#!script + + + +class C {} +<<< +#!script + +class C {} +>>> one line between script and variable +#!script +var x; +<<< +#!script + +var x; +>>> multiple lines between script and variable +#!script + + + +var x; +<<< +#!script + +var x; \ No newline at end of file From e5ad7d87d41a8c08ed60336a7ddeb2a2e14846e8 Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Thu, 19 Mar 2020 15:02:33 -0700 Subject: [PATCH 2/2] Update CHANGELOG. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebb360b3..1f82be25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Correctly handle `var` in `--fix-function-typedefs` (#826). * Preserve leading indentation in fixed doc comments (#821). * Add `--verbose` to hide advanced options in `--help` output +* Always place a blank line after script tags (#782). # 1.3.3