diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-11 19:26:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-12 03:26:12 +0800 |
commit | 83197ffdb3c9055b5699674e111d2dee390d5560 (patch) | |
tree | 76fb066c8c4d4510a5399560285a31b618eb054e /lib/compress.js | |
parent | 952765be66e45a10f59ef900a1bd4d90e38e9cf5 (diff) | |
download | tracifyjs-83197ffdb3c9055b5699674e111d2dee390d5560.tar.gz tracifyjs-83197ffdb3c9055b5699674e111d2dee390d5560.zip |
fix corner case in `evaluate` (#4645)
fixes #4644
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/compress.js b/lib/compress.js index 1eed09ba..38d25b15 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4368,6 +4368,7 @@ merge(Compressor.prototype, { } return !(sym instanceof AST_Destructured); })) return this; + if (fn.rest instanceof AST_Destructured) return this; if (!args && !ignore_side_effects) return this; var stat = fn.first_statement(); if (!(stat instanceof AST_Return)) { @@ -4394,18 +4395,8 @@ merge(Compressor.prototype, { if (!val) return; var cached_args = []; if (!args || all(fn.argnames, function(sym, i) { - if (sym instanceof AST_DefaultValue) sym = sym.name; - var def = sym.definition(); - if (def.orig[def.orig.length - 1] !== sym) return false; - var value = args[i]; - def.references.forEach(function(node) { - node._eval = function() { - return value; - }; - cached_args.push(node); - }); - return true; - }) || ignore_side_effects) { + return assign(sym, args[i]); + }) && !(fn.rest && !assign(fn.rest, args.slice(fn.argnames.length))) || ignore_side_effects) { fn.evaluating = true; val = val._eval(compressor, ignore_side_effects, cached, depth); delete fn.evaluating; @@ -4450,6 +4441,20 @@ merge(Compressor.prototype, { } } return this; + + function assign(sym, arg) { + if (sym instanceof AST_DefaultValue) sym = sym.name; + var def = sym.definition(); + if (def.orig[def.orig.length - 1] !== sym) return false; + var value = arg; + def.references.forEach(function(node) { + node._eval = function() { + return value; + }; + cached_args.push(node); + }); + return true; + } }); def(AST_New, return_this); def(AST_Template, function(compressor, ignore_side_effects, cached, depth) { |