From f8af64f0e86dc814c2bb29e6ca98c57ae085df28 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Wed, 15 Mar 2023 15:39:00 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#53268=20(fix(53204)?= =?UTF-8?q?:=20Bug:=20=5F=5FrunInitializers(...)=20into=20release-5.0=20(#?= =?UTF-8?q?53273)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Oleksandr T --- src/compiler/transformers/esDecorators.ts | 6 ++- ...Decorators-classExpression-classSuper.7.js | 50 +++++++++++++++++++ ...Decorators-classExpression-classSuper.7.ts | 24 +++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/esDecorators-classExpression-classSuper.7.js create mode 100644 tests/cases/conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.7.ts diff --git a/src/compiler/transformers/esDecorators.ts b/src/compiler/transformers/esDecorators.ts index d0614bf9f907d..ede888850b445 100644 --- a/src/compiler/transformers/esDecorators.ts +++ b/src/compiler/transformers/esDecorators.ts @@ -36,6 +36,7 @@ import { Expression, ExpressionStatement, findComputedPropertyNameCacheAssignment, + findSuperStatementIndex, firstOrUndefined, forEachEntry, ForStatement, @@ -1072,8 +1073,11 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc if (initializerStatements) { const statements: Statement[] = []; const nonPrologueStart = factory.copyPrologue(node.body.statements, statements, /*ensureUseStrict*/ false, visitor); + const superStatementIndex = findSuperStatementIndex(node.body.statements, nonPrologueStart); + const indexOfFirstStatementAfterSuper = superStatementIndex >= 0 ? superStatementIndex + 1 : undefined; + addRange(statements, visitNodes(node.body.statements, visitor, isStatement, nonPrologueStart, indexOfFirstStatementAfterSuper ? indexOfFirstStatementAfterSuper - nonPrologueStart : undefined)); addRange(statements, initializerStatements); - addRange(statements, visitNodes(node.body.statements, visitor, isStatement, nonPrologueStart)); + addRange(statements, visitNodes(node.body.statements, visitor, isStatement, indexOfFirstStatementAfterSuper)); body = factory.createBlock(statements, /*multiLine*/ true); setOriginalNode(body, node.body); setTextRange(body, node.body); diff --git a/tests/baselines/reference/esDecorators-classExpression-classSuper.7.js b/tests/baselines/reference/esDecorators-classExpression-classSuper.7.js new file mode 100644 index 0000000000000..b496925f6861f --- /dev/null +++ b/tests/baselines/reference/esDecorators-classExpression-classSuper.7.js @@ -0,0 +1,50 @@ +//// [esDecorators-classExpression-classSuper.7.ts] +class A {} +class B extends A { + public constructor() { + 'inject'; + super(); + const a = 1; + const b = 1; + } + + @foo + public m(): void {} +} + +function foo(method: any, _context: any): any { + return function (this: any) { + method.call(this); + }; +} + +new B(); + + +//// [esDecorators-classExpression-classSuper.7.js] +class A { +} +let B = (() => { + let _instanceExtraInitializers = []; + let _m_decorators; + return class B extends A { + static { + _m_decorators = [foo]; + __esDecorate(this, null, _m_decorators, { kind: "method", name: "m", static: false, private: false, access: { has: obj => "m" in obj, get: obj => obj.m } }, null, _instanceExtraInitializers); + } + constructor() { + 'inject'; + super(); + __runInitializers(this, _instanceExtraInitializers); + const a = 1; + const b = 1; + } + m() { } + }; +})(); +function foo(method, _context) { + return function () { + method.call(this); + }; +} +new B(); diff --git a/tests/cases/conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.7.ts b/tests/cases/conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.7.ts new file mode 100644 index 0000000000000..2c1452bbcbf4e --- /dev/null +++ b/tests/cases/conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.7.ts @@ -0,0 +1,24 @@ +// @target: es2022 +// @noEmitHelpers: true +// @noTypesAndSymbols: true + +class A {} +class B extends A { + public constructor() { + 'inject'; + super(); + const a = 1; + const b = 1; + } + + @foo + public m(): void {} +} + +function foo(method: any, _context: any): any { + return function (this: any) { + method.call(this); + }; +} + +new B();