diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-18 00:41:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-18 08:41:13 +0800 |
commit | c1256c399a4db3228b461a742c66deb1ea5064e5 (patch) | |
tree | 5c990ee2758c70bc018281c678e695295f3c6f6c | |
parent | 2c637fea8a4a2023e8ff0ac9211f266580bdce85 (diff) | |
download | tracifyjs-c1256c399a4db3228b461a742c66deb1ea5064e5.tar.gz tracifyjs-c1256c399a4db3228b461a742c66deb1ea5064e5.zip |
fix corner case in `arguments` (#4396)
fixes #4395
-rw-r--r-- | lib/compress.js | 5 | ||||
-rw-r--r-- | test/compress/destructured.js | 20 | ||||
-rw-r--r-- | test/reduce.js | 6 |
3 files changed, 30 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index b8f4b3a5..4279dc7c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -9897,7 +9897,10 @@ merge(Compressor.prototype, { } else if (argname instanceof AST_Destructured) { argname = null; } else if (argname && (compressor.has_directive("use strict") - || !(fn_parent instanceof AST_Call && index < fn_parent.args.length))) { + || !(fn_parent instanceof AST_Call && index < fn_parent.args.length) + || !all(fn.argnames, function(argname) { + return !(argname instanceof AST_Destructured); + }))) { var arg_def = argname.definition(); if (!compressor.option("reduce_vars") || def.reassigned diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 81beb7f7..1c448f2a 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -1886,3 +1886,23 @@ issue_4386: { expect_stdout: "PASS" node_version: ">=6" } + +issue_4395: { + options = { + arguments: true, + } + input: { + console.log(function(a, {}) { + a = "FAIL"; + return arguments[0]; + }("PASS", 42)); + } + expect: { + console.log(function(a, {}) { + a = "FAIL"; + return arguments[0]; + }("PASS", 42)); + } + expect_stdout: "PASS" + node_version: ">=6" +} diff --git a/test/reduce.js b/test/reduce.js index db4b7521..1ab18411 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -175,6 +175,12 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) CHANGED = true; return expr instanceof U.AST_Spread ? expr.expression : expr; } + if (node.expression instanceof U.AST_Arrow && node.expression.value) { + var seq = node.args.slice(); + seq.push(node.expression.value); + CHANGED = true; + return to_sequence(seq); + } if (node.expression instanceof U.AST_Function) { // hoist and return expressions from the IIFE function expression var body = node.expression.body; |