Skip to content

Keep this for wrapped super calls and super tags in downlevel async bodies, and detect wrapped super writes - #65693

Open
Kaique da Silva (ktfth) wants to merge 3 commits into
microsoft:mainfrom
ktfth:fix-65641-async-super-wrapped
Open

Kaique da Silva (ktfth) wants to merge 3 commits into
microsoft:mainfrom
ktfth:fix-65641-async-super-wrapped

Conversation

@ktfth

Copy link
Copy Markdown

Fixes #65641

This is an automated PR authored by Claude Code using Claude Opus 5.5 with high reasoning level.

Motivation & Guidance

Motivation:
The user filed #65641 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

An async method lowered below ES2017, or an async generator lowered below ES2018, replaces super.x with _super.x (or super[x] with _superIndex(x)) in a second pass, visitSuperAccessNode, after the type eraser has turned !, as, satisfies and <T> into partially emitted expressions. That pass and its tracking helper only recognized the bare shapes:

  1. Calls. Only a callee that is exactly super.m gets .call(this, ...). With (super.m)(), (super.m as any)(), super.m!() and so on, the callee is an outer expression, so the call ran with this set to the null-prototype _super object.
  2. Tags. TaggedTemplateExpression had no case at all, so super.m`t` became _super.m `t` and lost its receiver even without a wrapper.
  3. Writes. assignmentTargetContainsSuperProperty skipped parentheses but no other outer expression. (super.x as any) = 1, super.x! = 1, (<any>super.x) += 1, super.x!++ and wrapped destructuring targets left _super getter-only, so the write threw. (super["x"] as any) = 1 emitted _superIndex("x") = 1, which is invalid JS.
  4. Nested super in an element argument. The argument of super[...] was passed through without being visited, so super[super.k]() kept a raw super.k inside the generator body, which is a SyntaxError. 6.0 substituted it. This shares the cause (the substitution pass does not reach every super reference) and the code path of (1) and (2), so it is fixed here too.

Fix

All in estransforms:

  • visitSuperAccessNode checks the callee with ast.SkipOuterExpressions(…, OEKAll). The new createSuperCallTarget replaces the inner super property and restores the wrappers with RestoreOuterExpressions, the same approach as fix(65598): preserve this binding in wrapped private member calls #65602 for private names. (super.m as any)() becomes _super.m.call(this) and (super.m)() becomes (_super.m).call(this).
  • A new TaggedTemplateExpression case binds the tag: super.m`t` becomes _super.m.bind(this) `t` , as the class fields transform does for #private tags. The template literal's identity per call site is kept.
  • assignmentTargetContainsSuperProperty skips all outer expressions before inspecting the target, so every wrapped write position (=, compound, logical, ++/--, destructuring) gives _super a setter and _superIndex(x).value.
  • createSuperElementAccessInAsyncMethod visits its argument.

The new test asyncMethodSuperWrappedCallsAndTags.ts (ES2015 and ES2017) covers:

  • calls, tags and writes through each wrapper (parentheses, double parentheses, as, satisfies, !, <T>), for property and element access
  • an await in an argument and in a template
  • async generator methods
  • static async methods
  • super[super.k]

No other baseline changes. The for-in/for-of head case is #65655 (fixed separately in #65690), which touches the same tracking function.

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.
  • The repro in the issue now prints D D D D / D D / 1 at ES2016, the same as --target es2017.
  • 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 removes every call, tag and wrapped-write divergence and introduces none. What remains is the for-in/for-of heads of Regression from 6.0: downlevel async methods throw for for (super.x of ...) and for (super.x in ...) because _super only gets a getter #65655. With both branches merged, all 1330 programs match esnext.

…methods

Wrapped `super.m()` calls and every `super.m` tag lose `this`, and wrapped
writes leave `_super` getter-only (`super["x"]` becomes `_superIndex("x") = 1`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7
…nc bodies

The async super-access substitution only recognized a bare `super.m(...)` callee,
never looked at tagged templates, and only skipped parentheses when deciding
whether a super property is written. Skip all outer expressions (parentheses,
`!`, `as`, `satisfies`, `<T>`) in all three places:

- a wrapped callee becomes `(_super.m).call(this, ...)`, keeping the wrappers;
- a super tag becomes `_super.m.bind(this)` so the tag keeps its receiver;
- a wrapped write such as `(super.x as any) = 1` gives `_super` a setter and
  makes `super[x]` an assignable `_superIndex(x).value`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7
…in async bodies

`super[super.k]()` kept the inner `super.k` inside the generator body, which is a
SyntaxError (6.0 replaced it). Visit the element argument when building the
`_superIndex(...)` reference.

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.

🟢 Approval recommended

No active review issues were identified in the async-transform changes for wrapped super expressions.

No open issues 🎉

What changed in this PR

Fixes #65641 in the compiler’s async transforms by preserving this for wrapped super calls and tagged templates, and correctly handling wrapped writes.

Changes:

  • Preserve expression wrappers while supplying the correct receiver for super calls and tags.
  • Detect wrapped assignment targets and transform nested super references in computed accesses.
  • Add regression tests and ES2015/ES2017 emit baselines. The separate for-in/for-of issue remains scoped to #65690.
File Description
tsc/​testdata/​tests/​cases/​compiler/​asyncMethodSuperWrappedCallsAndTags.ts Tests wrapped calls, tags, writes, and nested computed accesses.
tsc/​testdata/​baselines/​reference/​compiler/​asyncMethodSuperWrappedCallsAndTags(target=es2017).js Records native async and lowered async-generator output.
tsc/​testdata/​baselines/​reference/​compiler/​asyncMethodSuperWrappedCallsAndTags(target=es2015).js Records corrected downlevel async output.
tsc/​internal/​transformers/​estransforms/​utilities.go Preserves receivers and transforms nested super accesses.
tsc/​internal/​transformers/​estransforms/​async.go Recognizes wrapped super assignment targets.

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.

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

2 participants