Skip to content

Commit 1f54d0a

Browse files
authored
fix(59484): Constructor overload still present in emitted JS (#59491)
1 parent 67d0fc1 commit 1f54d0a

File tree

5 files changed

+87
-4
lines changed

5 files changed

+87
-4
lines changed

src/compiler/factory/nodeFactory.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,10 +1985,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
19851985
node.parameters = createNodeArray(parameters);
19861986
node.body = body;
19871987

1988-
node.transformFlags = propagateChildrenFlags(node.modifiers) |
1989-
propagateChildrenFlags(node.parameters) |
1990-
(propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) |
1991-
TransformFlags.ContainsES2015;
1988+
if (!node.body) {
1989+
node.transformFlags = TransformFlags.ContainsTypeScript;
1990+
}
1991+
else {
1992+
node.transformFlags = propagateChildrenFlags(node.modifiers) |
1993+
propagateChildrenFlags(node.parameters) |
1994+
(propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) |
1995+
TransformFlags.ContainsES2015;
1996+
}
19921997

19931998
node.typeParameters = undefined; // initialized by parser for grammar errors
19941999
node.type = undefined; // initialized by parser for grammar errors
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/constructorOverloads9.ts] ////
2+
3+
//// [constructorOverloads9.ts]
4+
export class C {
5+
a;
6+
constructor();
7+
constructor(x = '') {
8+
this.a = x;
9+
}
10+
}
11+
12+
13+
//// [constructorOverloads9.js]
14+
export class C {
15+
a;
16+
constructor(x = '') {
17+
this.a = x;
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [tests/cases/compiler/constructorOverloads9.ts] ////
2+
3+
=== constructorOverloads9.ts ===
4+
export class C {
5+
>C : Symbol(C, Decl(constructorOverloads9.ts, 0, 0))
6+
7+
a;
8+
>a : Symbol(C.a, Decl(constructorOverloads9.ts, 0, 16))
9+
10+
constructor();
11+
constructor(x = '') {
12+
>x : Symbol(x, Decl(constructorOverloads9.ts, 3, 16))
13+
14+
this.a = x;
15+
>this.a : Symbol(C.a, Decl(constructorOverloads9.ts, 0, 16))
16+
>this : Symbol(C, Decl(constructorOverloads9.ts, 0, 0))
17+
>a : Symbol(C.a, Decl(constructorOverloads9.ts, 0, 16))
18+
>x : Symbol(x, Decl(constructorOverloads9.ts, 3, 16))
19+
}
20+
}
21+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// [tests/cases/compiler/constructorOverloads9.ts] ////
2+
3+
=== constructorOverloads9.ts ===
4+
export class C {
5+
>C : C
6+
> : ^
7+
8+
a;
9+
>a : any
10+
11+
constructor();
12+
constructor(x = '') {
13+
>x : string
14+
> : ^^^^^^
15+
>'' : ""
16+
> : ^^
17+
18+
this.a = x;
19+
>this.a = x : string
20+
> : ^^^^^^
21+
>this.a : any
22+
>this : this
23+
> : ^^^^
24+
>a : any
25+
> : ^^^
26+
>x : string
27+
> : ^^^^^^
28+
}
29+
}
30+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: esnext
2+
export class C {
3+
a;
4+
constructor();
5+
constructor(x = '') {
6+
this.a = x;
7+
}
8+
}

0 commit comments

Comments
 (0)