[js_ast] Fully migrated to 2.16

Change-Id: I3b216c529b6917f4a6ea1eb8e04c147c015d0f1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239601
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
This commit is contained in:
Stephen Adams 2022-04-05 23:49:44 +00:00 committed by Commit Bot
parent c6e4832d41
commit 74348ea127
5 changed files with 32 additions and 35 deletions

View file

@ -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;

View file

@ -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<Expression, DeferredExpression> map, String template,
List<Expression> 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<Expression, DeferredExpression> 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<Expression, DeferredExpression> 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);

View file

@ -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.

View file

@ -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<TestMode, String> 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) {

View file

@ -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<int>.from(input as Iterable));
String actual = DebugPrint(js.string(string), utf8: utf8);
if (expected is List) {
expect(actual.codeUnits, expected);
} else {