From 74348ea12773555c720ef847ee1ce4f9a8a6e2e3 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Tue, 5 Apr 2022 23:49:44 +0000 Subject: [PATCH] [js_ast] Fully migrated to 2.16 Change-Id: I3b216c529b6917f4a6ea1eb8e04c147c015d0f1c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239601 Reviewed-by: Nicholas Shahan Commit-Queue: Stephen Adams --- pkg/js_ast/lib/src/characters.dart | 2 -- pkg/js_ast/test/deferred_expression_test.dart | 12 ++++---- pkg/js_ast/test/deferred_statement_test.dart | 30 +++++++++++-------- pkg/js_ast/test/printer_callback_test.dart | 13 +++----- pkg/js_ast/test/string_escape_test.dart | 10 +++---- 5 files changed, 32 insertions(+), 35 deletions(-) diff --git a/pkg/js_ast/lib/src/characters.dart b/pkg/js_ast/lib/src/characters.dart index aaa068d8e7e..5fd11967269 100644 --- a/pkg/js_ast/lib/src/characters.dart +++ b/pkg/js_ast/lib/src/characters.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.15 - library js_character_codes; const int $EOF = 0; diff --git a/pkg/js_ast/test/deferred_expression_test.dart b/pkg/js_ast/test/deferred_expression_test.dart index da1e1587637..f5199641ebb 100644 --- a/pkg/js_ast/test/deferred_expression_test.dart +++ b/pkg/js_ast/test/deferred_expression_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.10 - import 'package:expect/expect.dart'; import 'package:js_ast/js_ast.dart'; @@ -55,7 +53,7 @@ void main() { void test(Map map, String template, List arguments, String expectedOutput) { Expression directExpression = - js.expressionTemplateFor(template).instantiate(arguments); + js.expressionTemplateFor(template).instantiate(arguments) as Expression; _Context directContext = _Context(); Printer directPrinter = Printer(const JavaScriptPrintingOptions(), directContext); @@ -64,7 +62,7 @@ void test(Map map, String template, Expression deferredExpression = js .expressionTemplateFor(template) - .instantiate(arguments.map((e) => map[e]).toList()); + .instantiate(arguments.map((e) => map[e]).toList()) as Expression; _Context deferredContext = _Context(); Printer deferredPrinter = Printer(const JavaScriptPrintingOptions(), deferredContext); @@ -72,7 +70,7 @@ void test(Map map, String template, Expect.equals(expectedOutput, deferredContext.text); for (Expression argument in arguments) { - DeferredExpression deferred = map[argument]; + DeferredExpression deferred = map[argument]!; Expect.isTrue( directContext.enterPositions.containsKey(argument), 'Argument ${DebugPrint(argument)} not found in direct enter positions: ' @@ -144,7 +142,7 @@ class _Context implements JavaScriptPrintingContext { @override void exitNode( - Node node, int startPosition, int endPosition, int closingPosition) { + Node node, int startPosition, int endPosition, int? closingPosition) { exitPositions[node] = _Position(startPosition, endPosition, closingPosition); Expect.equals(enterPositions[node], startPosition); @@ -161,7 +159,7 @@ class _Context implements JavaScriptPrintingContext { class _Position { final int startPosition; final int endPosition; - final int closingPosition; + final int? closingPosition; _Position(this.startPosition, this.endPosition, this.closingPosition); diff --git a/pkg/js_ast/test/deferred_statement_test.dart b/pkg/js_ast/test/deferred_statement_test.dart index 4db27a6eee2..1ec6f13fb57 100644 --- a/pkg/js_ast/test/deferred_statement_test.dart +++ b/pkg/js_ast/test/deferred_statement_test.dart @@ -2,16 +2,15 @@ // 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. -// @dart = 2.10 - import 'package:expect/expect.dart'; import 'package:js_ast/js_ast.dart'; class _DeferredStatement extends DeferredStatement { + final Statement? _statement; @override - final Statement statement; + Statement get statement => _statement!; - _DeferredStatement(this.statement); + _DeferredStatement(this._statement); } void main() { @@ -38,14 +37,21 @@ void main() { // Nested Blocks in DeferredStatements are elided. Expect.equals( - DebugPrint(Block([ - _DeferredStatement(Block([ - _DeferredStatement(Block.empty()), - Block.empty(), - Block([_DeferredStatement(Block.empty()), Block.empty()]), - _DeferredStatement(_DeferredStatement(Block.empty())) - ])) - ])), + DebugPrint( + Block([ + _DeferredStatement( + Block([ + _DeferredStatement(Block.empty()), + Block.empty(), + Block([ + _DeferredStatement(Block.empty()), + Block.empty(), + ]), + _DeferredStatement(_DeferredStatement(Block.empty())), + ]), + ), + ]), + ), '{\n}\n'); // DeferredStatement with empty Statement prints semicolon and a newline. diff --git a/pkg/js_ast/test/printer_callback_test.dart b/pkg/js_ast/test/printer_callback_test.dart index 433d3ad1a44..45912bbbf03 100644 --- a/pkg/js_ast/test/printer_callback_test.dart +++ b/pkg/js_ast/test/printer_callback_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.10 - // Note: This test relies on LF line endings in the source file. // Test that JS printer callbacks occur when expected. @@ -178,11 +176,8 @@ class FixedName extends Name { void check(TestCase testCase) { Map map = testCase.data; - String code = map[TestMode.INPUT]; - - // Input is the same as output. - code ??= map[TestMode.NONE]; - + // Unspecified input is the same as output. + String? code = map[TestMode.INPUT] ?? map[TestMode.NONE]!; JavaScriptPrintingOptions options = JavaScriptPrintingOptions(); Map arguments = {}; testCase.environment.forEach((String name, String value) { @@ -221,7 +216,7 @@ class Context extends SimpleJavaScriptPrintingContext { @override void exitNode( - Node node, int startPosition, int endPosition, int delimiterPosition) { + Node node, int startPosition, int endPosition, int? delimiterPosition) { int value = id(node); if (mode == TestMode.DELIMITER && delimiterPosition != null) { tagMap.putIfAbsent(delimiterPosition, () => []).add(tag(value)); @@ -239,7 +234,7 @@ class Context extends SimpleJavaScriptPrintingContext { if (offset < position) { sb.write(text.substring(offset, position)); } - tagMap[position].forEach((String tag) => sb.write(tag)); + tagMap[position]!.forEach((String tag) => sb.write(tag)); offset = position; } if (offset < text.length) { diff --git a/pkg/js_ast/test/string_escape_test.dart b/pkg/js_ast/test/string_escape_test.dart index c483ba92bc5..c61a3ff52ef 100644 --- a/pkg/js_ast/test/string_escape_test.dart +++ b/pkg/js_ast/test/string_escape_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.10 - library js_ast.string_escape_test; import 'package:js_ast/js_ast.dart'; @@ -14,9 +12,11 @@ const int $LCURLY = $OPEN_CURLY_BRACKET; const int $RCURLY = $CLOSE_CURLY_BRACKET; void main() { - void check(input, expected, {bool utf8 = false}) { - if (input is List) input = String.fromCharCodes(input); - String actual = DebugPrint(js.string(input), utf8: utf8); + void check(Object input, Object expected, {bool utf8 = false}) { + String string = input is String + ? input + : String.fromCharCodes(List.from(input as Iterable)); + String actual = DebugPrint(js.string(string), utf8: utf8); if (expected is List) { expect(actual.codeUnits, expected); } else {