Skip to content

for var expression bindings and lexical declarations #1365

@leobalter

Description

@leobalter

I'd like to clarify something I've been reading from the specs, and verify if there is any action necessary.

for productions like for ( var f in [] ) { ... } and for (var f; ; ) { ... } we have the f binding name added to VarDeclaredNames of the for Statement. This happens from Static Semantics.

If it's a BlockStatement, we might encounter the Early SyntaxError when a lexical declared name also occurs in the VarDeclaredNames of the respective StatementList. Basically: { let f; var f; }.

Considering in the examples above for for, where bindings are appended to VarDeclaredNames, should this error also be observed?

Currently no engine observes the SyntaxError for cases like: for (var f in []) { let f; } and for (var f; ; ) { let f }.

So the possible solutions are:

  1. Am I missing any text in the spec saying this SyntaxError won't happen to names appended to VarDeclaredNames?
  2. We enforce the SyntaxError to be consistent and throw a SyntaxError also for names added to VarDeclaredNames and then redeclared as lexical names in the respective statement list? We add tests and expect all engines to fix this?
  3. We might add a text saying the Early Error doesn't observe names appended to the respective VarDeclaredNames from extensive productions. All browsers already comply to this behavior.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions