Function declarations should be block scoped in ES2015 (#1952)
This commit is contained in:
parent
01f23cf5a1
commit
8223bf6568
|
|
@ -202,11 +202,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||||
// scope when we encounter the AST_Defun node (which is
|
// scope when we encounter the AST_Defun node (which is
|
||||||
// instanceof AST_Scope) but we get to the symbol a bit
|
// instanceof AST_Scope) but we get to the symbol a bit
|
||||||
// later.
|
// later.
|
||||||
var parent_lambda = defun.parent_scope;
|
(node.scope = defun.parent_scope).def_function(node, in_export, in_block);
|
||||||
while (parent_lambda.is_block_scope()) {
|
|
||||||
parent_lambda = parent_lambda.parent_scope;
|
|
||||||
}
|
|
||||||
(node.scope = parent_lambda).def_function(node, in_export, in_block);
|
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolClass) {
|
else if (node instanceof AST_SymbolClass) {
|
||||||
defun.def_variable(node, in_export, in_block);
|
defun.def_variable(node, in_export, in_block);
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,9 @@ dead_code_constant_boolean_should_warn_more: {
|
||||||
side_effects : true,
|
side_effects : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
while (!((foo && bar) || (x + "0"))) {
|
while (!(foo || (x + "0"))) {
|
||||||
console.log("unreachable");
|
console.log("unreachable");
|
||||||
var foo;
|
var foo;
|
||||||
function bar() {}
|
|
||||||
}
|
}
|
||||||
for (var x = 10, y; x && (y || x) && (!typeof x); ++x) {
|
for (var x = 10, y; x && (y || x) && (!typeof x); ++x) {
|
||||||
asdf();
|
asdf();
|
||||||
|
|
@ -81,7 +80,6 @@ dead_code_constant_boolean_should_warn_more: {
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo;
|
var foo;
|
||||||
function bar() {}
|
|
||||||
// nothing for the while
|
// nothing for the while
|
||||||
// as for the for, it should keep:
|
// as for the for, it should keep:
|
||||||
var x = 10, y;
|
var x = 10, y;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user