Skip to content

Commit 2b7a547

Browse files
committed
fix: update diagnostic message for class name 'Object' to reflect targeting ES5 and above
1 parent 538e542 commit 2b7a547

10 files changed

Lines changed: 15 additions & 34 deletions

src/compiler/checker.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46569,13 +46569,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4656946569
languageVersion >= ScriptTarget.ES5 && name.escapedText === "Object"
4657046570
&& host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < ModuleKind.ES2015
4657146571
) {
46572-
// https://github.com/Microsoft/TypeScript/issues/17494
46573-
error(
46574-
name,
46575-
Diagnostics.Class_name_cannot_be_Object_when_targeting_0_with_module_1,
46576-
ScriptTarget[languageVersion],
46577-
ModuleKind[moduleKind],
46578-
);
46572+
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_and_above_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
4657946573
}
4658046574
}
4658146575

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3419,7 +3419,7 @@
34193419
"category": "Error",
34203420
"code": 2724
34213421
},
3422-
"Class name cannot be 'Object' when targeting {0} with module {1}.": {
3422+
"Class name cannot be 'Object' when targeting ES5 and above with module {0}.": {
34233423
"category": "Error",
34243424
"code": 2725
34253425
},

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7654,7 +7654,7 @@ export const enum ScriptKind {
76547654
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
76557655
// `ScriptTargetFeatures` transformers/esnext.ts, compiler/commandLineParser.ts,
76567656
// compiler/utilitiesPublic.ts, and the contents of each lib/esnext.*.d.ts file.
7657-
export enum ScriptTarget {
7657+
export const enum ScriptTarget {
76587658
/** @deprecated */
76597659
ES3 = 0,
76607660
ES5 = 1,

tests/baselines/reference/nodeModulesAllowJsGeneratedNameCollisions(module=node16).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
subfolder/index.js(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
22
subfolder/index.js(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
3-
subfolder/index.js(4,7): error TS2725: Class name cannot be 'Object' when targeting ES2022 with module Node16.
3+
subfolder/index.js(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node16.
44
subfolder/index.js(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
55

66

@@ -14,7 +14,7 @@ subfolder/index.js(5,14): error TS1216: Identifier expected. '__esModule' is res
1414
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
1515
class Object {}
1616
~~~~~~
17-
!!! error TS2725: Class name cannot be 'Object' when targeting ES2022 with module Node16.
17+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node16.
1818
export const __esModule = false;
1919
~~~~~~~~~~
2020
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.

tests/baselines/reference/nodeModulesAllowJsGeneratedNameCollisions(module=node18).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
subfolder/index.js(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
22
subfolder/index.js(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
3-
subfolder/index.js(4,7): error TS2725: Class name cannot be 'Object' when targeting ES2022 with module Node18.
3+
subfolder/index.js(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node18.
44
subfolder/index.js(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
55

66

@@ -14,7 +14,7 @@ subfolder/index.js(5,14): error TS1216: Identifier expected. '__esModule' is res
1414
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
1515
class Object {}
1616
~~~~~~
17-
!!! error TS2725: Class name cannot be 'Object' when targeting ES2022 with module Node18.
17+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node18.
1818
export const __esModule = false;
1919
~~~~~~~~~~
2020
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.

tests/baselines/reference/nodeModulesAllowJsGeneratedNameCollisions(module=nodenext).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
subfolder/index.js(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
22
subfolder/index.js(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
3-
subfolder/index.js(4,7): error TS2725: Class name cannot be 'Object' when targeting Latest with module NodeNext.
3+
subfolder/index.js(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module NodeNext.
44
subfolder/index.js(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
55

66

@@ -14,7 +14,7 @@ subfolder/index.js(5,14): error TS1216: Identifier expected. '__esModule' is res
1414
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
1515
class Object {}
1616
~~~~~~
17-
!!! error TS2725: Class name cannot be 'Object' when targeting Latest with module NodeNext.
17+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module NodeNext.
1818
export const __esModule = false;
1919
~~~~~~~~~~
2020
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.

tests/baselines/reference/nodeModulesGeneratedNameCollisions(module=node16).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
subfolder/index.ts(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
22
subfolder/index.ts(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
3-
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES2022 with module Node16.
3+
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node16.
44
subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
55

66

@@ -14,7 +14,7 @@ subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is res
1414
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
1515
class Object {}
1616
~~~~~~
17-
!!! error TS2725: Class name cannot be 'Object' when targeting ES2022 with module Node16.
17+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node16.
1818
export const __esModule = false;
1919
~~~~~~~~~~
2020
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.

tests/baselines/reference/nodeModulesGeneratedNameCollisions(module=node18).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
subfolder/index.ts(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
22
subfolder/index.ts(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
3-
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES2022 with module Node18.
3+
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node18.
44
subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
55

66

@@ -14,7 +14,7 @@ subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is res
1414
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
1515
class Object {}
1616
~~~~~~
17-
!!! error TS2725: Class name cannot be 'Object' when targeting ES2022 with module Node18.
17+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node18.
1818
export const __esModule = false;
1919
~~~~~~~~~~
2020
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.

tests/baselines/reference/nodeModulesGeneratedNameCollisions(module=nodenext).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
subfolder/index.ts(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
22
subfolder/index.ts(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
3-
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting Latest with module NodeNext.
3+
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module NodeNext.
44
subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
55

66

@@ -14,7 +14,7 @@ subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is res
1414
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
1515
class Object {}
1616
~~~~~~
17-
!!! error TS2725: Class name cannot be 'Object' when targeting Latest with module NodeNext.
17+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module NodeNext.
1818
export const __esModule = false;
1919
~~~~~~~~~~
2020
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.

tests/cases/fourslash/issue61270.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)