Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: pkg/compiler/lib/src/js/printer.dart

Issue 750323003: Remove js.ArrayElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/js/nodes.dart ('k') | pkg/compiler/lib/src/js/template.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 for (int i = 0; i < elements.length; i++) {
779 for (int i = 0; i < node.length; i++) { 779 Expression element = elements[i];
780 if (elementIndex < elements.length && 780 if (element is ArrayHole) {
781 elements[elementIndex].index == i) { 781 // Note that array holes must have a trailing "," even if they are
782 visitNestedExpression(elements[elementIndex].value, ASSIGNMENT, 782 // in last position. Otherwise `[,]` (having length 1) would become
783 newInForInit: false, newAtStatementBegin: false); 783 // equal to `[]` (the empty array)
784 elementIndex++; 784 // and [1,,] (array with 1 and a hole) would become [1,] = [1].
785 // We can avoid a trailing "," if there was an element just before. So
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(","); 785 out(",");
786 continue;
793 } 787 }
788 if (i != 0) spaceOut();
789 visitNestedExpression(element, ASSIGNMENT,
790 newInForInit: false, newAtStatementBegin: false);
791 // We can skip the trailing "," for the last element (since it's not
792 // an array hole).
793 if (i != elements.length - 1) out(",");
794 } 794 }
795 out("]"); 795 out("]");
796 } 796 }
797 797
798 visitArrayElement(ArrayElement node) { 798 visitArrayHole(ArrayHole node) {
799 throw "Unreachable"; 799 throw "Unreachable";
800 } 800 }
801 801
802 visitObjectInitializer(ObjectInitializer node) { 802 visitObjectInitializer(ObjectInitializer node) {
803 // Print all the properties on one line until we see a function-valued 803 // 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 804 // property. Ideally, we would use a proper pretty-printer to make the
805 // decision based on layout. 805 // decision based on layout.
806 List<Property> properties = node.properties; 806 List<Property> properties = node.properties;
807 out("{"); 807 out("{");
808 indentMore(); 808 indentMore();
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); 1168 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS));
1169 } 1169 }
1170 codes.add(charCodes.$0 + digit); 1170 codes.add(charCodes.$0 + digit);
1171 newName = new String.fromCharCodes(codes); 1171 newName = new String.fromCharCodes(codes);
1172 } 1172 }
1173 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); 1173 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName));
1174 maps.last[oldName] = newName; 1174 maps.last[oldName] = newName;
1175 return newName; 1175 return newName;
1176 } 1176 }
1177 } 1177 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js/nodes.dart ('k') | pkg/compiler/lib/src/js/template.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698