From 03c385dded772f5c86a9a67c472cbea700028153 Mon Sep 17 00:00:00 2001 From: kzc Date: Mon, 22 May 2017 13:36:28 -0400 Subject: [PATCH] fix destructuring mangle --- lib/scope.js | 1 - test/compress/destructuring.js | 106 +++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/lib/scope.js b/lib/scope.js index afd6c1f2..ccb836e7 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -569,7 +569,6 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ }); this.walk(tw); to_mangle.forEach(function(def){ - if (def.destructuring && !def.destructuring.is_array) return; def.mangle(options); }); diff --git a/test/compress/destructuring.js b/test/compress/destructuring.js index c4d927a3..4b328442 100644 --- a/test/compress/destructuring.js +++ b/test/compress/destructuring.js @@ -405,3 +405,109 @@ destructuring_assign_of_computed_key: { expect_stdout: "42" node_version: ">=6" } + +mangle_destructuring_decl: { + mangle = { + } + input: { + function test(opts) { + let a = opts.a || { e: 7, n: 8 }; + let { t, e, n, s = 9, 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 }}); + test({}); + } + expect: { + function test(t) { + let e = t.a || { e: 7, n: 8 }; + let {t: n, e: o, n: s, s: a = 9, o: c, r: l} = e; + console.log(n, o, s, a, c, l); + } + test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } }); + test({}); + } + expect_stdout: [ + "1 2 3 4 5 6", + "undefined 7 8 9 undefined undefined", + ] + node_version: ">=6" +} + +mangle_destructuring_assign_toplevel_true: { + options = { + toplevel: true, + } + mangle = { + toplevel: true, + } + beautify = { + ecma: 6 + } + input: { + function test(opts) { + let s, o, r; + let a = opts.a || { e: 7, n: 8 }; + ({ t, e, n, s = 9, o, r } = a); + console.log(t, e, n, s, o, r); + } + let t, e, n; + test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }}); + test({}); + } + expect: { + function n(n) { + let t, a, c; + let l = n.a || { e: 7, n: 8 }; + ({t: o, e, n: s, s: t = 9, o: a, r: c} = l); + console.log(o, e, s, t, a, c); + } + let o, e, s; + n({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } }); + n({}); + } + expect_stdout: [ + "1 2 3 4 5 6", + "undefined 7 8 9 undefined undefined", + ] + node_version: ">=6" +} + +mangle_destructuring_assign_toplevel_false: { + options = { + toplevel: false, + } + mangle = { + toplevel: false, + } + beautify = { + ecma: 6 + } + input: { + function test(opts) { + let s, o, r; + let a = opts.a || { e: 7, n: 8 }; + ({ t, e, n, s = 9, o, r } = a); + console.log(t, e, n, s, o, r); + } + let t, e, n; + test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }}); + test({}); + } + expect: { + function test(o) { + let s, a, c; + let l = o.a || { e: 7, n: 8 }; + ({t, e, n, s = 9, o: a, r: c} = l); + console.log(t, e, n, s, a, c); + } + let t, e, n; + test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } }); + test({}); + } + expect_stdout: [ + "1 2 3 4 5 6", + "undefined 7 8 9 undefined undefined", + ] + node_version: ">=6" +}