Merge branch 'master' into harmony
This commit is contained in:
@@ -39,7 +39,7 @@ non_hoisted_function_after_return_2a: {
|
||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
||||
collapse_vars: false
|
||||
collapse_vars: false, passes: 2
|
||||
}
|
||||
input: {
|
||||
function foo(x) {
|
||||
@@ -57,20 +57,11 @@ non_hoisted_function_after_return_2a: {
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
// NOTE: Output is correct, but suboptimal. Not a regression. Can be improved in future.
|
||||
// This output is run through non_hoisted_function_after_return_2b with same flags.
|
||||
function foo(x) {
|
||||
if (x) {
|
||||
return bar(1);
|
||||
} else {
|
||||
return bar(2);
|
||||
var b;
|
||||
}
|
||||
var c = bar(3);
|
||||
return bar(x ? 1 : 2);
|
||||
function bar(x) {
|
||||
return 7 - x;
|
||||
}
|
||||
return b || c;
|
||||
}
|
||||
}
|
||||
expect_warnings: [
|
||||
@@ -79,7 +70,12 @@ non_hoisted_function_after_return_2a: {
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:51,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:51,16]",
|
||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:48,20]",
|
||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:55,21]"
|
||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:55,21]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:53,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
|
||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
|
||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -91,7 +87,6 @@ non_hoisted_function_after_return_2b: {
|
||||
collapse_vars: false
|
||||
}
|
||||
input: {
|
||||
// Note: output of test non_hoisted_function_after_return_2a run through compress again
|
||||
function foo(x) {
|
||||
if (x) {
|
||||
return bar(1);
|
||||
@@ -107,31 +102,20 @@ non_hoisted_function_after_return_2b: {
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
// the output we would have liked to see from non_hoisted_function_after_return_2a
|
||||
function foo(x) {
|
||||
return bar(x ? 1 : 2);
|
||||
function bar(x) { return 7 - x; }
|
||||
}
|
||||
}
|
||||
expect_warnings: [
|
||||
// Notice that some warnings are repeated by multiple compress passes.
|
||||
// Not a regression. There is room for improvement here.
|
||||
// Warnings should be cached and only output if unique.
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:102,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:102,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:106,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
|
||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:100,20]",
|
||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:102,16]"
|
||||
// duplicate warnings no longer emitted
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:95,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:95,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:97,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:101,12]",
|
||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:95,20]",
|
||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:97,16]"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
96
test/compress/issue-1052.js
Normal file
96
test/compress/issue-1052.js
Normal file
@@ -0,0 +1,96 @@
|
||||
multiple_functions: {
|
||||
options = { if_return: true, hoist_funs: false };
|
||||
input: {
|
||||
( function() {
|
||||
if ( !window ) {
|
||||
return;
|
||||
}
|
||||
|
||||
function f() {}
|
||||
function g() {}
|
||||
} )();
|
||||
}
|
||||
expect: {
|
||||
( function() {
|
||||
function f() {}
|
||||
function g() {}
|
||||
|
||||
// NOTE: other compression steps will reduce this
|
||||
// down to just `window`.
|
||||
if ( window );
|
||||
} )();
|
||||
}
|
||||
}
|
||||
|
||||
single_function: {
|
||||
options = { if_return: true, hoist_funs: false };
|
||||
input: {
|
||||
( function() {
|
||||
if ( !window ) {
|
||||
return;
|
||||
}
|
||||
|
||||
function f() {}
|
||||
} )();
|
||||
}
|
||||
expect: {
|
||||
( function() {
|
||||
function f() {}
|
||||
|
||||
if ( window );
|
||||
} )();
|
||||
}
|
||||
}
|
||||
|
||||
deeply_nested: {
|
||||
options = { if_return: true, hoist_funs: false };
|
||||
input: {
|
||||
( function() {
|
||||
if ( !window ) {
|
||||
return;
|
||||
}
|
||||
|
||||
function f() {}
|
||||
function g() {}
|
||||
|
||||
if ( !document ) {
|
||||
return;
|
||||
}
|
||||
|
||||
function h() {}
|
||||
} )();
|
||||
}
|
||||
expect: {
|
||||
( function() {
|
||||
function f() {}
|
||||
function g() {}
|
||||
|
||||
function h() {}
|
||||
|
||||
// NOTE: other compression steps will reduce this
|
||||
// down to just `window`.
|
||||
if ( window )
|
||||
if (document);
|
||||
} )();
|
||||
}
|
||||
}
|
||||
|
||||
not_hoisted_when_already_nested: {
|
||||
options = { if_return: true, hoist_funs: false };
|
||||
input: {
|
||||
( function() {
|
||||
if ( !window ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( foo ) function f() {}
|
||||
|
||||
} )();
|
||||
}
|
||||
expect: {
|
||||
( function() {
|
||||
if ( window )
|
||||
if ( foo ) function f() {}
|
||||
} )();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user