Skip to content

Fix object rest for-of lowering skipping direct body statement transformation - #65519

Open
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/object-rest-forof-visitnode-65513
Open

刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/object-rest-forof-visitnode-65513

Conversation

@zhengdaodeguL

Copy link
Copy Markdown

In visitForOftatement, both the block and non-block branches visited each
body statement's children without dispatching the statement's root through
the transformer. A nested for-of with an object-rest binding therefore
missed its own lowering, and a direct function declaration missed its
parameter/body transformation, so valid source silently produced broken
output for targets below ES2018:

for (const {...outer} of [{a: 1}]) {
    for (const {...inner} of [{b: 2}]) {
        sum += outer.a + inner.b;
    }
}

was emitted for ES2015/ES2017 as for (const inner = __rest(void 0, []) of ...), which Node rejects with a SyntaxError; the function-declaration
case emitted a parameter without its destructuring prologue, throwing a
ReferenceError at runtime.

This PR dispatches each body statement's root via VisitNode in both
branches, so nested loops and direct function declarations are lowered
correctly. Added objectRestForOfDirectBodies.ts covering nested loops
with and without blocks, a direct function declaration called before its
declaration, per-iteration closures, and continue, with ES2015/ES2017/
ES2018 baselines. The new test fails on the base commit for ES2015/ES2017
and passes with the fix; the existing object-rest and for-of tests pass,
and the reported repros now run correctly (3, 3, 6, 3, 2).

Credit: the root cause, the VisitNode fix direction, and the regression
coverage were identified by the issue reporter (Vl4dC), who investigated
this with Codex and prepared a local fix while waiting for the issue to be
milestoned.

Note: the JavaScript emitter (TypeScript 6.x) has the same pattern in its
for-of handling, so 6.x is affected too; this PR fixes the native (Go)
compiler only, and the JS-side fix is left as a follow-up.

Fixes #65513.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 20:37
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 15, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues have been identified for the object-rest for-of body transformation change.

No open issues 🎉

Review effort: Balanced

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

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Object-rest for-of lowering skips transformations on direct body statements

2 participants