fix corner case in merge_vars (#4151)
This commit is contained in:
@@ -4331,7 +4331,7 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
AST_Scope.DEFMETHOD("merge_variables", function(compressor) {
|
AST_Scope.DEFMETHOD("merge_variables", function(compressor) {
|
||||||
if (!compressor.option("merge_vars")) return;
|
if (!compressor.option("merge_vars")) return;
|
||||||
var self = this, segment = {};
|
var self = this, segment = {}, root;
|
||||||
var first = [], last = [], index = 0;
|
var first = [], last = [], index = 0;
|
||||||
var declarations = new Dictionary();
|
var declarations = new Dictionary();
|
||||||
var references = Object.create(null);
|
var references = Object.create(null);
|
||||||
@@ -4414,10 +4414,8 @@ merge(Compressor.prototype, {
|
|||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
push();
|
push();
|
||||||
segment.block = node;
|
segment.block = node;
|
||||||
if (node instanceof AST_Lambda && node.name) {
|
if (node === self) root = segment;
|
||||||
if (node !== self) segment.loop = true;
|
if (node instanceof AST_Lambda && node.name) references[node.name.definition().id] = false;
|
||||||
references[node.name.definition().id] = false;
|
|
||||||
}
|
|
||||||
descend();
|
descend();
|
||||||
pop();
|
pop();
|
||||||
return true;
|
return true;
|
||||||
@@ -4563,7 +4561,8 @@ merge(Compressor.prototype, {
|
|||||||
definition: def,
|
definition: def,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
refs.start = self;
|
if (segment.block !== self) return references[def.id] = false;
|
||||||
|
refs.start = root;
|
||||||
}
|
}
|
||||||
prev[def.id] = last.length;
|
prev[def.id] = last.length;
|
||||||
last.push({
|
last.push({
|
||||||
|
|||||||
@@ -2766,3 +2766,37 @@ issue_4139: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "object"
|
expect_stdout: "object"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lambda_reuse: {
|
||||||
|
options = {
|
||||||
|
merge_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a, b, f = function() {
|
||||||
|
console.log(a);
|
||||||
|
};
|
||||||
|
f();
|
||||||
|
a = "PASS";
|
||||||
|
b = "FAIL";
|
||||||
|
f();
|
||||||
|
if (console.log(typeof b))
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a, b, f = function() {
|
||||||
|
console.log(a);
|
||||||
|
};
|
||||||
|
f();
|
||||||
|
a = "PASS";
|
||||||
|
b = "FAIL";
|
||||||
|
f();
|
||||||
|
if (console.log(typeof b))
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"undefined",
|
||||||
|
"PASS",
|
||||||
|
"string",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user