Disallow export declarations in internal modules

This commit is contained in:
Mohamed Hegazy
2015-03-24 21:17:11 -07:00
parent 27c5d6fa50
commit 6c40c95313
13 changed files with 201 additions and 284 deletions
+5
View File
@@ -10236,6 +10236,11 @@ module ts {
// export { x, y }
// export { x, y } from "foo"
forEach(node.exportClause.elements, checkExportSpecifier);
let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (<ModuleDeclaration>node.parent.parent).name.kind === SyntaxKind.StringLiteral;
if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) {
error(node, Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module);
}
}
else {
// export * from "foo"
+1 -29
View File
@@ -3838,35 +3838,7 @@ module ts {
}
function emitExportDeclaration(node: ExportDeclaration) {
if (node.parent.kind !== SyntaxKind.SourceFile) {
// internal module
if (node.exportClause) {
// export { x, y, ... }
for (let specifier of node.exportClause.elements) {
if (resolver.isValueAliasDeclaration(specifier)) {
writeLine();
emitStart(specifier);
emitContainingModuleName(specifier);
write(".");
emitNodeWithoutSourceMap(specifier.name);
write(" = ");
var name = specifier.propertyName || specifier.name;
var generatedName = getGeneratedNameForIdentifier(name);
if (generatedName) {
write(generatedName);
}
else {
emitExpressionIdentifier(name);
}
write(";");
emitEnd(specifier);
}
}
}
}
else if (languageVersion < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) {
emitStart(node);
let generatedName = resolver.getGeneratedNameForNode(node);
@@ -0,0 +1,59 @@
tests/cases/compiler/es5ModuleInternalNamedImports.ts(23,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es5ModuleInternalNamedImports.ts(24,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es5ModuleInternalNamedImports.ts(25,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es5ModuleInternalNamedImports.ts(26,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es5ModuleInternalNamedImports.ts(27,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es5ModuleInternalNamedImports.ts(28,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es5ModuleInternalNamedImports.ts(29,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es5ModuleInternalNamedImports.ts(30,5): error TS1194: Export declarations are not permitted in an internal module.
==== tests/cases/compiler/es5ModuleInternalNamedImports.ts (8 errors) ====
export module M {
// variable
export var M_V = 0;
// interface
export interface M_I { }
//calss
export class M_C { }
// instantiated module
export module M_M { var x; }
// uninstantiated module
export module M_MU { }
// function
export function M_F() { }
// enum
export enum M_E { }
// type
export type M_T = number;
// alias
export import M_A = M_M;
// Reexports
export {M_V as v};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_I as i};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_C as c};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_M as m};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_MU as mu};
~~~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_F as f};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_E as e};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_A as a};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
}
@@ -61,11 +61,5 @@ define(["require", "exports"], function (require, exports) {
// alias
M.M_A = M_M;
// Reexports
M.v = M.M_V;
M.c = M_C;
M.m = M_M;
M.f = M_F;
M.e = M_E;
M.a = M.M_A;
})(M = exports.M || (exports.M = {}));
});
@@ -1,77 +0,0 @@
=== tests/cases/compiler/es5ModuleInternalNamedImports.ts ===
export module M {
>M : typeof M
// variable
export var M_V = 0;
>M_V : number
// interface
export interface M_I { }
>M_I : M_I
//calss
export class M_C { }
>M_C : M_C
// instantiated module
export module M_M { var x; }
>M_M : typeof M_M
>x : any
// uninstantiated module
export module M_MU { }
>M_MU : unknown
// function
export function M_F() { }
>M_F : () => void
// enum
export enum M_E { }
>M_E : M_E
// type
export type M_T = number;
>M_T : number
// alias
export import M_A = M_M;
>M_A : typeof M_M
>M_M : typeof M_M
// Reexports
export {M_V as v};
>M_V : number
>v : number
export {M_I as i};
>M_I : unknown
>i : unknown
export {M_C as c};
>M_C : typeof M_C
>c : typeof M_C
export {M_M as m};
>M_M : typeof M_M
>m : typeof M_M
export {M_MU as mu};
>M_MU : unknown
>mu : unknown
export {M_F as f};
>M_F : () => void
>f : () => void
export {M_E as e};
>M_E : typeof M_E
>e : typeof M_E
export {M_A as a};
>M_A : typeof M_M
>a : typeof M_M
}
@@ -0,0 +1,59 @@
tests/cases/compiler/es6ModuleInternalNamedImports.ts(23,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports.ts(24,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports.ts(25,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports.ts(26,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports.ts(27,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports.ts(28,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports.ts(29,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports.ts(30,5): error TS1194: Export declarations are not permitted in an internal module.
==== tests/cases/compiler/es6ModuleInternalNamedImports.ts (8 errors) ====
export module M {
// variable
export var M_V = 0;
// interface
export interface M_I { }
//calss
export class M_C { }
// instantiated module
export module M_M { var x; }
// uninstantiated module
export module M_MU { }
// function
export function M_F() { }
// enum
export enum M_E { }
// type
export type M_T = number;
// alias
export import M_A = M_M;
// Reexports
export {M_V as v};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_I as i};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_C as c};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_M as m};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_MU as mu};
~~~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_F as f};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_E as e};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_A as a};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
}
@@ -57,11 +57,11 @@ var M;
// alias
M.M_A = M_M;
// Reexports
M.v = M.M_V;
M.c = M_C;
M.m = M_M;
M.f = M_F;
M.e = M_E;
M.a = M.M_A;
export { M_V as v };
export { M_C as c };
export { M_M as m };
export { M_F as f };
export { M_E as e };
export { M_A as a };
})(M || (M = {}));
export { M };
@@ -1,77 +0,0 @@
=== tests/cases/compiler/es6ModuleInternalNamedImports.ts ===
export module M {
>M : typeof M
// variable
export var M_V = 0;
>M_V : number
// interface
export interface M_I { }
>M_I : M_I
//calss
export class M_C { }
>M_C : M_C
// instantiated module
export module M_M { var x; }
>M_M : typeof M_M
>x : any
// uninstantiated module
export module M_MU { }
>M_MU : unknown
// function
export function M_F() { }
>M_F : () => void
// enum
export enum M_E { }
>M_E : M_E
// type
export type M_T = number;
>M_T : number
// alias
export import M_A = M_M;
>M_A : typeof M_M
>M_M : typeof M_M
// Reexports
export {M_V as v};
>M_V : number
>v : number
export {M_I as i};
>M_I : unknown
>i : unknown
export {M_C as c};
>M_C : typeof M_C
>c : typeof M_C
export {M_M as m};
>M_M : typeof M_M
>m : typeof M_M
export {M_MU as mu};
>M_MU : unknown
>mu : unknown
export {M_F as f};
>M_F : () => void
>f : () => void
export {M_E as e};
>M_E : typeof M_E
>e : typeof M_E
export {M_A as a};
>M_A : typeof M_M
>a : typeof M_M
}
@@ -0,0 +1,61 @@
tests/cases/compiler/es6ModuleInternalNamedImports2.ts(25,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports2.ts(26,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports2.ts(27,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports2.ts(28,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports2.ts(29,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports2.ts(30,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports2.ts(31,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/es6ModuleInternalNamedImports2.ts(32,5): error TS1194: Export declarations are not permitted in an internal module.
==== tests/cases/compiler/es6ModuleInternalNamedImports2.ts (8 errors) ====
export module M {
// variable
export var M_V = 0;
// interface
export interface M_I { }
//calss
export class M_C { }
// instantiated module
export module M_M { var x; }
// uninstantiated module
export module M_MU { }
// function
export function M_F() { }
// enum
export enum M_E { }
// type
export type M_T = number;
// alias
export import M_A = M_M;
}
export module M {
// Reexports
export {M_V as v};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_I as i};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_C as c};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_M as m};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_MU as mu};
~~~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_F as f};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_E as e};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
export {M_A as a};
~~~~~~~~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
}
@@ -63,11 +63,11 @@ export { M };
var M;
(function (M) {
// Reexports
M.v = M.M_V;
M.c = M.M_C;
M.m = M.M_M;
M.f = M.M_F;
M.e = M.M_E;
M.a = M.M_A;
export { M_V as v };
export { M_C as c };
export { M_M as m };
export { M_F as f };
export { M_E as e };
export { M_A as a };
})(M || (M = {}));
export { M };
@@ -1,81 +0,0 @@
=== tests/cases/compiler/es6ModuleInternalNamedImports2.ts ===
export module M {
>M : typeof M
// variable
export var M_V = 0;
>M_V : number
// interface
export interface M_I { }
>M_I : M_I
//calss
export class M_C { }
>M_C : M_C
// instantiated module
export module M_M { var x; }
>M_M : typeof M_M
>x : any
// uninstantiated module
export module M_MU { }
>M_MU : unknown
// function
export function M_F() { }
>M_F : () => void
// enum
export enum M_E { }
>M_E : M_E
// type
export type M_T = number;
>M_T : number
// alias
export import M_A = M_M;
>M_A : typeof M_M
>M_M : typeof M_M
}
export module M {
>M : typeof M
// Reexports
export {M_V as v};
>M_V : number
>v : number
export {M_I as i};
>M_I : unknown
>i : unknown
export {M_C as c};
>M_C : typeof M_C
>c : typeof M_C
export {M_M as m};
>M_M : typeof M_M
>m : typeof M_M
export {M_MU as mu};
>M_MU : unknown
>mu : unknown
export {M_F as f};
>M_F : () => void
>f : () => void
export {M_E as e};
>M_E : typeof M_E
>e : typeof M_E
export {M_A as a};
>M_A : typeof M_M
>a : typeof M_M
}
@@ -1,7 +1,8 @@
tests/cases/compiler/multipleExports.ts(10,5): error TS1194: Export declarations are not permitted in an internal module.
tests/cases/compiler/multipleExports.ts(10,13): error TS2484: Export declaration conflicts with exported declaration of 'x'
==== tests/cases/compiler/multipleExports.ts (1 errors) ====
==== tests/cases/compiler/multipleExports.ts (2 errors) ====
export module M {
export var v = 0;
@@ -12,6 +13,8 @@ tests/cases/compiler/multipleExports.ts(10,13): error TS2484: Export declaration
export module M {
v;
export {x};
~~~~~~~~~~~
!!! error TS1194: Export declarations are not permitted in an internal module.
~
!!! error TS2484: Export declaration conflicts with exported declaration of 'x'
}
@@ -22,5 +22,4 @@ var x = 0;
var M;
(function (M) {
M.v;
M.x = M.x;
})(M = exports.M || (exports.M = {}));