-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block-level functions and web extensions #73
Comments
The behavior of the compatibility semantics (as I understand it) is as follows: For such functions, a var-scoped binding is created in the function body's scope, in addition to the lexical binding created in the block containing the function declaration. This additional binding is initially undefined. When the function declaration statement is executed, instead of the statement doing nothing (recall that function declarations are hoisted to the top of the containing block), the statement will fetch the value of the normal, lexical binding created by the declaration and set the additional var-scoped binding to that value. This can can lead to some surprising behavior. For example, the following snippet prints (function(){
{
f = 0;
function f(){};
}
console.log(f);
})(); Note also that there is currently a spec bug, which I just reported, which means that none of this will actually happen. |
It looks like a bug to me. I guess escope should use |
Ah, there is a comment above the line... |
I don't think there's anything wrong with the current behaviour. Even if it may work while not being recognised by this tool, you should strife to write valid code that does not rely on being executed in a legacy environment anyway. |
Context: http://stackoverflow.com/questions/31419897/what-are-the-precise-semantics-of-block-level-functions-in-es6
I'm not well versed with the ES6 spec details, but from my understanding, there is some optional behavior for block-level function declarations that
escope
does not take into account.In the following code:
the call to
bar
would not throw aReferenceError
if the web compatibility semantics extension is in effect.The
escope
output for this code with{ecmaVersion: 6}
does not link thebar
reference with thebar
declaration at all. Maybe an additionalwebExtensions
flag forescope.analyze
is needed.The text was updated successfully, but these errors were encountered: