Merge branch 'Kingwl-fix-es5-export-class-name-object'

This commit is contained in:
Mohamed Hegazy 2018-05-25 15:45:42 -07:00
commit 27faffb865
39 changed files with 258 additions and 0 deletions

View File

@ -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);

View File

@ -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

View File

@ -0,0 +1,11 @@
//// [es6modulekindExportClassNameWithObject.ts]
export class Object {}
//// [es6modulekindExportClassNameWithObject.js]
var Object = /** @class */ (function () {
function Object() {
}
return Object;
}());
export { Object };

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/es6/es6modulekindExportClassNameWithObject.ts ===
export class Object {}
>Object : Symbol(Object, Decl(es6modulekindExportClassNameWithObject.ts, 0, 0))

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/es6/es6modulekindExportClassNameWithObject.ts ===
export class Object {}
>Object : Object

View File

@ -0,0 +1,11 @@
//// [exnextmodulekindExportClassNameWithObject.ts]
export class Object {}
//// [exnextmodulekindExportClassNameWithObject.js]
var Object = /** @class */ (function () {
function Object() {
}
return Object;
}());
export { Object };

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/esnext/exnextmodulekindExportClassNameWithObject.ts ===
export class Object {}
>Object : Symbol(Object, Decl(exnextmodulekindExportClassNameWithObject.ts, 0, 0))

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/esnext/exnextmodulekindExportClassNameWithObject.ts ===
export class Object {}
>Object : Object

View File

@ -0,0 +1,7 @@
//// [exportAmbientClassNameWithObject.ts]
export declare class Object {}
//// [exportAmbientClassNameWithObject.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportAmbientClassNameWithObject.ts ===
export declare class Object {}
>Object : Symbol(Object, Decl(exportAmbientClassNameWithObject.ts, 0, 0))

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportAmbientClassNameWithObject.ts ===
export declare class Object {}
>Object : Object

View File

@ -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.

View 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;
});

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportClassNameWithObjectAMD.ts ===
export class Object {}
>Object : Symbol(Object, Decl(exportClassNameWithObjectAMD.ts, 0, 0))

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportClassNameWithObjectAMD.ts ===
export class Object {}
>Object : Object

View File

@ -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.

View File

@ -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;

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportClassNameWithObjectCommonJS.ts ===
export class Object {}
>Object : Symbol(Object, Decl(exportClassNameWithObjectCommonJS.ts, 0, 0))

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportClassNameWithObjectCommonJS.ts ===
export class Object {}
>Object : Object

View File

@ -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.

View 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);
}
};
});

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportClassNameWithObjectSystem.ts ===
export class Object {}
>Object : Symbol(Object, Decl(exportClassNameWithObjectSystem.ts, 0, 0))

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportClassNameWithObjectSystem.ts ===
export class Object {}
>Object : Object

View File

@ -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.

View 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;
});

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportClassNameWithObjectUMD.ts ===
export class Object {}
>Object : Symbol(Object, Decl(exportClassNameWithObjectUMD.ts, 0, 0))

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportClassNameWithObjectUMD.ts ===
export class Object {}
>Object : Object

View File

@ -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.

View File

@ -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;

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportDefaultClassNameWithObject.ts ===
export default class Object {}
>Object : Symbol(Object, Decl(exportDefaultClassNameWithObject.ts, 0, 0))

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/externalModules/exportDefaultClassNameWithObject.ts ===
export default class Object {}
>Object : Object

View File

@ -0,0 +1,3 @@
// @target: ES5
// @module: es2015
export class Object {}

View File

@ -0,0 +1,3 @@
// @target: ES5
// @module: esnext
export class Object {}

View File

@ -0,0 +1,2 @@
// @target: ES5
export declare class Object {}

View File

@ -0,0 +1,3 @@
// @target: ES5
// @module: amd
export class Object {}

View File

@ -0,0 +1,3 @@
// @target: ES5
// @module: commonjs
export class Object {}

View File

@ -0,0 +1,3 @@
// @target: ES5
// @module: system
export class Object {}

View File

@ -0,0 +1,3 @@
// @target: ES5
// @module: umd
export class Object {}

View File

@ -0,0 +1,2 @@
// @target: ES5
export default class Object {}