binjs-ref icon indicating copy to clipboard operation
binjs-ref copied to clipboard

This name is both non-const-lexical-bound and var-bound

Open Yoric opened this issue 6 years ago • 9 comments

With the latest master, attempt to parse the following example:

function f(t, e) {
}
if (foo) // NO braces here.
    function f(t, e) {
    }

This fails with

This name is both non-const-lexical-bound and var-bound: IdentifierName(Dynamic("f"))', crates/binjs_es6/src/scopes.rs:251:13

Original file: https://player.ivideosmart.com/ivxplayer/v1/js/all.02201641.js

Yoric avatar Feb 26 '19 21:02 Yoric

@arai-a you have touched this code more recently than me, do you want to take a look?

Yoric avatar Feb 26 '19 21:02 Yoric

do you mean this is a regression?

arai-a avatar Feb 27 '19 00:02 arai-a

No, I mean that you may understand that piece of code better than I do these days :)

If I'm wrong, don't worry, I'll take a look at it this week.

Yoric avatar Feb 27 '19 04:02 Yoric

it's this case https://tc39.github.io/ecma262/#sec-functiondeclarations-in-ifstatement-statement-clauses and I think we don't handle Annex B things.

arai-a avatar Feb 27 '19 04:02 arai-a

See, I knew you knew that stuff better than me :)

Maybe we should find a way to fail gracefully instead of asserting?

Yoric avatar Feb 27 '19 04:02 Yoric

will try adding the handling, at least for strict mode.

arai-a avatar Feb 27 '19 04:02 arai-a

to properly handle non-strict-mode code, we need to add block statement, or something like that (maybe, new interface for implicit block?), in order to store scope information for the function. that needs to be handled in the spec I think. I'll address strict mode case here.

arai-a avatar Feb 27 '19 05:02 arai-a

we need to add block statement

Could you elaborate please? Where would it be inserted?

In non-strict code the second function is meant to shadow the first one if the condition is true, so they should share the same scope.

RReverser avatar Feb 28 '19 21:02 RReverser

I misunderstood the current situation. currently we're adding block with lexical scope for if (foo) { function f() {} }, but apparently that's wrong. (I was trying to align if (foo) function f() {} with that)

so, this should be fixed by changing the function declaration not-to-use lexical scope.

arai-a avatar Mar 01 '19 00:03 arai-a