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

Unified Diff: lib/src/js/printer.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/nodes.dart ('k') | lib/src/js/template.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/js/printer.dart
diff --git a/lib/src/js/printer.dart b/lib/src/js/printer.dart
index 4f5f24c647021d8a79e554079bccd6653ef7a14b..155ce854febd115c28cde134099c0378b465deba 100644
--- a/lib/src/js/printer.dart
+++ b/lib/src/js/printer.dart
@@ -595,6 +595,38 @@ class Printer implements NodeVisitor {
newInForInit: inForInit, newAtStatementBegin: false);
}
+ visitArrayBindingPattern(ArrayBindingPattern node) {
+ out("[");
+ visitCommaSeparated(node.variables, EXPRESSION,
+ newInForInit: false, newAtStatementBegin: false);
+ out("]");
+ }
+ visitObjectBindingPattern(ObjectBindingPattern node) {
+ out("{");
+ visitCommaSeparated(node.variables, EXPRESSION,
+ newInForInit: false, newAtStatementBegin: false);
+ out("}");
+ }
+
+ visitDestructuredVariable(DestructuredVariable node) {
+ var hasName = node.name != null;
+ if (hasName) visit(node.name);
+ if (node.structure != null) {
+ if (hasName) {
+ out(":");
+ spaceOut();
+ }
+ visit(node.structure);
+ }
+ if (node.defaultValue != null) {
+ spaceOut();
+ out("=");
+ spaceOut();
+ visitNestedExpression(node.defaultValue, EXPRESSION,
+ newInForInit: false, newAtStatementBegin: false);
+ }
+ }
+
visitAssignment(Assignment assignment) {
visitNestedExpression(assignment.leftHandSide, LEFT_HAND_SIDE,
newInForInit: inForInit,
@@ -1542,14 +1574,23 @@ abstract class VariableDeclarationVisitor<T> extends BaseVisitor<T> {
declare(Identifier node);
visitFunctionExpression(FunctionExpression node) {
- for (var p in node.params) {
- declare(p is RestParameter ? p.parameter : p);
- }
+ node.params.forEach(_scanVariableBinding);
node.body.accept(this);
}
+ _scanVariableBinding(VariableBinding d) {
+ if (d is Identifier) declare(d);
+ if (d is RestParameter) _scanVariableBinding(d.parameter);
+ else if (d is BindingPattern) {
+ for (var v in d.variables) {
+ if (v.name != null) declare(v.name);
+ if (v.structure != null) _scanVariableBinding(v.structure);
+ }
+ }
+ }
+
visitVariableInitialization(VariableInitialization node) {
- declare(node.declaration);
+ _scanVariableBinding(node.declaration);
if (node.value != null) node.value.accept(this);
}
« no previous file with comments | « lib/src/js/nodes.dart ('k') | lib/src/js/template.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698