fix sub-optimal optimisation

This commit is contained in:
alexlamsl 2017-04-18 16:51:12 +08:00
parent 5037c186e3
commit e9495bb82a
2 changed files with 42 additions and 3 deletions

View File

@ -722,10 +722,9 @@ merge(Compressor.prototype, {
var unwind = false; var unwind = false;
var tt = new TreeTransformer( var tt = new TreeTransformer(
function preorder(node) { function preorder(node) {
if (unwind) return node; if (unwind || node instanceof AST_Scope && node !== scope) return node;
var parent = tt.parent(); var parent = tt.parent();
if (node instanceof AST_Lambda if (node instanceof AST_Try
|| node instanceof AST_Try
|| node instanceof AST_With || node instanceof AST_With
|| node instanceof AST_Case || node instanceof AST_Case
|| node instanceof AST_IterationStatement || node instanceof AST_IterationStatement

View File

@ -1614,3 +1614,43 @@ reduce_vars_assign: {
} }
expect_stdout: "0" expect_stdout: "0"
} }
iife_1: {
options = {
collapse_vars: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var log = function(x) {
console.log(x);
}, foo = bar();
log(foo);
}
expect: {
(function(x) {
console.log(x);
})(bar());
}
}
iife_2: {
options = {
collapse_vars: true,
reduce_vars: false,
toplevel: true,
unused: false,
}
input: {
var foo = bar();
!function(x) {
console.log(x);
}(foo);
}
expect: {
!function(x) {
console.log(x);
}(bar());
}
}