Skip to content

fix(safe-js): honor TDZ in loop destructuring - #797

Open
wrestle-R wants to merge 1 commit into
poe-platform:mainfrom
wrestle-R:fix/safe-js-loop-binding-tdz
Open

wrestle-R wants to merge 1 commit into
poe-platform:mainfrom
wrestle-R:fix/safe-js-loop-binding-tdz

Conversation

@wrestle-R

Copy link
Copy Markdown

What changed

A destructuring default in a lexical loop declaration could read a same-named variable from the enclosing scope. The iteration scope now declares all of the pattern's lexical names before evaluating any defaults. Reading one before initialization throws a ReferenceError.

The regression covers for...in, for...of, and for await...of, along with var and defaults that read an already initialized binding.

Closes #796.

Validation

  • Reproduced eight failures on main. All 13 regression cases now pass.
  • Ran 764 tests in 15 interpreter, loop and generator suites, including iteration and snapshot restoration coverage.
  • Ran npm run build --workspace=@poe-code/safe-js, including 20 post-build checks, and npm run typecheck:fs --workspace=@poe-code/safe-js.
  • Ran ESLint on both changed files and Prettier on the new test. The interpreter file has existing Prettier drift. Formatting the before and after versions confirmed that the new lines add no drift.
  • Validation used the focused suites. The full interpreter matrix was not run to completion.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

safe-js: for (let { x: a = a } of ...) destructuring default reads outer binding instead of throwing TDZ ReferenceError

2 participants