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

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: Destructure function params directly (no more opts in most cases) Created 5 years, 1 month 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
Index: lib/src/js/printer.dart
diff --git a/lib/src/js/printer.dart b/lib/src/js/printer.dart
index 1903e81f09facf9378313a133d1b73f97caaccfb..fa1a8e6e141a2ff0cbb28d720461f6eefc8389e5 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);
}
+ visitArrayDestructuring(ArrayDestructuring node) {
+ out("[");
+ visitCommaSeparated(node.variables, EXPRESSION,
+ newInForInit: false, newAtStatementBegin: false);
+ out("]");
+ }
+ visitObjectDestructuring(ObjectDestructuring 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,
@@ -1472,14 +1504,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(_scanDeclarator);
node.body.accept(this);
}
+ _scanDeclarator(Declarator d) {
+ if (d is Identifier) declare(d);
+ if (d is RestParameter) _scanDeclarator(d.parameter);
+ else if (d is Destructuring) {
+ for (var v in d.variables) {
+ if (v.name != null) declare(v.name);
+ if (v.structure != null) _scanDeclarator(v.structure);
+ }
+ }
+ }
+
visitVariableInitialization(VariableInitialization node) {
- declare(node.declaration);
+ _scanDeclarator(node.declaration);
if (node.value != null) node.value.accept(this);
}

Powered by Google App Engine
This is Rietveld 408576698