From 8f344a6d55e9f5deaa9cb8c4ba322cce9e222dad Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Thu, 26 Nov 2026 00:17:44 -0300 Subject: [PATCH 1/3] test: add baseline for wrapped super calls, tags and writes in async 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 Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7 --- ...SuperWrappedCallsAndTags(target=es2015).js | 226 ++++++++++++++++++ ...SuperWrappedCallsAndTags(target=es2017).js | 171 +++++++++++++ .../asyncMethodSuperWrappedCallsAndTags.ts | 89 +++++++ 3 files changed, 486 insertions(+) create mode 100644 tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js create mode 100644 tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js create mode 100644 tsc/testdata/tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js new file mode 100644 index 0000000000000..9da119f7ec6c6 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js @@ -0,0 +1,226 @@ +//// [tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts] //// + +//// [asyncMethodSuperWrappedCallsAndTags.ts] +// https://github.com/microsoft/TypeScript/issues/65641 +// Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, +// and a `super` member written through any outer expression gets a setter, whatever +// parentheses, type assertions or non-null assertions wrap the reference. + +class B { + m(..._: unknown[]): any { } + get x(): any { return 0; } + set x(v: any) { } + static sm(..._: unknown[]): any { } +} + +class C extends B { + async calls() { + super.m(); + (super.m)(); + ((super.m))(); + (super.m as any)(); + (super.m satisfies unknown as any)(); + super.m!(); + (super.m)(); + (super.m as any)(await 0); + super["m"](); + (super["m"])(); + (super["m"] as any)(); + super["m"]!(); + } + + async tags() { + super.m`t`; + (super.m)`t`; + (super.m as any)`t${await 0}`; + super.m!`t`; + super["m"]`t`; + (super["m"] as any)`t`; + } + + async assignAs() { + (super.x as any) = 1; + } + + async assignSatisfies() { + (super.x satisfies any) = 1; + } + + async assignNonNull() { + super.x! = 1; + } + + async assignTypeAssertion() { + (super.x) = 1; + } + + async compoundAs() { + (super.x as any) += 1; + } + + async incrementNonNull() { + super.x!++; + } + + async destructuringWrapped() { + [(super.x as any)] = [1]; + ({ a: super.x! } = { a: 1 }); + } + + async elementAssignAs() { + (super["x"] as any) = 1; + } + + async *asyncGenerator() { + (super.m as any)(); + super.m`t`; + } + + async *assignAsyncGenerator() { + (super.x as any) = 1; + } + + static async staticCalls() { + (super.sm as any)(); + super.sm`t`; + } +} + + +//// [asyncMethodSuperWrappedCallsAndTags.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/65641 +// Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, +// and a `super` member written through any outer expression gets a setter, whatever +// parentheses, type assertions or non-null assertions wrap the reference. +class B { + m(..._) { } + get x() { return 0; } + set x(v) { } + static sm(..._) { } +} +class C extends B { + calls() { + const _superIndex = name => super[name]; + const _super = Object.create(null, { + m: { get: () => super.m } + }); + return __awaiter(this, void 0, void 0, function* () { + _super.m.call(this); + (_super.m)(); + ((_super.m))(); + _super.m(); + _super.m(); + _super.m(); + _super.m(); + _super.m(yield 0); + _superIndex("m").call(this); + (_superIndex("m"))(); + _superIndex("m")(); + _superIndex("m")(); + }); + } + tags() { + const _superIndex = name => super[name]; + const _super = Object.create(null, { + m: { get: () => super.m } + }); + return __awaiter(this, void 0, void 0, function* () { + _super.m `t`; + (_super.m) `t`; + _super.m `t${yield 0}`; + _super.m `t`; + _superIndex("m") `t`; + _superIndex("m") `t`; + }); + } + assignAs() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + _super.x = 1; + }); + } + assignSatisfies() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + _super.x = 1; + }); + } + assignNonNull() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + _super.x = 1; + }); + } + assignTypeAssertion() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + _super.x = 1; + }); + } + compoundAs() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + _super.x += 1; + }); + } + incrementNonNull() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + _super.x++; + }); + } + destructuringWrapped() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + [_super.x] = [1]; + ({ a: _super.x } = { a: 1 }); + }); + } + elementAssignAs() { + const _superIndex = name => super[name]; + return __awaiter(this, void 0, void 0, function* () { + _superIndex("x") = 1; + }); + } + asyncGenerator() { + const _super = Object.create(null, { + m: { get: () => super.m } + }); + return __asyncGenerator(this, arguments, function* asyncGenerator_1() { + _super.m(); + _super.m `t`; + }); + } + assignAsyncGenerator() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __asyncGenerator(this, arguments, function* assignAsyncGenerator_1() { + _super.x = 1; + }); + } + static staticCalls() { + const _super = Object.create(null, { + sm: { get: () => super.sm } + }); + return __awaiter(this, void 0, void 0, function* () { + _super.sm(); + _super.sm `t`; + }); + } +} diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js new file mode 100644 index 0000000000000..a95660be934e2 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js @@ -0,0 +1,171 @@ +//// [tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts] //// + +//// [asyncMethodSuperWrappedCallsAndTags.ts] +// https://github.com/microsoft/TypeScript/issues/65641 +// Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, +// and a `super` member written through any outer expression gets a setter, whatever +// parentheses, type assertions or non-null assertions wrap the reference. + +class B { + m(..._: unknown[]): any { } + get x(): any { return 0; } + set x(v: any) { } + static sm(..._: unknown[]): any { } +} + +class C extends B { + async calls() { + super.m(); + (super.m)(); + ((super.m))(); + (super.m as any)(); + (super.m satisfies unknown as any)(); + super.m!(); + (super.m)(); + (super.m as any)(await 0); + super["m"](); + (super["m"])(); + (super["m"] as any)(); + super["m"]!(); + } + + async tags() { + super.m`t`; + (super.m)`t`; + (super.m as any)`t${await 0}`; + super.m!`t`; + super["m"]`t`; + (super["m"] as any)`t`; + } + + async assignAs() { + (super.x as any) = 1; + } + + async assignSatisfies() { + (super.x satisfies any) = 1; + } + + async assignNonNull() { + super.x! = 1; + } + + async assignTypeAssertion() { + (super.x) = 1; + } + + async compoundAs() { + (super.x as any) += 1; + } + + async incrementNonNull() { + super.x!++; + } + + async destructuringWrapped() { + [(super.x as any)] = [1]; + ({ a: super.x! } = { a: 1 }); + } + + async elementAssignAs() { + (super["x"] as any) = 1; + } + + async *asyncGenerator() { + (super.m as any)(); + super.m`t`; + } + + async *assignAsyncGenerator() { + (super.x as any) = 1; + } + + static async staticCalls() { + (super.sm as any)(); + super.sm`t`; + } +} + + +//// [asyncMethodSuperWrappedCallsAndTags.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/65641 +// Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, +// and a `super` member written through any outer expression gets a setter, whatever +// parentheses, type assertions or non-null assertions wrap the reference. +class B { + m(..._) { } + get x() { return 0; } + set x(v) { } + static sm(..._) { } +} +class C extends B { + async calls() { + super.m(); + (super.m)(); + ((super.m))(); + super.m(); + super.m(); + super.m(); + super.m(); + super.m(await 0); + super["m"](); + (super["m"])(); + super["m"](); + super["m"](); + } + async tags() { + super.m `t`; + (super.m) `t`; + super.m `t${await 0}`; + super.m `t`; + super["m"] `t`; + super["m"] `t`; + } + async assignAs() { + super.x = 1; + } + async assignSatisfies() { + super.x = 1; + } + async assignNonNull() { + super.x = 1; + } + async assignTypeAssertion() { + super.x = 1; + } + async compoundAs() { + super.x += 1; + } + async incrementNonNull() { + super.x++; + } + async destructuringWrapped() { + [super.x] = [1]; + ({ a: super.x } = { a: 1 }); + } + async elementAssignAs() { + super["x"] = 1; + } + asyncGenerator() { + const _super = Object.create(null, { + m: { get: () => super.m } + }); + return __asyncGenerator(this, arguments, function* asyncGenerator_1() { + _super.m(); + _super.m `t`; + }); + } + assignAsyncGenerator() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __asyncGenerator(this, arguments, function* assignAsyncGenerator_1() { + _super.x = 1; + }); + } + static async staticCalls() { + super.sm(); + super.sm `t`; + } +} diff --git a/tsc/testdata/tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts b/tsc/testdata/tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts new file mode 100644 index 0000000000000..87c40a4896cb6 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts @@ -0,0 +1,89 @@ +// @target: es2015,es2017 +// @lib: esnext +// @noEmitHelpers: true +// @noTypesAndSymbols: true + +// https://github.com/microsoft/TypeScript/issues/65641 +// Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, +// and a `super` member written through any outer expression gets a setter, whatever +// parentheses, type assertions or non-null assertions wrap the reference. + +class B { + m(..._: unknown[]): any { } + get x(): any { return 0; } + set x(v: any) { } + static sm(..._: unknown[]): any { } +} + +class C extends B { + async calls() { + super.m(); + (super.m)(); + ((super.m))(); + (super.m as any)(); + (super.m satisfies unknown as any)(); + super.m!(); + (super.m)(); + (super.m as any)(await 0); + super["m"](); + (super["m"])(); + (super["m"] as any)(); + super["m"]!(); + } + + async tags() { + super.m`t`; + (super.m)`t`; + (super.m as any)`t${await 0}`; + super.m!`t`; + super["m"]`t`; + (super["m"] as any)`t`; + } + + async assignAs() { + (super.x as any) = 1; + } + + async assignSatisfies() { + (super.x satisfies any) = 1; + } + + async assignNonNull() { + super.x! = 1; + } + + async assignTypeAssertion() { + (super.x) = 1; + } + + async compoundAs() { + (super.x as any) += 1; + } + + async incrementNonNull() { + super.x!++; + } + + async destructuringWrapped() { + [(super.x as any)] = [1]; + ({ a: super.x! } = { a: 1 }); + } + + async elementAssignAs() { + (super["x"] as any) = 1; + } + + async *asyncGenerator() { + (super.m as any)(); + super.m`t`; + } + + async *assignAsyncGenerator() { + (super.x as any) = 1; + } + + static async staticCalls() { + (super.sm as any)(); + super.sm`t`; + } +} From 561bb5513dad0a3f308999906b0f1dd7ad69a796 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Thu, 26 Nov 2026 00:26:18 -0300 Subject: [PATCH 2/3] fix(65641): keep `this` for wrapped super calls and super tags in async 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`, ``) 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 Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7 --- .../transformers/estransforms/async.go | 5 +- .../transformers/estransforms/utilities.go | 60 +++++++++++++----- ...SuperWrappedCallsAndTags(target=es2015).js | 63 ++++++++++--------- ...SuperWrappedCallsAndTags(target=es2017).js | 6 +- 4 files changed, 85 insertions(+), 49 deletions(-) diff --git a/tsc/internal/transformers/estransforms/async.go b/tsc/internal/transformers/estransforms/async.go index 74a6aa18b3ef3..565a155c669ca 100644 --- a/tsc/internal/transformers/estransforms/async.go +++ b/tsc/internal/transformers/estransforms/async.go @@ -897,11 +897,12 @@ func (tx *asyncTransformer) transformAsyncFunctionBodyWorker(body *ast.Node) *as // This avoids relying on parent pointers (IsAssignmentTarget) which may not be set // on synthesized AST nodes from prior transforms. func assignmentTargetContainsSuperProperty(node *ast.Node) bool { + // An assignment target may be wrapped in parentheses, `!`, `as`, `satisfies` or ``; + // the type eraser has already turned the assertions into partially emitted expressions. + node = ast.SkipOuterExpressions(node, ast.OEKAll) switch node.Kind { case ast.KindPropertyAccessExpression, ast.KindElementAccessExpression: return node.Expression().Kind == ast.KindSuperKeyword - case ast.KindParenthesizedExpression: - return assignmentTargetContainsSuperProperty(node.AsParenthesizedExpression().Expression) case ast.KindArrayLiteralExpression: return slices.ContainsFunc(node.AsArrayLiteralExpression().Elements.Nodes, assignmentTargetContainsSuperProperty) case ast.KindObjectLiteralExpression: diff --git a/tsc/internal/transformers/estransforms/utilities.go b/tsc/internal/transformers/estransforms/utilities.go index f30003ba09cff..7aa9c9db2274d 100644 --- a/tsc/internal/transformers/estransforms/utilities.go +++ b/tsc/internal/transformers/estransforms/utilities.go @@ -78,10 +78,16 @@ func (s *superAccessState) visitSuperAccessNode(node *ast.Node) *ast.Node { switch node.Kind { case ast.KindCallExpression: call := node.AsCallExpression() - if ast.IsSuperProperty(call.Expression) { + if ast.IsSuperProperty(ast.SkipOuterExpressions(call.Expression, ast.OEKAll)) { return s.substituteCallExpressionWithSuperAccess(call, s.superAccessVisitor) } return s.superAccessVisitor.VisitEachChild(node) + case ast.KindTaggedTemplateExpression: + tagged := node.AsTaggedTemplateExpression() + if ast.IsSuperProperty(ast.SkipOuterExpressions(tagged.Tag, ast.OEKAll)) { + return s.substituteTaggedTemplateWithSuperAccess(tagged, s.superAccessVisitor) + } + return s.superAccessVisitor.VisitEachChild(node) case ast.KindPropertyAccessExpression: if node.Expression().Kind == ast.KindSuperKeyword { // super.x → _super.x @@ -112,28 +118,31 @@ func (s *superAccessState) substituteSuperAccessesInBody(body *ast.Node) *ast.No return s.superAccessVisitor.VisitNode(body) } -// substituteCallExpressionWithSuperAccess handles super.x(args) and super[x](args). -func (s *superAccessState) substituteCallExpressionWithSuperAccess(call *ast.CallExpression, visitor *ast.NodeVisitor) *ast.Node { - expression := call.Expression +// createSuperCallTarget replaces the super property in `expression`, which may be wrapped in +// parentheses or type assertions, with its _super/_superIndex reference and keeps the wrappers. +func (s *superAccessState) createSuperCallTarget(expression *ast.Expression) *ast.Expression { + superProperty := ast.SkipOuterExpressions(expression, ast.OEKAll) var target *ast.Node - - if ast.IsPropertyAccessExpression(expression) { - // super.x(args) → _super.x.call(this, args) + if ast.IsPropertyAccessExpression(superProperty) { target = s.factory.NewPropertyAccessExpression( s.superBinding, nil, - expression.AsPropertyAccessExpression().Name(), ast.NodeFlagsNone, + superProperty.AsPropertyAccessExpression().Name(), ast.NodeFlagsNone, ) - } else if ast.IsElementAccessExpression(expression) { - // super[x](args) → _superIndex(x).call(this, args) or _superIndex(x).value.call(this, args) + } else { target = s.createSuperElementAccessInAsyncMethod( - expression.AsElementAccessExpression().ArgumentExpression, + superProperty.AsElementAccessExpression().ArgumentExpression, ) - } else { - return visitor.VisitEachChild(call.AsNode()) } + return s.factory.RestoreOuterExpressions(expression, target, ast.OEKAll) +} +// substituteCallExpressionWithSuperAccess handles super.x(args) and super[x](args), including +// a callee wrapped in parentheses or type assertions such as (super.x as any)(args). +func (s *superAccessState) substituteCallExpressionWithSuperAccess(call *ast.CallExpression, visitor *ast.NodeVisitor) *ast.Node { + // super.x(args) → _super.x.call(this, args) + // super[x](args) → _superIndex(x).call(this, args) or _superIndex(x).value.call(this, args) callTarget := s.factory.NewPropertyAccessExpression( - target, nil, + s.createSuperCallTarget(call.Expression), nil, s.factory.NewIdentifier("call"), ast.NodeFlagsNone, ) @@ -154,6 +163,29 @@ func (s *superAccessState) substituteCallExpressionWithSuperAccess(call *ast.Cal return result } +// substituteTaggedTemplateWithSuperAccess handles super.x`...` and super[x]`...`, binding the +// tag to `this` the way a call through `.call(this, ...)` would. +func (s *superAccessState) substituteTaggedTemplateWithSuperAccess(node *ast.TaggedTemplateExpression, visitor *ast.NodeVisitor) *ast.Node { + // super.x`t` → _super.x.bind(this)`t` + bindTarget := s.factory.NewCallExpression( + s.factory.NewPropertyAccessExpression( + s.createSuperCallTarget(node.Tag), nil, + s.factory.NewIdentifier("bind"), ast.NodeFlagsNone, + ), + nil, nil, + s.factory.NewNodeList([]*ast.Node{s.factory.NewThisExpression()}), + ast.NodeFlagsNone, + ) + return s.factory.UpdateTaggedTemplateExpression( + node, + bindTarget, + node.QuestionDotToken, + nil, /*typeArguments*/ + visitor.VisitNode(node.Template), + node.Flags, + ) +} + // createSuperElementAccessInAsyncMethod creates _superIndex(x) or _superIndex(x).value. func (s *superAccessState) createSuperElementAccessInAsyncMethod(argumentExpression *ast.Node) *ast.Node { superIndexCall := s.factory.NewCallExpression( diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js index 9da119f7ec6c6..5bbecbd70247e 100644 --- a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js @@ -107,17 +107,17 @@ class C extends B { }); return __awaiter(this, void 0, void 0, function* () { _super.m.call(this); - (_super.m)(); - ((_super.m))(); - _super.m(); - _super.m(); - _super.m(); - _super.m(); - _super.m(yield 0); + (_super.m).call(this); + ((_super.m)).call(this); + _super.m.call(this); + _super.m.call(this); + _super.m.call(this); + _super.m.call(this); + _super.m.call(this, yield 0); + _superIndex("m").call(this); + (_superIndex("m")).call(this); + _superIndex("m").call(this); _superIndex("m").call(this); - (_superIndex("m"))(); - _superIndex("m")(); - _superIndex("m")(); }); } tags() { @@ -126,17 +126,17 @@ class C extends B { m: { get: () => super.m } }); return __awaiter(this, void 0, void 0, function* () { - _super.m `t`; - (_super.m) `t`; - _super.m `t${yield 0}`; - _super.m `t`; - _superIndex("m") `t`; - _superIndex("m") `t`; + _super.m.bind(this) `t`; + (_super.m).bind(this) `t`; + _super.m.bind(this) `t${yield 0}`; + _super.m.bind(this) `t`; + _superIndex("m").bind(this) `t`; + _superIndex("m").bind(this) `t`; }); } assignAs() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __awaiter(this, void 0, void 0, function* () { _super.x = 1; @@ -144,7 +144,7 @@ class C extends B { } assignSatisfies() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __awaiter(this, void 0, void 0, function* () { _super.x = 1; @@ -152,7 +152,7 @@ class C extends B { } assignNonNull() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __awaiter(this, void 0, void 0, function* () { _super.x = 1; @@ -160,7 +160,7 @@ class C extends B { } assignTypeAssertion() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __awaiter(this, void 0, void 0, function* () { _super.x = 1; @@ -168,7 +168,7 @@ class C extends B { } compoundAs() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __awaiter(this, void 0, void 0, function* () { _super.x += 1; @@ -176,7 +176,7 @@ class C extends B { } incrementNonNull() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __awaiter(this, void 0, void 0, function* () { _super.x++; @@ -184,7 +184,7 @@ class C extends B { } destructuringWrapped() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __awaiter(this, void 0, void 0, function* () { [_super.x] = [1]; @@ -192,9 +192,12 @@ class C extends B { }); } elementAssignAs() { - const _superIndex = name => super[name]; + const _superIndex = (function (geti, seti) { + const cache = Object.create(null); + return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); + })(name => super[name], (name, value) => super[name] = value); return __awaiter(this, void 0, void 0, function* () { - _superIndex("x") = 1; + _superIndex("x").value = 1; }); } asyncGenerator() { @@ -202,13 +205,13 @@ class C extends B { m: { get: () => super.m } }); return __asyncGenerator(this, arguments, function* asyncGenerator_1() { - _super.m(); - _super.m `t`; + _super.m.call(this); + _super.m.bind(this) `t`; }); } assignAsyncGenerator() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __asyncGenerator(this, arguments, function* assignAsyncGenerator_1() { _super.x = 1; @@ -219,8 +222,8 @@ class C extends B { sm: { get: () => super.sm } }); return __awaiter(this, void 0, void 0, function* () { - _super.sm(); - _super.sm `t`; + _super.sm.call(this); + _super.sm.bind(this) `t`; }); } } diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js index a95660be934e2..af7e697e17c43 100644 --- a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js @@ -152,13 +152,13 @@ class C extends B { m: { get: () => super.m } }); return __asyncGenerator(this, arguments, function* asyncGenerator_1() { - _super.m(); - _super.m `t`; + _super.m.call(this); + _super.m.bind(this) `t`; }); } assignAsyncGenerator() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __asyncGenerator(this, arguments, function* assignAsyncGenerator_1() { _super.x = 1; From e39f3e2932515a0cd1c332283b659f6515e86c9f Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Thu, 26 Nov 2026 01:38:04 -0300 Subject: [PATCH 3/3] fix(65641): replace super accesses inside the argument of super[...] 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 Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7 --- .../transformers/estransforms/utilities.go | 3 ++- ...SuperWrappedCallsAndTags(target=es2015).js | 25 +++++++++++++++++-- ...SuperWrappedCallsAndTags(target=es2017).js | 19 ++++++++++++-- .../asyncMethodSuperWrappedCallsAndTags.ts | 10 +++++++- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/tsc/internal/transformers/estransforms/utilities.go b/tsc/internal/transformers/estransforms/utilities.go index 7aa9c9db2274d..e7f6178382154 100644 --- a/tsc/internal/transformers/estransforms/utilities.go +++ b/tsc/internal/transformers/estransforms/utilities.go @@ -187,10 +187,11 @@ func (s *superAccessState) substituteTaggedTemplateWithSuperAccess(node *ast.Tag } // createSuperElementAccessInAsyncMethod creates _superIndex(x) or _superIndex(x).value. +// The argument is visited too, since it may itself contain super accesses (super[super.k]). func (s *superAccessState) createSuperElementAccessInAsyncMethod(argumentExpression *ast.Node) *ast.Node { superIndexCall := s.factory.NewCallExpression( s.superIndexBinding, nil, nil, - s.factory.NewNodeList([]*ast.Node{argumentExpression}), + s.factory.NewNodeList([]*ast.Node{s.superAccessVisitor.VisitNode(argumentExpression)}), ast.NodeFlagsNone, ) if s.hasSuperPropertyAssignment { diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js index 5bbecbd70247e..181173111f557 100644 --- a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2015).js @@ -4,12 +4,14 @@ // https://github.com/microsoft/TypeScript/issues/65641 // Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, // and a `super` member written through any outer expression gets a setter, whatever -// parentheses, type assertions or non-null assertions wrap the reference. +// parentheses, type assertions or non-null assertions wrap the reference. A super access +// inside the argument of `super[...]` is replaced too. class B { m(..._: unknown[]): any { } get x(): any { return 0; } set x(v: any) { } + get k(): "m" { return "m"; } static sm(..._: unknown[]): any { } } @@ -71,6 +73,12 @@ class C extends B { (super["x"] as any) = 1; } + async elementArgumentWithSuper() { + super[super.k](); + super[super.k]`t`; + return super[(super.k as "m")]; + } + async *asyncGenerator() { (super.m as any)(); super.m`t`; @@ -92,11 +100,13 @@ class C extends B { // https://github.com/microsoft/TypeScript/issues/65641 // Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, // and a `super` member written through any outer expression gets a setter, whatever -// parentheses, type assertions or non-null assertions wrap the reference. +// parentheses, type assertions or non-null assertions wrap the reference. A super access +// inside the argument of `super[...]` is replaced too. class B { m(..._) { } get x() { return 0; } set x(v) { } + get k() { return "m"; } static sm(..._) { } } class C extends B { @@ -200,6 +210,17 @@ class C extends B { _superIndex("x").value = 1; }); } + elementArgumentWithSuper() { + const _superIndex = name => super[name]; + const _super = Object.create(null, { + k: { get: () => super.k } + }); + return __awaiter(this, void 0, void 0, function* () { + _superIndex(_super.k).call(this); + _superIndex(_super.k).bind(this) `t`; + return _superIndex(_super.k); + }); + } asyncGenerator() { const _super = Object.create(null, { m: { get: () => super.m } diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js index af7e697e17c43..829e016f3273a 100644 --- a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperWrappedCallsAndTags(target=es2017).js @@ -4,12 +4,14 @@ // https://github.com/microsoft/TypeScript/issues/65641 // Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, // and a `super` member written through any outer expression gets a setter, whatever -// parentheses, type assertions or non-null assertions wrap the reference. +// parentheses, type assertions or non-null assertions wrap the reference. A super access +// inside the argument of `super[...]` is replaced too. class B { m(..._: unknown[]): any { } get x(): any { return 0; } set x(v: any) { } + get k(): "m" { return "m"; } static sm(..._: unknown[]): any { } } @@ -71,6 +73,12 @@ class C extends B { (super["x"] as any) = 1; } + async elementArgumentWithSuper() { + super[super.k](); + super[super.k]`t`; + return super[(super.k as "m")]; + } + async *asyncGenerator() { (super.m as any)(); super.m`t`; @@ -92,11 +100,13 @@ class C extends B { // https://github.com/microsoft/TypeScript/issues/65641 // Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, // and a `super` member written through any outer expression gets a setter, whatever -// parentheses, type assertions or non-null assertions wrap the reference. +// parentheses, type assertions or non-null assertions wrap the reference. A super access +// inside the argument of `super[...]` is replaced too. class B { m(..._) { } get x() { return 0; } set x(v) { } + get k() { return "m"; } static sm(..._) { } } class C extends B { @@ -147,6 +157,11 @@ class C extends B { async elementAssignAs() { super["x"] = 1; } + async elementArgumentWithSuper() { + super[super.k](); + super[super.k] `t`; + return super[super.k]; + } asyncGenerator() { const _super = Object.create(null, { m: { get: () => super.m } diff --git a/tsc/testdata/tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts b/tsc/testdata/tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts index 87c40a4896cb6..2032df436f05c 100644 --- a/tsc/testdata/tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts +++ b/tsc/testdata/tests/cases/compiler/asyncMethodSuperWrappedCallsAndTags.ts @@ -6,12 +6,14 @@ // https://github.com/microsoft/TypeScript/issues/65641 // Inside a lowered async body, a `super` member call or tag keeps `this` as its receiver, // and a `super` member written through any outer expression gets a setter, whatever -// parentheses, type assertions or non-null assertions wrap the reference. +// parentheses, type assertions or non-null assertions wrap the reference. A super access +// inside the argument of `super[...]` is replaced too. class B { m(..._: unknown[]): any { } get x(): any { return 0; } set x(v: any) { } + get k(): "m" { return "m"; } static sm(..._: unknown[]): any { } } @@ -73,6 +75,12 @@ class C extends B { (super["x"] as any) = 1; } + async elementArgumentWithSuper() { + super[super.k](); + super[super.k]`t`; + return super[(super.k as "m")]; + } + async *asyncGenerator() { (super.m as any)(); super.m`t`;