Skip to content

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
microsoft:mainfrom
ktfth:fix-65655-async-super-for-of
Open

Kaique da Silva (ktfth) wants to merge 2 commits into
microsoft:mainfrom
ktfth:fix-65655-async-super-for-of

Conversation

@ktfth

@ktfth Kaique da Silva (ktfth) commented Nov 26, 2026 •

Copy link
Copy Markdown

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, super accesses become _super.x. _super only gets a setter when hasSuperPropertyAssignment is set. trackSuperAccess sets that flag for the left side of an assignment and for ++/-- operands, but never for the initializer of a for-in or for-of statement, which is also an assignment target. Strada's IsAssignmentTarget covered those heads. The top-down assignmentTargetContainsSuperProperty that replaced it does not.

There was a second gap. In async function bodies, for-in/for-of statements (and other statements that may hoist declarations) go through visitAsyncBodyNode, which never calls trackSuperAccess for the statement node itself. Async generator bodies go through visit, which does. So a fix in trackSuperAccess alone only repaired async generators.

As a result:

  • for (super.x of …) threw Cannot set property x … which has only a getter.
  • for (super["x"] of …) emitted for (_superIndex("x") of …), which is not a valid assignment target (a SyntaxError at load time).

Fix

  • trackSuperAccess now treats the initializer of a ForInStatement or ForOfStatement like the left side of an assignment. The existing assignmentTargetContainsSuperProperty covers bare targets, parentheses, and array and object destructuring patterns.
  • visitAsyncBodyNode calls trackSuperAccess for the statements it handles itself. That call is a no-op for every kind except for-in/for-of.

The new test asyncMethodSuperPropertyForInOfTarget.ts (ES2015 and ES2017) covers these cases. Each now gets a setter, or _superIndex(x).value:

  • property and element access
  • for-of and for-in
  • a parenthesized target
  • array and object patterns
  • an async arrow inside an async method
  • async generators
  • a static async method

Wrapped 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.
  • gofmt and go vet ./internal/transformers/estransforms/ are clean.
  • Runtime differential: a matrix of 1330 programs runs each lowered output in node and compares it with --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. Against main at ES2016/ES2017, this branch fixes all 96 bare and parenthesized for-in/for-of divergences and introduces none. The divergences that remain are the wrapped and tagged forms of Downlevel async methods lose this for super.m tagged templates and for wrapped super.m() calls, and turn wrapped super.x = v into a getter-only write #65641. With both branches merged, all 1330 programs match esnext.

… 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

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.

🟡 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

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.

Regression from 6.0: downlevel async methods throw for for (super.x of ...) and for (super.x in ...) because _super only gets a getter

2 participants