diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-01-04 02:17:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 10:17:32 +0800 |
commit | 5fbbb43839d010ec609da3bf15308cb5b6f74dc5 (patch) | |
tree | 9676cdb73f92dddf88dbb93b75aa0b30d1dff923 /lib | |
parent | df2cfcb5fcd7e4549df5015580c838138cd24130 (diff) | |
download | tracifyjs-5fbbb43839d010ec609da3bf15308cb5b6f74dc5.tar.gz tracifyjs-5fbbb43839d010ec609da3bf15308cb5b6f74dc5.zip |
fix corner cases in `inline` & `side_effects` (#4503)
fixes #4502
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index ca2880ec..aedbe448 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8055,6 +8055,7 @@ merge(Compressor.prototype, { var stat = is_func && fn.first_statement(); var has_default = false; var can_drop = is_func && all(fn.argnames, function(argname, index) { + if (has_default && self.args[index] instanceof AST_Spread) return false; if (argname instanceof AST_DefaultValue) { has_default = true; var arg = self.args[index]; @@ -8062,7 +8063,7 @@ merge(Compressor.prototype, { var abort = false; argname.value.walk(new TreeWalker(function(node) { if (abort) return true; - if (node instanceof AST_SymbolRef && fn.find_variable(node.name) === node.definition()) { + if (node instanceof AST_SymbolRef && fn.variables.get(node.name) === node.definition()) { return abort = true; } })); @@ -8407,29 +8408,47 @@ merge(Compressor.prototype, { for (var i = self.args.length; --i >= len;) { expressions.push(self.args[i]); } + var default_args = []; for (i = len; --i >= 0;) { - var name = fn.argnames[i]; - var value = self.args[i]; - if (name instanceof AST_DefaultValue) { - value = value ? make_sequence(self, [ value, name.value ]) : name.value; - name = name.name; + var argname = fn.argnames[i]; + var name; + if (argname instanceof AST_DefaultValue) { + default_args.push(argname); + name = argname.name; + } else { + name = argname; } + var value = self.args[i]; if (name.__unused || scope.var_names()[name.name]) { if (value) expressions.push(value); } else { var symbol = make_node(AST_SymbolVar, name, name); name.definition().orig.push(symbol); - if (!value && in_loop) value = make_node(AST_Undefined, self); if ("__unused" in name) { append_var(decls, expressions, symbol); if (value) expressions.push(value); } else { + if (!value && in_loop && argname === name) value = make_node(AST_Undefined, self); append_var(decls, expressions, symbol, value); } } } decls.reverse(); expressions.reverse(); + for (i = default_args.length; --i >= 0;) { + var node = default_args[i]; + if ("__unused" in node.name) { + expressions.push(node.value); + } else { + var sym = make_node(AST_SymbolRef, node.name, node.name); + node.name.definition().references.push(sym); + expressions.push(make_node(AST_Assign, node, { + operator: "=", + left: sym, + right: node.value, + })); + } + } } function flatten_vars(decls, expressions) { |