fix escape analysis for AST_Throw (#2564)

This commit is contained in:
Alex Lam S.L
2017-12-08 02:54:37 +08:00
committed by GitHub
parent e20935c3f2
commit 74a2f53683
2 changed files with 164 additions and 1 deletions

View File

@@ -652,7 +652,7 @@ merge(Compressor.prototype, {
} }
if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right
|| parent instanceof AST_Call && node !== parent.expression || parent instanceof AST_Call && node !== parent.expression
|| parent instanceof AST_Return && node === parent.value && node.scope !== d.scope || parent instanceof AST_Exit && node === parent.value && node.scope !== d.scope
|| parent instanceof AST_VarDef && node === parent.value) { || parent instanceof AST_VarDef && node === parent.value) {
d.escaped = true; d.escaped = true;
return; return;

View File

@@ -4621,3 +4621,166 @@ issue_2560_2: {
} }
expect_stdout: "PASS" expect_stdout: "PASS"
} }
issue_2560_3: {
options = {
reduce_funcs: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
function main() {
var thing = baz();
if (thing !== (thing = baz()))
console.log("FAIL");
else
console.log("PASS");
}
function baz() {
try {
throw foo;
} catch (bar) {
return bar;
}
}
function foo() {}
main();
}
expect: {
function baz() {
try {
throw foo;
} catch (bar) {
return bar;
}
}
function foo() {}
(function() {
var thing = baz();
if (thing !== (thing = baz()))
console.log("FAIL");
else
console.log("PASS");
})();
}
expect_stdout: "PASS"
}
issue_2560_4: {
options = {
reduce_funcs: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
function main() {
var thing = baz();
if (thing !== (thing = baz()))
console.log("PASS");
else
console.log("FAIL");
}
function baz(s) {
function foo() {}
function bar() {}
return s ? foo : bar;
}
main();
}
expect: {
function baz(s) {
return s ? function() {} : function() {};
}
(function() {
var thing = baz();
if (thing !== (thing = baz()))
console.log("PASS");
else
console.log("FAIL");
})();
}
expect_stdout: "PASS"
}
issue_2560_5: {
options = {
reduce_funcs: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
function main() {
var thing = baz();
if (thing !== (thing = baz()))
console.log("PASS");
else
console.log("FAIL");
}
function baz() {
function foo() {}
function bar() {}
return foo, bar;
}
main();
}
expect: {
function baz() {
return function() {}, function() {};
}
(function() {
var thing = baz();
if (thing !== (thing = baz()))
console.log("PASS");
else
console.log("FAIL");
})();
}
expect_stdout: "PASS"
}
issue_2560_6: {
options = {
reduce_funcs: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
function main() {
var thing = baz();
if (thing !== (thing = baz()))
console.log("PASS");
else
console.log("FAIL");
}
function baz() {
function foo() {}
try {
throw foo;
} catch (bar) {
return bar;
}
}
main();
}
expect: {
function baz() {
try {
throw function() {};
} catch (bar) {
return bar;
}
}
(function() {
var thing = baz();
if (thing !== (thing = baz()))
console.log("PASS");
else
console.log("FAIL");
})();
}
expect_stdout: "PASS"
}