diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cb85104fb79..1f152a83b99 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 && (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" diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 93ff34fef8e..3d80a9eb08a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -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); diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt b/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt new file mode 100644 index 00000000000..65f29984d59 --- /dev/null +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt @@ -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. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.js b/tests/baselines/reference/es5ModuleInternalNamedImports.js index 66e94204c5a..456ad30523b 100644 --- a/tests/baselines/reference/es5ModuleInternalNamedImports.js +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.js @@ -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 = {})); }); diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.types b/tests/baselines/reference/es5ModuleInternalNamedImports.types deleted file mode 100644 index fa88ab399a3..00000000000 --- a/tests/baselines/reference/es5ModuleInternalNamedImports.types +++ /dev/null @@ -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 -} - diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt b/tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt new file mode 100644 index 00000000000..4e097ec1a33 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt @@ -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. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.js b/tests/baselines/reference/es6ModuleInternalNamedImports.js index 096cdd1ca40..e4881d7ec4e 100644 --- a/tests/baselines/reference/es6ModuleInternalNamedImports.js +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.js @@ -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 }; diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.types b/tests/baselines/reference/es6ModuleInternalNamedImports.types deleted file mode 100644 index 6b614926a0a..00000000000 --- a/tests/baselines/reference/es6ModuleInternalNamedImports.types +++ /dev/null @@ -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 -} - diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt b/tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt new file mode 100644 index 00000000000..77ee76cf9c8 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt @@ -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. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.js b/tests/baselines/reference/es6ModuleInternalNamedImports2.js index c48d3214401..3f86def1d42 100644 --- a/tests/baselines/reference/es6ModuleInternalNamedImports2.js +++ b/tests/baselines/reference/es6ModuleInternalNamedImports2.js @@ -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 }; diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.types b/tests/baselines/reference/es6ModuleInternalNamedImports2.types deleted file mode 100644 index 3612b1922ef..00000000000 --- a/tests/baselines/reference/es6ModuleInternalNamedImports2.types +++ /dev/null @@ -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 -} - diff --git a/tests/baselines/reference/multipleExports.errors.txt b/tests/baselines/reference/multipleExports.errors.txt index d0750b65313..254717843cf 100644 --- a/tests/baselines/reference/multipleExports.errors.txt +++ b/tests/baselines/reference/multipleExports.errors.txt @@ -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' } diff --git a/tests/baselines/reference/multipleExports.js b/tests/baselines/reference/multipleExports.js index 12ee1590cef..b8c08952b67 100644 --- a/tests/baselines/reference/multipleExports.js +++ b/tests/baselines/reference/multipleExports.js @@ -22,5 +22,4 @@ var x = 0; var M; (function (M) { M.v; - M.x = M.x; })(M = exports.M || (exports.M = {}));