From 348547286611eaf665b00d5ee21a8fee2c2f0660 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 1 Mar 2020 05:04:21 +0000 Subject: [PATCH] avoid reducing setter argument (#3737) --- test/input/reduce/setter.js | 8 ++++++++ test/input/reduce/setter.reduced.js | 19 +++++++++++++++++++ test/mocha/reduce.js | 13 +++++++++++++ test/reduce.js | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/input/reduce/setter.js create mode 100644 test/input/reduce/setter.reduced.js diff --git a/test/input/reduce/setter.js b/test/input/reduce/setter.js new file mode 100644 index 00000000..87228bc4 --- /dev/null +++ b/test/input/reduce/setter.js @@ -0,0 +1,8 @@ +console.log(function f(a) { + ({ + set p(v) { + f++; + } + }); + return f.length; +}()); diff --git a/test/input/reduce/setter.reduced.js b/test/input/reduce/setter.reduced.js new file mode 100644 index 00000000..d947226f --- /dev/null +++ b/test/input/reduce/setter.reduced.js @@ -0,0 +1,19 @@ +console.log(function f(a) { + ({ + set p(v) { + f++; + } + }); + return f.length; +}()); +// output: 1 +// +// minify: 0 +// +// options: { +// "compress": { +// "keep_fargs": false, +// "unsafe": true +// }, +// "mangle": false +// } \ No newline at end of file diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js index 7eacbd7f..a8ab67b3 100644 --- a/test/mocha/reduce.js +++ b/test/mocha/reduce.js @@ -31,6 +31,19 @@ describe("test/reduce.js", function() { if (result.error) throw result.error; assert.strictEqual(result.code, read("test/input/reduce/label.reduced.js")); }); + it("Should retain setter arguments", function() { + var result = reduce_test(read("test/input/reduce/setter.js"), { + compress: { + keep_fargs: false, + unsafe: true, + }, + mangle: false, + }, { + verbose: false, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, read("test/input/reduce/setter.reduced.js")); + }); it("Should handle test cases with --toplevel", function() { var result = reduce_test([ "var Infinity = 42;", diff --git a/test/reduce.js b/test/reduce.js index eb6fb5c1..f9e08254 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -75,8 +75,8 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) if (node instanceof U.AST_LabelRef) return; if (!in_list && node instanceof U.AST_SymbolDeclaration) return; if (node instanceof U.AST_Toplevel) return; - var parent = tt.parent(); + if (node instanceof U.AST_SymbolFunarg && parent instanceof U.AST_Accessor) return; // ensure that the _permute prop is a number. // can not use `node.start._permute |= 0;` as it will erase fractional part. -- 2.34.1