enhance reduce_vars (#5171)
This commit is contained in:
@@ -613,12 +613,14 @@ merge(Compressor.prototype, {
|
|||||||
if (def.single_use == "m") return false;
|
if (def.single_use == "m") return false;
|
||||||
var safe = tw.safe_ids[def.id];
|
var safe = tw.safe_ids[def.id];
|
||||||
if (safe) {
|
if (safe) {
|
||||||
if (!HOP(tw.safe_ids, def.id)) safe.read = safe.read && safe.read !== tw.safe_ids ? true : tw.safe_ids;
|
var in_order = HOP(tw.safe_ids, def.id);
|
||||||
|
if (!in_order) safe.read = safe.read && safe.read !== tw.safe_ids ? true : tw.safe_ids;
|
||||||
if (def.fixed == null) {
|
if (def.fixed == null) {
|
||||||
if (is_arguments(def)) return false;
|
if (is_arguments(def)) return false;
|
||||||
if (def.global && def.name == "arguments") return false;
|
if (def.global && def.name == "arguments") return false;
|
||||||
tw.loop_ids[def.id] = null;
|
tw.loop_ids[def.id] = null;
|
||||||
def.fixed = make_node(AST_Undefined, def.orig[0]);
|
def.fixed = make_node(AST_Undefined, def.orig[0]);
|
||||||
|
if (in_order) delete def.safe_ids;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return !safe.assign || safe.assign === tw.safe_ids;
|
return !safe.assign || safe.assign === tw.safe_ids;
|
||||||
|
|||||||
@@ -3062,7 +3062,7 @@ issue_4184: {
|
|||||||
expect_stdout: "42"
|
expect_stdout: "42"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_4235: {
|
issue_4235_1: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -3081,13 +3081,37 @@ issue_4235: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
void function() {
|
void function() {
|
||||||
var f;
|
var f = console.log(f);
|
||||||
console.log(f);
|
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_4235_2: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
varify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
{
|
||||||
|
const f = 0;
|
||||||
|
}
|
||||||
|
(function f() {
|
||||||
|
var f = console.log(f);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(void 0);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
issue_4404: {
|
issue_4404: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ issue_2295: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_4487: {
|
issue_4487_1: {
|
||||||
options = {
|
options = {
|
||||||
functions: true,
|
functions: true,
|
||||||
hoist_vars: true,
|
hoist_vars: true,
|
||||||
@@ -152,14 +152,37 @@ issue_4487: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function a() {
|
function a() {
|
||||||
var f;
|
var f = console.log(typeof f);
|
||||||
console.log(typeof f);
|
|
||||||
}
|
}
|
||||||
a();
|
a();
|
||||||
}
|
}
|
||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_4487_2: {
|
||||||
|
options = {
|
||||||
|
functions: true,
|
||||||
|
hoist_vars: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = function f() {
|
||||||
|
var f = console.log(typeof f);
|
||||||
|
};
|
||||||
|
var b = a();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function a() {
|
||||||
|
console.log(typeof void 0);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
issue_4489: {
|
issue_4489: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
|||||||
@@ -7340,6 +7340,24 @@ local_assignment_modified: {
|
|||||||
expect_stdout: "42"
|
expect_stdout: "42"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local_declaration: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
a || console.log(a = "PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
local_definition_modified: {
|
local_definition_modified: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user