Fix output for arrays containing undefined values.

1b6bcca7 was a first attempt at this. That commit made Uglify stop replacing
holes with undefined, but instead it started replacing undefined with
holes. This is slightly problematic, because there is a difference between a
hole and an undefined value. More problematically, it changed [1,undefined] to
[1,] which generally doesn't even parse as a hole (just as a trailing comma), so
it didn't even preserve the length of the array!

Instead, parse holes as their own special AST node which prints invisibly.
This commit is contained in:
David Glasser
2013-01-16 14:59:19 -05:00
committed by Mihai Bazon
parent 605f330e69
commit 1529ab965a
4 changed files with 22 additions and 3 deletions

View File

@@ -984,8 +984,7 @@ function OutputStream(options) {
if (len > 0) output.space();
a.forEach(function(exp, i){
if (i) output.comma();
if (!(exp instanceof AST_Undefined))
exp.print(output);
exp.print(output);
});
if (len > 0) output.space();
});
@@ -1036,6 +1035,9 @@ function OutputStream(options) {
DEFPRINT(AST_Undefined, function(self, output){
output.print("void 0");
});
DEFPRINT(AST_Hole, function(self, output){
output.print("");
});
DEFPRINT(AST_Infinity, function(self, output){
output.print("1/0");
});