Chromium Code Reviews| 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..0c0223d02b781fec4517db6ac9e0364957a405a6 100644 |
| --- a/pkg/compiler/lib/src/js/printer.dart |
| +++ b/pkg/compiler/lib/src/js/printer.dart |
| @@ -774,29 +774,24 @@ class Printer extends Indentation implements NodeVisitor { |
| visitArrayInitializer(ArrayInitializer node) { |
| out("["); |
| - List<ArrayElement> elements = node.elements; |
| + List<Expression> 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 { |
| + for (int i = 0; i < elements.length; i++) { |
| + visitNestedExpression(elements[i], ASSIGNMENT, |
| + newInForInit: false, newAtStatementBegin: false); |
| + // 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 != elements.length - 1 || |
| + (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
|
| out(","); |
| + 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
|
| } |
| } |
| out("]"); |
| } |
| - visitArrayElement(ArrayElement node) { |
| - throw "Unreachable"; |
| + 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.
|
| + // An array hole is represented by the empty string. |
| } |
| visitObjectInitializer(ObjectInitializer node) { |