πŸ€– Pick PR #53547 (Fix double-emit in constructor) into release-5.0 (#53550)

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
This commit is contained in:
TypeScript Bot 2023-03-27 18:12:23 -07:00 ΠΊΠΎΠΌΠΌΠΈΡ‚ ΠΏΡ€ΠΎΠΈΠ·Π²Ρ‘Π» GitHub
Π ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒ b78f920ea0
ΠšΠΎΠΌΠΌΠΈΡ‚ aebd31be07
НС Π½Π°ΠΉΠ΄Π΅Π½ ΠΊΠ»ΡŽΡ‡, ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ Π΄Π°Π½Π½ΠΎΠΉ подписи
Π˜Π΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ ΠΊΠ»ΡŽΡ‡Π° GPG: 4AEE18F83AFDEB23
4 ΠΈΠ·ΠΌΠ΅Π½Ρ‘Π½Π½Ρ‹Ρ… Ρ„Π°ΠΉΠ»ΠΎΠ²: 129 Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠΉ ΠΈ 54 ΡƒΠ΄Π°Π»Π΅Π½ΠΈΠΉ

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -1074,10 +1074,15 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
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, indexOfFirstStatementAfterSuper));
if (superStatementIndex >= 0) {
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, nonPrologueStart, superStatementIndex + 1 - nonPrologueStart));
addRange(statements, initializerStatements);
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, superStatementIndex + 1));
}
else {
addRange(statements, initializerStatements);
addRange(statements, visitNodes(node.body.statements, visitor, isStatement));
}
body = factory.createBlock(statements, /*multiLine*/ true);
setOriginalNode(body, node.body);
setTextRange(body, node.body);

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -0,0 +1,101 @@
//// [esDecorators-classDeclaration-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();
// https://github.com/microsoft/TypeScript/issues/53448
class C {
public constructor() {
this.val;
}
@foo
public get val(): number { return 3; }
}
class D extends A {
public constructor() {
super();
this.val;
}
@foo
public get val(): number { return 3; }
}
//// [esDecorators-classDeclaration-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();
// https://github.com/microsoft/TypeScript/issues/53448
let C = (() => {
let _instanceExtraInitializers_1 = [];
let _get_val_decorators;
return class C {
static {
_get_val_decorators = [foo];
__esDecorate(this, null, _get_val_decorators, { kind: "getter", name: "val", static: false, private: false, access: { has: obj => "val" in obj, get: obj => obj.val } }, null, _instanceExtraInitializers_1);
}
constructor() {
__runInitializers(this, _instanceExtraInitializers_1);
this.val;
}
get val() { return 3; }
};
})();
let D = (() => {
let _instanceExtraInitializers_2 = [];
let _get_val_decorators;
return class D extends A {
static {
_get_val_decorators = [foo];
__esDecorate(this, null, _get_val_decorators, { kind: "getter", name: "val", static: false, private: false, access: { has: obj => "val" in obj, get: obj => obj.val } }, null, _instanceExtraInitializers_2);
}
constructor() {
super();
__runInitializers(this, _instanceExtraInitializers_2);
this.val;
}
get val() { return 3; }
};
})();

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -1,50 +0,0 @@
//// [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();

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -22,3 +22,22 @@ function foo(method: any, _context: any): any {
}
new B();
// https://github.com/microsoft/TypeScript/issues/53448
class C {
public constructor() {
this.val;
}
@foo
public get val(): number { return 3; }
}
class D extends A {
public constructor() {
super();
this.val;
}
@foo
public get val(): number { return 3; }
}