From e8c88ed8740beb1365b232cc45ac47f89c0f5e3a Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Wed, 25 Nov 2026 23:35:57 -0300 Subject: [PATCH 1/2] test: add baseline for super property in for-of/for-in heads of async 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 Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7 --- ...perPropertyForInOfTarget(target=es2015).js | 167 ++++++++++++++++++ ...perPropertyForInOfTarget(target=es2017).js | 126 +++++++++++++ .../asyncMethodSuperPropertyForInOfTarget.ts | 61 +++++++ 3 files changed, 354 insertions(+) create mode 100644 tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2015).js create mode 100644 tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2017).js create mode 100644 tsc/testdata/tests/cases/compiler/asyncMethodSuperPropertyForInOfTarget.ts diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2015).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2015).js new file mode 100644 index 0000000000000..1f2a07c901d04 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2015).js @@ -0,0 +1,167 @@ +//// [tests/cases/compiler/asyncMethodSuperPropertyForInOfTarget.ts] //// + +//// [asyncMethodSuperPropertyForInOfTarget.ts] +// https://github.com/microsoft/TypeScript/issues/65655 +// A `super` property in the head of a `for-of` or `for-in` statement is an assignment +// target, so `_super` needs a setter (and `_superIndex` a `value` accessor). + +class B { + get x(): any { return 0; } + set x(v: any) { } + static get x(): any { return 0; } + static set x(v: any) { } +} + +class C extends B { + async forOfProperty() { + for (super.x of [1]); + } + + async forInProperty() { + for (super.x in { k: 0 }); + } + + async forOfElement() { + for (super["x"] of [1]); + } + + async forInElement() { + for (super["x"] in { k: 0 }); + } + + async forOfParenthesized() { + for ((super.x) of [1]); + } + + async forOfArrayPattern() { + for ([super.x] of [[1]]); + } + + async forOfObjectPattern() { + for ({ a: super.x } of [{ a: 1 }]); + } + + async forInAsyncArrow() { + return async () => { for (super.x in { k: 0 }); }; + } + + async *forOfAsyncGenerator() { + for (super.x of [1]); + } + + async *forInElementAsyncGenerator() { + for (super["x"] in { k: 0 }); + } + + static async forOfStatic() { + for (super.x of [1]); + } +} + + +//// [asyncMethodSuperPropertyForInOfTarget.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/65655 +// A `super` property in the head of a `for-of` or `for-in` statement is an assignment +// target, so `_super` needs a setter (and `_superIndex` a `value` accessor). +class B { + get x() { return 0; } + set x(v) { } + static get x() { return 0; } + static set x(v) { } +} +class C extends B { + forOfProperty() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + for (_super.x of [1]) + ; + }); + } + forInProperty() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + for (_super.x in { k: 0 }) + ; + }); + } + forOfElement() { + const _superIndex = name => super[name]; + return __awaiter(this, void 0, void 0, function* () { + for (_superIndex("x") of [1]) + ; + }); + } + forInElement() { + const _superIndex = name => super[name]; + return __awaiter(this, void 0, void 0, function* () { + for (_superIndex("x") in { k: 0 }) + ; + }); + } + forOfParenthesized() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + for ((_super.x) of [1]) + ; + }); + } + forOfArrayPattern() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + for ([_super.x] of [[1]]) + ; + }); + } + forOfObjectPattern() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + for ({ a: _super.x } of [{ a: 1 }]) + ; + }); + } + forInAsyncArrow() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + return () => __awaiter(this, void 0, void 0, function* () { for (_super.x in { k: 0 }) + ; }); + }); + } + forOfAsyncGenerator() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __asyncGenerator(this, arguments, function* forOfAsyncGenerator_1() { + for (_super.x of [1]) + ; + }); + } + forInElementAsyncGenerator() { + const _superIndex = name => super[name]; + return __asyncGenerator(this, arguments, function* forInElementAsyncGenerator_1() { + for (_superIndex("x") in { k: 0 }) + ; + }); + } + static forOfStatic() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __awaiter(this, void 0, void 0, function* () { + for (_super.x of [1]) + ; + }); + } +} diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2017).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2017).js new file mode 100644 index 0000000000000..a93dd2edc15cf --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2017).js @@ -0,0 +1,126 @@ +//// [tests/cases/compiler/asyncMethodSuperPropertyForInOfTarget.ts] //// + +//// [asyncMethodSuperPropertyForInOfTarget.ts] +// https://github.com/microsoft/TypeScript/issues/65655 +// A `super` property in the head of a `for-of` or `for-in` statement is an assignment +// target, so `_super` needs a setter (and `_superIndex` a `value` accessor). + +class B { + get x(): any { return 0; } + set x(v: any) { } + static get x(): any { return 0; } + static set x(v: any) { } +} + +class C extends B { + async forOfProperty() { + for (super.x of [1]); + } + + async forInProperty() { + for (super.x in { k: 0 }); + } + + async forOfElement() { + for (super["x"] of [1]); + } + + async forInElement() { + for (super["x"] in { k: 0 }); + } + + async forOfParenthesized() { + for ((super.x) of [1]); + } + + async forOfArrayPattern() { + for ([super.x] of [[1]]); + } + + async forOfObjectPattern() { + for ({ a: super.x } of [{ a: 1 }]); + } + + async forInAsyncArrow() { + return async () => { for (super.x in { k: 0 }); }; + } + + async *forOfAsyncGenerator() { + for (super.x of [1]); + } + + async *forInElementAsyncGenerator() { + for (super["x"] in { k: 0 }); + } + + static async forOfStatic() { + for (super.x of [1]); + } +} + + +//// [asyncMethodSuperPropertyForInOfTarget.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/65655 +// A `super` property in the head of a `for-of` or `for-in` statement is an assignment +// target, so `_super` needs a setter (and `_superIndex` a `value` accessor). +class B { + get x() { return 0; } + set x(v) { } + static get x() { return 0; } + static set x(v) { } +} +class C extends B { + async forOfProperty() { + for (super.x of [1]) + ; + } + async forInProperty() { + for (super.x in { k: 0 }) + ; + } + async forOfElement() { + for (super["x"] of [1]) + ; + } + async forInElement() { + for (super["x"] in { k: 0 }) + ; + } + async forOfParenthesized() { + for ((super.x) of [1]) + ; + } + async forOfArrayPattern() { + for ([super.x] of [[1]]) + ; + } + async forOfObjectPattern() { + for ({ a: super.x } of [{ a: 1 }]) + ; + } + async forInAsyncArrow() { + return async () => { for (super.x in { k: 0 }) + ; }; + } + forOfAsyncGenerator() { + const _super = Object.create(null, { + x: { get: () => super.x } + }); + return __asyncGenerator(this, arguments, function* forOfAsyncGenerator_1() { + for (_super.x of [1]) + ; + }); + } + forInElementAsyncGenerator() { + const _superIndex = name => super[name]; + return __asyncGenerator(this, arguments, function* forInElementAsyncGenerator_1() { + for (_superIndex("x") in { k: 0 }) + ; + }); + } + static async forOfStatic() { + for (super.x of [1]) + ; + } +} diff --git a/tsc/testdata/tests/cases/compiler/asyncMethodSuperPropertyForInOfTarget.ts b/tsc/testdata/tests/cases/compiler/asyncMethodSuperPropertyForInOfTarget.ts new file mode 100644 index 0000000000000..7bd4388489db1 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/asyncMethodSuperPropertyForInOfTarget.ts @@ -0,0 +1,61 @@ +// @target: es2015,es2017 +// @lib: esnext +// @noEmitHelpers: true +// @noTypesAndSymbols: true + +// https://github.com/microsoft/TypeScript/issues/65655 +// A `super` property in the head of a `for-of` or `for-in` statement is an assignment +// target, so `_super` needs a setter (and `_superIndex` a `value` accessor). + +class B { + get x(): any { return 0; } + set x(v: any) { } + static get x(): any { return 0; } + static set x(v: any) { } +} + +class C extends B { + async forOfProperty() { + for (super.x of [1]); + } + + async forInProperty() { + for (super.x in { k: 0 }); + } + + async forOfElement() { + for (super["x"] of [1]); + } + + async forInElement() { + for (super["x"] in { k: 0 }); + } + + async forOfParenthesized() { + for ((super.x) of [1]); + } + + async forOfArrayPattern() { + for ([super.x] of [[1]]); + } + + async forOfObjectPattern() { + for ({ a: super.x } of [{ a: 1 }]); + } + + async forInAsyncArrow() { + return async () => { for (super.x in { k: 0 }); }; + } + + async *forOfAsyncGenerator() { + for (super.x of [1]); + } + + async *forInElementAsyncGenerator() { + for (super["x"] in { k: 0 }); + } + + static async forOfStatic() { + for (super.x of [1]); + } +} From 45ecccd2d0be76d4f50a90777e410ed1db0c6680 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Wed, 25 Nov 2026 23:49:21 -0300 Subject: [PATCH 2/2] fix(65655): give `_super` a setter for super properties in for-in/for-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 Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7 --- .../transformers/estransforms/async.go | 3 ++ .../transformers/estransforms/utilities.go | 5 +++ ...perPropertyForInOfTarget(target=es2015).js | 37 ++++++++++++------- ...perPropertyForInOfTarget(target=es2017).js | 9 +++-- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tsc/internal/transformers/estransforms/async.go b/tsc/internal/transformers/estransforms/async.go index 74a6aa18b3ef3..e06ad276743a3 100644 --- a/tsc/internal/transformers/estransforms/async.go +++ b/tsc/internal/transformers/estransforms/async.go @@ -164,6 +164,9 @@ func (tx *asyncTransformer) visit(node *ast.Node) *ast.Node { func (tx *asyncTransformer) visitAsyncBodyNode(node *ast.Node) *ast.Node { if isNodeWithPossibleHoistedDeclaration(node) { + // These statements bypass `visit`, so their own super accesses are recorded here: + // the initializer of a `for-in` or `for-of` statement is an assignment target. + tx.trackSuperAccess(node) switch node.Kind { case ast.KindVariableStatement: return tx.visitVariableStatementInAsyncBody(node) diff --git a/tsc/internal/transformers/estransforms/utilities.go b/tsc/internal/transformers/estransforms/utilities.go index f30003ba09cff..5b46906c2ad86 100644 --- a/tsc/internal/transformers/estransforms/utilities.go +++ b/tsc/internal/transformers/estransforms/utilities.go @@ -273,6 +273,11 @@ func (s *superAccessState) trackSuperAccess(node *ast.Node) { if isUpdateExpression(node) && assignmentTargetContainsSuperProperty(node.AsPostfixUnaryExpression().Operand) { s.hasSuperPropertyAssignment = true } + case ast.KindForInStatement, ast.KindForOfStatement: + // `for (super.x in ...)` and `for (super.x of ...)` assign to the initializer on each iteration. + if assignmentTargetContainsSuperProperty(node.Initializer()) { + s.hasSuperPropertyAssignment = true + } } } diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2015).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2015).js index 1f2a07c901d04..68be14b7f4f90 100644 --- a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2015).js +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2015).js @@ -73,7 +73,7 @@ class B { class C extends B { forOfProperty() { 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* () { for (_super.x of [1]) @@ -82,7 +82,7 @@ class C extends B { } forInProperty() { 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* () { for (_super.x in { k: 0 }) @@ -90,22 +90,28 @@ class C extends B { }); } forOfElement() { - 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* () { - for (_superIndex("x") of [1]) + for (_superIndex("x").value of [1]) ; }); } forInElement() { - 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* () { - for (_superIndex("x") in { k: 0 }) + for (_superIndex("x").value in { k: 0 }) ; }); } forOfParenthesized() { 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* () { for ((_super.x) of [1]) @@ -114,7 +120,7 @@ class C extends B { } forOfArrayPattern() { 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* () { for ([_super.x] of [[1]]) @@ -123,7 +129,7 @@ class C extends B { } forOfObjectPattern() { 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* () { for ({ a: _super.x } of [{ a: 1 }]) @@ -132,7 +138,7 @@ class C extends B { } forInAsyncArrow() { 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* () { return () => __awaiter(this, void 0, void 0, function* () { for (_super.x in { k: 0 }) @@ -141,7 +147,7 @@ class C extends B { } forOfAsyncGenerator() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __asyncGenerator(this, arguments, function* forOfAsyncGenerator_1() { for (_super.x of [1]) @@ -149,15 +155,18 @@ class C extends B { }); } forInElementAsyncGenerator() { - 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 __asyncGenerator(this, arguments, function* forInElementAsyncGenerator_1() { - for (_superIndex("x") in { k: 0 }) + for (_superIndex("x").value in { k: 0 }) ; }); } static forOfStatic() { 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* () { for (_super.x of [1]) diff --git a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2017).js b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2017).js index a93dd2edc15cf..5ae505a980099 100644 --- a/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2017).js +++ b/tsc/testdata/baselines/reference/compiler/asyncMethodSuperPropertyForInOfTarget(target=es2017).js @@ -105,7 +105,7 @@ class C extends B { } forOfAsyncGenerator() { const _super = Object.create(null, { - x: { get: () => super.x } + x: { get: () => super.x, set: v => super.x = v } }); return __asyncGenerator(this, arguments, function* forOfAsyncGenerator_1() { for (_super.x of [1]) @@ -113,9 +113,12 @@ class C extends B { }); } forInElementAsyncGenerator() { - 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 __asyncGenerator(this, arguments, function* forInElementAsyncGenerator_1() { - for (_superIndex("x") in { k: 0 }) + for (_superIndex("x").value in { k: 0 }) ; }); }