Repository navigation
Fix object rest for-of lowering skipping direct body statement transformation - #65519
Open
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
Open
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
visitForOftatement, both the block and non-block branches visited eachbody statement's children without dispatching the statement's root through
the transformer. A nested
for-ofwith an object-rest binding thereforemissed its own lowering, and a direct function declaration missed its
parameter/body transformation, so valid source silently produced broken
output for targets below ES2018:
was emitted for ES2015/ES2017 as
for (const inner = __rest(void 0, []) of ...), which Node rejects with aSyntaxError; the function-declarationcase emitted a parameter without its destructuring prologue, throwing a
ReferenceErrorat runtime.This PR dispatches each body statement's root via
VisitNodein bothbranches, so nested loops and direct function declarations are lowered
correctly. Added
objectRestForOfDirectBodies.tscovering nested loopswith 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
VisitNodefix direction, and the regressioncoverage 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.