Skip to content

Closure in a block can't see a binding declared later in the same block (ReferenceError) #11778

Description

@proggeramlug

Inside a plain { } block, a closure that refers to a const/let/class declared later in the same block throws a ReferenceError when it runs after that declaration. Node runs it fine. The same code at top level works in perry.

{
  const f = () => g;
  const g = 5;
  console.log(f());   // node: 5   perry: ReferenceError: g is not defined
}

It's the same with a class declared later in the block ({ const f = () => new SC(); class SC {} f(); } gives ReferenceError: SC is not defined). This was found while working on #11777 and reproduces on main before that change (6a61c2ceff), so it's not caused by #11777. It looks related to closed #6523. Probes are in secret-tests scratchpad/class-super/fw2.ts and fw3.ts.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions