Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Unified Diff: lib/src/js/nodes.dart

Issue 1484263002: Use destructuring assignments for named parameters (#180) (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/js/builder.dart ('k') | lib/src/js/printer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/js/nodes.dart
diff --git a/lib/src/js/nodes.dart b/lib/src/js/nodes.dart
index 879f9fa0634e74358f388b25d6936890cf8ec8c9..af0fc120c6717ec0d0d75ec84a3b48f702075534 100644
--- a/lib/src/js/nodes.dart
+++ b/lib/src/js/nodes.dart
@@ -88,6 +88,10 @@ abstract class NodeVisitor<T> {
T visitInterpolatedStatement(InterpolatedStatement node);
T visitInterpolatedMethod(InterpolatedMethod node);
T visitInterpolatedIdentifier(InterpolatedIdentifier node);
+
+ T visitArrayBindingPattern(ArrayBindingPattern node);
+ T visitObjectBindingPattern(ObjectBindingPattern node);
+ T visitDestructuredVariable(DestructuredVariable node);
}
class BaseVisitor<T> implements NodeVisitor<T> {
@@ -210,6 +214,13 @@ class BaseVisitor<T> implements NodeVisitor<T> {
T visitAwait(Await node) => visitExpression(node);
T visitDartYield(DartYield node) => visitStatement(node);
+
+ T visitBindingPattern(BindingPattern node) => visitNode(node);
+ T visitArrayBindingPattern(ArrayBindingPattern node)
+ => visitBindingPattern(node);
+ T visitObjectBindingPattern(ObjectBindingPattern node)
+ => visitBindingPattern(node);
+ T visitDestructuredVariable(DestructuredVariable node) => visitNode(node);
}
abstract class Node {
@@ -230,7 +241,7 @@ abstract class Node {
withClosureAnnotation(ClosureAnnotation closureAnnotation) {
if (this.closureAnnotation == closureAnnotation) return this;
-
+
return _clone()
..sourceInformation = sourceInformation
.._closureAnnotation = closureAnnotation;
@@ -751,10 +762,10 @@ class Assignment extends Expression {
class VariableInitialization extends Assignment {
/** [value] may be null. */
- VariableInitialization(Identifier declaration, Expression value)
+ VariableInitialization(VariableBinding declaration, Expression value)
: super(declaration, value);
- Identifier get declaration => leftHandSide;
+ VariableBinding get declaration => leftHandSide;
accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this);
@@ -762,6 +773,60 @@ class VariableInitialization extends Assignment {
new VariableInitialization(declaration, value);
}
+abstract class VariableBinding extends Expression {
+}
+
+class DestructuredVariable extends Expression implements Parameter {
+ final Identifier name;
+ final BindingPattern structure;
+ final Expression defaultValue;
+ DestructuredVariable({this.name, this.structure, this.defaultValue}) {
+ assert(name != null || structure != null);
+ }
+
+ accept(NodeVisitor visitor) => visitor.visitDestructuredVariable(this);
+ void visitChildren(NodeVisitor visitor) {
+ name?.accept(visitor);
+ structure?.accept(visitor);
+ defaultValue?.accept(visitor);
+ }
+
+ /// Avoid parenthesis when pretty-printing.
+ @override int get precedenceLevel => PRIMARY;
+ @override Node _clone() =>
+ new DestructuredVariable(
+ name: name, structure: structure, defaultValue: defaultValue);
+}
+
+abstract class BindingPattern extends Expression implements VariableBinding {
+ final List<DestructuredVariable> variables;
+ BindingPattern(this.variables);
+
+ void visitChildren(NodeVisitor visitor) {
+ for (DestructuredVariable v in variables) v.accept(visitor);
+ }
+}
+
+class ObjectBindingPattern extends BindingPattern {
+ ObjectBindingPattern(List<DestructuredVariable> variables)
+ : super(variables);
+ accept(NodeVisitor visitor) => visitor.visitObjectBindingPattern(this);
+
+ /// Avoid parenthesis when pretty-printing.
+ @override int get precedenceLevel => PRIMARY;
+ @override Node _clone() => new ObjectBindingPattern(variables);
+}
+
+class ArrayBindingPattern extends BindingPattern {
+ ArrayBindingPattern(List<DestructuredVariable> variables)
+ : super(variables);
+ accept(NodeVisitor visitor) => visitor.visitArrayBindingPattern(this);
+
+ /// Avoid parenthesis when pretty-printing.
+ @override int get precedenceLevel => PRIMARY;
+ @override Node _clone() => new ObjectBindingPattern(variables);
+}
+
class Conditional extends Expression {
final Expression condition;
final Expression then;
@@ -930,7 +995,7 @@ class Prefix extends Expression {
}
// SpreadElement isn't really a prefix expression, as it can only appear in
-// certain places such as ArgumentList and destructuring, but we pretend
+// certain places such as ArgumentList and BindingPattern, but we pretend
// it is for simplicity's sake.
class Spread extends Prefix {
Spread(Expression operand) : super('...', operand);
@@ -957,9 +1022,9 @@ class Postfix extends Expression {
int get precedenceLevel => UNARY;
}
-abstract class Parameter implements Expression {}
+abstract class Parameter implements Expression, VariableBinding {}
-class Identifier extends Expression implements Parameter {
+class Identifier extends Expression implements Parameter, VariableBinding {
final String name;
final bool allowRename;
« no previous file with comments | « lib/src/js/builder.dart ('k') | lib/src/js/printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698