-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Harmony - Function scope wrong #1952
Comments
While I cannot answer the question regarding ES6, I am fairly certain that the scope assignment happens within |
I have tried to confirm how this should work. I have found a StackOverflow question What are the precise semantics of block-level functions in ES6? about this, which IIUC says the behaviour I expect is guranteed only in strict mode. I am not sure if and how is Uglify distinguishing strict/non strict code and what is desired behaviour here. Should the new behaviour be applied only in the strict mode? |
In an ideal world we'd like it to work as the ES spec dictates, but since the spec is difficult to interpret we tend just accept whatever behavior node and Chrome have, and assume they've done their homework. So if you can test a few examples in |
@kzc I've been able to verify that node does block-scope function declarations when 'use strict' is applied
|
Thanks @fabiosantoscode. When the same test code you supplied is run through |
Thanks @fabiosantoscode @kzc for confirmation. |
When I analyse AST and symbol information of the following JS, the symbol
C
is considered global:Additionally, in the following code both
C
s are considered to be the same symbol:When I use
var
orclass
instead offunction
, the scoping seems correct, it is only seen with functions. When I wrap the function in IIFE, as follows, it is no longer global:I think in ES2015 function declaration should be block scoped, not function scoped (see http://2ality.com/2015/02/es6-scoping.html):
Can someone confirm the issue and perhaps give me some hint where this could be fixed? I would be glad to develop a PR for that if confirmed.
The text was updated successfully, but these errors were encountered: