Function declarations should be block scoped in ES2015 (#1952)

This commit is contained in:
Ondřej Španěl 2017-05-16 15:09:18 +02:00
parent 01f23cf5a1
commit 8223bf6568
2 changed files with 2 additions and 8 deletions

View File

@ -202,11 +202,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
// scope when we encounter the AST_Defun node (which is
// instanceof AST_Scope) but we get to the symbol a bit
// later.
var parent_lambda = defun.parent_scope;
while (parent_lambda.is_block_scope()) {
parent_lambda = parent_lambda.parent_scope;
}
(node.scope = parent_lambda).def_function(node, in_export, in_block);
(node.scope = defun.parent_scope).def_function(node, in_export, in_block);
}
else if (node instanceof AST_SymbolClass) {
defun.def_variable(node, in_export, in_block);

View File

@ -68,10 +68,9 @@ dead_code_constant_boolean_should_warn_more: {
side_effects : true,
};
input: {
while (!((foo && bar) || (x + "0"))) {
while (!(foo || (x + "0"))) {
console.log("unreachable");
var foo;
function bar() {}
}
for (var x = 10, y; x && (y || x) && (!typeof x); ++x) {
asdf();
@ -81,7 +80,6 @@ dead_code_constant_boolean_should_warn_more: {
}
expect: {
var foo;
function bar() {}
// nothing for the while
// as for the for, it should keep:
var x = 10, y;