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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « lib/src/js/nodes.dart ('k') | lib/src/js/template.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of js_ast; 5 part of js_ast;
6 6
7 7
8 class JavaScriptPrintingOptions { 8 class JavaScriptPrintingOptions {
9 final bool shouldCompressOutput; 9 final bool shouldCompressOutput;
10 final bool minifyLocalVariables; 10 final bool minifyLocalVariables;
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 588 }
589 589
590 visitVariableDeclarationList(VariableDeclarationList list) { 590 visitVariableDeclarationList(VariableDeclarationList list) {
591 outClosureAnnotation(list); 591 outClosureAnnotation(list);
592 out(list.keyword); 592 out(list.keyword);
593 out(" "); 593 out(" ");
594 visitCommaSeparated(list.declarations, ASSIGNMENT, 594 visitCommaSeparated(list.declarations, ASSIGNMENT,
595 newInForInit: inForInit, newAtStatementBegin: false); 595 newInForInit: inForInit, newAtStatementBegin: false);
596 } 596 }
597 597
598 visitArrayBindingPattern(ArrayBindingPattern node) {
599 out("[");
600 visitCommaSeparated(node.variables, EXPRESSION,
601 newInForInit: false, newAtStatementBegin: false);
602 out("]");
603 }
604 visitObjectBindingPattern(ObjectBindingPattern node) {
605 out("{");
606 visitCommaSeparated(node.variables, EXPRESSION,
607 newInForInit: false, newAtStatementBegin: false);
608 out("}");
609 }
610
611 visitDestructuredVariable(DestructuredVariable node) {
612 var hasName = node.name != null;
613 if (hasName) visit(node.name);
614 if (node.structure != null) {
615 if (hasName) {
616 out(":");
617 spaceOut();
618 }
619 visit(node.structure);
620 }
621 if (node.defaultValue != null) {
622 spaceOut();
623 out("=");
624 spaceOut();
625 visitNestedExpression(node.defaultValue, EXPRESSION,
626 newInForInit: false, newAtStatementBegin: false);
627 }
628 }
629
598 visitAssignment(Assignment assignment) { 630 visitAssignment(Assignment assignment) {
599 visitNestedExpression(assignment.leftHandSide, LEFT_HAND_SIDE, 631 visitNestedExpression(assignment.leftHandSide, LEFT_HAND_SIDE,
600 newInForInit: inForInit, 632 newInForInit: inForInit,
601 newAtStatementBegin: atStatementBegin); 633 newAtStatementBegin: atStatementBegin);
602 if (assignment.value != null) { 634 if (assignment.value != null) {
603 spaceOut(); 635 spaceOut();
604 String op = assignment.op; 636 String op = assignment.op;
605 if (op != null) out(op); 637 if (op != null) out(op);
606 out("="); 638 out("=");
607 spaceOut(); 639 spaceOut();
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 return newName; 1567 return newName;
1536 } 1568 }
1537 } 1569 }
1538 1570
1539 /// Like [BaseVisitor], but calls [declare] for [Identifier] declarations, and 1571 /// Like [BaseVisitor], but calls [declare] for [Identifier] declarations, and
1540 /// [visitIdentifier] otherwise. 1572 /// [visitIdentifier] otherwise.
1541 abstract class VariableDeclarationVisitor<T> extends BaseVisitor<T> { 1573 abstract class VariableDeclarationVisitor<T> extends BaseVisitor<T> {
1542 declare(Identifier node); 1574 declare(Identifier node);
1543 1575
1544 visitFunctionExpression(FunctionExpression node) { 1576 visitFunctionExpression(FunctionExpression node) {
1545 for (var p in node.params) { 1577 node.params.forEach(_scanVariableBinding);
1546 declare(p is RestParameter ? p.parameter : p);
1547 }
1548 node.body.accept(this); 1578 node.body.accept(this);
1549 } 1579 }
1550 1580
1581 _scanVariableBinding(VariableBinding d) {
1582 if (d is Identifier) declare(d);
1583 if (d is RestParameter) _scanVariableBinding(d.parameter);
1584 else if (d is BindingPattern) {
1585 for (var v in d.variables) {
1586 if (v.name != null) declare(v.name);
1587 if (v.structure != null) _scanVariableBinding(v.structure);
1588 }
1589 }
1590 }
1591
1551 visitVariableInitialization(VariableInitialization node) { 1592 visitVariableInitialization(VariableInitialization node) {
1552 declare(node.declaration); 1593 _scanVariableBinding(node.declaration);
1553 if (node.value != null) node.value.accept(this); 1594 if (node.value != null) node.value.accept(this);
1554 } 1595 }
1555 1596
1556 visitCatch(Catch node) { 1597 visitCatch(Catch node) {
1557 declare(node.declaration); 1598 declare(node.declaration);
1558 node.body.accept(this); 1599 node.body.accept(this);
1559 } 1600 }
1560 1601
1561 visitFunctionDeclaration(FunctionDeclaration node) { 1602 visitFunctionDeclaration(FunctionDeclaration node) {
1562 declare(node.name); 1603 declare(node.name);
1563 node.function.accept(this); 1604 node.function.accept(this);
1564 } 1605 }
1565 1606
1566 visitNamedFunction(NamedFunction node) { 1607 visitNamedFunction(NamedFunction node) {
1567 declare(node.name); 1608 declare(node.name);
1568 node.function.accept(this); 1609 node.function.accept(this);
1569 } 1610 }
1570 1611
1571 visitClassExpression(ClassExpression node) { 1612 visitClassExpression(ClassExpression node) {
1572 declare(node.name); 1613 declare(node.name);
1573 if (node.heritage != null) node.heritage.accept(this); 1614 if (node.heritage != null) node.heritage.accept(this);
1574 for (Method element in node.methods) element.accept(this); 1615 for (Method element in node.methods) element.accept(this);
1575 } 1616 }
1576 } 1617 }
OLDNEW
« 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