From 3286ba045f04a2eff97d146b79a5ff2077c33e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 22 Jul 2023 13:04:26 +0200 Subject: [PATCH 1/6] Fixed issue with method called `new` being emitted as construct signature --- src/compiler/emitter.ts | 7 ++- .../reference/emitMethodCalledNew.js | 43 +++++++++++++++++++ .../reference/emitMethodCalledNew.symbols | 31 +++++++++++++ .../reference/emitMethodCalledNew.types | 40 +++++++++++++++++ tests/cases/compiler/emitMethodCalledNew.ts | 13 ++++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/emitMethodCalledNew.js create mode 100644 tests/baselines/reference/emitMethodCalledNew.symbols create mode 100644 tests/baselines/reference/emitMethodCalledNew.types create mode 100644 tests/cases/compiler/emitMethodCalledNew.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a58223868f8b0..e3a1a5d9d2e38 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2618,7 +2618,12 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri function emitMethodSignature(node: MethodSignature) { pushNameGenerationScope(node); emitModifierList(node, node.modifiers); - emit(node.name); + if (node.name.kind === SyntaxKind.Identifier && node.name.escapedText === "new") { + emit(factory.createStringLiteralFromNode(node.name)); + } + else { + emit(node.name); + } emit(node.questionToken); emitTypeParameters(node, node.typeParameters); emitParameters(node, node.parameters); diff --git a/tests/baselines/reference/emitMethodCalledNew.js b/tests/baselines/reference/emitMethodCalledNew.js new file mode 100644 index 0000000000000..eec54a1904dd0 --- /dev/null +++ b/tests/baselines/reference/emitMethodCalledNew.js @@ -0,0 +1,43 @@ +//// [tests/cases/compiler/emitMethodCalledNew.ts] //// + +//// [emitMethodCalledNew.ts] +// https://github.com/microsoft/TypeScript/issues/55075 + +export const a = { + new(x: number) { return x + 1 } +} +export const b = { + "new"(x: number) { return x + 1 } +} +export const c = { + ["new"](x: number) { return x + 1 } +} + + +//// [emitMethodCalledNew.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/55075 +var _a; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.c = exports.b = exports.a = void 0; +exports.a = { + new: function (x) { return x + 1; } +}; +exports.b = { + "new": function (x) { return x + 1; } +}; +exports.c = (_a = {}, + _a["new"] = function (x) { return x + 1; }, + _a); + + +//// [emitMethodCalledNew.d.ts] +export declare const a: { + "new"(x: number): number; +}; +export declare const b: { + "new"(x: number): number; +}; +export declare const c: { + "new"(x: number): number; +}; diff --git a/tests/baselines/reference/emitMethodCalledNew.symbols b/tests/baselines/reference/emitMethodCalledNew.symbols new file mode 100644 index 0000000000000..834678bff4fd5 --- /dev/null +++ b/tests/baselines/reference/emitMethodCalledNew.symbols @@ -0,0 +1,31 @@ +//// [tests/cases/compiler/emitMethodCalledNew.ts] //// + +=== emitMethodCalledNew.ts === +// https://github.com/microsoft/TypeScript/issues/55075 + +export const a = { +>a : Symbol(a, Decl(emitMethodCalledNew.ts, 2, 12)) + + new(x: number) { return x + 1 } +>new : Symbol(new, Decl(emitMethodCalledNew.ts, 2, 18)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 3, 6)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 3, 6)) +} +export const b = { +>b : Symbol(b, Decl(emitMethodCalledNew.ts, 5, 12)) + + "new"(x: number) { return x + 1 } +>"new" : Symbol("new", Decl(emitMethodCalledNew.ts, 5, 18)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 6, 8)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 6, 8)) +} +export const c = { +>c : Symbol(c, Decl(emitMethodCalledNew.ts, 8, 12)) + + ["new"](x: number) { return x + 1 } +>["new"] : Symbol(["new"], Decl(emitMethodCalledNew.ts, 8, 18)) +>"new" : Symbol(["new"], Decl(emitMethodCalledNew.ts, 8, 18)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 9, 10)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 9, 10)) +} + diff --git a/tests/baselines/reference/emitMethodCalledNew.types b/tests/baselines/reference/emitMethodCalledNew.types new file mode 100644 index 0000000000000..de0be00a5120c --- /dev/null +++ b/tests/baselines/reference/emitMethodCalledNew.types @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/emitMethodCalledNew.ts] //// + +=== emitMethodCalledNew.ts === +// https://github.com/microsoft/TypeScript/issues/55075 + +export const a = { +>a : { "new"(x: number): number; } +>{ new(x: number) { return x + 1 }} : { "new"(x: number): number; } + + new(x: number) { return x + 1 } +>new : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 +} +export const b = { +>b : { "new"(x: number): number; } +>{ "new"(x: number) { return x + 1 }} : { "new"(x: number): number; } + + "new"(x: number) { return x + 1 } +>"new" : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 +} +export const c = { +>c : { "new"(x: number): number; } +>{ ["new"](x: number) { return x + 1 }} : { "new"(x: number): number; } + + ["new"](x: number) { return x + 1 } +>["new"] : (x: number) => number +>"new" : "new" +>x : number +>x + 1 : number +>x : number +>1 : 1 +} + diff --git a/tests/cases/compiler/emitMethodCalledNew.ts b/tests/cases/compiler/emitMethodCalledNew.ts new file mode 100644 index 0000000000000..0bc59c9a54e50 --- /dev/null +++ b/tests/cases/compiler/emitMethodCalledNew.ts @@ -0,0 +1,13 @@ +// @declaration: true + +// https://github.com/microsoft/TypeScript/issues/55075 + +export const a = { + new(x: number) { return x + 1 } +} +export const b = { + "new"(x: number) { return x + 1 } +} +export const c = { + ["new"](x: number) { return x + 1 } +} From 3825f0e568cc91a1101de93abd13b7a675397a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 22 Jul 2023 19:11:08 +0200 Subject: [PATCH 2/6] update baselines --- ...ypesIdentityWithConstructSignatures2.types | 34 +++++++-------- ...structSignaturesDifferingParamCounts.types | 34 +++++++-------- ...ructSignaturesDifferingByConstraints.types | 34 +++++++-------- ...uctSignaturesDifferingByConstraints2.types | 34 +++++++-------- ...uctSignaturesDifferingByConstraints3.types | 34 +++++++-------- ...tructSignaturesDifferingByReturnType.types | 42 +++++++++---------- ...ructSignaturesDifferingByReturnType2.types | 34 +++++++-------- ...gnaturesDifferingTypeParameterCounts.types | 34 +++++++-------- ...ignaturesDifferingTypeParameterNames.types | 34 +++++++-------- ...ricConstructSignaturesOptionalParams.types | 34 +++++++-------- ...icConstructSignaturesOptionalParams2.types | 34 +++++++-------- ...icConstructSignaturesOptionalParams3.types | 34 +++++++-------- tests/baselines/reference/parser645484.types | 2 +- tests/baselines/reference/vardecl.js | 2 +- tests/baselines/reference/vardecl.types | 2 +- 15 files changed, 211 insertions(+), 211 deletions(-) diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types index 0dfc19dea0665..34c399156fd78 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types @@ -32,8 +32,8 @@ var a: { new(x: Date): string } >x : Date var b = { new(x: RegExp) { return ''; } }; // not a construct signature, function called new ->b : { new(x: RegExp): string; } ->{ new(x: RegExp) { return ''; } } : { new(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } +>{ new(x: RegExp) { return ''; } } : { "new"(x: RegExp): string; } >new : (x: RegExp) => string >x : RegExp >'' : "" @@ -89,17 +89,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: RegExp): string; }): any; } ->x : { new(x: RegExp): string; } ->b : { new(x: RegExp): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: RegExp): string; }): any; } +>x : { "new"(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: RegExp): string; }): any; (x: typeof b): any; } ->x : { new(x: RegExp): string; } ->b : { new(x: RegExp): string; } +>foo4 : { (x: { "new"(x: RegExp): string; }): any; (x: typeof b): any; } +>x : { "new"(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: RegExp): string; }): any; (x: { new(x: RegExp): string; }): any; } +>foo4 : { (x: { "new"(x: RegExp): string; }): any; (x: { "new"(x: RegExp): string; }): any; } >x : any function foo8(x: B); @@ -140,16 +140,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: RegExp): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: RegExp): string; } ->b : { new(x: RegExp): string; } +>x : { "new"(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: RegExp): string; }): any; } >x : any function foo12(x: I); @@ -190,16 +190,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: RegExp): string; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: RegExp): string; } ->b : { new(x: RegExp): string; } +>x : { "new"(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: RegExp): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types index d77dd7fb06a90..bd1c494205e8c 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types @@ -35,8 +35,8 @@ var a: { new(x: string, y: string): string } >y : string var b = { new(x: string) { return ''; } }; // not a construct signature, function called new ->b : { new(x: string): string; } ->{ new(x: string) { return ''; } } : { new(x: string): string; } +>b : { "new"(x: string): string; } +>{ new(x: string) { return ''; } } : { "new"(x: string): string; } >new : (x: string) => string >x : string >'' : "" @@ -92,17 +92,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: string): string; }): any; } ->x : { new(x: string): string; } ->b : { new(x: string): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: string): string; }): any; } +>x : { "new"(x: string): string; } +>b : { "new"(x: string): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: string): string; }): any; (x: typeof b): any; } ->x : { new(x: string): string; } ->b : { new(x: string): string; } +>foo4 : { (x: { "new"(x: string): string; }): any; (x: typeof b): any; } +>x : { "new"(x: string): string; } +>b : { "new"(x: string): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: string): string; }): any; (x: { new(x: string): string; }): any; } +>foo4 : { (x: { "new"(x: string): string; }): any; (x: { "new"(x: string): string; }): any; } >x : any function foo8(x: B); @@ -143,16 +143,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: string): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: string): string; } ->b : { new(x: string): string; } +>x : { "new"(x: string): string; } +>b : { "new"(x: string): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: string): string; }): any; } >x : any function foo12(x: I); @@ -193,16 +193,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: string): string; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: string): string; } ->b : { new(x: string): string; } +>x : { "new"(x: string): string; } +>b : { "new"(x: string): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: string): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types index 0f0ef8d5d02ee..de2e1e509a695 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types @@ -34,8 +34,8 @@ var a: { new>(x: T): string } >x : T var b = { new(x: T) { return ''; } }; // not a construct signature, function called new ->b : { new(x: T): string; } ->{ new(x: T) { return ''; } } : { new(x: T): string; } +>b : { "new"(x: T): string; } +>{ new(x: T) { return ''; } } : { "new"(x: T): string; } >new : (x: T) => string >x : T >'' : "" @@ -91,17 +91,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T): string; }): any; } ->x : { new(x: T): string; } ->b : { new(x: T): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T): string; }): any; } +>x : { "new"(x: T): string; } +>b : { "new"(x: T): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T): string; }): any; (x: typeof b): any; } ->x : { new(x: T): string; } ->b : { new(x: T): string; } +>foo4 : { (x: { "new"(x: T): string; }): any; (x: typeof b): any; } +>x : { "new"(x: T): string; } +>b : { "new"(x: T): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T): string; }): any; (x: { new(x: T): string; }): any; } +>foo4 : { (x: { "new"(x: T): string; }): any; (x: { "new"(x: T): string; }): any; } >x : any function foo8(x: B>); @@ -142,16 +142,16 @@ function foo10(x: any) { } >x : any function foo11(x: B>); ->foo11 : { (x: B>): any; (x: { new(x: T): string; }): any; } +>foo11 : { (x: B>): any; (x: { "new"(x: T): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T): string; } ->b : { new(x: T): string; } +>x : { "new"(x: T): string; } +>b : { "new"(x: T): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): string; }): any; } >x : any function foo12(x: I); @@ -192,15 +192,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): string; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T): string; } ->b : { new(x: T): string; } +>x : { "new"(x: T): string; } +>b : { "new"(x: T): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): string; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints2.types index 32ccfc172bf7e..f356abc56a9f7 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints2.types @@ -47,8 +47,8 @@ var a: { new>(x: T, y: U): string } >y : U var b = { new(x: T, y: U) { return ''; } }; // not a construct signature, function called new ->b : { new(x: T, y: U): string; } ->{ new(x: T, y: U) { return ''; } } : { new(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } +>{ new(x: T, y: U) { return ''; } } : { "new"(x: T, y: U): string; } >new : (x: T, y: U) => string >x : T >y : U @@ -105,17 +105,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y: U): string; }): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y: U): string; }): any; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y: U): string; }): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>foo4 : { (x: { "new"(x: T, y: U): string; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y: U): string; }): any; (x: { new(x: T, y: U): string; }): any; } +>foo4 : { (x: { "new"(x: T, y: U): string; }): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any function foo5c(x: C); @@ -180,16 +180,16 @@ function foo10(x: any) { } >x : any function foo11(x: B, Array>); ->foo11 : { (x: B, Array>): any; (x: { new(x: T, y: U): string; }): any; } +>foo11 : { (x: B, Array>): any; (x: { "new"(x: T, y: U): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y: U): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any function foo12(x: I); @@ -230,15 +230,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T, y: U): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y: U): string; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T, y: U): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints3.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints3.types index bf97ae6b02c1b..02e645c133426 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints3.types @@ -67,8 +67,8 @@ var a: { new(x: T, y: U): string } >y : U var b = { new(x: T, y: U) { return ''; } }; // not a construct signature, function called new ->b : { new(x: T, y: U): string; } ->{ new(x: T, y: U) { return ''; } } : { new(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } +>{ new(x: T, y: U) { return ''; } } : { "new"(x: T, y: U): string; } >new : (x: T, y: U) => string >x : T >y : U @@ -125,17 +125,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y: U): string; }): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y: U): string; }): any; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y: U): string; }): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>foo4 : { (x: { "new"(x: T, y: U): string; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y: U): string; }): any; (x: { new(x: T, y: U): string; }): any; } +>foo4 : { (x: { "new"(x: T, y: U): string; }): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any function foo5c(x: C); @@ -200,16 +200,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T, y: U): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y: U): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any function foo12(x: I, Five>); @@ -250,15 +250,15 @@ function foo13(x: any) { } >x : any function foo14(x: I, Five>); ->foo14 : { (x: I, Five>): any; (x: { new(x: T, y: U): string; }): any; } +>foo14 : { (x: I, Five>): any; (x: { "new"(x: T, y: U): string; }): any; } >x : I, Five> function foo14(x: typeof b); // ok >foo14 : { (x: I, Five>): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo14(x: any) { } ->foo14 : { (x: I, Five>): any; (x: { new(x: T, y: U): string; }): any; } +>foo14 : { (x: I, Five>): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types index 6c35b07b35179..6fae02bf0cd03 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types @@ -34,8 +34,8 @@ var a: { new(x: T): T } >x : T var b = { new(x: T): T { return null; } }; // not a construct signature, function called new ->b : { new(x: T): T; } ->{ new(x: T): T { return null; } } : { new(x: T): T; } +>b : { "new"(x: T): T; } +>{ new(x: T): T { return null; } } : { "new"(x: T): T; } >new : (x: T) => T >x : T @@ -90,31 +90,31 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T): T; }): any; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T): T; }): any; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T): T; }): any; (x: typeof b): any; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>foo4 : { (x: { "new"(x: T): T; }): any; (x: typeof b): any; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T): T; }): any; (x: { new(x: T): T; }): any; } +>foo4 : { (x: { "new"(x: T): T; }): any; (x: { "new"(x: T): T; }): any; } >x : any function foo5(x: typeof a): number; ->foo5 : { (x: typeof a): number; (x: { new(x: T): T; }): string; } +>foo5 : { (x: typeof a): number; (x: { "new"(x: T): T; }): string; } >x : new (x: T) => T >a : new (x: T) => T function foo5(x: typeof b): string; // ok >foo5 : { (x: new (x: T) => T): number; (x: typeof b): string; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo5(x: any): any { } ->foo5 : { (x: new (x: T) => T): number; (x: { new(x: T): T; }): string; } +>foo5 : { (x: new (x: T) => T): number; (x: { "new"(x: T): T; }): string; } >x : any function foo8(x: B); @@ -155,16 +155,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): T; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): T; }): any; } >x : any function foo12(x: I); @@ -205,16 +205,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): T; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types index 1d95296be6e2c..09002456b70ee 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types @@ -34,8 +34,8 @@ var a: { new(x: T): T } >x : T var b = { new(x: T) { return null; } }; // not a construct signature, function called new ->b : { new(x: T): any; } ->{ new(x: T) { return null; } } : { new(x: T): any; } +>b : { "new"(x: T): any; } +>{ new(x: T) { return null; } } : { "new"(x: T): any; } >new : (x: T) => any >x : T @@ -90,17 +90,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T): any; }): any; } ->x : { new(x: T): any; } ->b : { new(x: T): any; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T): any; }): any; } +>x : { "new"(x: T): any; } +>b : { "new"(x: T): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T): any; }): any; (x: typeof b): any; } ->x : { new(x: T): any; } ->b : { new(x: T): any; } +>foo4 : { (x: { "new"(x: T): any; }): any; (x: typeof b): any; } +>x : { "new"(x: T): any; } +>b : { "new"(x: T): any; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T): any; }): any; (x: { new(x: T): any; }): any; } +>foo4 : { (x: { "new"(x: T): any; }): any; (x: { "new"(x: T): any; }): any; } >x : any function foo8(x: B); @@ -141,16 +141,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): any; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T): any; } ->b : { new(x: T): any; } +>x : { "new"(x: T): any; } +>b : { "new"(x: T): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): any; }): any; } >x : any function foo12(x: I); @@ -191,16 +191,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): any; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T): any; } ->b : { new(x: T): any; } +>x : { "new"(x: T): any; } +>b : { "new"(x: T): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types index a498c166bc9bf..477e469cc1482 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types @@ -32,8 +32,8 @@ var a: { new (x: Z): C; } >x : Z var b = { new(x: A) { return x; } }; ->b : { new(x: A): A; } ->{ new(x: A) { return x; } } : { new(x: A): A; } +>b : { "new"(x: A): A; } +>{ new(x: A) { return x; } } : { "new"(x: A): A; } >new : (x: A) => A >x : A >x : A @@ -89,17 +89,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: A): A; }): any; } ->x : { new(x: A): A; } ->b : { new(x: A): A; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: A): A; }): any; } +>x : { "new"(x: A): A; } +>b : { "new"(x: A): A; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: A): A; }): any; (x: typeof b): any; } ->x : { new(x: A): A; } ->b : { new(x: A): A; } +>foo4 : { (x: { "new"(x: A): A; }): any; (x: typeof b): any; } +>x : { "new"(x: A): A; } +>b : { "new"(x: A): A; } function foo4(x: any) { } ->foo4 : { (x: { new(x: A): A; }): any; (x: { new(x: A): A; }): any; } +>foo4 : { (x: { "new"(x: A): A; }): any; (x: { "new"(x: A): A; }): any; } >x : any function foo8(x: B); @@ -140,16 +140,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: A): A; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: A): A; } ->b : { new(x: A): A; } +>x : { "new"(x: A): A; } +>b : { "new"(x: A): A; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: A): A; }): any; } >x : any function foo12(x: I, number, Date, string>); @@ -190,15 +190,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: A): A; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: A): A; } ->b : { new(x: A): A; } +>x : { "new"(x: A): A; } +>b : { "new"(x: A): A; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: A): A; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types index 9e5e401ce5ac3..64b2d8ca3795f 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types @@ -32,8 +32,8 @@ var a: { new(x: Z): B } >x : Z var b = { new(x: A) { return new C(x); } }; ->b : { new(x: A): C; } ->{ new(x: A) { return new C(x); } } : { new(x: A): C; } +>b : { "new"(x: A): C; } +>{ new(x: A) { return new C(x); } } : { "new"(x: A): C; } >new : (x: A) => C >x : A >new C(x) : C @@ -91,17 +91,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: A): C; }): any; } ->x : { new(x: A): C; } ->b : { new(x: A): C; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: A): C; }): any; } +>x : { "new"(x: A): C; } +>b : { "new"(x: A): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: A): C; }): any; (x: typeof b): any; } ->x : { new(x: A): C; } ->b : { new(x: A): C; } +>foo4 : { (x: { "new"(x: A): C; }): any; (x: typeof b): any; } +>x : { "new"(x: A): C; } +>b : { "new"(x: A): C; } function foo4(x: any) { } ->foo4 : { (x: { new(x: A): C; }): any; (x: { new(x: A): C; }): any; } +>foo4 : { (x: { "new"(x: A): C; }): any; (x: { "new"(x: A): C; }): any; } >x : any function foo8(x: B); @@ -142,16 +142,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: A): C; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: A): C; } ->b : { new(x: A): C; } +>x : { "new"(x: A): C; } +>b : { "new"(x: A): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: A): C; }): any; } >x : any function foo12(x: I); @@ -192,15 +192,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: A): C; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: A): C; } ->b : { new(x: A): C; } +>x : { "new"(x: A): C; } +>b : { "new"(x: A): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: A): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types index 2fc3493fae3b1..f07a9f58d6e9f 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types @@ -39,8 +39,8 @@ var a: { new(x: T, y?: T): B } >y : T var b = { new(x: T, y?: T) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new(x: T, y?: T): C; } ->{ new(x: T, y?: T) { return new C(x, y); } } : { new(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } +>{ new(x: T, y?: T) { return new C(x, y); } } : { "new"(x: T, y?: T): C; } >new : (x: T, y?: T) => C >x : T >y : T @@ -100,17 +100,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y?: T): C; }): any; } ->x : { new(x: T, y?: T): C; } ->b : { new(x: T, y?: T): C; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y?: T): C; }): any; } +>x : { "new"(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: typeof b): any; } ->x : { new(x: T, y?: T): C; } ->b : { new(x: T, y?: T): C; } +>foo4 : { (x: { "new"(x: T, y?: T): C; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: { new(x: T, y?: T): C; }): any; } +>foo4 : { (x: { "new"(x: T, y?: T): C; }): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : any function foo8(x: B): string; @@ -151,16 +151,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y?: T): C; } ->b : { new(x: T, y?: T): C; } +>x : { "new"(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : any function foo12(x: I); @@ -201,15 +201,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T, y?: T): C; } ->b : { new(x: T, y?: T): C; } +>x : { "new"(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types index f629ad0673838..79967629250e4 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types @@ -39,8 +39,8 @@ var a: { new(x: T, y?: U): B } >y : U var b = { new(x: T, y?: U) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new(x: T, y?: U): C; } ->{ new(x: T, y?: U) { return new C(x, y); } } : { new(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } +>{ new(x: T, y?: U) { return new C(x, y); } } : { "new"(x: T, y?: U): C; } >new : (x: T, y?: U) => C >x : T >y : U @@ -100,17 +100,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y?: U): C; }): any; } ->x : { new(x: T, y?: U): C; } ->b : { new(x: T, y?: U): C; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y?: U): C; }): any; } +>x : { "new"(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: typeof b): any; } ->x : { new(x: T, y?: U): C; } ->b : { new(x: T, y?: U): C; } +>foo4 : { (x: { "new"(x: T, y?: U): C; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: { new(x: T, y?: U): C; }): any; } +>foo4 : { (x: { "new"(x: T, y?: U): C; }): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : any function foo8(x: B); @@ -151,16 +151,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y?: U): C; } ->b : { new(x: T, y?: U): C; } +>x : { "new"(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : any function foo12(x: I); @@ -201,15 +201,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T, y?: U): C; } ->b : { new(x: T, y?: U): C; } +>x : { "new"(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types index 5917ef0e0ae11..9d1c287e6e356 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types @@ -39,8 +39,8 @@ var a: { new (x: T, y?: U): B }; >y : U var b = { new(x: T, y: U) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new(x: T, y: U): C; } ->{ new(x: T, y: U) { return new C(x, y); } } : { new(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } +>{ new(x: T, y: U) { return new C(x, y); } } : { "new"(x: T, y: U): C; } >new : (x: T, y: U) => C >x : T >y : U @@ -100,17 +100,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y: U): C; }): any; } ->x : { new(x: T, y: U): C; } ->b : { new(x: T, y: U): C; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y: U): C; }): any; } +>x : { "new"(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y: U): C; }): any; (x: typeof b): any; } ->x : { new(x: T, y: U): C; } ->b : { new(x: T, y: U): C; } +>foo4 : { (x: { "new"(x: T, y: U): C; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y: U): C; }): any; (x: { new(x: T, y: U): C; }): any; } +>foo4 : { (x: { "new"(x: T, y: U): C; }): any; (x: { "new"(x: T, y: U): C; }): any; } >x : any function foo8(x: B); @@ -151,16 +151,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): C; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y: U): C; } ->b : { new(x: T, y: U): C; } +>x : { "new"(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): C; }): any; } >x : any function foo12(x: I); @@ -201,15 +201,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y: U): C; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T, y: U): C; } ->b : { new(x: T, y: U): C; } +>x : { "new"(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y: U): C; }): any; } >x : any diff --git a/tests/baselines/reference/parser645484.types b/tests/baselines/reference/parser645484.types index 290fb19fcc9f8..7dcf7f95eca7b 100644 --- a/tests/baselines/reference/parser645484.types +++ b/tests/baselines/reference/parser645484.types @@ -2,7 +2,7 @@ === parser645484.ts === var c : { ->c : { new?(): any; } +>c : { "new"?(): any; } new?(): any; >new : () => any diff --git a/tests/baselines/reference/vardecl.js b/tests/baselines/reference/vardecl.js index 1356ade167d92..77fbc628e8483 100644 --- a/tests/baselines/reference/vardecl.js +++ b/tests/baselines/reference/vardecl.js @@ -194,7 +194,7 @@ declare var n1: { [s: string]: number; }; declare var c: { - new?(): any; + "new"?(): any; }; declare var d: { foo?(): { diff --git a/tests/baselines/reference/vardecl.types b/tests/baselines/reference/vardecl.types index 39ed0dbee7492..1703a6fed1d9a 100644 --- a/tests/baselines/reference/vardecl.types +++ b/tests/baselines/reference/vardecl.types @@ -66,7 +66,7 @@ var n1: { [s: string]: number; }; >s : string var c : { ->c : { new?(): any; } +>c : { "new"?(): any; } new? (): any; >new : () => any From b96cd35457bdbb69baa1ddd059c1702d1bc1f6c3 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 14 Sep 2023 20:17:53 -0700 Subject: [PATCH 3/6] Undo fix --- src/compiler/emitter.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3ab648665b277..4a0b03f7285d5 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2628,12 +2628,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri function emitMethodSignature(node: MethodSignature) { pushNameGenerationScope(node); emitModifierList(node, node.modifiers); - if (node.name.kind === SyntaxKind.Identifier && node.name.escapedText === "new") { - emit(factory.createStringLiteralFromNode(node.name)); - } - else { - emit(node.name); - } + emit(node.name); emit(node.questionToken); emitTypeParameters(node, node.typeParameters); emitParameters(node, node.parameters); From 8e430b72a364be65981b7a903c6f5de55a3e13a1 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 14 Sep 2023 20:33:19 -0700 Subject: [PATCH 4/6] Use alternative fix that doesn't change emit --- src/compiler/checker.ts | 9 +++++---- src/compiler/utilities.ts | 5 +++-- src/services/codefixes/fixAddMissingMember.ts | 3 ++- tests/baselines/reference/vardecl.js | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 65673177efe59..8c86e931eb0d0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8213,16 +8213,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getPropertyNameNodeForSymbol(symbol: Symbol, context: NodeBuilderContext) { const stringNamed = !!length(symbol.declarations) && every(symbol.declarations, isStringNamed); const singleQuote = !!length(symbol.declarations) && every(symbol.declarations, isSingleQuotedStringNamed); - const fromNameType = getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote, stringNamed); + const isMethod = !!(symbol.flags & SymbolFlags.Method); + const fromNameType = getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote, stringNamed, isMethod); if (fromNameType) { return fromNameType; } const rawName = unescapeLeadingUnderscores(symbol.escapedName); - return createPropertyNameNodeForIdentifierOrLiteral(rawName, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed); + return createPropertyNameNodeForIdentifierOrLiteral(rawName, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed, isMethod); } // See getNameForSymbolFromNameType for a stringy equivalent - function getPropertyNameNodeForSymbolFromNameType(symbol: Symbol, context: NodeBuilderContext, singleQuote?: boolean, stringNamed?: boolean) { + function getPropertyNameNodeForSymbolFromNameType(symbol: Symbol, context: NodeBuilderContext, singleQuote: boolean, stringNamed: boolean, isMethod: boolean) { const nameType = getSymbolLinks(symbol).nameType; if (nameType) { if (nameType.flags & TypeFlags.StringOrNumberLiteral) { @@ -8233,7 +8234,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (isNumericLiteralName(name) && startsWith(name, "-")) { return factory.createComputedPropertyName(factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(+name)))); } - return createPropertyNameNodeForIdentifierOrLiteral(name, getEmitScriptTarget(compilerOptions)); + return createPropertyNameNodeForIdentifierOrLiteral(name, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed, isMethod); } if (nameType.flags & TypeFlags.UniqueESSymbol) { return factory.createComputedPropertyName(symbolToExpression((nameType as UniqueESSymbolType).symbol, context, SymbolFlags.Value)); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index cd375d12e759a..e95bc460c3e59 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -10216,8 +10216,9 @@ export function isNumericLiteralName(name: string | __String) { } /** @internal */ -export function createPropertyNameNodeForIdentifierOrLiteral(name: string, target: ScriptTarget, singleQuote?: boolean, stringNamed?: boolean) { - return isIdentifierText(name, target) ? factory.createIdentifier(name) : +export function createPropertyNameNodeForIdentifierOrLiteral(name: string, target: ScriptTarget, singleQuote: boolean, stringNamed: boolean, isMethod: boolean) { + const isNew = isMethod && name === "new"; + return !isNew && isIdentifierText(name, target) ? factory.createIdentifier(name) : !stringNamed && isNumericLiteralName(name) && +name >= 0 ? factory.createNumericLiteral(+name) : factory.createStringLiteral(name, !!singleQuote); } diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 90b718fe8437d..1b9ea40230613 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -772,7 +772,8 @@ function createPropertyNameFromSymbol(symbol: Symbol, target: ScriptTarget, quot const prop = checker.symbolToNode(symbol, SymbolFlags.Value, /*enclosingDeclaration*/ undefined, NodeBuilderFlags.WriteComputedProps); if (prop && isComputedPropertyName(prop)) return prop; } - return createPropertyNameNodeForIdentifierOrLiteral(symbol.name, target, quotePreference === QuotePreference.Single); + const isMethod = !!(symbol.flags & SymbolFlags.Method); + return createPropertyNameNodeForIdentifierOrLiteral(symbol.name, target, quotePreference === QuotePreference.Single, /*stringNamed*/ false, isMethod); } function findScope(node: Node) { diff --git a/tests/baselines/reference/vardecl.js b/tests/baselines/reference/vardecl.js index 77fbc628e8483..1356ade167d92 100644 --- a/tests/baselines/reference/vardecl.js +++ b/tests/baselines/reference/vardecl.js @@ -194,7 +194,7 @@ declare var n1: { [s: string]: number; }; declare var c: { - "new"?(): any; + new?(): any; }; declare var d: { foo?(): { From 3e0b686b66fb32a65ef60f71023b44cea00081ac Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:03:29 -0700 Subject: [PATCH 5/6] Add test for fixAddMissingMember, make it work correctly with a comment --- src/compiler/utilities.ts | 6 +++--- src/services/codefixes/fixAddMissingMember.ts | 4 ++-- .../fourslash/codeFixAddMissingMember31.ts | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/codeFixAddMissingMember31.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e95bc460c3e59..4d63c9124a7ac 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -10217,9 +10217,9 @@ export function isNumericLiteralName(name: string | __String) { /** @internal */ export function createPropertyNameNodeForIdentifierOrLiteral(name: string, target: ScriptTarget, singleQuote: boolean, stringNamed: boolean, isMethod: boolean) { - const isNew = isMethod && name === "new"; - return !isNew && isIdentifierText(name, target) ? factory.createIdentifier(name) : - !stringNamed && isNumericLiteralName(name) && +name >= 0 ? factory.createNumericLiteral(+name) : + const isMethodNamedNew = isMethod && name === "new"; + return !isMethodNamedNew && isIdentifierText(name, target) ? factory.createIdentifier(name) : + !stringNamed && !isMethodNamedNew && isNumericLiteralName(name) && +name >= 0 ? factory.createNumericLiteral(+name) : factory.createStringLiteral(name, !!singleQuote); } diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 1b9ea40230613..2935ca9c1c1ea 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -772,8 +772,8 @@ function createPropertyNameFromSymbol(symbol: Symbol, target: ScriptTarget, quot const prop = checker.symbolToNode(symbol, SymbolFlags.Value, /*enclosingDeclaration*/ undefined, NodeBuilderFlags.WriteComputedProps); if (prop && isComputedPropertyName(prop)) return prop; } - const isMethod = !!(symbol.flags & SymbolFlags.Method); - return createPropertyNameNodeForIdentifierOrLiteral(symbol.name, target, quotePreference === QuotePreference.Single, /*stringNamed*/ false, isMethod); + // We're using these nodes as property names in an object literal; no need to handle quoting names. + return createPropertyNameNodeForIdentifierOrLiteral(symbol.name, target, quotePreference === QuotePreference.Single, /*stringNamed*/ false, /*isMethod*/ false); } function findScope(node: Node) { diff --git a/tests/cases/fourslash/codeFixAddMissingMember31.ts b/tests/cases/fourslash/codeFixAddMissingMember31.ts new file mode 100644 index 0000000000000..62f488b3ac3a2 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingMember31.ts @@ -0,0 +1,17 @@ +/// + +////class C { +//// "new"(x: number) {} +////} +////[|const foo: C = {}|]; + +verify.codeFix({ + index: 0, + description: ts.Diagnostics.Add_missing_properties.message, + newRangeContent: +`const foo: C = { + new: function(x: number): void { + throw new Error("Function not implemented."); + } +}` +}); From 81827b07e0f9a27c59581452c91e09da0e375fb3 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:08:25 -0700 Subject: [PATCH 6/6] Tweak comment --- src/services/codefixes/fixAddMissingMember.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 2935ca9c1c1ea..3b9340f4e2bf3 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -772,7 +772,7 @@ function createPropertyNameFromSymbol(symbol: Symbol, target: ScriptTarget, quot const prop = checker.symbolToNode(symbol, SymbolFlags.Value, /*enclosingDeclaration*/ undefined, NodeBuilderFlags.WriteComputedProps); if (prop && isComputedPropertyName(prop)) return prop; } - // We're using these nodes as property names in an object literal; no need to handle quoting names. + // We're using these nodes as property names in an object literal; no need to quote names when not needed. return createPropertyNameNodeForIdentifierOrLiteral(symbol.name, target, quotePreference === QuotePreference.Single, /*stringNamed*/ false, /*isMethod*/ false); }