Skip to content

Recursive let/const references should error #2188

@JsonFreeman

Description

@JsonFreeman

The constructs:

let v = v;
const c = c;

should error because they are uses before definition. Indeed IE gives this error.

This also applies to:

for (let v = v; ; ) { }
for (let v in v) { }
for (let v of v) { }

For the latter two in particular, look at section 13.6.4.12 in the ES6 spec:

  1. Let oldEnv be the running execution context’s LexicalEnvironment.

  2. If TDZnames is not an empty List, then

    a. Assert: TDZnames has no duplicate entries.
    b. Let TDZ be NewDeclarativeEnvironment(oldEnv).
    c. For each string name in TDZnames, do

      i. Let status be TDZ.CreateMutableBinding(name, false).
      ii. Assert: status is never an abrupt completion.
    

    d. Set the running execution context’s LexicalEnvironment to TDZ.

  3. Let exprRef be the result of evaluating the production that is expr.

  4. Set the running execution context’s LexicalEnvironment to oldEnv.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptES6Relates to the ES6 SpecFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions