Skip to content

Commit 569757d

Browse files
kzcalexlamsl
authored andcommitted
fix collapse_vars regression in destructuring (#2897)
fixes #2896
1 parent aebc916 commit 569757d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

lib/compress.js

+1
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ merge(Compressor.prototype, {
15121512
}
15131513

15141514
function may_modify(sym) {
1515+
if (!sym.definition) return true; // AST_Destructuring
15151516
var def = sym.definition();
15161517
if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false;
15171518
if (def.scope.get_defun_scope() !== scope) return true;

test/compress/destructuring.js

+33
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,39 @@ mangle_destructuring_decl: {
439439
node_version: ">=6"
440440
}
441441

442+
mangle_destructuring_decl_collapse_vars: {
443+
options = {
444+
collapse_vars: true,
445+
evaluate: true,
446+
unused: true,
447+
}
448+
mangle = {
449+
}
450+
input: {
451+
function test(opts) {
452+
let a = opts.a || { e: 7, n: 8 };
453+
let { t, e, n, s = 5 + 4, o, r } = a;
454+
console.log(t, e, n, s, o, r);
455+
}
456+
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
457+
test({});
458+
}
459+
expect: {
460+
function test(t) {
461+
let e = t.a || { e: 7, n: 8 };
462+
let {t: n, e: o, n: s, s: l = 9, o: a, r: c} = e;
463+
console.log(n, o, s, l, a, c);
464+
}
465+
test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } });
466+
test({});
467+
}
468+
expect_stdout: [
469+
"1 2 3 4 5 6",
470+
"undefined 7 8 9 undefined undefined",
471+
]
472+
node_version: ">=6"
473+
}
474+
442475
mangle_destructuring_assign_toplevel_true: {
443476
options = {
444477
toplevel: true,

test/run-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function run_compress_tests() {
208208
});
209209
return false;
210210
}
211-
if (0 && test.reminify && !reminify(test.options, input_code, input_formatted, test.expect_stdout)) {
211+
if (test.reminify && !reminify(test.options, input_code, input_formatted, test.expect_stdout)) {
212212
return false;
213213
}
214214
}

0 commit comments

Comments
 (0)