aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-04-10 17:34:45 +0100
committerGitHub <noreply@github.com>2020-04-11 00:34:45 +0800
commita2b16e89a475d3f7744481a5e07e1c7168d878af (patch)
treea2dfdb279ace186b7725c3e479bc0994ee0ee62b /lib
parentb35f4c5a83247251922e1d695576db29e821aee1 (diff)
downloadtracifyjs-a2b16e89a475d3f7744481a5e07e1c7168d878af.tar.gz
tracifyjs-a2b16e89a475d3f7744481a5e07e1c7168d878af.zip
fix corner cases in `inline` (#3773)
fixes #3770 fixes #3771 fixes #3772
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 79614864..94b76670 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5828,14 +5828,17 @@ merge(Compressor.prototype, {
&& !(fn.name && fn instanceof AST_Function)
&& (value = can_flatten_body(stat))
&& (exp === fn
- || !recursive_ref(compressor, def = exp.definition) && fn.is_constant_expression(exp.scope))
+ || !recursive_ref(compressor, def = exp.definition()) && fn.is_constant_expression(exp.scope))
&& !fn.contains_this()) {
if (can_substitute_directly()) {
var args = self.args.slice();
args.push(value.clone(true).transform(new TreeTransformer(function(node) {
if (node instanceof AST_SymbolRef) {
var def = node.definition();
- if (fn.variables.get(node.name) !== def) return node;
+ if (fn.variables.get(node.name) !== def) {
+ if (exp !== fn) def.references.push(node);
+ return node;
+ }
var index = resolve_index(def);
var arg = args[index];
if (!arg) return make_node(AST_Undefined, self);
@@ -5931,10 +5934,14 @@ merge(Compressor.prototype, {
function can_substitute_directly() {
if (compressor.option("inline") <= 1 && fn.argnames.length) return;
- if (fn.variables.size() > fn.argnames.length + 1) return;
+ var var_count = fn.variables.size() - 1;
+ if (var_count > fn.argnames.length) return;
+ var var_names = [];
if (!all(fn.argnames, function(argname) {
+ push_uniq(var_names, argname.name);
return argname.definition().references.length < 2;
})) return;
+ if (var_count > var_names.length) return;
var abort = false;
var begin;
var in_order = [];