Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tsc/internal/transformers/estransforms/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tsc/internal/transformers/estransforms/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +278 to +279
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
//// [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, set: v => super.x = v }
});
return __awaiter(this, void 0, void 0, function* () {
for (_super.x of [1])
;
});
}
forInProperty() {
const _super = Object.create(null, {
x: { get: () => super.x, set: v => super.x = v }
});
return __awaiter(this, void 0, void 0, function* () {
for (_super.x in { k: 0 })
;
});
}
forOfElement() {
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").value of [1])
;
});
}
forInElement() {
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").value in { k: 0 })
;
});
}
forOfParenthesized() {
const _super = Object.create(null, {
x: { get: () => super.x, set: v => super.x = v }
});
return __awaiter(this, void 0, void 0, function* () {
for ((_super.x) of [1])
;
});
}
forOfArrayPattern() {
const _super = Object.create(null, {
x: { get: () => super.x, set: v => super.x = v }
});
return __awaiter(this, void 0, void 0, function* () {
for ([_super.x] of [[1]])
;
});
}
forOfObjectPattern() {
const _super = Object.create(null, {
x: { get: () => super.x, set: v => super.x = v }
});
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, 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 })
; });
});
}
forOfAsyncGenerator() {
const _super = Object.create(null, {
x: { get: () => super.x, set: v => super.x = v }
});
return __asyncGenerator(this, arguments, function* forOfAsyncGenerator_1() {
for (_super.x of [1])
;
});
}
forInElementAsyncGenerator() {
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").value in { k: 0 })
;
});
}
static forOfStatic() {
const _super = Object.create(null, {
x: { get: () => super.x, set: v => super.x = v }
});
return __awaiter(this, void 0, void 0, function* () {
for (_super.x of [1])
;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//// [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, set: v => super.x = v }
});
return __asyncGenerator(this, arguments, function* forOfAsyncGenerator_1() {
for (_super.x of [1])
;
});
}
forInElementAsyncGenerator() {
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").value in { k: 0 })
;
});
}
static async forOfStatic() {
for (super.x of [1])
;
}
}
Original file line number Diff line number Diff line change
@@ -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]);
}
}