Chromium Code Reviews| Index: lib/src/js/nodes.dart |
| diff --git a/lib/src/js/nodes.dart b/lib/src/js/nodes.dart |
| index 2f32feb0cfd8faa544e98ce718c8b92ea127956e..457caf98cdf4b2e2c27026ba041f778acbb479ef 100644 |
| --- a/lib/src/js/nodes.dart |
| +++ b/lib/src/js/nodes.dart |
| @@ -82,6 +82,10 @@ abstract class NodeVisitor<T> { |
| T visitInterpolatedStatement(InterpolatedStatement node); |
| T visitInterpolatedMethod(InterpolatedMethod node); |
| T visitInterpolatedIdentifier(InterpolatedIdentifier node); |
| + |
| + T visitArrayDestructuring(ArrayDestructuring node); |
| + T visitObjectDestructuring(ObjectDestructuring node); |
| + T visitDestructuredVariable(DestructuredVariable node); |
| } |
| class BaseVisitor<T> implements NodeVisitor<T> { |
| @@ -197,6 +201,13 @@ class BaseVisitor<T> implements NodeVisitor<T> { |
| T visitAwait(Await node) => visitExpression(node); |
| T visitDartYield(DartYield node) => visitStatement(node); |
| + |
| + T visitDestructuring(Destructuring node) => visitNode(node); |
| + T visitArrayDestructuring(ArrayDestructuring node) |
| + => visitDestructuring(node); |
| + T visitObjectDestructuring(ObjectDestructuring node) |
| + => visitDestructuring(node); |
| + T visitDestructuredVariable(DestructuredVariable node) => visitNode(node); |
| } |
| abstract class Node { |
| @@ -217,7 +228,7 @@ abstract class Node { |
| withClosureAnnotation(ClosureAnnotation closureAnnotation) { |
| if (this.closureAnnotation == closureAnnotation) return this; |
| - |
| + |
| return _clone() |
| ..sourceInformation = sourceInformation |
| .._closureAnnotation = closureAnnotation; |
| @@ -738,10 +749,10 @@ class Assignment extends Expression { |
| class VariableInitialization extends Assignment { |
| /** [value] may be null. */ |
| - VariableInitialization(Identifier declaration, Expression value) |
| + VariableInitialization(Declarator declaration, Expression value) |
| : super(declaration, value); |
| - Identifier get declaration => leftHandSide; |
| + Declarator get declaration => leftHandSide; |
| accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); |
| @@ -749,6 +760,55 @@ class VariableInitialization extends Assignment { |
| new VariableInitialization(declaration, value); |
| } |
| +abstract class Declarator extends Expression { |
|
Jennifer Messerly
2015/12/01 02:10:27
The ES6 spec calls this a "Binding", as in Binding
ochafik
2015/12/02 20:05:46
Done (thank you so much for all these links, I fee
|
| +} |
| + |
| +class DestructuredVariable extends Expression implements Parameter { |
| + final Identifier name; |
| + final Destructuring structure; |
| + final Expression defaultValue; |
| + DestructuredVariable({this.name, this.structure, this.defaultValue}); |
| + |
| + accept(NodeVisitor visitor) => visitor.visitDestructuredVariable(this); |
| + void visitChildren(NodeVisitor visitor) { |
| + name?.accept(visitor); |
| + structure?.accept(visitor); |
| + defaultValue?.accept(visitor); |
| + } |
| + |
| + @override int get precedenceLevel => DESTRUCTURING; |
| + @override Node _clone() => |
| + new DestructuredVariable( |
| + name: name, structure: structure, defaultValue: defaultValue); |
| +} |
| + |
| +abstract class Destructuring extends Expression implements Declarator { |
| + final List<DestructuredVariable> variables; |
| + Destructuring(this.variables); |
| + |
| + void visitChildren(NodeVisitor visitor) { |
| + for (DestructuredVariable v in variables) v.accept(visitor); |
| + } |
| +} |
| + |
| +class ObjectDestructuring extends Destructuring { |
| + ObjectDestructuring(List<DestructuredVariable> variables) |
| + : super(variables); |
| + accept(NodeVisitor visitor) => visitor.visitObjectDestructuring(this); |
| + |
| + @override int get precedenceLevel => DESTRUCTURING; |
| + @override Node _clone() => new ObjectDestructuring(variables); |
| +} |
| + |
| +class ArrayDestructuring extends Destructuring { |
| + ArrayDestructuring(List<DestructuredVariable> variables) |
| + : super(variables); |
| + accept(NodeVisitor visitor) => visitor.visitArrayDestructuring(this); |
| + |
| + @override int get precedenceLevel => DESTRUCTURING; |
| + @override Node _clone() => new ObjectDestructuring(variables); |
| +} |
| + |
| class Conditional extends Expression { |
| final Expression condition; |
| final Expression then; |
| @@ -944,9 +1004,9 @@ class Postfix extends Expression { |
| int get precedenceLevel => UNARY; |
| } |
| -abstract class Parameter implements Expression {} |
| +abstract class Parameter implements Expression, Declarator {} |
| -class Identifier extends Expression implements Parameter { |
| +class Identifier extends Expression implements Parameter, Declarator { |
| final String name; |
| final bool allowRename; |