fix corner case in arguments & reduce_vars (#3331)

fixes #3282
This commit is contained in:
Alex Lam S.L
2019-03-13 08:46:03 +08:00
committed by GitHub
parent e250396d7e
commit d4ac84b255
2 changed files with 174 additions and 2 deletions

View File

@@ -6334,8 +6334,8 @@ merge(Compressor.prototype, {
&& expr instanceof AST_SymbolRef && expr instanceof AST_SymbolRef
&& expr.name == "arguments" && expr.name == "arguments"
&& expr.definition().orig.length == 1 && expr.definition().orig.length == 1
&& (fn = expr.scope) instanceof AST_Lambda && prop instanceof AST_Number
&& prop instanceof AST_Number) { && (fn = expr.scope) === compressor.find_parent(AST_Lambda)) {
var index = prop.getValue(); var index = prop.getValue();
var argname = fn.argnames[index]; var argname = fn.argnames[index];
if (argname && compressor.has_directive("use strict")) { if (argname && compressor.has_directive("use strict")) {

View File

@@ -404,3 +404,175 @@ issue_3273_global_strict_reduce_vars: {
"1 0", "1 0",
] ]
} }
issue_3282_1: {
options = {
arguments: true,
reduce_funcs: true,
reduce_vars: true,
keep_fargs: false,
unused: true,
}
input: {
(function(t) {
return function() {
t();
};
})(function() {
'use strict';
function e() {
return arguments[0];
}
e();
e();
})();
}
expect: {
(function() {
return function() {
(function() {
"use strict";
function e() {
return arguments[0];
}
e();
e();
})();
};
})()();
}
expect_stdout: true
}
issue_3282_1_passes: {
options = {
arguments: true,
passes: 2,
reduce_funcs: true,
reduce_vars: true,
keep_fargs: false,
unused: true,
}
input: {
(function(t) {
return function() {
t();
};
})(function() {
'use strict';
function e() {
return arguments[0];
}
e();
e();
})();
}
expect: {
(function() {
return function() {
(function() {
"use strict";
function e(argument_0) {
return argument_0;
}
e();
e();
})();
};
})()();
}
expect_stdout: true
}
issue_3282_2: {
options = {
arguments: true,
reduce_vars: true,
keep_fargs: false,
unused: true,
}
input: {
(function(f) {
f();
})(function() {
return (function(t) {
return function() {
t();
};
})(function() {
'use strict';
function e() {
return arguments[0];
}
e();
e();
})();
});
}
expect: {
(function() {
(function() {
return function(t) {
return function() {
t();
};
}(function() {
"use strict";
function e() {
return arguments[0];
}
e();
e();
})();
})();
})();
}
expect_stdout: true
}
issue_3282_2_passes: {
options = {
arguments: true,
passes: 2,
reduce_vars: true,
keep_fargs: false,
unused: true,
}
input: {
(function(f) {
f();
})(function() {
return (function(t) {
return function() {
t();
};
})(function() {
'use strict';
function e() {
return arguments[0];
}
e();
e();
})();
});
}
expect: {
(function() {
(function() {
return function(t) {
return function() {
t();
};
}(function() {
"use strict";
function e(argument_0) {
return argument_0;
}
e();
e();
})();
})();
})();
}
expect_stdout: true
}