diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-03-13 06:59:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-13 06:59:53 +0800 |
commit | e250396d7e9f494bc772bbee03c63a3912998b15 (patch) | |
tree | e38bef8954d989da1cff77ed6fe5274c8712785e /lib/compress.js | |
parent | c6fa39b48217983b3a498ad906fa630356694621 (diff) | |
download | tracifyjs-e250396d7e9f494bc772bbee03c63a3912998b15.tar.gz tracifyjs-e250396d7e9f494bc772bbee03c63a3912998b15.zip |
fix corner case in `arguments` (#3330)
Track modifications to `arguments[i]` under Strict Mode.
fixes #3273
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index 61c3a268..9109a696 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -497,6 +497,15 @@ merge(Compressor.prototype, { d.direct_access = true; } + function mark_assignment_to_arguments(node) { + if (!(node instanceof AST_Sub)) return; + var expr = node.expression; + var prop = node.property; + if (expr instanceof AST_SymbolRef && expr.name == "arguments" && prop instanceof AST_Number) { + expr.definition().reassigned = true; + } + } + var suppressor = new TreeWalker(function(node) { if (!(node instanceof AST_Symbol)) return; var d = node.definition(); @@ -515,7 +524,10 @@ merge(Compressor.prototype, { def(AST_Assign, function(tw, descend, compressor) { var node = this; var sym = node.left; - if (!(sym instanceof AST_SymbolRef)) return; + if (!(sym instanceof AST_SymbolRef)) { + mark_assignment_to_arguments(sym); + return; + } var d = sym.definition(); var safe = safe_to_assign(tw, d, sym.scope, node.right); d.assignments++; @@ -758,7 +770,10 @@ merge(Compressor.prototype, { var node = this; if (node.operator != "++" && node.operator != "--") return; var exp = node.expression; - if (!(exp instanceof AST_SymbolRef)) return; + if (!(exp instanceof AST_SymbolRef)) { + mark_assignment_to_arguments(exp); + return; + } var d = exp.definition(); var safe = safe_to_assign(tw, d, exp.scope, true); d.assignments++; @@ -6325,7 +6340,10 @@ merge(Compressor.prototype, { var argname = fn.argnames[index]; if (argname && compressor.has_directive("use strict")) { var def = argname.definition(); - if (!compressor.option("reduce_vars") || def.assignments || def.orig.length > 1) { + if (!compressor.option("reduce_vars") + || expr.definition().reassigned + || def.assignments + || def.orig.length > 1) { argname = null; } } else if (!argname && !compressor.option("keep_fargs") && index < fn.argnames.length + 5) { |