| 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; | 5 part of js; |
| 6 | 6 |
| 7 class Printer implements NodeVisitor { | 7 class Printer implements NodeVisitor { |
| 8 final bool shouldCompressOutput; | 8 final bool shouldCompressOutput; |
| 9 leg.Compiler compiler; | 9 leg.Compiler compiler; |
| 10 leg.CodeBuffer outBuffer; | 10 leg.CodeBuffer outBuffer; |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 } | 795 } |
| 796 | 796 |
| 797 visitArrayElement(ArrayElement node) { | 797 visitArrayElement(ArrayElement node) { |
| 798 throw "Unreachable"; | 798 throw "Unreachable"; |
| 799 } | 799 } |
| 800 | 800 |
| 801 visitObjectInitializer(ObjectInitializer node) { | 801 visitObjectInitializer(ObjectInitializer node) { |
| 802 // Print all the properties on one line until we see a function-valued | 802 // Print all the properties on one line until we see a function-valued |
| 803 // property. Ideally, we would use a proper pretty-printer to make the | 803 // property. Ideally, we would use a proper pretty-printer to make the |
| 804 // decision based on layout. | 804 // decision based on layout. |
| 805 bool onePerLine = false; | |
| 806 List<Property> properties = node.properties; | 805 List<Property> properties = node.properties; |
| 807 out("{"); | 806 out("{"); |
| 808 ++indentLevel; | 807 ++indentLevel; |
| 809 for (int i = 0; i < properties.length; i++) { | 808 for (int i = 0; i < properties.length; i++) { |
| 810 Expression value = properties[i].value; | 809 Expression value = properties[i].value; |
| 811 if (value is Fun || value is NamedFunction) onePerLine = true; | |
| 812 if (i != 0) { | 810 if (i != 0) { |
| 813 out(","); | 811 out(","); |
| 814 if (!onePerLine) spaceOut(); | 812 if (node.isOneLiner) spaceOut(); |
| 815 } | 813 } |
| 816 if (onePerLine) { | 814 if (!node.isOneLiner) { |
| 817 forceLine(); | 815 forceLine(); |
| 818 indent(); | 816 indent(); |
| 819 } | 817 } |
| 820 visitProperty(properties[i]); | 818 visitProperty(properties[i]); |
| 821 } | 819 } |
| 822 --indentLevel; | 820 --indentLevel; |
| 823 if (onePerLine) lineOut(); | 821 if (!node.isOneLiner && !properties.isEmpty) { |
| 822 lineOut(); |
| 823 indent(); |
| 824 } |
| 824 out("}"); | 825 out("}"); |
| 825 } | 826 } |
| 826 | 827 |
| 827 visitProperty(Property node) { | 828 visitProperty(Property node) { |
| 828 if (node.name is LiteralString) { | 829 if (node.name is LiteralString) { |
| 829 LiteralString nameString = node.name; | 830 LiteralString nameString = node.name; |
| 830 String name = nameString.value; | 831 String name = nameString.value; |
| 831 if (isValidJavaScriptId(name)) { | 832 if (isValidJavaScriptId(name)) { |
| 832 out(name.substring(1, name.length - 1)); | 833 out(name.substring(1, name.length - 1)); |
| 833 } else { | 834 } else { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); | 1142 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); |
| 1142 } | 1143 } |
| 1143 codes.add(charCodes.$0 + digit); | 1144 codes.add(charCodes.$0 + digit); |
| 1144 newName = new String.fromCharCodes(codes); | 1145 newName = new String.fromCharCodes(codes); |
| 1145 } | 1146 } |
| 1146 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); | 1147 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
| 1147 maps.last[oldName] = newName; | 1148 maps.last[oldName] = newName; |
| 1148 return newName; | 1149 return newName; |
| 1149 } | 1150 } |
| 1150 } | 1151 } |
| OLD | NEW |