fix destructuring array default values

This commit is contained in:
kzc 2017-05-22 14:19:17 -04:00
parent 03c385dded
commit 028b3548c4
2 changed files with 42 additions and 6 deletions

View File

@ -2097,9 +2097,6 @@ merge(Compressor.prototype, {
}));
}
}
else if (node.names[i] instanceof AST_Hole) {
continue;
}
else if (node.names[i] instanceof AST_ObjectKeyVal) {
if (typeof node.names[i].key === "string") {
initializations.add(node.names[i].key, destructuring_value);
@ -2107,7 +2104,14 @@ merge(Compressor.prototype, {
}
else if (node.names[i] instanceof AST_Symbol) {
initializations.add(node.names[i].name, destructuring_value);
} else {
}
else if (node.names[i] instanceof AST_DefaultAssign) {
continue;
}
else if (node.names[i] instanceof AST_Hole) {
continue;
}
else {
throw new Error(string_template("Unknown destructuring element of type: {type}", {
type: Object.getPrototypeOf(node.names[i]).TYPE
}));

View File

@ -407,12 +407,16 @@ destructuring_assign_of_computed_key: {
}
mangle_destructuring_decl: {
options = {
evaluate: true,
unused: true,
}
mangle = {
}
input: {
function test(opts) {
let a = opts.a || { e: 7, n: 8 };
let { t, e, n, s = 9, o, r } = a;
let { t, e, n, s = 5 + 4, o, r } = a;
console.log(t, e, n, s, o, r);
}
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
@ -437,6 +441,8 @@ mangle_destructuring_decl: {
mangle_destructuring_assign_toplevel_true: {
options = {
toplevel: true,
evaluate: true,
unused: true,
}
mangle = {
toplevel: true,
@ -448,7 +454,7 @@ mangle_destructuring_assign_toplevel_true: {
function test(opts) {
let s, o, r;
let a = opts.a || { e: 7, n: 8 };
({ t, e, n, s = 9, o, r } = a);
({ t, e, n, s = 5 + 4, o, r } = a);
console.log(t, e, n, s, o, r);
}
let t, e, n;
@ -476,6 +482,8 @@ mangle_destructuring_assign_toplevel_true: {
mangle_destructuring_assign_toplevel_false: {
options = {
toplevel: false,
evaluate: true,
unused: true,
}
mangle = {
toplevel: false,
@ -511,3 +519,27 @@ mangle_destructuring_assign_toplevel_false: {
]
node_version: ">=6"
}
mangle_destructuring_decl_array: {
options = {
evaluate: true,
unused: true,
toplevel: true,
}
mangle = {
toplevel: true,
}
beautify = {
ecma: 6
}
input: {
var [, t, e, n, s, o = 2, r = [ 1 + 2 ]] = [ 9, 8, 7, 6 ];
console.log(t, e, n, s, o, r);
}
expect: {
var [, o, l, a, c, e = 2, g = [ 3 ]] = [ 9, 8, 7, 6 ];
console.log(o, l, a, c, e, g);
}
expect_stdout: "8 7 6 undefined 2 [ 3 ]"
node_version: ">=6"
}