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

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: Created 6 years, 1 month 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
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) {

Powered by Google App Engine
This is Rietveld 408576698