Repository navigation
Give _super a setter for super properties in for-in/for-of heads of async methods - #65690
Open
Kaique da Silva (ktfth) wants to merge 2 commits into
Open
Kaique da Silva (ktfth) wants to merge 2 commits into
Kaique da Silva (ktfth) wants to merge 2 commits into
Conversation
… methods
The `_super` object of these methods only gets a getter, and `super["x"]`
becomes `_superIndex("x")`, an invalid assignment target.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7
…-of heads The initializer of a `for-in` or `for-of` statement is an assignment target, but the async super-access tracking never looked at it. Async function bodies also route these statements through `visitAsyncBodyNode`, which skipped `trackSuperAccess` for the statement itself. Track the statement there and treat its initializer like the left side of an assignment, so `_super` gets a setter and `super[x]` becomes `_superIndex(x).value`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A critical transform bug causes nested async arrows preceding a super-property loop write to return an accessor object instead of the base getter’s value at ES2015/ES2016 targets.
1 open issue
What changed in this PR
This PR addresses #65655 by recognizing super properties in for-in and for-of heads as assignment targets during async lowering.
Changes:
- Tracks loop-head assignments so generated super-access helpers include setters.
- Adds tracking to the async-body visitor path that bypasses the main visitor.
- Adds regression coverage and ES2015/ES2017 emit baselines for property, element, destructuring, and nested async cases.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/asyncMethodSuperPropertyForInOfTarget.ts |
Adds loop-head super-assignment regression cases. |
tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2017).js |
Records native async and lowered async-generator output. |
tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2015).js |
Records lowered async output with writable super helpers. |
tsc/internal/transformers/estransforms/utilities.go |
Recognizes loop initializers as super-assignment targets. |
tsc/internal/transformers/estransforms/async.go |
Tracks super assignments in specially handled async-body statements. |
Review effort: Balanced
Comment on lines
+278
to
+279
| if assignmentTargetContainsSuperProperty(node.Initializer()) { | ||
| s.hasSuperPropertyAssignment = true |
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.

Fixes #65655
This is an automated PR authored by Claude Code using Claude Opus 5.5 with high reasoning level.
Motivation & Guidance
Motivation:
The user filed #65655 with my help, after finding it with a runtime differential fuzzer. Once the issue was triaged into Backlog, they asked me to open PRs for their own issues that had no PR yet.
Guidance:
The prompt was "Crie os PR's para as issues livres" ("Create the PRs for the free issues"). The user also reminded me to fix the root cause for the whole class of inputs, not just the repro in the issue. No other implementation guidance was given.
Analysis
In an async method lowered below ES2017,
superaccesses become_super.x._superonly gets a setter whenhasSuperPropertyAssignmentis set.trackSuperAccesssets that flag for the left side of an assignment and for++/--operands, but never for the initializer of afor-inorfor-ofstatement, which is also an assignment target. Strada'sIsAssignmentTargetcovered those heads. The top-downassignmentTargetContainsSuperPropertythat replaced it does not.There was a second gap. In async function bodies,
for-in/for-ofstatements (and other statements that may hoist declarations) go throughvisitAsyncBodyNode, which never callstrackSuperAccessfor the statement node itself. Async generator bodies go throughvisit, which does. So a fix intrackSuperAccessalone only repaired async generators.As a result:
for (super.x of …)threwCannot set property x … which has only a getter.for (super["x"] of …)emittedfor (_superIndex("x") of …), which is not a valid assignment target (aSyntaxErrorat load time).Fix
trackSuperAccessnow treats the initializer of aForInStatementorForOfStatementlike the left side of an assignment. The existingassignmentTargetContainsSuperPropertycovers bare targets, parentheses, and array and object destructuring patterns.visitAsyncBodyNodecallstrackSuperAccessfor the statements it handles itself. That call is a no-op for every kind exceptfor-in/for-of.The new test
asyncMethodSuperPropertyForInOfTarget.ts(ES2015 and ES2017) covers these cases. Each now gets a setter, or_superIndex(x).value:for-ofandfor-inWrapped targets (
!,as,satisfies) are handled by the fix for #65641 (#65693), which changes the same helper.Verification
go test -timeout 0 ./internal/testrunner/ ./internal/transformers/...passes on this branch. The only baseline change is the new test.gofmtandgo vet ./internal/transformers/estransforms/are clean.--target esnext. The matrix crosses five hosts (async method, async arrow in a method, async generator, static async method, object-literal async method) with 19 read/call/tag/write positions, property and element access, and seven wrappers. Againstmainat ES2016/ES2017, this branch fixes all 96 bare and parenthesizedfor-in/for-ofdivergences and introduces none. The divergences that remain are the wrapped and tagged forms of Downlevel async methods losethisforsuper.mtagged templates and for wrappedsuper.m()calls, and turn wrappedsuper.x = vinto a getter-only write #65641. With both branches merged, all 1330 programs matchesnext.