From bc937ca1d5281d49aaf567ff2d3dfed3a9bdde59 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Thu, 26 Nov 2026 00:39:03 -0300 Subject: [PATCH 1/2] test: add baselines for wrapped super references in static initializers The es2015 and es2021 outputs call wrapped `super.m` without `this`, drop the optional call of `super.m?.()`, and emit `Reflect.get(...)` as the target of wrapped assignments, updates and destructuring. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7 --- ...tializerWrappedReference(target=es2015).js | 160 ++++++++++++++++++ ...tializerWrappedReference(target=es2021).js | 148 ++++++++++++++++ ...tializerWrappedReference(target=es2022).js | 81 +++++++++ ...uperInStaticInitializerWrappedReference.ts | 42 +++++ 4 files changed, 431 insertions(+) create mode 100644 tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2015).js create mode 100644 tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2021).js create mode 100644 tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2022).js create mode 100644 tsc/testdata/tests/cases/compiler/superInStaticInitializerWrappedReference.ts diff --git a/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2015).js b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2015).js new file mode 100644 index 0000000000000..e31b6f6bc095e --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2015).js @@ -0,0 +1,160 @@ +//// [tests/cases/compiler/superInStaticInitializerWrappedReference.ts] //// + +//// [superInStaticInitializerWrappedReference.ts] +// A `super` property wrapped in parentheses, `!`, `as`, `satisfies` or a type assertion is still +// the same reference: calls must keep `this` and assignments must still go through `Reflect.set`. + +class B { + static x: any = 0; + static m(): any { return this; } + static t(..._: any[]): any { return this; } +} + +class D extends B { + static a = super.m(); + static b = (super.m)(); + static c = (super.m as any)(); + static d = super.m!(); + static e = (super.m satisfies any)(); + static f = (super.m)(); + static g = (super.m)?.(); + static h = super.m?.(); + static i = (super["m"] as any)(); + static j = (super.t)`x`; + static k = (super.t as any)`x`; + static l = ((super.x) = 1); + static { + (super.x as any) = 1; + super.x! = 2; + (super["x"] satisfies any) = 3; + (super.x as any) += 1; + (super.x as any)++; + --(super.x as any); + [(super.x)] = [1]; + [super.x!] = [2]; + ({ a: (super.x as any) } = { a: 3 }); + [(super.x) = 4] = []; + ({ a: (super["x"] as any) = 5 } = {}); + [, ...(super.x as any)] = [0, 1]; + ({ ...(super.x as any) } = {}); + } +} + + +//// [superInStaticInitializerWrappedReference.js] +"use strict"; +// A `super` property wrapped in parentheses, `!`, `as`, `satisfies` or a type assertion is still +// the same reference: calls must keep `this` and assignments must still go through `Reflect.set`. +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a; +var _b, _c; +class B { + static m() { return this; } + static t(..._) { return this; } +} +Object.defineProperty(B, "x", { + enumerable: true, + configurable: true, + writable: true, + value: 0 +}); +class D extends (_c = B) { +} +_b = D; +Object.defineProperty(D, "a", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "m", _b).call(_b) +}); +Object.defineProperty(D, "b", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.get(_c, "m", _b))() +}); +Object.defineProperty(D, "c", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "m", _b)() +}); +Object.defineProperty(D, "d", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "m", _b)() +}); +Object.defineProperty(D, "e", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "m", _b)() +}); +Object.defineProperty(D, "f", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "m", _b)() +}); +Object.defineProperty(D, "g", { + enumerable: true, + configurable: true, + writable: true, + value: (_a = (Reflect.get(_c, "m", _b))) === null || _a === void 0 ? void 0 : _a() +}); +Object.defineProperty(D, "h", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "m", _b).call(_b) +}); +Object.defineProperty(D, "i", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "m", _b)() +}); +Object.defineProperty(D, "j", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.get(_c, "t", _b)) `x` +}); +Object.defineProperty(D, "k", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "t", _b) `x` +}); +Object.defineProperty(D, "l", { + enumerable: true, + configurable: true, + writable: true, + value: ((Reflect.get(_c, "x", _b)) = 1) +}); +(() => { + Reflect.get(_c, "x", _b) = 1; + Reflect.get(_c, "x", _b) = 2; + Reflect.get(_c, "x", _b) = 3; + Reflect.get(_c, "x", _b) += 1; + Reflect.get(_c, "x", _b)++; + --Reflect.get(_c, "x", _b); + [(Reflect.get(_c, "x", _b))] = [1]; + [Reflect.get(_c, "x", _b)] = [2]; + ({ a: Reflect.get(_c, "x", _b) } = { a: 3 }); + [(Reflect.get(_c, "x", _b)) = 4] = []; + ({ a: Reflect.get(_c, "x", _b) = 5 } = {}); + [, ...Reflect.get(_c, "x", _b)] = [0, 1]; + (Reflect.get(_c, "x", _b) = __rest({}, [])); +})(); diff --git a/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2021).js b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2021).js new file mode 100644 index 0000000000000..dc67457a8c5e1 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2021).js @@ -0,0 +1,148 @@ +//// [tests/cases/compiler/superInStaticInitializerWrappedReference.ts] //// + +//// [superInStaticInitializerWrappedReference.ts] +// A `super` property wrapped in parentheses, `!`, `as`, `satisfies` or a type assertion is still +// the same reference: calls must keep `this` and assignments must still go through `Reflect.set`. + +class B { + static x: any = 0; + static m(): any { return this; } + static t(..._: any[]): any { return this; } +} + +class D extends B { + static a = super.m(); + static b = (super.m)(); + static c = (super.m as any)(); + static d = super.m!(); + static e = (super.m satisfies any)(); + static f = (super.m)(); + static g = (super.m)?.(); + static h = super.m?.(); + static i = (super["m"] as any)(); + static j = (super.t)`x`; + static k = (super.t as any)`x`; + static l = ((super.x) = 1); + static { + (super.x as any) = 1; + super.x! = 2; + (super["x"] satisfies any) = 3; + (super.x as any) += 1; + (super.x as any)++; + --(super.x as any); + [(super.x)] = [1]; + [super.x!] = [2]; + ({ a: (super.x as any) } = { a: 3 }); + [(super.x) = 4] = []; + ({ a: (super["x"] as any) = 5 } = {}); + [, ...(super.x as any)] = [0, 1]; + ({ ...(super.x as any) } = {}); + } +} + + +//// [superInStaticInitializerWrappedReference.js] +"use strict"; +// A `super` property wrapped in parentheses, `!`, `as`, `satisfies` or a type assertion is still +// the same reference: calls must keep `this` and assignments must still go through `Reflect.set`. +var _a, _b; +class B { + static m() { return this; } + static t(..._) { return this; } +} +Object.defineProperty(B, "x", { + enumerable: true, + configurable: true, + writable: true, + value: 0 +}); +class D extends (_b = B) { +} +_a = D; +Object.defineProperty(D, "a", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_b, "m", _a).call(_a) +}); +Object.defineProperty(D, "b", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.get(_b, "m", _a))() +}); +Object.defineProperty(D, "c", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_b, "m", _a)() +}); +Object.defineProperty(D, "d", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_b, "m", _a)() +}); +Object.defineProperty(D, "e", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_b, "m", _a)() +}); +Object.defineProperty(D, "f", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_b, "m", _a)() +}); +Object.defineProperty(D, "g", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.get(_b, "m", _a))?.() +}); +Object.defineProperty(D, "h", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_b, "m", _a).call(_a) +}); +Object.defineProperty(D, "i", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_b, "m", _a)() +}); +Object.defineProperty(D, "j", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.get(_b, "t", _a)) `x` +}); +Object.defineProperty(D, "k", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_b, "t", _a) `x` +}); +Object.defineProperty(D, "l", { + enumerable: true, + configurable: true, + writable: true, + value: ((Reflect.get(_b, "x", _a)) = 1) +}); +(() => { + Reflect.get(_b, "x", _a) = 1; + Reflect.get(_b, "x", _a) = 2; + Reflect.get(_b, "x", _a) = 3; + Reflect.get(_b, "x", _a) += 1; + Reflect.get(_b, "x", _a)++; + --Reflect.get(_b, "x", _a); + [(Reflect.get(_b, "x", _a))] = [1]; + [Reflect.get(_b, "x", _a)] = [2]; + ({ a: Reflect.get(_b, "x", _a) } = { a: 3 }); + [(Reflect.get(_b, "x", _a)) = 4] = []; + ({ a: Reflect.get(_b, "x", _a) = 5 } = {}); + [, ...Reflect.get(_b, "x", _a)] = [0, 1]; + ({ ...Reflect.get(_b, "x", _a) } = {}); +})(); diff --git a/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2022).js b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2022).js new file mode 100644 index 0000000000000..469ff8de17417 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2022).js @@ -0,0 +1,81 @@ +//// [tests/cases/compiler/superInStaticInitializerWrappedReference.ts] //// + +//// [superInStaticInitializerWrappedReference.ts] +// A `super` property wrapped in parentheses, `!`, `as`, `satisfies` or a type assertion is still +// the same reference: calls must keep `this` and assignments must still go through `Reflect.set`. + +class B { + static x: any = 0; + static m(): any { return this; } + static t(..._: any[]): any { return this; } +} + +class D extends B { + static a = super.m(); + static b = (super.m)(); + static c = (super.m as any)(); + static d = super.m!(); + static e = (super.m satisfies any)(); + static f = (super.m)(); + static g = (super.m)?.(); + static h = super.m?.(); + static i = (super["m"] as any)(); + static j = (super.t)`x`; + static k = (super.t as any)`x`; + static l = ((super.x) = 1); + static { + (super.x as any) = 1; + super.x! = 2; + (super["x"] satisfies any) = 3; + (super.x as any) += 1; + (super.x as any)++; + --(super.x as any); + [(super.x)] = [1]; + [super.x!] = [2]; + ({ a: (super.x as any) } = { a: 3 }); + [(super.x) = 4] = []; + ({ a: (super["x"] as any) = 5 } = {}); + [, ...(super.x as any)] = [0, 1]; + ({ ...(super.x as any) } = {}); + } +} + + +//// [superInStaticInitializerWrappedReference.js] +"use strict"; +// A `super` property wrapped in parentheses, `!`, `as`, `satisfies` or a type assertion is still +// the same reference: calls must keep `this` and assignments must still go through `Reflect.set`. +class B { + static x = 0; + static m() { return this; } + static t(..._) { return this; } +} +class D extends B { + static a = super.m(); + static b = (super.m)(); + static c = super.m(); + static d = super.m(); + static e = super.m(); + static f = super.m(); + static g = (super.m)?.(); + static h = super.m?.(); + static i = super["m"](); + static j = (super.t) `x`; + static k = super.t `x`; + static l = ((super.x) = 1); + static { + super.x = 1; + super.x = 2; + super["x"] = 3; + super.x += 1; + super.x++; + --super.x; + [(super.x)] = [1]; + [super.x] = [2]; + ({ a: super.x } = { a: 3 }); + [(super.x) = 4] = []; + ({ a: super["x"] = 5 } = {}); + [, ...super.x] = [0, 1]; + ({ ...super.x } = {}); + } +} diff --git a/tsc/testdata/tests/cases/compiler/superInStaticInitializerWrappedReference.ts b/tsc/testdata/tests/cases/compiler/superInStaticInitializerWrappedReference.ts new file mode 100644 index 0000000000000..0dd1876386bd1 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/superInStaticInitializerWrappedReference.ts @@ -0,0 +1,42 @@ +// @target: es2015, es2021, es2022 +// @useDefineForClassFields: true +// @noTypesAndSymbols: true + +// A `super` property wrapped in parentheses, `!`, `as`, `satisfies` or a type assertion is still +// the same reference: calls must keep `this` and assignments must still go through `Reflect.set`. + +class B { + static x: any = 0; + static m(): any { return this; } + static t(..._: any[]): any { return this; } +} + +class D extends B { + static a = super.m(); + static b = (super.m)(); + static c = (super.m as any)(); + static d = super.m!(); + static e = (super.m satisfies any)(); + static f = (super.m)(); + static g = (super.m)?.(); + static h = super.m?.(); + static i = (super["m"] as any)(); + static j = (super.t)`x`; + static k = (super.t as any)`x`; + static l = ((super.x) = 1); + static { + (super.x as any) = 1; + super.x! = 2; + (super["x"] satisfies any) = 3; + (super.x as any) += 1; + (super.x as any)++; + --(super.x as any); + [(super.x)] = [1]; + [super.x!] = [2]; + ({ a: (super.x as any) } = { a: 3 }); + [(super.x) = 4] = []; + ({ a: (super["x"] as any) = 5 } = {}); + [, ...(super.x as any)] = [0, 1]; + ({ ...(super.x as any) } = {}); + } +} From 3f01d7719f65f749710c2691be2000a96c5f4e76 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Thu, 26 Nov 2026 07:39:01 -0300 Subject: [PATCH 2/2] fix: lower wrapped super references in static initializers A `super` property wrapped in parentheses, `!`, `as`, `satisfies` or a type assertion is still the same reference. The call, tagged template, assignment, update and destructuring branches for `super` in static initializers now match on the target with those wrappers skipped, and wrapped array elements reach the target lowering. The call branch also keeps the `?.` of `super.m?.()`, which it used to drop. Fixes #65640 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7 --- .../transformers/estransforms/classfields.go | 62 ++++++++++++------- ...tializerWrappedReference(target=es2015).js | 59 +++++++++--------- ...tializerWrappedReference(target=es2021).js | 51 +++++++-------- 3 files changed, 95 insertions(+), 77 deletions(-) diff --git a/tsc/internal/transformers/estransforms/classfields.go b/tsc/internal/transformers/estransforms/classfields.go index 5513ec8111e84..4923d0ce2b991 100644 --- a/tsc/internal/transformers/estransforms/classfields.go +++ b/tsc/internal/transformers/estransforms/classfields.go @@ -382,20 +382,23 @@ func (tx *classFieldsTransformer) visitDestructuringAssignmentTarget(node *ast.N if ast.IsPropertyAccessExpression(node) && ast.IsPrivateIdentifier(node.AsPropertyAccessExpression().Name()) { return tx.wrapPrivateIdentifierForDestructuringTarget(node) } + // A target wrapped in parentheses or in a type assertion, `!` or `satisfies` (all erased to partially emitted + // expressions by now) is still the same reference, so it is lowered like the bare target. + target := ast.SkipOuterExpressions(node, ast.OEKPartiallyEmittedExpressions|ast.OEKParentheses) if tx.shouldTransformSuperInStaticInitializers && tx.currentClassElement != nil && - ast.IsSuperProperty(node) && + ast.IsSuperProperty(target) && isStaticPropertyDeclarationOrClassStaticBlock(tx.currentClassElement) && tx.lexicalEnvironment != nil && tx.lexicalEnvironment.data != nil { data := tx.lexicalEnvironment.data if data.facts&classFactsClassWasDecorated != 0 { - return tx.visitInvalidSuperProperty(node) + return tx.visitInvalidSuperProperty(target) } if data.classConstructor != nil && data.superClassReference != nil { var name *ast.Expression - if ast.IsElementAccessExpression(node) { - name = tx.Visitor().VisitNode(node.AsElementAccessExpression().ArgumentExpression) - } else if ast.IsPropertyAccessExpression(node) && ast.IsIdentifier(node.AsPropertyAccessExpression().Name()) { - name = tx.Factory().NewStringLiteralFromNode(node.AsPropertyAccessExpression().Name()) + if ast.IsElementAccessExpression(target) { + name = tx.Visitor().VisitNode(target.AsElementAccessExpression().ArgumentExpression) + } else if ast.IsPropertyAccessExpression(target) && ast.IsIdentifier(target.AsPropertyAccessExpression().Name()) { + name = tx.Factory().NewStringLiteralFromNode(target.AsPropertyAccessExpression().Name()) } if name != nil { temp := tx.Factory().NewTempVariable() @@ -1149,7 +1152,7 @@ func (tx *classFieldsTransformer) visitPreOrPostfixUnaryExpression(node *ast.Nod } if operator == ast.KindPlusPlusToken || operator == ast.KindMinusMinusToken { - operandSkipped := ast.SkipParentheses(operand) + operandSkipped := ast.SkipOuterExpressions(operand, ast.OEKPartiallyEmittedExpressions|ast.OEKParentheses) // Private identifier property access if ast.IsPropertyAccessExpression(operandSkipped) && ast.IsPrivateIdentifier(operandSkipped.Name()) { @@ -1315,7 +1318,7 @@ func (tx *classFieldsTransformer) visitCallExpression(node *ast.CallExpression) } if tx.shouldTransformSuperInStaticInitializers && tx.currentClassElement != nil && - ast.IsSuperProperty(node.Expression) && + ast.IsSuperProperty(expression) && isStaticPropertyDeclarationOrClassStaticBlock(tx.currentClassElement) && tx.lexicalEnvironment != nil && tx.lexicalEnvironment.data != nil && tx.lexicalEnvironment.data.classConstructor != nil { @@ -1323,10 +1326,22 @@ func (tx *classFieldsTransformer) visitCallExpression(node *ast.CallExpression) // super[x]() // converts `super.f(...)` into `Reflect.get(_baseTemp, "f", _classTemp).call(_classTemp, ...)` - invocation := tx.Factory().NewFunctionCallCall( - tx.Visitor().VisitNode(node.Expression), - tx.lexicalEnvironment.data.classConstructor, - tx.Visitor().VisitNodes(node.Arguments).Nodes, + // converts `super.f?.(...)` into `Reflect.get(_baseTemp, "f", _classTemp)?.call(_classTemp, ...)` + visitedTarget := tx.Factory().RestoreOuterExpressions(node.Expression, tx.Visitor().VisitNode(expression), ast.OEKAll) + visitedArgs := tx.Visitor().VisitNodes(node.Arguments) + allArgs := make([]*ast.Node, 0, 1+len(visitedArgs.Nodes)) + allArgs = append(allArgs, tx.lexicalEnvironment.data.classConstructor) + allArgs = append(allArgs, visitedArgs.Nodes...) + flags := ast.NodeFlagsNone + if node.QuestionDotToken != nil { + flags = ast.NodeFlagsOptionalChain + } + invocation := tx.Factory().NewCallExpression( + tx.Factory().NewPropertyAccessExpression(visitedTarget, node.QuestionDotToken, tx.Factory().NewIdentifier("call"), flags), + nil, /*questionDotToken*/ + nil, /*typeArguments*/ + tx.Factory().NewNodeList(allArgs), + node.Flags, ) tx.EmitContext().SetOriginal(invocation, node.AsNode()) invocation.Loc = node.Loc @@ -1361,13 +1376,13 @@ func (tx *classFieldsTransformer) visitTaggedTemplateExpression(node *ast.Tagged } if tx.shouldTransformSuperInStaticInitializers && tx.currentClassElement != nil && - ast.IsSuperProperty(node.Tag) && + ast.IsSuperProperty(tag) && isStaticPropertyDeclarationOrClassStaticBlock(tx.currentClassElement) && tx.lexicalEnvironment != nil && tx.lexicalEnvironment.data != nil && tx.lexicalEnvironment.data.classConstructor != nil { // converts `` super.f`x` `` into `` Reflect.get(_baseTemp, "f", _classTemp).bind(_classTemp)`x` `` invocation := tx.Factory().NewFunctionBindCall( - tx.Visitor().VisitNode(node.Tag), + tx.Factory().RestoreOuterExpressions(node.Tag, tx.Visitor().VisitNode(tag), ast.OEKAll), tx.lexicalEnvironment.data.classConstructor, nil, ) @@ -1521,7 +1536,7 @@ func (tx *classFieldsTransformer) visitBinaryExpression(node *ast.BinaryExpressi return result } } else if tx.shouldTransformSuperInStaticInitializers && tx.currentClassElement != nil && - ast.IsSuperProperty(node.Left) && + ast.IsSuperProperty(left) && isStaticPropertyDeclarationOrClassStaticBlock(tx.currentClassElement) && tx.lexicalEnvironment != nil && tx.lexicalEnvironment.data != nil { // super.x = ... @@ -1533,7 +1548,7 @@ func (tx *classFieldsTransformer) visitBinaryExpression(node *ast.BinaryExpressi return tx.Factory().UpdateBinaryExpression( node, nil, - tx.visitInvalidSuperProperty(node.Left), + tx.visitInvalidSuperProperty(left), nil, node.OperatorToken, tx.Visitor().VisitNode(node.Right), @@ -1541,10 +1556,10 @@ func (tx *classFieldsTransformer) visitBinaryExpression(node *ast.BinaryExpressi } if data.classConstructor != nil && data.superClassReference != nil { var setterName *ast.Expression - if ast.IsElementAccessExpression(node.Left) { - setterName = tx.Visitor().VisitNode(node.Left.AsElementAccessExpression().ArgumentExpression) - } else if ast.IsPropertyAccessExpression(node.Left) && ast.IsIdentifier(node.Left.AsPropertyAccessExpression().Name()) { - setterName = tx.Factory().NewStringLiteralFromNode(node.Left.AsPropertyAccessExpression().Name()) + if ast.IsElementAccessExpression(left) { + setterName = tx.Visitor().VisitNode(left.AsElementAccessExpression().ArgumentExpression) + } else if ast.IsPropertyAccessExpression(left) && ast.IsIdentifier(left.AsPropertyAccessExpression().Name()) { + setterName = tx.Factory().NewStringLiteralFromNode(left.AsPropertyAccessExpression().Name()) } if setterName != nil { // converts `super.x = 1` into `(Reflect.set(_baseTemp, "x", _a = 1, _classTemp), _a)` @@ -1565,8 +1580,8 @@ func (tx *classFieldsTransformer) visitBinaryExpression(node *ast.BinaryExpressi getterName, data.classConstructor, ) - tx.EmitContext().SetOriginal(superPropertyGet, node.Left) - superPropertyGet.Loc = node.Left.Loc + tx.EmitContext().SetOriginal(superPropertyGet, left) + superPropertyGet.Loc = left.Loc expression = tx.Factory().NewBinaryExpression( nil, superPropertyGet, @@ -3275,7 +3290,8 @@ func (tx *classFieldsTransformer) visitAssignmentRestElement(node *ast.Node) *as } func (tx *classFieldsTransformer) visitArrayAssignmentElement(node *ast.Node) *ast.Node { - if ast.IsArrayBindingOrAssignmentElement(node) { + // A wrapped element such as `(this.#x)` or `super.x!` is a target too. + if ast.IsArrayBindingOrAssignmentElement(node) || ast.IsOuterExpression(node, ast.OEKPartiallyEmittedExpressions|ast.OEKParentheses) { if ast.IsSpreadElement(node) { return tx.visitAssignmentRestElement(node) } diff --git a/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2015).js b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2015).js index e31b6f6bc095e..91f1053e97e51 100644 --- a/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2015).js +++ b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2015).js @@ -56,8 +56,8 @@ var __rest = (this && this.__rest) || function (s, e) { } return t; }; -var _a; -var _b, _c; +var _a, _b; +var _c, _d, _e; class B { static m() { return this; } static t(..._) { return this; } @@ -68,93 +68,94 @@ Object.defineProperty(B, "x", { writable: true, value: 0 }); -class D extends (_c = B) { +class D extends (_d = B) { } -_b = D; +_c = D; Object.defineProperty(D, "a", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_c, "m", _b).call(_b) + value: Reflect.get(_d, "m", _c).call(_c) }); Object.defineProperty(D, "b", { enumerable: true, configurable: true, writable: true, - value: (Reflect.get(_c, "m", _b))() + value: (Reflect.get(_d, "m", _c)).call(_c) }); Object.defineProperty(D, "c", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_c, "m", _b)() + value: Reflect.get(_d, "m", _c).call(_c) }); Object.defineProperty(D, "d", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_c, "m", _b)() + value: Reflect.get(_d, "m", _c).call(_c) }); Object.defineProperty(D, "e", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_c, "m", _b)() + value: Reflect.get(_d, "m", _c).call(_c) }); Object.defineProperty(D, "f", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_c, "m", _b)() + value: Reflect.get(_d, "m", _c).call(_c) }); Object.defineProperty(D, "g", { enumerable: true, configurable: true, writable: true, - value: (_a = (Reflect.get(_c, "m", _b))) === null || _a === void 0 ? void 0 : _a() + value: (_a = (Reflect.get(_d, "m", _c))) === null || _a === void 0 ? void 0 : _a.call(_c) }); Object.defineProperty(D, "h", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_c, "m", _b).call(_b) + value: (_b = Reflect.get(_d, "m", _c)) === null || _b === void 0 ? void 0 : _b.call(_c) }); Object.defineProperty(D, "i", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_c, "m", _b)() + value: Reflect.get(_d, "m", _c).call(_c) }); Object.defineProperty(D, "j", { enumerable: true, configurable: true, writable: true, - value: (Reflect.get(_c, "t", _b)) `x` + value: (Reflect.get(_d, "t", _c)).bind(_c) `x` }); Object.defineProperty(D, "k", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_c, "t", _b) `x` + value: Reflect.get(_d, "t", _c).bind(_c) `x` }); Object.defineProperty(D, "l", { enumerable: true, configurable: true, writable: true, - value: ((Reflect.get(_c, "x", _b)) = 1) + value: (Reflect.set(_d, "x", _e = 1, _c), _e) }); (() => { - Reflect.get(_c, "x", _b) = 1; - Reflect.get(_c, "x", _b) = 2; - Reflect.get(_c, "x", _b) = 3; - Reflect.get(_c, "x", _b) += 1; - Reflect.get(_c, "x", _b)++; - --Reflect.get(_c, "x", _b); - [(Reflect.get(_c, "x", _b))] = [1]; - [Reflect.get(_c, "x", _b)] = [2]; - ({ a: Reflect.get(_c, "x", _b) } = { a: 3 }); - [(Reflect.get(_c, "x", _b)) = 4] = []; - ({ a: Reflect.get(_c, "x", _b) = 5 } = {}); - [, ...Reflect.get(_c, "x", _b)] = [0, 1]; - (Reflect.get(_c, "x", _b) = __rest({}, [])); + var _a, _b; + Reflect.set(_d, "x", 1, _c); + Reflect.set(_d, "x", 2, _c); + Reflect.set(_d, "x", 3, _c); + Reflect.set(_d, "x", Reflect.get(_d, "x", _c) + 1, _c); + Reflect.set(_d, "x", (_a = Reflect.get(_d, "x", _c), _a++, _a), _c); + Reflect.set(_d, "x", (_b = Reflect.get(_d, "x", _c), --_b), _c); + [({ set value(_a) { Reflect.set(_d, "x", _a, _c); } }).value] = [1]; + [({ set value(_a) { Reflect.set(_d, "x", _a, _c); } }).value] = [2]; + ({ a: ({ set value(_a) { Reflect.set(_d, "x", _a, _c); } }).value } = { a: 3 }); + [({ set value(_a) { Reflect.set(_d, "x", _a, _c); } }).value = 4] = []; + ({ a: ({ set value(_a) { Reflect.set(_d, "x", _a, _c); } }).value = 5 } = {}); + [, ...({ set value(_a) { Reflect.set(_d, "x", _a, _c); } }).value] = [0, 1]; + (({ set value(_a) { Reflect.set(_d, "x", _a, _c); } }).value = __rest({}, [])); })(); diff --git a/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2021).js b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2021).js index dc67457a8c5e1..333878c90908d 100644 --- a/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2021).js +++ b/tsc/testdata/baselines/reference/compiler/superInStaticInitializerWrappedReference(target=es2021).js @@ -45,7 +45,7 @@ class D extends B { "use strict"; // A `super` property wrapped in parentheses, `!`, `as`, `satisfies` or a type assertion is still // the same reference: calls must keep `this` and assignments must still go through `Reflect.set`. -var _a, _b; +var _a, _b, _c; class B { static m() { return this; } static t(..._) { return this; } @@ -69,80 +69,81 @@ Object.defineProperty(D, "b", { enumerable: true, configurable: true, writable: true, - value: (Reflect.get(_b, "m", _a))() + value: (Reflect.get(_b, "m", _a)).call(_a) }); Object.defineProperty(D, "c", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_b, "m", _a)() + value: Reflect.get(_b, "m", _a).call(_a) }); Object.defineProperty(D, "d", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_b, "m", _a)() + value: Reflect.get(_b, "m", _a).call(_a) }); Object.defineProperty(D, "e", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_b, "m", _a)() + value: Reflect.get(_b, "m", _a).call(_a) }); Object.defineProperty(D, "f", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_b, "m", _a)() + value: Reflect.get(_b, "m", _a).call(_a) }); Object.defineProperty(D, "g", { enumerable: true, configurable: true, writable: true, - value: (Reflect.get(_b, "m", _a))?.() + value: (Reflect.get(_b, "m", _a))?.call(_a) }); Object.defineProperty(D, "h", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_b, "m", _a).call(_a) + value: Reflect.get(_b, "m", _a)?.call(_a) }); Object.defineProperty(D, "i", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_b, "m", _a)() + value: Reflect.get(_b, "m", _a).call(_a) }); Object.defineProperty(D, "j", { enumerable: true, configurable: true, writable: true, - value: (Reflect.get(_b, "t", _a)) `x` + value: (Reflect.get(_b, "t", _a)).bind(_a) `x` }); Object.defineProperty(D, "k", { enumerable: true, configurable: true, writable: true, - value: Reflect.get(_b, "t", _a) `x` + value: Reflect.get(_b, "t", _a).bind(_a) `x` }); Object.defineProperty(D, "l", { enumerable: true, configurable: true, writable: true, - value: ((Reflect.get(_b, "x", _a)) = 1) + value: (Reflect.set(_b, "x", _c = 1, _a), _c) }); (() => { - Reflect.get(_b, "x", _a) = 1; - Reflect.get(_b, "x", _a) = 2; - Reflect.get(_b, "x", _a) = 3; - Reflect.get(_b, "x", _a) += 1; - Reflect.get(_b, "x", _a)++; - --Reflect.get(_b, "x", _a); - [(Reflect.get(_b, "x", _a))] = [1]; - [Reflect.get(_b, "x", _a)] = [2]; - ({ a: Reflect.get(_b, "x", _a) } = { a: 3 }); - [(Reflect.get(_b, "x", _a)) = 4] = []; - ({ a: Reflect.get(_b, "x", _a) = 5 } = {}); - [, ...Reflect.get(_b, "x", _a)] = [0, 1]; - ({ ...Reflect.get(_b, "x", _a) } = {}); + var _c, _d; + Reflect.set(_b, "x", 1, _a); + Reflect.set(_b, "x", 2, _a); + Reflect.set(_b, "x", 3, _a); + Reflect.set(_b, "x", Reflect.get(_b, "x", _a) + 1, _a); + Reflect.set(_b, "x", (_c = Reflect.get(_b, "x", _a), _c++, _c), _a); + Reflect.set(_b, "x", (_d = Reflect.get(_b, "x", _a), --_d), _a); + [({ set value(_c) { Reflect.set(_b, "x", _c, _a); } }).value] = [1]; + [({ set value(_c) { Reflect.set(_b, "x", _c, _a); } }).value] = [2]; + ({ a: ({ set value(_c) { Reflect.set(_b, "x", _c, _a); } }).value } = { a: 3 }); + [({ set value(_c) { Reflect.set(_b, "x", _c, _a); } }).value = 4] = []; + ({ a: ({ set value(_c) { Reflect.set(_b, "x", _c, _a); } }).value = 5 } = {}); + [, ...({ set value(_c) { Reflect.set(_b, "x", _c, _a); } }).value] = [0, 1]; + ({ ...({ set value(_c) { Reflect.set(_b, "x", _c, _a); } }).value } = {}); })();