fix corner cases with block-scoped functions (#4695)
This commit is contained in:
@@ -1454,3 +1454,47 @@ issue_4689: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_4691: {
|
||||
options = {
|
||||
if_return: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
function A() {}
|
||||
A.prototype.f = function() {
|
||||
if (!this)
|
||||
return;
|
||||
const a = "PA";
|
||||
function g(b) {
|
||||
h(a + b);
|
||||
}
|
||||
[ "SS" ].forEach(function(c) {
|
||||
g(c);
|
||||
});
|
||||
};
|
||||
function h(d) {
|
||||
console.log(d);
|
||||
}
|
||||
new A().f();
|
||||
}
|
||||
expect: {
|
||||
function A() {}
|
||||
A.prototype.f = function() {
|
||||
if (this) {
|
||||
const a = "PA";
|
||||
[ "SS" ].forEach(function(c) {
|
||||
g(c);
|
||||
});
|
||||
function g(b) {
|
||||
h(a + b);
|
||||
}
|
||||
}
|
||||
};
|
||||
function h(d) {
|
||||
console.log(d);
|
||||
}
|
||||
new A().f();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -53,8 +53,10 @@ dead_code_2_should_warn: {
|
||||
g();
|
||||
x = 10;
|
||||
throw new Error("foo");
|
||||
var x;
|
||||
function g(){};
|
||||
{
|
||||
var x;
|
||||
function g(){};
|
||||
}
|
||||
}
|
||||
f();
|
||||
}
|
||||
@@ -62,7 +64,6 @@ dead_code_2_should_warn: {
|
||||
expect_warnings: [
|
||||
"WARN: Dropping unreachable code [test/compress/dead-code.js:8,12]",
|
||||
]
|
||||
node_version: "<=4"
|
||||
}
|
||||
|
||||
dead_code_constant_boolean_should_warn_more: {
|
||||
@@ -88,8 +89,10 @@ dead_code_constant_boolean_should_warn_more: {
|
||||
bar();
|
||||
}
|
||||
expect: {
|
||||
var foo;
|
||||
function bar() {}
|
||||
{
|
||||
var foo;
|
||||
function bar() {}
|
||||
}
|
||||
// nothing for the while
|
||||
// as for the for, it should keep:
|
||||
var x = 10, y;
|
||||
|
||||
@@ -5018,9 +5018,12 @@ catch_no_argname: {
|
||||
try {
|
||||
throw a;
|
||||
} catch {
|
||||
console.log(a, a, a);
|
||||
function g() {
|
||||
return a;
|
||||
}
|
||||
console.log(a, a, g());
|
||||
}
|
||||
console.log(a, a, a);
|
||||
console.log(a, a, g());
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS PASS PASS",
|
||||
@@ -5558,3 +5561,140 @@ issue_4659_3: {
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
block_scope_1: {
|
||||
input: {
|
||||
console.log(typeof f);
|
||||
function f() {}
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof f);
|
||||
function f() {}
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
block_scope_1_compress: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
typeofs: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof f);
|
||||
function f() {}
|
||||
}
|
||||
expect: {
|
||||
console.log("function");
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
block_scope_2: {
|
||||
input: {
|
||||
{
|
||||
console.log(typeof f);
|
||||
}
|
||||
function f() {}
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof f);
|
||||
function f() {}
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
block_scope_2_compress: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
typeofs: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
{
|
||||
console.log(typeof f);
|
||||
}
|
||||
function f() {}
|
||||
}
|
||||
expect: {
|
||||
console.log("function");
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
block_scope_3: {
|
||||
input: {
|
||||
console.log(typeof f);
|
||||
{
|
||||
function f() {}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof f);
|
||||
{
|
||||
function f() {}
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
block_scope_3_compress: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
typeofs: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof f);
|
||||
{
|
||||
function f() {}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof f);
|
||||
{
|
||||
function f() {}
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
block_scope_4: {
|
||||
input: {
|
||||
{
|
||||
console.log(typeof f);
|
||||
function f() {}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof f);
|
||||
function f() {}
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
block_scope_4_compress: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
typeofs: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
{
|
||||
console.log(typeof f);
|
||||
function f() {}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
console.log("function");
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
@@ -1357,3 +1357,50 @@ issue_4689: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_4691: {
|
||||
options = {
|
||||
if_return: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function A() {}
|
||||
A.prototype.f = function() {
|
||||
if (!this)
|
||||
return;
|
||||
let a = "PA";
|
||||
function g(b) {
|
||||
h(a + b);
|
||||
}
|
||||
[ "SS" ].forEach(function(c) {
|
||||
g(c);
|
||||
});
|
||||
};
|
||||
function h(d) {
|
||||
console.log(d);
|
||||
}
|
||||
new A().f();
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
function A() {}
|
||||
A.prototype.f = function() {
|
||||
if (this) {
|
||||
let a = "PA";
|
||||
[ "SS" ].forEach(function(c) {
|
||||
g(c);
|
||||
});
|
||||
function g(b) {
|
||||
h(a + b);
|
||||
}
|
||||
}
|
||||
};
|
||||
function h(d) {
|
||||
console.log(d);
|
||||
}
|
||||
new A().f();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user