-
Notifications
You must be signed in to change notification settings - Fork 973
Implement B.3.5 (Closes #548) #620
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
Conversation
Thanks for your feedback, it's really hard for me to understand the spec. My understanding is that Your other code examples should fail imho because |
|
The scope tracking code doesn't appear to have been written with performance in mind, and it would definitely be valuable is someone revisits that to be more efficient. |
Hey @KFlash, I really appreciate you giving me feedback here since I'm pretty new to the ECMAScript spec. However, I have a hard time actually learning something from the feedback, because you don't respond to my answers but instead add new suggestions. If my answers above show some misunderstanding of the spec, I would really like you to follow up on them specifically and challenge my understanding so that I can learn something. |
That's what I thought, too, but the ECMAScript test suite test262 has a test with the following code: try {
throw null;
} catch (f) {
if (false) ; else function f() { return 123; }
} I don't understand how this should be different than your example. |
@adrianheine This is different because function declaration in if statements is allowed separately by B.3.4. |
Of course, but that test is explicitly not in strict mode :) |
I understand that function declaration in if statements is allowed in B.3.4. The question here is how a function declaration as consequent or alternate of an if statement behaves in terms of scoping. I suppose the sentence »Code matching this production is processed as if each matching occurrence of FunctionDeclaration[?Yield, ?Await, ~Default] was the sole StatementListItem of a BlockStatement occupying that position in the source code.« from B.3.4 is relevant for this, right? Unfortunately, as I pointed out in the initial post of this pull request, acorn currently parses functions as What about |
I would think that with
I guess I'm wrong about |
I've pushed 21e852f...e4108f3 to address this, which seem to at least increase the amount of test262 cases we pass. |
Spec: B.3.5
I'm not sure I actually got the semantics right, test262 unfortunately doesn't include any specific negative tests for B.3.5.
There's definitely a problem with function declarations in the catch block, but that's present in current trunk as well. As far as I understand it, function declarations should be handled as lexical bindings, but B.3.3.1 allows them to re-declare each other (as in
if (a) function f() {} else function f() {}
). Currently, they are handled asvar
bindings, which makes them behave wrongly incatch
blocks.