[js_ast] dart format --fix

Formatted with `--fix`, followed by some small manual changes:

- Reflowed some comments to 80 columns.
- Replaced Map/Set constructor calls with {} literals.
- Removed type argument when on both sides of initialization.

Change-Id: I3f5d29dd7e144f96a02efa95db8b40bf63484442
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210940
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
This commit is contained in:
Stephen Adams 2021-08-25 03:08:21 +00:00 committed by commit-bot@chromium.org
parent 10125490a9
commit 2f66afbfb4
5 changed files with 505 additions and 554 deletions

File diff suppressed because it is too large Load diff

View file

@ -459,7 +459,7 @@ abstract class Node {
bool get isFinalized => true;
Statement toStatement() {
throw new UnsupportedError('toStatement');
throw UnsupportedError('toStatement');
}
String debugPrint() => DebugPrint(this);
@ -482,7 +482,7 @@ class Program extends Node {
for (Statement statement in body) statement.accept1(visitor, arg);
}
Program _clone() => new Program(body);
Program _clone() => Program(body);
}
abstract class Statement extends Node {
@ -513,7 +513,7 @@ class Block extends Statement {
Block(this.statements);
Block.empty() : this.statements = <Statement>[];
Block.empty() : this.statements = [];
T accept<T>(NodeVisitor<T> visitor) => visitor.visitBlock(this);
@ -528,7 +528,7 @@ class Block extends Statement {
for (Statement statement in statements) statement.accept1(visitor, arg);
}
Block _clone() => new Block(statements);
Block _clone() => Block(statements);
}
class ExpressionStatement extends Statement {
@ -551,7 +551,7 @@ class ExpressionStatement extends Statement {
expression.accept1(visitor, arg);
}
ExpressionStatement _clone() => new ExpressionStatement(expression);
ExpressionStatement _clone() => ExpressionStatement(expression);
}
class EmptyStatement extends Statement {
@ -566,7 +566,7 @@ class EmptyStatement extends Statement {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
EmptyStatement _clone() => new EmptyStatement();
EmptyStatement _clone() => EmptyStatement();
}
class If extends Statement {
@ -576,7 +576,7 @@ class If extends Statement {
If(this.condition, this.then, this.otherwise);
If.noElse(this.condition, this.then) : this.otherwise = new EmptyStatement();
If.noElse(this.condition, this.then) : this.otherwise = EmptyStatement();
bool get hasElse => otherwise is! EmptyStatement;
@ -597,7 +597,7 @@ class If extends Statement {
otherwise.accept1(visitor, arg);
}
If _clone() => new If(condition, then, otherwise);
If _clone() => If(condition, then, otherwise);
}
abstract class Loop extends Statement {
@ -632,7 +632,7 @@ class For extends Loop {
body.accept1(visitor, arg);
}
For _clone() => new For(init, condition, update, body);
For _clone() => For(init, condition, update, body);
}
class ForIn extends Loop {
@ -660,7 +660,7 @@ class ForIn extends Loop {
body.accept1(visitor, arg);
}
ForIn _clone() => new ForIn(leftHandSide, object, body);
ForIn _clone() => ForIn(leftHandSide, object, body);
}
class While extends Loop {
@ -683,7 +683,7 @@ class While extends Loop {
body.accept1(visitor, arg);
}
While _clone() => new While(condition, body);
While _clone() => While(condition, body);
}
class Do extends Loop {
@ -706,7 +706,7 @@ class Do extends Loop {
condition.accept1(visitor, arg);
}
Do _clone() => new Do(body, condition);
Do _clone() => Do(body, condition);
}
class Continue extends Statement {
@ -723,7 +723,7 @@ class Continue extends Statement {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
Continue _clone() => new Continue(targetLabel);
Continue _clone() => Continue(targetLabel);
}
class Break extends Statement {
@ -740,7 +740,7 @@ class Break extends Statement {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
Break _clone() => new Break(targetLabel);
Break _clone() => Break(targetLabel);
}
class Return extends Statement {
@ -761,7 +761,7 @@ class Return extends Statement {
if (value != null) value.accept1(visitor, arg);
}
Return _clone() => new Return(value);
Return _clone() => Return(value);
}
class Throw extends Statement {
@ -782,7 +782,7 @@ class Throw extends Statement {
expression.accept1(visitor, arg);
}
Throw _clone() => new Throw(expression);
Throw _clone() => Throw(expression);
}
class Try extends Statement {
@ -811,7 +811,7 @@ class Try extends Statement {
if (finallyPart != null) finallyPart.accept1(visitor, arg);
}
Try _clone() => new Try(body, catchPart, finallyPart);
Try _clone() => Try(body, catchPart, finallyPart);
}
class Catch extends Node {
@ -835,7 +835,7 @@ class Catch extends Node {
body.accept1(visitor, arg);
}
Catch _clone() => new Catch(declaration, body);
Catch _clone() => Catch(declaration, body);
}
class Switch extends Statement {
@ -859,7 +859,7 @@ class Switch extends Statement {
for (SwitchClause clause in cases) clause.accept1(visitor, arg);
}
Switch _clone() => new Switch(key, cases);
Switch _clone() => Switch(key, cases);
}
abstract class SwitchClause extends Node {
@ -888,7 +888,7 @@ class Case extends SwitchClause {
body.accept1(visitor, arg);
}
Case _clone() => new Case(expression, body);
Case _clone() => Case(expression, body);
}
class Default extends SwitchClause {
@ -907,7 +907,7 @@ class Default extends SwitchClause {
body.accept1(visitor, arg);
}
Default _clone() => new Default(body);
Default _clone() => Default(body);
}
class FunctionDeclaration extends Statement {
@ -931,7 +931,7 @@ class FunctionDeclaration extends Statement {
function.accept1(visitor, arg);
}
FunctionDeclaration _clone() => new FunctionDeclaration(name, function);
FunctionDeclaration _clone() => FunctionDeclaration(name, function);
}
class LabeledStatement extends Statement {
@ -953,7 +953,7 @@ class LabeledStatement extends Statement {
body.accept1(visitor, arg);
}
LabeledStatement _clone() => new LabeledStatement(label, body);
LabeledStatement _clone() => LabeledStatement(label, body);
}
class LiteralStatement extends Statement {
@ -970,7 +970,7 @@ class LiteralStatement extends Statement {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
LiteralStatement _clone() => new LiteralStatement(code);
LiteralStatement _clone() => LiteralStatement(code);
}
// Not a real JavaScript node, but represents the yield statement from a dart
@ -995,7 +995,7 @@ class DartYield extends Statement {
expression.accept1(visitor, arg);
}
DartYield _clone() => new DartYield(expression, hasStar);
DartYield _clone() => DartYield(expression, hasStar);
}
abstract class Expression extends Node {
@ -1003,7 +1003,7 @@ abstract class Expression extends Node {
// have precedence depending on how the deferred node is resolved.
int get precedenceLevel;
Statement toStatement() => new ExpressionStatement(this);
Statement toStatement() => ExpressionStatement(this);
}
abstract class Declaration implements VariableReference {}
@ -1081,10 +1081,8 @@ class LiteralExpression extends Expression {
int get precedenceLevel => PRIMARY;
}
/**
* [VariableDeclarationList] is a subclass of [Expression] to simplify the
* AST.
*/
/// [VariableDeclarationList] is a subclass of [Expression] to simplify the
/// AST.
class VariableDeclarationList extends Expression {
final List<VariableInitialization> declarations;
@ -1113,7 +1111,7 @@ class VariableDeclarationList extends Expression {
}
}
VariableDeclarationList _clone() => new VariableDeclarationList(declarations);
VariableDeclarationList _clone() => VariableDeclarationList(declarations);
int get precedenceLevel => EXPRESSION;
}
@ -1138,7 +1136,7 @@ class Parentheses extends Expression {
enclosed.accept1(visitor, arg);
}
Parentheses _clone() => new Parentheses(enclosed);
Parentheses _clone() => Parentheses(enclosed);
int get precedenceLevel => PRIMARY;
}
@ -1172,11 +1170,11 @@ class Assignment extends Expression {
if (value != null) value.accept1(visitor, arg);
}
Assignment _clone() => new Assignment.compound(leftHandSide, op, value);
Assignment _clone() => Assignment.compound(leftHandSide, op, value);
}
class VariableInitialization extends Assignment {
/** [value] may be null. */
/// [value] may be null.
VariableInitialization(Declaration declaration, Expression value)
: super(declaration, value);
@ -1188,8 +1186,7 @@ class VariableInitialization extends Assignment {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitVariableInitialization(this, arg);
VariableInitialization _clone() =>
new VariableInitialization(declaration, value);
VariableInitialization _clone() => VariableInitialization(declaration, value);
}
class Conditional extends Expression {
@ -1216,7 +1213,7 @@ class Conditional extends Expression {
otherwise.accept1(visitor, arg);
}
Conditional _clone() => new Conditional(condition, then, otherwise);
Conditional _clone() => Conditional(condition, then, otherwise);
int get precedenceLevel => ASSIGNMENT;
}
@ -1249,7 +1246,7 @@ class Call extends Expression {
}
}
Call _clone() => new Call(target, arguments);
Call _clone() => Call(target, arguments);
int get precedenceLevel => CALL;
}
@ -1262,7 +1259,7 @@ class New extends Call {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitNew(this, arg);
New _clone() => new New(target, arguments);
New _clone() => New(target, arguments);
}
class Binary extends Expression {
@ -1277,7 +1274,7 @@ class Binary extends Expression {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitBinary(this, arg);
Binary _clone() => new Binary(op, left, right);
Binary _clone() => Binary(op, left, right);
void visitChildren<T>(NodeVisitor<T> visitor) {
left.accept(visitor);
@ -1346,7 +1343,7 @@ class Prefix extends Expression {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitPrefix(this, arg);
Prefix _clone() => new Prefix(op, argument);
Prefix _clone() => Prefix(op, argument);
void visitChildren<T>(NodeVisitor<T> visitor) {
argument.accept(visitor);
@ -1370,7 +1367,7 @@ class Postfix extends Expression {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitPostfix(this, arg);
Postfix _clone() => new Postfix(op, argument);
Postfix _clone() => Postfix(op, argument);
void visitChildren<T>(NodeVisitor<T> visitor) {
argument.accept(visitor);
@ -1383,7 +1380,7 @@ class Postfix extends Expression {
int get precedenceLevel => UNARY;
}
RegExp _identifierRE = new RegExp(r'^[A-Za-z_$][A-Za-z_$0-9]*$');
RegExp _identifierRE = RegExp(r'^[A-Za-z_$][A-Za-z_$0-9]*$');
abstract class VariableReference extends Expression {
final String name;
@ -1409,7 +1406,7 @@ class VariableUse extends VariableReference {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitVariableUse(this, arg);
VariableUse _clone() => new VariableUse(name);
VariableUse _clone() => VariableUse(name);
String toString() => 'VariableUse($name)';
}
@ -1417,14 +1414,14 @@ class VariableUse extends VariableReference {
class VariableDeclaration extends VariableReference implements Declaration {
final bool allowRename;
VariableDeclaration(String name, {this.allowRename: true}) : super(name);
VariableDeclaration(String name, {this.allowRename = true}) : super(name);
T accept<T>(NodeVisitor<T> visitor) => visitor.visitVariableDeclaration(this);
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitVariableDeclaration(this, arg);
VariableDeclaration _clone() => new VariableDeclaration(name);
VariableDeclaration _clone() => VariableDeclaration(name);
}
class Parameter extends VariableDeclaration {
@ -1435,7 +1432,7 @@ class Parameter extends VariableDeclaration {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitParameter(this, arg);
Parameter _clone() => new Parameter(name);
Parameter _clone() => Parameter(name);
}
class This extends Parameter {
@ -1446,7 +1443,7 @@ class This extends Parameter {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitThis(this, arg);
This _clone() => new This();
This _clone() => This();
}
class NamedFunction extends Expression {
@ -1470,7 +1467,7 @@ class NamedFunction extends Expression {
function.accept1(visitor, arg);
}
NamedFunction _clone() => new NamedFunction(name, function);
NamedFunction _clone() => NamedFunction(name, function);
int get precedenceLevel => LEFT_HAND_SIDE;
}
@ -1489,7 +1486,7 @@ class Fun extends FunctionExpression {
@override
final AsyncModifier asyncModifier;
Fun(this.params, this.body, {this.asyncModifier: AsyncModifier.sync});
Fun(this.params, this.body, {this.asyncModifier = AsyncModifier.sync});
T accept<T>(NodeVisitor<T> visitor) => visitor.visitFun(this);
@ -1506,7 +1503,7 @@ class Fun extends FunctionExpression {
body.accept1(visitor, arg);
}
Fun _clone() => new Fun(params, body, asyncModifier: asyncModifier);
Fun _clone() => Fun(params, body, asyncModifier: asyncModifier);
int get precedenceLevel => LEFT_HAND_SIDE;
}
@ -1520,7 +1517,7 @@ class ArrowFunction extends FunctionExpression {
final AsyncModifier asyncModifier;
ArrowFunction(this.params, this.body,
{this.asyncModifier: AsyncModifier.sync});
{this.asyncModifier = AsyncModifier.sync});
T accept<T>(NodeVisitor<T> visitor) => visitor.visitArrowFunction(this);
@ -1538,7 +1535,7 @@ class ArrowFunction extends FunctionExpression {
}
ArrowFunction _clone() =>
new ArrowFunction(params, body, asyncModifier: asyncModifier);
ArrowFunction(params, body, asyncModifier: asyncModifier);
int get precedenceLevel => ASSIGNMENT;
}
@ -1553,13 +1550,13 @@ class AsyncModifier {
{this.isAsync, this.isYielding});
static const AsyncModifier sync =
const AsyncModifier(0, "sync", isAsync: false, isYielding: false);
AsyncModifier(0, "sync", isAsync: false, isYielding: false);
static const AsyncModifier async =
const AsyncModifier(1, "async", isAsync: true, isYielding: false);
AsyncModifier(1, "async", isAsync: true, isYielding: false);
static const AsyncModifier asyncStar =
const AsyncModifier(2, "async*", isAsync: true, isYielding: true);
AsyncModifier(2, "async*", isAsync: true, isYielding: true);
static const AsyncModifier syncStar =
const AsyncModifier(3, "sync*", isAsync: false, isYielding: true);
AsyncModifier(3, "sync*", isAsync: false, isYielding: true);
static const List<AsyncModifier> values = [sync, async, asyncStar, syncStar];
@ -1593,7 +1590,7 @@ class PropertyAccess extends Expression {
selector.accept1(visitor, arg);
}
PropertyAccess _clone() => new PropertyAccess(receiver, selector);
PropertyAccess _clone() => PropertyAccess(receiver, selector);
int get precedenceLevel => LEFT_HAND_SIDE;
}
@ -1669,7 +1666,7 @@ class LiteralBool extends Literal {
// [visitChildren] inherited from [Literal].
LiteralBool _clone() => new LiteralBool(value);
LiteralBool _clone() => LiteralBool(value);
}
class LiteralNull extends Literal {
@ -1680,7 +1677,7 @@ class LiteralNull extends Literal {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitLiteralNull(this, arg);
LiteralNull _clone() => new LiteralNull();
LiteralNull _clone() => LiteralNull();
}
class LiteralString extends Literal {
@ -1746,7 +1743,7 @@ class StringConcatenation extends Literal {
for (Literal part in parts) part.accept1(visitor, arg);
}
StringConcatenation _clone() => new StringConcatenation(this.parts);
StringConcatenation _clone() => StringConcatenation(this.parts);
}
class LiteralNumber extends Literal {
@ -1761,7 +1758,7 @@ class LiteralNumber extends Literal {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitLiteralNumber(this, arg);
LiteralNumber _clone() => new LiteralNumber(value);
LiteralNumber _clone() => LiteralNumber(value);
}
class ArrayInitializer extends Expression {
@ -1782,15 +1779,13 @@ class ArrayInitializer extends Expression {
for (Expression element in elements) element.accept1(visitor, arg);
}
ArrayInitializer _clone() => new ArrayInitializer(elements);
ArrayInitializer _clone() => ArrayInitializer(elements);
int get precedenceLevel => PRIMARY;
}
/**
* An empty place in an [ArrayInitializer].
* For example the list [1, , , 2] would contain two holes.
*/
/// An empty place in an [ArrayInitializer].
/// For example the list [1, , , 2] would contain two holes.
class ArrayHole extends Expression {
T accept<T>(NodeVisitor<T> visitor) => visitor.visitArrayHole(this);
@ -1801,7 +1796,7 @@ class ArrayHole extends Expression {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
ArrayHole _clone() => new ArrayHole();
ArrayHole _clone() => ArrayHole();
int get precedenceLevel => PRIMARY;
}
@ -1810,14 +1805,12 @@ class ObjectInitializer extends Expression {
final List<Property> properties;
final bool isOneLiner;
/**
* Constructs a new object-initializer containing the given [properties].
*
* [isOneLiner] describes the behaviour when pretty-printing (non-minified).
* If true print all properties on the same line.
* If false print each property on a seperate line.
*/
ObjectInitializer(this.properties, {this.isOneLiner: true});
/// Constructs a new object-initializer containing the given [properties].
///
/// [isOneLiner] describes the behaviour when pretty-printing (non-minified).
/// If true print all properties on the same line.
/// If false print each property on a seperate line.
ObjectInitializer(this.properties, {this.isOneLiner = true});
T accept<T>(NodeVisitor<T> visitor) => visitor.visitObjectInitializer(this);
@ -1833,7 +1826,7 @@ class ObjectInitializer extends Expression {
}
ObjectInitializer _clone() =>
new ObjectInitializer(properties, isOneLiner: isOneLiner);
ObjectInitializer(properties, isOneLiner: isOneLiner);
int get precedenceLevel => PRIMARY;
}
@ -1860,7 +1853,7 @@ class Property extends Node {
value.accept1(visitor, arg);
}
Property _clone() => new Property(name, value);
Property _clone() => Property(name, value);
}
class MethodDefinition extends Node implements Property {
@ -1919,7 +1912,7 @@ class InterpolatedExpression extends Expression with InterpolatedNode {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
InterpolatedExpression _clone() => new InterpolatedExpression(nameOrPosition);
InterpolatedExpression _clone() => InterpolatedExpression(nameOrPosition);
int get precedenceLevel => PRIMARY;
}
@ -1938,7 +1931,7 @@ class InterpolatedLiteral extends Literal with InterpolatedNode {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
InterpolatedLiteral _clone() => new InterpolatedLiteral(nameOrPosition);
InterpolatedLiteral _clone() => InterpolatedLiteral(nameOrPosition);
}
class InterpolatedParameter extends Expression
@ -1964,7 +1957,7 @@ class InterpolatedParameter extends Expression
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
InterpolatedParameter _clone() => new InterpolatedParameter(nameOrPosition);
InterpolatedParameter _clone() => InterpolatedParameter(nameOrPosition);
int get precedenceLevel => PRIMARY;
}
@ -1984,7 +1977,7 @@ class InterpolatedSelector extends Expression with InterpolatedNode {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
InterpolatedSelector _clone() => new InterpolatedSelector(nameOrPosition);
InterpolatedSelector _clone() => InterpolatedSelector(nameOrPosition);
int get precedenceLevel => PRIMARY;
}
@ -2004,7 +1997,7 @@ class InterpolatedStatement extends Statement with InterpolatedNode {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
InterpolatedStatement _clone() => new InterpolatedStatement(nameOrPosition);
InterpolatedStatement _clone() => InterpolatedStatement(nameOrPosition);
}
class InterpolatedDeclaration extends Expression
@ -2025,7 +2018,7 @@ class InterpolatedDeclaration extends Expression
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
InterpolatedDeclaration _clone() {
return new InterpolatedDeclaration(nameOrPosition);
return InterpolatedDeclaration(nameOrPosition);
}
@override
@ -2035,13 +2028,11 @@ class InterpolatedDeclaration extends Expression
int get precedenceLevel => PRIMARY;
}
/**
* [RegExpLiteral]s, despite being called "Literal", do not inherit from
* [Literal]. Indeed, regular expressions in JavaScript have a side-effect and
* are thus not in the same category as numbers or strings.
*/
/// [RegExpLiteral]s, despite being called "Literal", do not inherit from
/// [Literal]. Indeed, regular expressions in JavaScript have a side-effect and
/// are thus not in the same category as numbers or strings.
class RegExpLiteral extends Expression {
/** Contains the pattern and the flags.*/
/// Contains the pattern and the flags.
final String pattern;
RegExpLiteral(this.pattern);
@ -2055,19 +2046,17 @@ class RegExpLiteral extends Expression {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {}
RegExpLiteral _clone() => new RegExpLiteral(pattern);
RegExpLiteral _clone() => RegExpLiteral(pattern);
int get precedenceLevel => PRIMARY;
}
/**
* An asynchronous await.
*
* Not part of JavaScript. We desugar this expression before outputting.
* Should only occur in a [Fun] with `asyncModifier` async or asyncStar.
*/
/// An asynchronous await.
///
/// Not part of JavaScript. We desugar this expression before outputting.
/// Should only occur in a [Fun] with `asyncModifier` async or asyncStar.
class Await extends Expression {
/** The awaited expression. */
/// The awaited expression.
final Expression expression;
Await(this.expression);
@ -2084,15 +2073,13 @@ class Await extends Expression {
void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
expression.accept1(visitor, arg);
Await _clone() => new Await(expression);
Await _clone() => Await(expression);
}
/**
* A comment.
*
* Extends [Statement] so we can add comments before statements in
* [Block] and [Program].
*/
/// A comment.
///
/// Extends [Statement] so we can add comments before statements in
/// [Block] and [Program].
class Comment extends Statement {
final String comment;
@ -2103,7 +2090,7 @@ class Comment extends Statement {
R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) =>
visitor.visitComment(this, arg);
Comment _clone() => new Comment(comment);
Comment _clone() => Comment(comment);
void visitChildren<T>(NodeVisitor<T> visitor) {}

View file

@ -49,7 +49,7 @@ abstract class JavaScriptPrintingContext {
/// A simple implementation of [JavaScriptPrintingContext] suitable for tests.
class SimpleJavaScriptPrintingContext extends JavaScriptPrintingContext {
final StringBuffer buffer = new StringBuffer();
final StringBuffer buffer = StringBuffer();
void emit(String string) {
buffer.write(string);
@ -82,7 +82,7 @@ class Printer implements NodeVisitor {
// The current indentation level.
int _indentLevel = 0;
// A cache of all indentation strings used so far.
List<String> _indentList = <String>[""];
final List<String> _indentList = [""];
static final identifierCharacterRegExp = RegExp(r'^[a-zA-Z_0-9$]');
static final expressionContinuationRegExp = RegExp(r'^[-+([]');
@ -91,15 +91,15 @@ class Printer implements NodeVisitor {
: options = options,
context = context,
shouldCompressOutput = options.shouldCompressOutput,
danglingElseVisitor = new DanglingElseVisitor(context),
danglingElseVisitor = DanglingElseVisitor(context),
localNamer = determineRenamer(
options.shouldCompressOutput, options.minifyLocalVariables);
static LocalNamer determineRenamer(
bool shouldCompressOutput, bool allowVariableMinification) {
return (shouldCompressOutput && allowVariableMinification)
? new MinifyRenamer()
: new IdentityNamer();
? MinifyRenamer()
: IdentityNamer();
}
// The current indentation string.
@ -141,7 +141,7 @@ class Printer implements NodeVisitor {
return lastAddedString.codeUnitAt(lastAddedString.length - 1);
}
void out(String str, {bool isWhitespace: false}) {
void out(String str, {bool isWhitespace = false}) {
if (str != "") {
if (pendingSemicolon) {
if (!shouldCompressOutput) {
@ -218,7 +218,7 @@ class Printer implements NodeVisitor {
}
void startNode(Node node) {
currentNode = new EnterExitNode(currentNode, node);
currentNode = EnterExitNode(currentNode, node);
if (node is DeferredExpression) {
startNode(node.value);
}
@ -356,7 +356,7 @@ class Printer implements NodeVisitor {
if (hasElse) {
bool needsBraces = then.accept(danglingElseVisitor) || then is Do;
if (needsBraces) {
then = new Block(<Statement>[then]);
then = Block(<Statement>[then]);
}
}
if (shouldIndent) indent();
@ -598,7 +598,7 @@ class Printer implements NodeVisitor {
// See:
// https://connect.microsoft.com/IE/feedback/details/891889/parser-bugs
if (body is Break && body.targetLabel == node.label) {
visit(new EmptyStatement());
visit(EmptyStatement());
return;
}
outIndent("${node.label}:");
@ -645,7 +645,7 @@ class Printer implements NodeVisitor {
@override
visitFunctionDeclaration(FunctionDeclaration declaration) {
VarCollector vars = new VarCollector();
VarCollector vars = VarCollector();
vars.visitFunctionDeclaration(declaration);
indent();
startNode(declaration.function);
@ -1083,7 +1083,7 @@ class Printer implements NodeVisitor {
@override
void visitNamedFunction(NamedFunction namedFunction) {
VarCollector vars = new VarCollector();
VarCollector vars = VarCollector();
vars.visitNamedFunction(namedFunction);
startNode(namedFunction.function);
int closingPosition = currentNode.closingPosition =
@ -1096,14 +1096,14 @@ class Printer implements NodeVisitor {
@override
void visitFun(Fun fun) {
VarCollector vars = new VarCollector();
VarCollector vars = VarCollector();
vars.visitFun(fun);
currentNode.closingPosition = functionOut(fun, null, vars);
}
@override
void visitArrowFunction(ArrowFunction fun) {
VarCollector vars = new VarCollector();
VarCollector vars = VarCollector();
vars.visitArrowFunction(fun);
currentNode.closingPosition = arrowFunctionOut(fun, vars);
}
@ -1307,7 +1307,7 @@ class Printer implements NodeVisitor {
@override
visitMethodDefinition(MethodDefinition node) {
propertyNameOut(node);
VarCollector vars = new VarCollector();
VarCollector vars = VarCollector();
vars.visitMethodDefinition(node);
startNode(node.function);
currentNode.closingPosition = methodOut(node, vars);
@ -1465,7 +1465,7 @@ class OrderedSet<T> {
final List<T> list;
OrderedSet()
: set = new Set<T>(),
: set = Set<T>(),
list = <T>[];
void add(T x) {
@ -1493,8 +1493,8 @@ class VarCollector extends BaseVisitor {
VarCollector()
: nested = false,
vars = new OrderedSet<String>(),
params = new OrderedSet<String>();
vars = OrderedSet<String>(),
params = OrderedSet<String>();
void forEachVar(void fn(String v)) => vars.forEach(fn);
void forEachParam(void fn(String p)) => params.forEach(fn);
@ -1550,10 +1550,8 @@ class VarCollector extends BaseVisitor {
}
}
/**
* Returns true, if the given node must be wrapped into braces when used
* as then-statement in an [If] that has an else branch.
*/
/// Returns true, if the given node must be wrapped into braces when used
/// as then-statement in an [If] that has an else branch.
class DanglingElseVisitor extends BaseVisitor<bool> {
JavaScriptPrintingContext context;
@ -1631,7 +1629,7 @@ class MinifyRenamer implements LocalNamer {
MinifyRenamer();
void enterScope(VarCollector vars) {
maps.add(new Map<String, String>());
maps.add({});
variableNumberStack.add(variableNumber);
parameterNumberStack.add(parameterNumber);
vars.forEachVar(declareVariable);
@ -1711,7 +1709,7 @@ class MinifyRenamer implements LocalNamer {
String newName;
if (n < LETTERS) {
// Start naming variables a, b, c, ..., z, A, B, C, ..., Z.
newName = new String.fromCharCodes([nthLetter(n)]);
newName = String.fromCharCodes([nthLetter(n)]);
} else {
// Then name variables a0, a1, a2, ..., a9, b0, b1, ..., Z9, aa0, aa1, ...
// For all functions with fewer than 500 locals this is just as compact
@ -1734,9 +1732,9 @@ class MinifyRenamer implements LocalNamer {
codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS));
}
codes.add(charCodes.$0 + digit);
newName = new String.fromCharCodes(codes);
newName = String.fromCharCodes(codes);
}
assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName));
assert(RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName));
maps.last[oldName] = newName;
return newName;
}

View file

@ -5,8 +5,8 @@
part of js_ast;
class TemplateManager {
Map<String, Template> expressionTemplates = new Map<String, Template>();
Map<String, Template> statementTemplates = new Map<String, Template>();
Map<String, Template> expressionTemplates = {};
Map<String, Template> statementTemplates = {};
TemplateManager();
@ -16,7 +16,7 @@ class TemplateManager {
Template defineExpressionTemplate(String source, Node ast) {
Template template =
new Template(source, ast, isExpression: true, forceCopy: false);
Template(source, ast, isExpression: true, forceCopy: false);
expressionTemplates[source] = template;
return template;
}
@ -27,18 +27,16 @@ class TemplateManager {
Template defineStatementTemplate(String source, Node ast) {
Template template =
new Template(source, ast, isExpression: false, forceCopy: false);
Template(source, ast, isExpression: false, forceCopy: false);
statementTemplates[source] = template;
return template;
}
}
/**
* A Template is created with JavaScript AST containing placeholders (interface
* InterpolatedNode). The [instantiate] method creates an AST that looks like
* the original with the placeholders replaced by the arguments to
* [instantiate].
*/
/// A Template is created with JavaScript AST containing placeholders (interface
/// InterpolatedNode). The [instantiate] method creates an AST that looks like
/// the original with the placeholders replaced by the arguments to
/// [instantiate].
class Template {
final String source;
final bool isExpression;
@ -54,7 +52,7 @@ class Template {
bool get isPositional => holeNames == null;
Template(this.source, this.ast,
{this.isExpression: true, this.forceCopy: false}) {
{this.isExpression = true, this.forceCopy = false}) {
assert(this.isExpression ? ast is Expression : ast is Statement);
_compile();
}
@ -81,14 +79,14 @@ class Template {
bool _checkNoPlaceholders() {
InstantiatorGeneratorVisitor generator =
new InstantiatorGeneratorVisitor(false);
InstantiatorGeneratorVisitor(false);
generator.compile(ast);
return generator.analysis.count == 0;
}
void _compile() {
InstantiatorGeneratorVisitor generator =
new InstantiatorGeneratorVisitor(forceCopy);
InstantiatorGeneratorVisitor(forceCopy);
instantiator = generator.compile(ast);
positionalArgumentCount = generator.analysis.count;
Set<String> names = generator.analysis.holeNames;
@ -125,26 +123,20 @@ class Template {
}
}
/**
* An Instantiator is a Function that generates a JS AST tree or List of
* trees. [arguments] is a List for positional templates, or Map for
* named templates.
*/
typedef /*Node|Iterable<Node>*/ Instantiator(var arguments);
/// An Instantiator is a Function that generates a JS AST tree or List of
/// trees. [arguments] is a List for positional templates, or Map for named
/// templates.
typedef Instantiator = /*Node|Iterable<Node>*/ Function(dynamic arguments);
/**
* InstantiatorGeneratorVisitor compiles a template. This class compiles a tree
* containing [InterpolatedNode]s into a function that will create a copy of the
* tree with the interpolated nodes substituted with provided values.
*/
/// InstantiatorGeneratorVisitor compiles a template. This class compiles a tree
/// containing [InterpolatedNode]s into a function that will create a copy of the
/// tree with the interpolated nodes substituted with provided values.
class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
final bool forceCopy;
InterpolatedNodeAnalysis analysis = new InterpolatedNodeAnalysis();
InterpolatedNodeAnalysis analysis = InterpolatedNodeAnalysis();
/**
* The entire tree is cloned if [forceCopy] is true.
*/
/// The entire tree is cloned if [forceCopy] is true.
InstantiatorGeneratorVisitor(this.forceCopy);
Instantiator compile(Node node) {
@ -181,16 +173,16 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
throw 'Unimplemented InstantiatorGeneratorVisitor for $node';
}
static RegExp identifierRE = new RegExp(r'^[A-Za-z_$][A-Za-z_$0-9]*$');
static RegExp identifierRE = RegExp(r'^[A-Za-z_$][A-Za-z_$0-9]*$');
static Expression convertStringToVariableUse(String value) {
assert(identifierRE.hasMatch(value));
return new VariableUse(value);
return VariableUse(value);
}
static Expression convertStringToVariableDeclaration(String value) {
assert(identifierRE.hasMatch(value));
return new VariableDeclaration(value);
return VariableDeclaration(value);
}
Instantiator visitInterpolatedExpression(InterpolatedExpression node) {
@ -250,7 +242,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Parameter toParameter(item) {
if (item is Parameter) return item;
if (item is String) return new Parameter(item);
if (item is String) return Parameter(item);
throw error('Interpolated value #$nameOrPosition is not a Parameter or'
' List of Parameters: $value');
}
@ -307,7 +299,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
List<Instantiator> instantiators =
node.body.map(visitSplayableStatement).toList();
return (arguments) {
List<Statement> statements = <Statement>[];
List<Statement> statements = [];
void add(node) {
if (node is EmptyStatement) return;
if (node is Iterable) {
@ -320,7 +312,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
for (Instantiator instantiator in instantiators) {
add(instantiator(arguments));
}
return new Program(statements);
return Program(statements);
};
}
@ -328,7 +320,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
List<Instantiator> instantiators =
node.statements.map(visitSplayableStatement).toList();
return (arguments) {
List<Statement> statements = <Statement>[];
List<Statement> statements = [];
void add(node) {
if (node is EmptyStatement) return;
if (node is Iterable) {
@ -343,7 +335,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
for (Instantiator instantiator in instantiators) {
add(instantiator(arguments));
}
return new Block(statements);
return Block(statements);
};
}
@ -355,7 +347,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
}
Instantiator visitEmptyStatement(EmptyStatement node) =>
(arguments) => new EmptyStatement();
(arguments) => EmptyStatement();
Instantiator visitIf(If node) {
if (node.condition is InterpolatedExpression) {
@ -391,7 +383,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
return makeOtherwise(arguments);
}
}
return new If(condition, makeThen(arguments), makeOtherwise(arguments));
return If(condition, makeThen(arguments), makeOtherwise(arguments));
};
}
@ -400,7 +392,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeThen = visit(node.then);
Instantiator makeOtherwise = visit(node.otherwise);
return (arguments) {
return new If(makeCondition(arguments), makeThen(arguments),
return If(makeCondition(arguments), makeThen(arguments),
makeOtherwise(arguments));
};
}
@ -411,7 +403,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeUpdate = visitNullable(node.update);
Instantiator makeBody = visit(node.body);
return (arguments) {
return new For(makeInit(arguments), makeCondition(arguments),
return For(makeInit(arguments), makeCondition(arguments),
makeUpdate(arguments), makeBody(arguments));
};
}
@ -421,20 +413,20 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeObject = visit(node.object);
Instantiator makeBody = visit(node.body);
return (arguments) {
return new ForIn(makeLeftHandSide(arguments), makeObject(arguments),
return ForIn(makeLeftHandSide(arguments), makeObject(arguments),
makeBody(arguments));
};
}
TODO(String name) {
throw new UnimplementedError('$this.$name');
throw UnimplementedError('$this.$name');
}
Instantiator visitWhile(While node) {
Instantiator makeCondition = visit(node.condition);
Instantiator makeBody = visit(node.body);
return (arguments) {
return new While(makeCondition(arguments), makeBody(arguments));
return While(makeCondition(arguments), makeBody(arguments));
};
}
@ -442,52 +434,50 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeBody = visit(node.body);
Instantiator makeCondition = visit(node.condition);
return (arguments) {
return new Do(makeBody(arguments), makeCondition(arguments));
return Do(makeBody(arguments), makeCondition(arguments));
};
}
Instantiator visitContinue(Continue node) =>
(arguments) => new Continue(node.targetLabel);
(arguments) => Continue(node.targetLabel);
Instantiator visitBreak(Break node) =>
(arguments) => new Break(node.targetLabel);
Instantiator visitBreak(Break node) => (arguments) => Break(node.targetLabel);
Instantiator visitReturn(Return node) {
Instantiator makeExpression = visitNullable(node.value);
return (arguments) => new Return(makeExpression(arguments));
return (arguments) => Return(makeExpression(arguments));
}
Instantiator visitDartYield(DartYield node) {
Instantiator makeExpression = visit(node.expression);
return (arguments) =>
new DartYield(makeExpression(arguments), node.hasStar);
return (arguments) => DartYield(makeExpression(arguments), node.hasStar);
}
Instantiator visitThrow(Throw node) {
Instantiator makeExpression = visit(node.expression);
return (arguments) => new Throw(makeExpression(arguments));
return (arguments) => Throw(makeExpression(arguments));
}
Instantiator visitTry(Try node) {
Instantiator makeBody = visit(node.body);
Instantiator makeCatch = visitNullable(node.catchPart);
Instantiator makeFinally = visitNullable(node.finallyPart);
return (arguments) => new Try(
makeBody(arguments), makeCatch(arguments), makeFinally(arguments));
return (arguments) =>
Try(makeBody(arguments), makeCatch(arguments), makeFinally(arguments));
}
Instantiator visitCatch(Catch node) {
Instantiator makeDeclaration = visit(node.declaration);
Instantiator makeBody = visit(node.body);
return (arguments) =>
new Catch(makeDeclaration(arguments), makeBody(arguments));
Catch(makeDeclaration(arguments), makeBody(arguments));
}
Instantiator visitSwitch(Switch node) {
Instantiator makeKey = visit(node.key);
Iterable<Instantiator> makeCases = node.cases.map(visit);
return (arguments) {
return new Switch(
return Switch(
makeKey(arguments),
makeCases
.map<SwitchClause>((Instantiator makeCase) => makeCase(arguments))
@ -499,14 +489,14 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeExpression = visit(node.expression);
Instantiator makeBody = visit(node.body);
return (arguments) {
return new Case(makeExpression(arguments), makeBody(arguments));
return Case(makeExpression(arguments), makeBody(arguments));
};
}
Instantiator visitDefault(Default node) {
Instantiator makeBody = visit(node.body);
return (arguments) {
return new Default(makeBody(arguments));
return Default(makeBody(arguments));
};
}
@ -514,12 +504,12 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeName = visit(node.name);
Instantiator makeFunction = visit(node.function);
return (arguments) =>
new FunctionDeclaration(makeName(arguments), makeFunction(arguments));
FunctionDeclaration(makeName(arguments), makeFunction(arguments));
}
Instantiator visitLabeledStatement(LabeledStatement node) {
Instantiator makeBody = visit(node.body);
return (arguments) => new LabeledStatement(node.label, makeBody(arguments));
return (arguments) => LabeledStatement(node.label, makeBody(arguments));
}
Instantiator visitLiteralStatement(LiteralStatement node) =>
@ -531,12 +521,12 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
List<Instantiator> declarationMakers =
node.declarations.map(visit).toList();
return (arguments) {
List<VariableInitialization> declarations = <VariableInitialization>[];
List<VariableInitialization> declarations = [];
for (Instantiator instantiator in declarationMakers) {
var result = instantiator(arguments);
declarations.add(result);
}
return new VariableDeclarationList(declarations);
return VariableDeclarationList(declarations);
};
}
@ -545,7 +535,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
String op = node.op;
Instantiator makeValue = visitNullable(node.value);
return (arguments) {
return new Assignment.compound(
return Assignment.compound(
makeLeftHandSide(arguments), op, makeValue(arguments));
};
}
@ -554,7 +544,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeDeclaration = visit(node.declaration);
Instantiator makeValue = visitNullable(node.value);
return (arguments) {
return new VariableInitialization(
return VariableInitialization(
makeDeclaration(arguments), makeValue(arguments));
};
}
@ -563,15 +553,15 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeCondition = visit(cond.condition);
Instantiator makeThen = visit(cond.then);
Instantiator makeOtherwise = visit(cond.otherwise);
return (arguments) => new Conditional(makeCondition(arguments),
return (arguments) => Conditional(makeCondition(arguments),
makeThen(arguments), makeOtherwise(arguments));
}
Instantiator visitNew(New node) =>
handleCallOrNew(node, (target, arguments) => new New(target, arguments));
handleCallOrNew(node, (target, arguments) => New(target, arguments));
Instantiator visitCall(Call node) =>
handleCallOrNew(node, (target, arguments) => new Call(target, arguments));
handleCallOrNew(node, (target, arguments) => Call(target, arguments));
Instantiator handleCallOrNew(Call node, finish(target, arguments)) {
Instantiator makeTarget = visit(node.target);
@ -582,7 +572,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
// copying.
return (arguments) {
Node target = makeTarget(arguments);
List<Expression> callArguments = <Expression>[];
List<Expression> callArguments = [];
for (Instantiator instantiator in argumentMakers) {
var result = instantiator(arguments);
if (result is Iterable) {
@ -599,45 +589,44 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeLeft = visit(node.left);
Instantiator makeRight = visit(node.right);
String op = node.op;
return (arguments) =>
new Binary(op, makeLeft(arguments), makeRight(arguments));
return (arguments) => Binary(op, makeLeft(arguments), makeRight(arguments));
}
Instantiator visitPrefix(Prefix node) {
Instantiator makeOperand = visit(node.argument);
String op = node.op;
return (arguments) => new Prefix(op, makeOperand(arguments));
return (arguments) => Prefix(op, makeOperand(arguments));
}
Instantiator visitPostfix(Postfix node) {
Instantiator makeOperand = visit(node.argument);
String op = node.op;
return (arguments) => new Postfix(op, makeOperand(arguments));
return (arguments) => Postfix(op, makeOperand(arguments));
}
Instantiator visitVariableUse(VariableUse node) =>
(arguments) => new VariableUse(node.name);
(arguments) => VariableUse(node.name);
Instantiator visitThis(This node) => (arguments) => new This();
Instantiator visitThis(This node) => (arguments) => This();
Instantiator visitVariableDeclaration(VariableDeclaration node) =>
(arguments) => new VariableDeclaration(node.name);
(arguments) => VariableDeclaration(node.name);
Instantiator visitParameter(Parameter node) =>
(arguments) => new Parameter(node.name);
(arguments) => Parameter(node.name);
Instantiator visitAccess(PropertyAccess node) {
Instantiator makeReceiver = visit(node.receiver);
Instantiator makeSelector = visit(node.selector);
return (arguments) =>
new PropertyAccess(makeReceiver(arguments), makeSelector(arguments));
PropertyAccess(makeReceiver(arguments), makeSelector(arguments));
}
Instantiator visitNamedFunction(NamedFunction node) {
Instantiator makeDeclaration = visit(node.name);
Instantiator makeFunction = visit(node.function);
return (arguments) =>
new NamedFunction(makeDeclaration(arguments), makeFunction(arguments));
NamedFunction(makeDeclaration(arguments), makeFunction(arguments));
}
Instantiator visitFun(Fun node) {
@ -645,7 +634,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeBody = visit(node.body);
// TODO(sra): Avoid copying params if no interpolation or forced copying.
return (arguments) {
List<Parameter> params = <Parameter>[];
List<Parameter> params = [];
for (Instantiator instantiator in paramMakers) {
var result = instantiator(arguments);
if (result is Iterable) {
@ -655,7 +644,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
}
}
Statement body = makeBody(arguments);
return new Fun(params, body);
return Fun(params, body);
};
}
@ -664,7 +653,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeBody = visit(node.body);
// TODO(sra): Avoid copying params if no interpolation or forced copying.
return (arguments) {
List<Parameter> params = <Parameter>[];
List<Parameter> params = [];
for (Instantiator instantiator in paramMakers) {
var result = instantiator(arguments);
if (result is Iterable) {
@ -675,7 +664,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
}
// Either a Block or Expression.
Node body = makeBody(arguments);
return new ArrowFunction(params, body);
return ArrowFunction(params, body);
};
}
@ -688,16 +677,16 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator visitDeferredString(DeferredString node) => (arguments) => node;
Instantiator visitLiteralBool(LiteralBool node) =>
(arguments) => new LiteralBool(node.value);
(arguments) => LiteralBool(node.value);
Instantiator visitLiteralString(LiteralString node) =>
(arguments) => new LiteralString(node.value);
(arguments) => LiteralString(node.value);
Instantiator visitLiteralNumber(LiteralNumber node) =>
(arguments) => new LiteralNumber(node.value);
(arguments) => LiteralNumber(node.value);
Instantiator visitLiteralNull(LiteralNull node) =>
(arguments) => new LiteralNull();
(arguments) => LiteralNull();
Instantiator visitStringConcatenation(StringConcatenation node) {
List<Instantiator> partMakers =
@ -706,7 +695,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
List<Literal> parts = partMakers
.map((Instantiator instantiator) => instantiator(arguments))
.toList(growable: false);
return new StringConcatenation(parts);
return StringConcatenation(parts);
};
}
@ -729,12 +718,12 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
.map<Expression>(
(Instantiator instantiator) => instantiator(arguments))
.toList(growable: false);
return new ArrayInitializer(elements);
return ArrayInitializer(elements);
};
}
Instantiator visitArrayHole(ArrayHole node) {
return (arguments) => new ArrayHole();
return (arguments) => ArrayHole();
}
Instantiator visitObjectInitializer(ObjectInitializer node) {
@ -742,7 +731,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
node.properties.map(visitSplayable).toList();
bool isOneLiner = node.isOneLiner;
return (arguments) {
List<Property> properties = <Property>[];
List<Property> properties = [];
for (Instantiator instantiator in propertyMakers) {
var result = instantiator(arguments);
if (result is Iterable) {
@ -751,7 +740,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
properties.add(result);
}
}
return new ObjectInitializer(properties, isOneLiner: isOneLiner);
return ObjectInitializer(properties, isOneLiner: isOneLiner);
};
}
@ -759,7 +748,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeName = visit(node.name);
Instantiator makeValue = visit(node.value);
return (arguments) {
return new Property(makeName(arguments), makeValue(arguments));
return Property(makeName(arguments), makeValue(arguments));
};
}
@ -767,30 +756,28 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeName = visit(node.name);
Instantiator makeFunction = visit(node.function);
return (arguments) {
return new MethodDefinition(makeName(arguments), makeFunction(arguments));
return MethodDefinition(makeName(arguments), makeFunction(arguments));
};
}
Instantiator visitRegExpLiteral(RegExpLiteral node) =>
(arguments) => new RegExpLiteral(node.pattern);
(arguments) => RegExpLiteral(node.pattern);
Instantiator visitComment(Comment node) => TODO('visitComment');
Instantiator visitAwait(Await node) {
Instantiator makeExpression = visit(node.expression);
return (arguments) {
return new Await(makeExpression(arguments));
return Await(makeExpression(arguments));
};
}
}
/**
* InterpolatedNodeAnalysis determines which AST trees contain
* [InterpolatedNode]s, and the names of the named interpolated nodes.
*/
/// InterpolatedNodeAnalysis determines which AST trees contain
/// [InterpolatedNode]s, and the names of the named interpolated nodes.
class InterpolatedNodeAnalysis extends BaseVisitor {
final Set<Node> containsInterpolatedNode = new Set<Node>();
final Set<String> holeNames = new Set<String>();
final Set<Node> containsInterpolatedNode = {};
final Set<String> holeNames = {};
int count = 0;
InterpolatedNodeAnalysis();

View file

@ -28,8 +28,8 @@ class TestCase {
const TestCase(this.data, [this.environment = const {}]);
}
const List<TestCase> DATA = const <TestCase>[
const TestCase(const {
const List<TestCase> DATA = <TestCase>[
TestCase({
TestMode.NONE: """
function(a, b) {
return null;
@ -47,7 +47,7 @@ function(a@1, b@2) {
return null@5;
@4}@3@0"""
}),
const TestCase(const {
TestCase({
TestMode.NONE: """
function() {
if (true) {
@ -105,7 +105,7 @@ function() {
@26 }@22
@20}@1@0""",
}),
const TestCase(const {
TestCase({
TestMode.NONE: """
function() {
function foo() {
@ -127,7 +127,7 @@ function() {
}@5@3
@2}@1@0"""
}),
const TestCase(const {
TestCase({
TestMode.INPUT: """
function() {
a['b'];
@ -154,13 +154,13 @@ function() {
@2 [1@8,,@9 2@10]@7;
@6}@1@0""",
}),
const TestCase(const {
TestCase({
TestMode.INPUT: "a.#nameTemplate = #nameTemplate",
TestMode.NONE: "a.nameValue = nameValue",
TestMode.ENTER: "@0@1@2a.@3nameValue = @3nameValue",
TestMode.DELIMITER: "a.nameValue = nameValue",
TestMode.EXIT: "a@2.nameValue@3@1 = nameValue@3@0",
}, const {
}, {
'nameTemplate': 'nameValue'
}),
];
@ -179,16 +179,16 @@ void check(TestCase testCase) {
// Input is the same as output.
code = map[TestMode.NONE];
}
JavaScriptPrintingOptions options = new JavaScriptPrintingOptions();
JavaScriptPrintingOptions options = JavaScriptPrintingOptions();
Map arguments = {};
testCase.environment.forEach((String name, String value) {
arguments[name] = new FixedName(value);
arguments[name] = FixedName(value);
});
Node node = js.parseForeignJS(code).instantiate(arguments);
map.forEach((TestMode mode, String expectedOutput) {
if (mode == TestMode.INPUT) return;
Context context = new Context(mode);
new Printer(options, context).visit(node);
Context context = Context(mode);
Printer(options, context).visit(node);
// TODO(johnniwinther): Remove `replaceAll(...)` when dart2js behaves as the
// VM on newline in multiline strings.
expect(context.getText(), equals(expectedOutput.replaceAll('\r\n', '\n')),
@ -227,7 +227,7 @@ class Context extends SimpleJavaScriptPrintingContext {
String getText() {
String text = super.getText();
int offset = 0;
StringBuffer sb = new StringBuffer();
StringBuffer sb = StringBuffer();
for (int position in tagMap.keys.toList()..sort()) {
if (offset < position) {
sb.write(text.substring(offset, position));