aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-08-21 03:35:34 +0100
committerGitHub <noreply@github.com>2020-08-21 10:35:34 +0800
commitfee677786ed35faa3eea7b9cd287730550ddd7d3 (patch)
treef7c6961b96148b6d257e073c751c0adb53efc50d /lib/compress.js
parentaa83ecdb3b1ab4c50cb8347b559e13c3dcf8b343 (diff)
downloadtracifyjs-fee677786ed35faa3eea7b9cd287730550ddd7d3.tar.gz
tracifyjs-fee677786ed35faa3eea7b9cd287730550ddd7d3.zip
fix corner case in `collapse_vars` (#4061)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js35
1 files changed, 21 insertions, 14 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f15776c8..595e5032 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1952,6 +1952,7 @@ merge(Compressor.prototype, {
function get_lvalues(expr) {
var lvalues = new Dictionary();
if (expr instanceof AST_VarDef) lvalues.add(expr.name.name, lhs);
+ var find_arguments = scope.uses_arguments && !compressor.has_directive("use strict");
var scan_toplevel = scope instanceof AST_Toplevel;
var tw = new TreeWalker(function(node) {
var value;
@@ -1960,21 +1961,27 @@ merge(Compressor.prototype, {
} else if (node instanceof AST_This) {
value = node;
}
- if (value) {
- lvalues.add(node.name, is_modified(compressor, tw, node, value, 0));
- } else if (scan_toplevel) {
- if (node.TYPE == "Call") {
- if (modify_toplevel) return;
- var exp = node.expression;
- if (exp instanceof AST_PropAccess) return;
- if (exp instanceof AST_Function && !exp.contains_this()) return;
- modify_toplevel = true;
- } else if (node instanceof AST_PropAccess && may_be_global(node.expression)) {
- if (node === lhs && !(expr instanceof AST_Unary)) {
- modify_toplevel = true;
- } else {
- read_toplevel = true;
+ if (value) lvalues.add(node.name, is_modified(compressor, tw, node, value, 0));
+ if (find_arguments && node instanceof AST_Sub) {
+ scope.argnames.forEach(function(argname) {
+ if (!compressor.option("reduce_vars") || argname.definition().assignments) {
+ lvalues.add(argname.name, true);
}
+ });
+ find_arguments = false;
+ }
+ if (!scan_toplevel) return;
+ if (node.TYPE == "Call") {
+ if (modify_toplevel) return;
+ var exp = node.expression;
+ if (exp instanceof AST_PropAccess) return;
+ if (exp instanceof AST_Function && !exp.contains_this()) return;
+ modify_toplevel = true;
+ } else if (node instanceof AST_PropAccess && may_be_global(node.expression)) {
+ if (node === lhs && !(expr instanceof AST_Unary)) {
+ modify_toplevel = true;
+ } else {
+ read_toplevel = true;
}
}
});