From ec63588496a2bfa0f1aef1d8e465e25534381717 Mon Sep 17 00:00:00 2001 From: kzc Date: Tue, 30 May 2017 01:17:06 -0400 Subject: [PATCH] fix compress of IIFE with destructuring args (#2022) --- lib/compress.js | 18 +++++++----- test/compress/destructuring.js | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index de6a476a..24129a05 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -372,14 +372,16 @@ merge(Compressor.prototype, { // (function(a,b) {...})(c,d) => (function() {var a=c,b=d; ...})() // So existing transformation rules can work on them. node.argnames.forEach(function(arg, i) { - var d = arg.definition(); - if (!node.uses_arguments && d.fixed === undefined) { - d.fixed = function() { - return iife.args[i] || make_node(AST_Undefined, iife); - }; - mark(d, true); - } else { - d.fixed = false; + if (arg.definition) { + var d = arg.definition(); + if (!node.uses_arguments && d.fixed === undefined) { + d.fixed = function() { + return iife.args[i] || make_node(AST_Undefined, iife); + }; + mark(d, true); + } else { + d.fixed = false; + } } }); } diff --git a/test/compress/destructuring.js b/test/compress/destructuring.js index b79d5734..e7eab31e 100644 --- a/test/compress/destructuring.js +++ b/test/compress/destructuring.js @@ -543,3 +543,57 @@ mangle_destructuring_decl_array: { expect_stdout: "8 7 6 undefined 2 [ 3 ]" node_version: ">=6" } + +anon_func_with_destructuring_args: { + options = { + evaluate: true, + unused: true, + toplevel: true, + } + mangle = { + toplevel: true, + } + beautify = { + ecma: 5, + } + input: { + (function({foo = 1 + 0, bar = 2}, [car = 3, far = 4]) { + console.log(foo, bar, car, far); + })({bar: 5 - 0}, [, 6]); + } + expect: { + (function({foo: foo = 1, bar: bar = 2}, [o = 3, a = 4]){ + // FIXME: `foo` and `bar` should be mangled + console.log(foo, bar, o, a) + })({bar: 5}, [, 6]); + } + expect_stdout: "1 5 3 6" + node_version: ">=6" +} + +arrow_func_with_destructuring_args: { + options = { + evaluate: true, + unused: true, + toplevel: true, + } + mangle = { + toplevel: true, + } + beautify = { + ecma: 5, + } + input: { + (({foo = 1 + 0, bar = 2}, [car = 3, far = 4]) => { + console.log(foo, bar, car, far); + })({bar: 5 - 0}, [, 6]); + } + expect: { + (({foo: foo = 1, bar: bar = 2},[o = 3, a = 4]) => { + // FIXME: `foo` and `bar` should be mangled + console.log(foo, bar, o, a) + })({bar: 5}, [, 6]); + } + expect_stdout: "1 5 3 6" + node_version: ">=6" +}