From f79f737fb29d08e4448e099889cf8abe47ab5bba Mon Sep 17 00:00:00 2001 From: kzc Date: Sun, 15 Oct 2017 08:59:52 -0400 Subject: [PATCH] fix mangle of destructuring parameters with computed properties (#2359) fixes #2349 --- lib/parse.js | 3 -- test/compress/harmony.js | 72 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index 9c678929..619034c6 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -2000,9 +2000,6 @@ function parse($TEXT, options) { names: ex.properties.map(to_fun_args) }), default_seen_above); } else if (ex instanceof AST_ObjectKeyVal) { - if (ex.key instanceof AST_SymbolRef) { - ex.key = to_fun_args(ex.key, 0, [ex.key]); - } ex.value = to_fun_args(ex.value, 0, [ex.key]); return insert_default(ex, default_seen_above); } else if (ex instanceof AST_Hole) { diff --git a/test/compress/harmony.js b/test/compress/harmony.js index fb57ae8f..60bc5793 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -863,3 +863,75 @@ issue_2345: { ] node_version: ">=6" } + +issue_2349: { + mangle = {} + input: { + function foo(boo, key) { + const value = boo.get(); + return value.map(({[key]: bar}) => bar); + } + console.log(foo({ + get: () => [ { + blah: 42 + } ] + }, "blah")); + } + expect: { + function foo(o, n) { + const t = o.get(); + return t.map(({[n]: o}) => o); + } + console.log(foo({ + get: () => [ { + blah: 42 + } ] + }, "blah")); + } + expect_stdout: [ + "[ 42 ]", + ] + node_version: ">=7" +} + +issue_2349b: { + options = { + arrows: true, + collapse_vars: true, + ecma: 6, + evaluate: true, + inline: true, + passes: 3, + reduce_vars: true, + toplevel: true, + side_effects: true, + unsafe: true, + unsafe_arrows: true, + unused: true, + } + mangle = { + toplevel: true, + } + input: { + function foo(boo, key) { + const value = boo.get(); + return value.map(function({[key]: bar}){ return bar; }); + } + console.log(foo({ + get: function() { + return [ { + blah: 42 + } ]; + } + }, "blah")); + } + expect: { + console.log([ { + blah: 42 + } ].map(({["blah"]: l}) => l)); + } + expect_stdout: [ + "[ 42 ]", + ] + node_version: ">=7" +}