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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js/printer.dart
diff --git a/pkg/compiler/lib/src/js/printer.dart b/pkg/compiler/lib/src/js/printer.dart
index f64bdfb0840752ab5bb41694424df10571d14492..11c39cb1a260a6f4d80bdd06c86d27d5c77e18d7 100644
--- a/pkg/compiler/lib/src/js/printer.dart
+++ b/pkg/compiler/lib/src/js/printer.dart
@@ -774,28 +774,28 @@ class Printer extends Indentation implements NodeVisitor {
visitArrayInitializer(ArrayInitializer node) {
out("[");
- List<ArrayElement> elements = node.elements;
- int elementIndex = 0;
- for (int i = 0; i < node.length; i++) {
- if (elementIndex < elements.length &&
- elements[elementIndex].index == i) {
- visitNestedExpression(elements[elementIndex].value, ASSIGNMENT,
- newInForInit: false, newAtStatementBegin: false);
- elementIndex++;
- // We can avoid a trailing "," if there was an element just before. So
- // `[1]` and `[1,]` are the same, but `[,]` and `[]` are not.
- if (i != node.length - 1) {
- out(",");
- spaceOut();
- }
- } else {
+ List<Expression> elements = node.elements;
+ for (int i = 0; i < elements.length; i++) {
+ Expression element = elements[i];
+ if (element is ArrayHole) {
+ // Note that array holes must have a trailing "," even if they are
+ // in last position. Otherwise `[,]` (having length 1) would become
+ // equal to `[]` (the empty array)
+ // and [1,,] (array with 1 and a hole) would become [1,] = [1].
out(",");
+ continue;
}
+ if (i != 0) spaceOut();
+ visitNestedExpression(element, ASSIGNMENT,
+ newInForInit: false, newAtStatementBegin: false);
+ // We can skip the trailing "," for the last element (since it's not
+ // an array hole).
+ if (i != elements.length - 1) out(",");
}
out("]");
}
- visitArrayElement(ArrayElement node) {
+ visitArrayHole(ArrayHole node) {
throw "Unreachable";
}
« 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