Chromium Code Reviews| 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 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 newInForInit: false, newAtStatementBegin: false); | 613 newInForInit: false, newAtStatementBegin: false); |
| 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) { |
|
Jennifer Messerly
2016/02/09 00:33:07
this code looks a lot like propertyNameOut. Can th
ochafik
2016/02/09 01:51:20
I agree in principle, but see the other comment: I
| |
| 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 visitDestructuredVariable(DestructuredVariable node) { |
| 1592 if (v.structure != null) _scanVariableBinding(v.structure); | 1605 var name = node.name; |
| 1593 } | 1606 if (name is Identifier) _scanVariableBinding(name); |
| 1594 } | 1607 super.visitDestructuredVariable(node); |
| 1608 } | |
| 1609 | |
| 1610 visitSimpleBindingPattern(SimpleBindingPattern node) { | |
| 1611 _scanVariableBinding(node.name); | |
| 1612 super.visitSimpleBindingPattern(node); | |
| 1595 } | 1613 } |
| 1596 | 1614 |
| 1597 visitVariableInitialization(VariableInitialization node) { | 1615 visitVariableInitialization(VariableInitialization node) { |
| 1598 _scanVariableBinding(node.declaration); | 1616 _scanVariableBinding(node.declaration); |
| 1599 if (node.value != null) node.value.accept(this); | 1617 if (node.value != null) node.value.accept(this); |
| 1600 } | 1618 } |
| 1601 | 1619 |
| 1602 visitCatch(Catch node) { | 1620 visitCatch(Catch node) { |
| 1603 declare(node.declaration); | 1621 declare(node.declaration); |
| 1604 node.body.accept(this); | 1622 node.body.accept(this); |
| 1605 } | 1623 } |
| 1606 | 1624 |
| 1607 visitFunctionDeclaration(FunctionDeclaration node) { | 1625 visitFunctionDeclaration(FunctionDeclaration node) { |
| 1608 declare(node.name); | 1626 declare(node.name); |
| 1609 node.function.accept(this); | 1627 node.function.accept(this); |
| 1610 } | 1628 } |
| 1611 | 1629 |
| 1612 visitNamedFunction(NamedFunction node) { | 1630 visitNamedFunction(NamedFunction node) { |
| 1613 declare(node.name); | 1631 declare(node.name); |
| 1614 node.function.accept(this); | 1632 node.function.accept(this); |
| 1615 } | 1633 } |
| 1616 | 1634 |
| 1617 visitClassExpression(ClassExpression node) { | 1635 visitClassExpression(ClassExpression node) { |
| 1618 declare(node.name); | 1636 declare(node.name); |
| 1619 if (node.heritage != null) node.heritage.accept(this); | 1637 if (node.heritage != null) node.heritage.accept(this); |
| 1620 for (Method element in node.methods) element.accept(this); | 1638 for (Method element in node.methods) element.accept(this); |
| 1621 } | 1639 } |
| 1622 } | 1640 } |
| OLD | NEW |