Skip to content

Commit 27faffb

Browse files
committed
Merge branch 'Kingwl-fix-es5-export-class-name-object'
2 parents 725dbcc + a7a68d9 commit 27faffb

File tree

39 files changed

+258
-0
lines changed

39 files changed

+258
-0
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24153,6 +24153,16 @@ namespace ts {
2415324153
}
2415424154
}
2415524155

24156+
/**
24157+
* The name cannot be used as 'Object' of user defined types with special target.
24158+
*/
24159+
function checkClassNameCollisionWithObject(name: Identifier): void {
24160+
if (languageVersion === ScriptTarget.ES5 && name.escapedText === "Object"
24161+
&& moduleKind !== ModuleKind.ES2015 && moduleKind !== ModuleKind.ESNext) {
24162+
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
24163+
}
24164+
}
24165+
2415624166
/**
2415724167
* Check each type parameter and check that type parameters have no duplicate type parameter declarations
2415824168
*/
@@ -24279,6 +24289,9 @@ namespace ts {
2427924289
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0);
2428024290
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
2428124291
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
24292+
if (!(node.flags & NodeFlags.Ambient)) {
24293+
checkClassNameCollisionWithObject(node.name);
24294+
}
2428224295
}
2428324296
checkTypeParameters(getEffectiveTypeParameterDeclarations(node));
2428424297
checkExportsOnMergedDeclarations(node);

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,6 +2357,11 @@
23572357
"category": "Error",
23582358
"code": 2724
23592359
},
2360+
"Class name cannot be 'Object' when targeting ES5 with module {0}.": {
2361+
"category": "Error",
2362+
"code": 2725
2363+
},
2364+
23602365
"Import declaration '{0}' is using private name '{1}'.": {
23612366
"category": "Error",
23622367
"code": 4000
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [es6modulekindExportClassNameWithObject.ts]
2+
export class Object {}
3+
4+
5+
//// [es6modulekindExportClassNameWithObject.js]
6+
var Object = /** @class */ (function () {
7+
function Object() {
8+
}
9+
return Object;
10+
}());
11+
export { Object };
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/externalModules/es6/es6modulekindExportClassNameWithObject.ts ===
2+
export class Object {}
3+
>Object : Symbol(Object, Decl(es6modulekindExportClassNameWithObject.ts, 0, 0))
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/externalModules/es6/es6modulekindExportClassNameWithObject.ts ===
2+
export class Object {}
3+
>Object : Object
4+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [exnextmodulekindExportClassNameWithObject.ts]
2+
export class Object {}
3+
4+
5+
//// [exnextmodulekindExportClassNameWithObject.js]
6+
var Object = /** @class */ (function () {
7+
function Object() {
8+
}
9+
return Object;
10+
}());
11+
export { Object };
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/externalModules/esnext/exnextmodulekindExportClassNameWithObject.ts ===
2+
export class Object {}
3+
>Object : Symbol(Object, Decl(exnextmodulekindExportClassNameWithObject.ts, 0, 0))
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/externalModules/esnext/exnextmodulekindExportClassNameWithObject.ts ===
2+
export class Object {}
3+
>Object : Object
4+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [exportAmbientClassNameWithObject.ts]
2+
export declare class Object {}
3+
4+
5+
//// [exportAmbientClassNameWithObject.js]
6+
"use strict";
7+
Object.defineProperty(exports, "__esModule", { value: true });
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/externalModules/exportAmbientClassNameWithObject.ts ===
2+
export declare class Object {}
3+
>Object : Symbol(Object, Decl(exportAmbientClassNameWithObject.ts, 0, 0))
4+

0 commit comments

Comments
 (0)