Skip to content

Commit

Permalink
fix(86384): Constructor overload still present in emitted JS (#86391)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk authored Aug 8, 2024
1 parent 67d0fc1 commit 1f54d0a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1985,10 +1985,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
node.parameters = createNodeArray(parameters);
node.body = body;

node.transformFlags = propagateChildrenFlags(node.modifiers) |
propagateChildrenFlags(node.parameters) |
(propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) |
TransformFlags.ContainsES2015;
if (!node.body) {
node.transformFlags = TransformFlags.ContainsTypeScript;
}
else {
node.transformFlags = propagateChildrenFlags(node.modifiers) |
propagateChildrenFlags(node.parameters) |
(propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait) |
TransformFlags.ContainsES2015;
}

node.typeParameters = undefined; // initialized by parser for grammar errors
node.type = undefined; // initialized by parser for grammar errors
Expand Down
19 changes: 19 additions & 0 deletions tests/baselines/reference/constructorOverloads9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/constructorOverloads9.ts] ////

//// [constructorOverloads9.ts]
export class C {
a;
constructor();
constructor(x = '') {
this.a = x;
}
}


//// [constructorOverloads9.js]
export class C {
a;
constructor(x = '') {
this.a = x;
}
}
21 changes: 21 additions & 0 deletions tests/baselines/reference/constructorOverloads9.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/constructorOverloads9.ts] ////

=== constructorOverloads9.ts ===
export class C {
>C : Symbol(C, Decl(constructorOverloads9.ts, 0, 0))

a;
>a : Symbol(C.a, Decl(constructorOverloads9.ts, 0, 16))

constructor();
constructor(x = '') {
>x : Symbol(x, Decl(constructorOverloads9.ts, 3, 16))

this.a = x;
>this.a : Symbol(C.a, Decl(constructorOverloads9.ts, 0, 16))
>this : Symbol(C, Decl(constructorOverloads9.ts, 0, 0))
>a : Symbol(C.a, Decl(constructorOverloads9.ts, 0, 16))
>x : Symbol(x, Decl(constructorOverloads9.ts, 3, 16))
}
}

30 changes: 30 additions & 0 deletions tests/baselines/reference/constructorOverloads9.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//// [tests/cases/compiler/constructorOverloads9.ts] ////

=== constructorOverloads9.ts ===
export class C {
>C : C
> : ^

a;
>a : any

constructor();
constructor(x = '') {
>x : string
> : ^^^^^^
>'' : ""
> : ^^

this.a = x;
>this.a = x : string
> : ^^^^^^
>this.a : any
>this : this
> : ^^^^
>a : any
> : ^^^
>x : string
> : ^^^^^^
}
}

8 changes: 8 additions & 0 deletions tests/cases/compiler/constructorOverloads9.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @target: esnext
export class C {
a;
constructor();
constructor(x = '') {
this.a = x;
}
}

0 comments on commit 1f54d0a

Please sign in to comment.