Skip to content

Commit ba928e6

Browse files
committed
fix: diagnostic message for class name 'Object' when targeting different ECMAScript versions
1 parent c85e626 commit ba928e6

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/compiler/checker.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46005,7 +46005,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4600546005
languageVersion >= ScriptTarget.ES5 && name.escapedText === "Object"
4600646006
&& host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < ModuleKind.ES2015
4600746007
) {
46008-
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
46008+
// https://github.com/Microsoft/TypeScript/issues/17494
46009+
error(
46010+
name,
46011+
Diagnostics.Class_name_cannot_be_Object_when_targeting_0_with_module_1,
46012+
ScriptTarget[languageVersion],
46013+
ModuleKind[moduleKind]
46014+
);
4600946015
}
4601046016
}
4601146017

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3411,7 +3411,7 @@
34113411
"category": "Error",
34123412
"code": 2724
34133413
},
3414-
"Class name cannot be 'Object' when targeting ES5 with module {0}.": {
3414+
"Class name cannot be 'Object' when targeting {0} with module {1}.": {
34153415
"category": "Error",
34163416
"code": 2725
34173417
},

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7598,7 +7598,7 @@ export const enum ScriptKind {
75987598
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
75997599
// `ScriptTargetFeatures` transformers/esnext.ts, compiler/commandLineParser.ts,
76007600
// compiler/utilitiesPublic.ts, and the contents of each lib/esnext.*.d.ts file.
7601-
export const enum ScriptTarget {
7601+
export enum ScriptTarget {
76027602
/** @deprecated */
76037603
ES3 = 0,
76047604
ES5 = 1,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @target: es5
4+
// @module: node16
5+
6+
// @filename: test.ts
7+
//// namespace NS { class Object {} }
8+
9+
verify.getSemanticDiagnostics([{
10+
code: 2725,
11+
message: "Class name cannot be 'Object' when targeting ES5 with module Node16.",
12+
range: { pos: 21, end: 27, fileName: "test.ts" }
13+
}]);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @target: es2024
4+
// @module: commonjs
5+
6+
// @filename: test.ts
7+
//// namespace NS { class Object {} }
8+
9+
verify.getSemanticDiagnostics([{
10+
code: 2725,
11+
message: "Class name cannot be 'Object' when targeting ES2024 with module CommonJS.",
12+
range: { pos: 21, end: 27, fileName: "test.ts" }
13+
}]);

0 commit comments

Comments
 (0)