fix block-scoped function for ES6

fixes #1903
This commit is contained in:
alexlamsl
2017-05-27 19:13:09 +08:00
parent aa835eb0f6
commit 94d2aeee89
4 changed files with 23 additions and 17 deletions

View File

@@ -54,12 +54,12 @@ dead_code_2_should_warn: {
x = 10;
throw new Error("foo");
var x;
function g(){};
var g;
}
f();
}
expect_stdout: true
node_version: "<=4"
node_version: ">=6"
}
dead_code_2_should_warn_strict: {
@@ -99,7 +99,7 @@ dead_code_2_should_warn_strict: {
f();
}
expect_stdout: true
node_version: "=4"
node_version: ">=4"
}
dead_code_constant_boolean_should_warn_more: {
@@ -126,7 +126,7 @@ dead_code_constant_boolean_should_warn_more: {
}
expect: {
var foo;
function bar() {}
var bar;
// nothing for the while
// as for the for, it should keep:
var x = 10, y;
@@ -134,7 +134,7 @@ dead_code_constant_boolean_should_warn_more: {
bar();
}
expect_stdout: true
node_version: "<=4"
node_version: ">=6"
}
dead_code_constant_boolean_should_warn_more_strict: {
@@ -217,7 +217,7 @@ dead_code_const_declaration: {
var unused;
const CONST_FOO = !1;
var moo;
function bar() {}
var bar;
}
expect_stdout: true
}
@@ -245,7 +245,7 @@ dead_code_const_annotation: {
var unused;
var CONST_FOO_ANN = !1;
var moo;
function bar() {}
var bar;
}
expect_stdout: true
}
@@ -312,7 +312,7 @@ dead_code_const_annotation_complex_scope: {
var CONST_FOO_ANN = !1;
var unused_var_2;
var moo;
function bar() {}
var bar;
var beef = 'good';
var meat = 'beef';
var pork = 'bad';

View File

@@ -185,25 +185,25 @@ hoist_funs: {
console.log(6, typeof f, typeof g);
}
expect: {
function f() {}
function g() {}
console.log(1, typeof f, typeof g);
if (console.log(2, typeof f, typeof g))
console.log(3, typeof f, typeof g);
else {
console.log(4, typeof f, typeof g);
function f() {}
console.log(5, typeof f, typeof g);
}
console.log(6, typeof f, typeof g);
}
expect_stdout: [
"1 'function' 'function'",
"2 'function' 'function'",
"1 'undefined' 'function'",
"2 'undefined' 'function'",
"4 'function' 'function'",
"5 'function' 'function'",
"6 'function' 'function'",
]
node_version: "<=4"
node_version: ">=6"
}
hoist_funs_strict: {
@@ -243,5 +243,5 @@ hoist_funs_strict: {
"5 'function' 'function'",
"6 'undefined' 'function'",
]
node_version: "=4"
node_version: ">=4"
}

View File

@@ -134,9 +134,8 @@ defun_hoist_funs: {
expect: {
function e() {
function f() {}
function g() {}
function h() {}
!window;
if (window) function g() {}
}
}
}