mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Merge branch 'Kingwl-fix-es5-export-class-name-object'
This commit is contained in:
commit
27faffb865
@ -24153,6 +24153,16 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The name cannot be used as 'Object' of user defined types with special target.
|
||||
*/
|
||||
function checkClassNameCollisionWithObject(name: Identifier): void {
|
||||
if (languageVersion === ScriptTarget.ES5 && name.escapedText === "Object"
|
||||
&& moduleKind !== ModuleKind.ES2015 && moduleKind !== ModuleKind.ESNext) {
|
||||
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check each type parameter and check that type parameters have no duplicate type parameter declarations
|
||||
*/
|
||||
@ -24279,6 +24289,9 @@ namespace ts {
|
||||
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0);
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
|
||||
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
|
||||
if (!(node.flags & NodeFlags.Ambient)) {
|
||||
checkClassNameCollisionWithObject(node.name);
|
||||
}
|
||||
}
|
||||
checkTypeParameters(getEffectiveTypeParameterDeclarations(node));
|
||||
checkExportsOnMergedDeclarations(node);
|
||||
|
||||
@ -2357,6 +2357,11 @@
|
||||
"category": "Error",
|
||||
"code": 2724
|
||||
},
|
||||
"Class name cannot be 'Object' when targeting ES5 with module {0}.": {
|
||||
"category": "Error",
|
||||
"code": 2725
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
//// [es6modulekindExportClassNameWithObject.ts]
|
||||
export class Object {}
|
||||
|
||||
|
||||
//// [es6modulekindExportClassNameWithObject.js]
|
||||
var Object = /** @class */ (function () {
|
||||
function Object() {
|
||||
}
|
||||
return Object;
|
||||
}());
|
||||
export { Object };
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/es6/es6modulekindExportClassNameWithObject.ts ===
|
||||
export class Object {}
|
||||
>Object : Symbol(Object, Decl(es6modulekindExportClassNameWithObject.ts, 0, 0))
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/es6/es6modulekindExportClassNameWithObject.ts ===
|
||||
export class Object {}
|
||||
>Object : Object
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
//// [exnextmodulekindExportClassNameWithObject.ts]
|
||||
export class Object {}
|
||||
|
||||
|
||||
//// [exnextmodulekindExportClassNameWithObject.js]
|
||||
var Object = /** @class */ (function () {
|
||||
function Object() {
|
||||
}
|
||||
return Object;
|
||||
}());
|
||||
export { Object };
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/esnext/exnextmodulekindExportClassNameWithObject.ts ===
|
||||
export class Object {}
|
||||
>Object : Symbol(Object, Decl(exnextmodulekindExportClassNameWithObject.ts, 0, 0))
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/esnext/exnextmodulekindExportClassNameWithObject.ts ===
|
||||
export class Object {}
|
||||
>Object : Object
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
//// [exportAmbientClassNameWithObject.ts]
|
||||
export declare class Object {}
|
||||
|
||||
|
||||
//// [exportAmbientClassNameWithObject.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportAmbientClassNameWithObject.ts ===
|
||||
export declare class Object {}
|
||||
>Object : Symbol(Object, Decl(exportAmbientClassNameWithObject.ts, 0, 0))
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportAmbientClassNameWithObject.ts ===
|
||||
export declare class Object {}
|
||||
>Object : Object
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
tests/cases/conformance/externalModules/exportClassNameWithObjectAMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module AMD.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/exportClassNameWithObjectAMD.ts (1 errors) ====
|
||||
export class Object {}
|
||||
~~~~~~
|
||||
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module AMD.
|
||||
|
||||
15
tests/baselines/reference/exportClassNameWithObjectAMD.js
Normal file
15
tests/baselines/reference/exportClassNameWithObjectAMD.js
Normal file
@ -0,0 +1,15 @@
|
||||
//// [exportClassNameWithObjectAMD.ts]
|
||||
export class Object {}
|
||||
|
||||
|
||||
//// [exportClassNameWithObjectAMD.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Object = /** @class */ (function () {
|
||||
function Object() {
|
||||
}
|
||||
return Object;
|
||||
}());
|
||||
exports.Object = Object;
|
||||
});
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportClassNameWithObjectAMD.ts ===
|
||||
export class Object {}
|
||||
>Object : Symbol(Object, Decl(exportClassNameWithObjectAMD.ts, 0, 0))
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportClassNameWithObjectAMD.ts ===
|
||||
export class Object {}
|
||||
>Object : Object
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
tests/cases/conformance/externalModules/exportClassNameWithObjectCommonJS.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/exportClassNameWithObjectCommonJS.ts (1 errors) ====
|
||||
export class Object {}
|
||||
~~~~~~
|
||||
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
//// [exportClassNameWithObjectCommonJS.ts]
|
||||
export class Object {}
|
||||
|
||||
|
||||
//// [exportClassNameWithObjectCommonJS.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Object = /** @class */ (function () {
|
||||
function Object() {
|
||||
}
|
||||
return Object;
|
||||
}());
|
||||
exports.Object = Object;
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportClassNameWithObjectCommonJS.ts ===
|
||||
export class Object {}
|
||||
>Object : Symbol(Object, Decl(exportClassNameWithObjectCommonJS.ts, 0, 0))
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportClassNameWithObjectCommonJS.ts ===
|
||||
export class Object {}
|
||||
>Object : Object
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
tests/cases/conformance/externalModules/exportClassNameWithObjectSystem.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module System.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/exportClassNameWithObjectSystem.ts (1 errors) ====
|
||||
export class Object {}
|
||||
~~~~~~
|
||||
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module System.
|
||||
|
||||
21
tests/baselines/reference/exportClassNameWithObjectSystem.js
Normal file
21
tests/baselines/reference/exportClassNameWithObjectSystem.js
Normal file
@ -0,0 +1,21 @@
|
||||
//// [exportClassNameWithObjectSystem.ts]
|
||||
export class Object {}
|
||||
|
||||
|
||||
//// [exportClassNameWithObjectSystem.js]
|
||||
System.register([], function (exports_1, context_1) {
|
||||
var Object;
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
Object = /** @class */ (function () {
|
||||
function Object() {
|
||||
}
|
||||
return Object;
|
||||
}());
|
||||
exports_1("Object", Object);
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportClassNameWithObjectSystem.ts ===
|
||||
export class Object {}
|
||||
>Object : Symbol(Object, Decl(exportClassNameWithObjectSystem.ts, 0, 0))
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportClassNameWithObjectSystem.ts ===
|
||||
export class Object {}
|
||||
>Object : Object
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
tests/cases/conformance/externalModules/exportClassNameWithObjectUMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module UMD.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/exportClassNameWithObjectUMD.ts (1 errors) ====
|
||||
export class Object {}
|
||||
~~~~~~
|
||||
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module UMD.
|
||||
|
||||
23
tests/baselines/reference/exportClassNameWithObjectUMD.js
Normal file
23
tests/baselines/reference/exportClassNameWithObjectUMD.js
Normal file
@ -0,0 +1,23 @@
|
||||
//// [exportClassNameWithObjectUMD.ts]
|
||||
export class Object {}
|
||||
|
||||
|
||||
//// [exportClassNameWithObjectUMD.js]
|
||||
(function (factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") {
|
||||
var v = factory(require, exports);
|
||||
if (v !== undefined) module.exports = v;
|
||||
}
|
||||
else if (typeof define === "function" && define.amd) {
|
||||
define(["require", "exports"], factory);
|
||||
}
|
||||
})(function (require, exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Object = /** @class */ (function () {
|
||||
function Object() {
|
||||
}
|
||||
return Object;
|
||||
}());
|
||||
exports.Object = Object;
|
||||
});
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportClassNameWithObjectUMD.ts ===
|
||||
export class Object {}
|
||||
>Object : Symbol(Object, Decl(exportClassNameWithObjectUMD.ts, 0, 0))
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportClassNameWithObjectUMD.ts ===
|
||||
export class Object {}
|
||||
>Object : Object
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
tests/cases/conformance/externalModules/exportDefaultClassNameWithObject.ts(1,22): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/exportDefaultClassNameWithObject.ts (1 errors) ====
|
||||
export default class Object {}
|
||||
~~~~~~
|
||||
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
//// [exportDefaultClassNameWithObject.ts]
|
||||
export default class Object {}
|
||||
|
||||
|
||||
//// [exportDefaultClassNameWithObject.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Object = /** @class */ (function () {
|
||||
function Object() {
|
||||
}
|
||||
return Object;
|
||||
}());
|
||||
exports.default = Object;
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportDefaultClassNameWithObject.ts ===
|
||||
export default class Object {}
|
||||
>Object : Symbol(Object, Decl(exportDefaultClassNameWithObject.ts, 0, 0))
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/externalModules/exportDefaultClassNameWithObject.ts ===
|
||||
export default class Object {}
|
||||
>Object : Object
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
// @target: ES5
|
||||
// @module: es2015
|
||||
export class Object {}
|
||||
@ -0,0 +1,3 @@
|
||||
// @target: ES5
|
||||
// @module: esnext
|
||||
export class Object {}
|
||||
@ -0,0 +1,2 @@
|
||||
// @target: ES5
|
||||
export declare class Object {}
|
||||
@ -0,0 +1,3 @@
|
||||
// @target: ES5
|
||||
// @module: amd
|
||||
export class Object {}
|
||||
@ -0,0 +1,3 @@
|
||||
// @target: ES5
|
||||
// @module: commonjs
|
||||
export class Object {}
|
||||
@ -0,0 +1,3 @@
|
||||
// @target: ES5
|
||||
// @module: system
|
||||
export class Object {}
|
||||
@ -0,0 +1,3 @@
|
||||
// @target: ES5
|
||||
// @module: umd
|
||||
export class Object {}
|
||||
@ -0,0 +1,2 @@
|
||||
// @target: ES5
|
||||
export default class Object {}
|
||||
Loading…
x
Reference in New Issue
Block a user