| 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 class Printer implements NodeVisitor { | 5 class Printer implements NodeVisitor { |
| 6 final bool shouldCompressOutput = false; | 6 final bool shouldCompressOutput = false; |
| 7 leg.Compiler compiler; | 7 leg.Compiler compiler; |
| 8 var positionElement; | 8 var positionElement; |
| 9 leg.CodeBuffer outBuffer; | 9 leg.CodeBuffer outBuffer; |
| 10 int indentLevel = 0; | 10 int indentLevel = 0; |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 // a reserved word. | 630 // a reserved word. |
| 631 return true; | 631 return true; |
| 632 } | 632 } |
| 633 | 633 |
| 634 visitAccess(PropertyAccess access) { | 634 visitAccess(PropertyAccess access) { |
| 635 visitNestedExpression(access.receiver, CALL, | 635 visitNestedExpression(access.receiver, CALL, |
| 636 newInForInit: inForInit, | 636 newInForInit: inForInit, |
| 637 newAtStatementBegin: atStatementBegin); | 637 newAtStatementBegin: atStatementBegin); |
| 638 Node selector = access.selector; | 638 Node selector = access.selector; |
| 639 if (selector is LiteralString) { | 639 if (selector is LiteralString) { |
| 640 String fieldWithQuotes = (selector as LiteralString).value; | 640 LiteralString selectorString = selector; |
| 641 String fieldWithQuotes = selectorString.value; |
| 641 if (isValidJavaScriptId(fieldWithQuotes)) { | 642 if (isValidJavaScriptId(fieldWithQuotes)) { |
| 642 if (isDigit(lastCharCode)) out(" "); | 643 if (isDigit(lastCharCode)) out(" "); |
| 643 out("."); | 644 out("."); |
| 644 out(fieldWithQuotes.substring(1, fieldWithQuotes.length - 1)); | 645 out(fieldWithQuotes.substring(1, fieldWithQuotes.length - 1)); |
| 645 return; | 646 return; |
| 646 } | 647 } |
| 647 } | 648 } |
| 648 out("["); | 649 out("["); |
| 649 visitNestedExpression(selector, EXPRESSION, | 650 visitNestedExpression(selector, EXPRESSION, |
| 650 newInForInit: false, newAtStatementBegin: false); | 651 newInForInit: false, newAtStatementBegin: false); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 out(","); | 715 out(","); |
| 715 spaceOut(); | 716 spaceOut(); |
| 716 } | 717 } |
| 717 visitProperty(properties[i]); | 718 visitProperty(properties[i]); |
| 718 } | 719 } |
| 719 out("}"); | 720 out("}"); |
| 720 } | 721 } |
| 721 | 722 |
| 722 visitProperty(Property node) { | 723 visitProperty(Property node) { |
| 723 if (node.name is LiteralString) { | 724 if (node.name is LiteralString) { |
| 724 String name = (node.name as LiteralString).value; | 725 LiteralString nameString = node.name; |
| 726 String name = nameString.value; |
| 725 if (isValidJavaScriptId(name)) { | 727 if (isValidJavaScriptId(name)) { |
| 726 out(name.substring(1, name.length - 1)); | 728 out(name.substring(1, name.length - 1)); |
| 727 } else { | 729 } else { |
| 728 out(name); | 730 out(name); |
| 729 } | 731 } |
| 730 } else { | 732 } else { |
| 731 assert(node.name is LiteralNumber); | 733 assert(node.name is LiteralNumber); |
| 732 out((node.name as LiteralNumber).value); | 734 LiteralNumber nameNumber = node.name; |
| 735 out(nameNumber.value); |
| 733 } | 736 } |
| 734 out(":"); | 737 out(":"); |
| 735 spaceOut(); | 738 spaceOut(); |
| 736 visitNestedExpression(node.value, ASSIGNMENT, | 739 visitNestedExpression(node.value, ASSIGNMENT, |
| 737 newInForInit: false, newAtStatementBegin: false); | 740 newInForInit: false, newAtStatementBegin: false); |
| 738 } | 741 } |
| 739 | 742 |
| 740 visitRegExpLiteral(RegExpLiteral node) { | 743 visitRegExpLiteral(RegExpLiteral node) { |
| 741 out(node.pattern); | 744 out(node.pattern); |
| 742 } | 745 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 } | 816 } |
| 814 | 817 |
| 815 | 818 |
| 816 leg.CodeBuffer prettyPrint(Node node, | 819 leg.CodeBuffer prettyPrint(Node node, |
| 817 leg.Compiler compiler, | 820 leg.Compiler compiler, |
| 818 Dynamic positionElement) { | 821 Dynamic positionElement) { |
| 819 Printer printer = new Printer(compiler, positionElement); | 822 Printer printer = new Printer(compiler, positionElement); |
| 820 printer.visit(node); | 823 printer.visit(node); |
| 821 return printer.outBuffer; | 824 return printer.outBuffer; |
| 822 } | 825 } |
| OLD | NEW |