OLD | NEW |
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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 out("]"); | 614 out("]"); |
615 } | 615 } |
616 visitObjectBindingPattern(ObjectBindingPattern node) { | 616 visitObjectBindingPattern(ObjectBindingPattern node) { |
617 out("{"); | 617 out("{"); |
618 visitCommaSeparated(node.variables, EXPRESSION, | 618 visitCommaSeparated(node.variables, EXPRESSION, |
619 newInForInit: false, newAtStatementBegin: false); | 619 newInForInit: false, newAtStatementBegin: false); |
620 out("}"); | 620 out("}"); |
621 } | 621 } |
622 | 622 |
623 visitDestructuredVariable(DestructuredVariable node) { | 623 visitDestructuredVariable(DestructuredVariable node) { |
624 var hasName = node.name != null; | 624 var name = node.name; |
625 if (hasName) visit(node.name); | 625 var hasName = name != null; |
| 626 if (hasName) { |
| 627 if (name is LiteralString) { |
| 628 out("["); |
| 629 out(name.value); |
| 630 out("]"); |
| 631 } else { |
| 632 visit(name); |
| 633 } |
| 634 } |
626 if (node.structure != null) { | 635 if (node.structure != null) { |
627 if (hasName) { | 636 if (hasName) { |
628 out(":"); | 637 out(":"); |
629 spaceOut(); | 638 spaceOut(); |
630 } | 639 } |
631 visit(node.structure); | 640 visit(node.structure); |
632 } | 641 } |
633 if (node.defaultValue != null) { | 642 if (node.defaultValue != null) { |
634 spaceOut(); | 643 spaceOut(); |
635 out("="); | 644 out("="); |
636 spaceOut(); | 645 spaceOut(); |
637 visitNestedExpression(node.defaultValue, EXPRESSION, | 646 visitNestedExpression(node.defaultValue, EXPRESSION, |
638 newInForInit: false, newAtStatementBegin: false); | 647 newInForInit: false, newAtStatementBegin: false); |
639 } | 648 } |
640 } | 649 } |
641 | 650 |
| 651 visitSimpleBindingPattern(SimpleBindingPattern node) { |
| 652 visit(node.name); |
| 653 } |
| 654 |
642 visitAssignment(Assignment assignment) { | 655 visitAssignment(Assignment assignment) { |
643 visitNestedExpression(assignment.leftHandSide, LEFT_HAND_SIDE, | 656 visitNestedExpression(assignment.leftHandSide, LEFT_HAND_SIDE, |
644 newInForInit: inForInit, | 657 newInForInit: inForInit, |
645 newAtStatementBegin: atStatementBegin); | 658 newAtStatementBegin: atStatementBegin); |
646 if (assignment.value != null) { | 659 if (assignment.value != null) { |
647 spaceOut(); | 660 spaceOut(); |
648 String op = assignment.op; | 661 String op = assignment.op; |
649 if (op != null) out(op); | 662 if (op != null) out(op); |
650 out("="); | 663 out("="); |
651 spaceOut(); | 664 spaceOut(); |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1578 abstract class VariableDeclarationVisitor<T> extends BaseVisitor<T> { | 1591 abstract class VariableDeclarationVisitor<T> extends BaseVisitor<T> { |
1579 declare(Identifier node); | 1592 declare(Identifier node); |
1580 | 1593 |
1581 visitFunctionExpression(FunctionExpression node) { | 1594 visitFunctionExpression(FunctionExpression node) { |
1582 node.params.forEach(_scanVariableBinding); | 1595 node.params.forEach(_scanVariableBinding); |
1583 node.body.accept(this); | 1596 node.body.accept(this); |
1584 } | 1597 } |
1585 | 1598 |
1586 _scanVariableBinding(VariableBinding d) { | 1599 _scanVariableBinding(VariableBinding d) { |
1587 if (d is Identifier) declare(d); | 1600 if (d is Identifier) declare(d); |
1588 if (d is RestParameter) _scanVariableBinding(d.parameter); | 1601 else d.accept(this); |
1589 else if (d is BindingPattern) { | 1602 } |
1590 for (var v in d.variables) { | 1603 |
1591 if (v.name != null) declare(v.name); | 1604 visitRestParameter(RestParameter node) { |
1592 if (v.structure != null) _scanVariableBinding(v.structure); | 1605 _scanVariableBinding(node.parameter); |
1593 } | 1606 super.visitRestParameter(node); |
1594 } | 1607 } |
| 1608 |
| 1609 visitDestructuredVariable(DestructuredVariable node) { |
| 1610 var name = node.name; |
| 1611 if (name is Identifier) _scanVariableBinding(name); |
| 1612 super.visitDestructuredVariable(node); |
| 1613 } |
| 1614 |
| 1615 visitSimpleBindingPattern(SimpleBindingPattern node) { |
| 1616 _scanVariableBinding(node.name); |
| 1617 super.visitSimpleBindingPattern(node); |
1595 } | 1618 } |
1596 | 1619 |
1597 visitVariableInitialization(VariableInitialization node) { | 1620 visitVariableInitialization(VariableInitialization node) { |
1598 _scanVariableBinding(node.declaration); | 1621 _scanVariableBinding(node.declaration); |
1599 if (node.value != null) node.value.accept(this); | 1622 if (node.value != null) node.value.accept(this); |
1600 } | 1623 } |
1601 | 1624 |
1602 visitCatch(Catch node) { | 1625 visitCatch(Catch node) { |
1603 declare(node.declaration); | 1626 declare(node.declaration); |
1604 node.body.accept(this); | 1627 node.body.accept(this); |
1605 } | 1628 } |
1606 | 1629 |
1607 visitFunctionDeclaration(FunctionDeclaration node) { | 1630 visitFunctionDeclaration(FunctionDeclaration node) { |
1608 declare(node.name); | 1631 declare(node.name); |
1609 node.function.accept(this); | 1632 node.function.accept(this); |
1610 } | 1633 } |
1611 | 1634 |
1612 visitNamedFunction(NamedFunction node) { | 1635 visitNamedFunction(NamedFunction node) { |
1613 declare(node.name); | 1636 declare(node.name); |
1614 node.function.accept(this); | 1637 node.function.accept(this); |
1615 } | 1638 } |
1616 | 1639 |
1617 visitClassExpression(ClassExpression node) { | 1640 visitClassExpression(ClassExpression node) { |
1618 declare(node.name); | 1641 declare(node.name); |
1619 if (node.heritage != null) node.heritage.accept(this); | 1642 if (node.heritage != null) node.heritage.accept(this); |
1620 for (Method element in node.methods) element.accept(this); | 1643 for (Method element in node.methods) element.accept(this); |
1621 } | 1644 } |
1622 } | 1645 } |
OLD | NEW |