fix destructuring array default values
This commit is contained in:
parent
03c385dded
commit
028b3548c4
|
|
@ -2097,9 +2097,6 @@ merge(Compressor.prototype, {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node.names[i] instanceof AST_Hole) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (node.names[i] instanceof AST_ObjectKeyVal) {
|
else if (node.names[i] instanceof AST_ObjectKeyVal) {
|
||||||
if (typeof node.names[i].key === "string") {
|
if (typeof node.names[i].key === "string") {
|
||||||
initializations.add(node.names[i].key, destructuring_value);
|
initializations.add(node.names[i].key, destructuring_value);
|
||||||
|
|
@ -2107,7 +2104,14 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
else if (node.names[i] instanceof AST_Symbol) {
|
else if (node.names[i] instanceof AST_Symbol) {
|
||||||
initializations.add(node.names[i].name, destructuring_value);
|
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}", {
|
throw new Error(string_template("Unknown destructuring element of type: {type}", {
|
||||||
type: Object.getPrototypeOf(node.names[i]).TYPE
|
type: Object.getPrototypeOf(node.names[i]).TYPE
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -407,12 +407,16 @@ destructuring_assign_of_computed_key: {
|
||||||
}
|
}
|
||||||
|
|
||||||
mangle_destructuring_decl: {
|
mangle_destructuring_decl: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function test(opts) {
|
function test(opts) {
|
||||||
let a = opts.a || { e: 7, n: 8 };
|
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);
|
console.log(t, e, n, s, o, r);
|
||||||
}
|
}
|
||||||
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
|
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: {
|
mangle_destructuring_assign_toplevel_true: {
|
||||||
options = {
|
options = {
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
evaluate: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
|
@ -448,7 +454,7 @@ mangle_destructuring_assign_toplevel_true: {
|
||||||
function test(opts) {
|
function test(opts) {
|
||||||
let s, o, r;
|
let s, o, r;
|
||||||
let a = opts.a || { e: 7, n: 8 };
|
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);
|
console.log(t, e, n, s, o, r);
|
||||||
}
|
}
|
||||||
let t, e, n;
|
let t, e, n;
|
||||||
|
|
@ -476,6 +482,8 @@ mangle_destructuring_assign_toplevel_true: {
|
||||||
mangle_destructuring_assign_toplevel_false: {
|
mangle_destructuring_assign_toplevel_false: {
|
||||||
options = {
|
options = {
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
|
evaluate: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
|
|
@ -511,3 +519,27 @@ mangle_destructuring_assign_toplevel_false: {
|
||||||
]
|
]
|
||||||
node_version: ">=6"
|
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"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user