aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Glasser <glasser@davidglasser.net>2013-01-16 14:59:19 -0500
committerMihai Bazon <mihai@bazon.net>2013-07-18 15:39:22 +0300
commitb1febde3e9be32b9d88918ed733efc3796e3f143 (patch)
tree01d6eb5082dc04ea323ab154e3747259e0b5640c
parent193049af197ee73275dced11289b9b6755f4f469 (diff)
downloadtracifyjs-b1febde3e9be32b9d88918ed733efc3796e3f143.tar.gz
tracifyjs-b1febde3e9be32b9d88918ed733efc3796e3f143.zip
Fix output for arrays whose last element is a hole: [1,,]
1529ab96 started to do this (by considering holes to be separate from "undefined") but it still converted [1,,] (length 2, last element hole, trailing comma) to [1,] (length 1, trailing comma) Unfortunately the test suite doesn't really make this clear: the new test here passes with or without this patch because run-tests.js beautifys the expected output (in "make_code"), which does the incorrect transformation! If you make some manual change to arrays.js to make the test fail and see the INPUT and OUTPUT, then you can see that without this fix, [1,,] -> [1,], and with this fix it stays [1,,].
-rw-r--r--lib/output.js5
-rw-r--r--test/compress/arrays.js2
2 files changed, 7 insertions, 0 deletions
diff --git a/lib/output.js b/lib/output.js
index dc78a5da..90589a2d 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -1016,6 +1016,11 @@ function OutputStream(options) {
a.forEach(function(exp, i){
if (i) output.comma();
exp.print(output);
+ // If the final element is a hole, we need to make sure it
+ // doesn't look like a trailing comma, by inserting an actual
+ // trailing comma.
+ if (i === len - 1 && exp instanceof AST_Hole)
+ output.comma();
});
if (len > 0) output.space();
});
diff --git a/test/compress/arrays.js b/test/compress/arrays.js
index 10fe6eb5..0c3d8ba2 100644
--- a/test/compress/arrays.js
+++ b/test/compress/arrays.js
@@ -1,10 +1,12 @@
holes_and_undefined: {
input: {
+ w = [1,,];
x = [1, 2, undefined];
y = [1, , 2, ];
z = [1, undefined, 3];
}
expect: {
+ w=[1,,];
x=[1,2,void 0];
y=[1,,2];
z=[1,void 0,3];