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; | 5 part of js; |
| 6 | 6 |
| 7 class Printer extends Indentation implements NodeVisitor { | 7 class Printer extends Indentation 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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 } | 767 } |
| 768 out(node.value); | 768 out(node.value); |
| 769 } | 769 } |
| 770 | 770 |
| 771 visitLiteralNull(LiteralNull node) { | 771 visitLiteralNull(LiteralNull node) { |
| 772 out("null"); | 772 out("null"); |
| 773 } | 773 } |
| 774 | 774 |
| 775 visitArrayInitializer(ArrayInitializer node) { | 775 visitArrayInitializer(ArrayInitializer node) { |
| 776 out("["); | 776 out("["); |
| 777 List<ArrayElement> elements = node.elements; | 777 List<Expression> elements = node.elements; |
| 778 int elementIndex = 0; | 778 int elementIndex = 0; |
| 779 for (int i = 0; i < node.length; i++) { | 779 for (int i = 0; i < elements.length; i++) { |
| 780 if (elementIndex < elements.length && | 780 visitNestedExpression(elements[i], ASSIGNMENT, |
| 781 elements[elementIndex].index == i) { | 781 newInForInit: false, newAtStatementBegin: false); |
| 782 visitNestedExpression(elements[elementIndex].value, ASSIGNMENT, | 782 // We can avoid a trailing "," if there was an element just before. So |
| 783 newInForInit: false, newAtStatementBegin: false); | 783 // `[1]` and `[1,]` are the same, but `[,]` and `[]` are not. |
| 784 elementIndex++; | 784 if (i != elements.length - 1 || |
| 785 // We can avoid a trailing "," if there was an element just before. So | 785 (i == 0 && elements[i] is ArrayHole)) { |
|
floitsch
2014/11/28 12:42:50
Why the check for "i == 0" ?
I think it should be
sigurdm
2014/11/28 14:52:11
Yes, something was wrong in my logic. Thanks.
Addi
| |
| 786 // `[1]` and `[1,]` are the same, but `[,]` and `[]` are not. | |
| 787 if (i != node.length - 1) { | |
| 788 out(","); | |
| 789 spaceOut(); | |
| 790 } | |
| 791 } else { | |
| 792 out(","); | 786 out(","); |
| 787 spaceOut(); | |
|
floitsch
2014/11/28 12:42:50
This means that we now have "[, ]" instead of "[,]
sigurdm
2014/11/28 14:52:11
True
Fixed
| |
| 793 } | 788 } |
| 794 } | 789 } |
| 795 out("]"); | 790 out("]"); |
| 796 } | 791 } |
| 797 | 792 |
| 798 visitArrayElement(ArrayElement node) { | 793 visitArrayHole(ArrayHole node) { |
|
floitsch
2014/11/28 12:42:50
Should be unreachable again, if you use my code.
sigurdm
2014/11/28 14:52:11
Done.
| |
| 799 throw "Unreachable"; | 794 // An array hole is represented by the empty string. |
| 800 } | 795 } |
| 801 | 796 |
| 802 visitObjectInitializer(ObjectInitializer node) { | 797 visitObjectInitializer(ObjectInitializer node) { |
| 803 // Print all the properties on one line until we see a function-valued | 798 // Print all the properties on one line until we see a function-valued |
| 804 // property. Ideally, we would use a proper pretty-printer to make the | 799 // property. Ideally, we would use a proper pretty-printer to make the |
| 805 // decision based on layout. | 800 // decision based on layout. |
| 806 List<Property> properties = node.properties; | 801 List<Property> properties = node.properties; |
| 807 out("{"); | 802 out("{"); |
| 808 indentMore(); | 803 indentMore(); |
| 809 for (int i = 0; i < properties.length; i++) { | 804 for (int i = 0; i < properties.length; i++) { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); | 1163 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); |
| 1169 } | 1164 } |
| 1170 codes.add(charCodes.$0 + digit); | 1165 codes.add(charCodes.$0 + digit); |
| 1171 newName = new String.fromCharCodes(codes); | 1166 newName = new String.fromCharCodes(codes); |
| 1172 } | 1167 } |
| 1173 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); | 1168 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
| 1174 maps.last[oldName] = newName; | 1169 maps.last[oldName] = newName; |
| 1175 return newName; | 1170 return newName; |
| 1176 } | 1171 } |
| 1177 } | 1172 } |
| OLD | NEW |