Handel export name bindings in internal modules in ES6

This commit is contained in:
Mohamed Hegazy
2015-03-16 21:58:57 -07:00
parent 3d802438f1
commit 1932f720cb
7 changed files with 380 additions and 2 deletions
+19 -2
View File
@@ -4930,7 +4930,7 @@ module ts {
writeLine();
emitMemberAssignments(node, NodeFlags.Static);
// If this is an exported classes, but not on the top level (i.e. on an internal
// If this is an exported class, but not on the top level (i.e. on an internal
// module), export it
if (!isES6ModuleMemberDeclaration(node) && (node.flags & NodeFlags.Export)) {
writeLine();
@@ -5348,7 +5348,7 @@ module ts {
}
function emitExportDeclaration(node: ExportDeclaration) {
if (languageVersion < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6 || node.parent.kind !== SyntaxKind.SourceFile) {
if (node.moduleSpecifier) {
emitStart(node);
let generatedName = resolver.getGeneratedNameForNode(node);
@@ -5386,6 +5386,23 @@ module ts {
}
emitEnd(node);
}
else {
// internal module
if (node.exportClause) {
// export { x, y, ... }
forEach(node.exportClause.elements, specifier => {
writeLine();
emitStart(specifier);
emitContainingModuleName(specifier);
write(".");
emitNodeWithoutSourceMap(specifier.name);
write(" = ");
emitNodeWithoutSourceMap(specifier.propertyName || specifier.name);
write(";");
emitEnd(specifier);
});
}
}
}
else {
write("export ");
@@ -0,0 +1,73 @@
//// [es5ModuleInternalNamedImports.ts]
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};
export {M_I as i};
export {M_C as c};
export {M_M as m};
export {M_MU as mu};
export {M_F as f};
export {M_E as e};
export {M_A as a};
}
//// [es5ModuleInternalNamedImports.js]
define(["require", "exports"], function (require, exports) {
var M;
(function (M) {
// variable
M.M_V = 0;
//calss
var M_C = (function () {
function M_C() {
}
return M_C;
})();
M.M_C = M_C;
// instantiated module
var M_M;
(function (M_M) {
var x;
})(M_M = M.M_M || (M.M_M = {}));
// function
function M_F() {
}
M.M_F = M_F;
// enum
(function (M_E) {
})(M.M_E || (M.M_E = {}));
var M_E = M.M_E;
// alias
M.M_A = M_M;
// Reexports
M.v = M.M_V;
M.i = M_I;
M.c = M_C;
M.m = M_M;
M.mu = M_MU;
M.f = M_F;
M.e = M_E;
M.a = M.M_A;
})(M = exports.M || (exports.M = {}));
});
@@ -0,0 +1,77 @@
=== 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,69 @@
//// [es6ModuleInternalNamedImports.ts]
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};
export {M_I as i};
export {M_C as c};
export {M_M as m};
export {M_MU as mu};
export {M_F as f};
export {M_E as e};
export {M_A as a};
}
//// [es6ModuleInternalNamedImports.js]
var M;
(function (M) {
// variable
M.M_V = 0;
//calss
class M_C {
}
M.M_C = M_C;
// instantiated module
var M_M;
(function (M_M) {
var x;
})(M_M = M.M_M || (M.M_M = {}));
// function
function M_F() {
}
M.M_F = M_F;
// enum
(function (M_E) {
})(M.M_E || (M.M_E = {}));
var M_E = M.M_E;
// alias
M.M_A = M_M;
// Reexports
M.v = M.M_V;
M.i = M_I;
M.c = M_C;
M.m = M_M;
M.mu = M_MU;
M.f = M_F;
M.e = M_E;
M.a = M.M_A;
})(M || (M = {}));
export { M };
@@ -0,0 +1,77 @@
=== 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,33 @@
// @target: ES5
// @module: AMD
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};
export {M_I as i};
export {M_C as c};
export {M_M as m};
export {M_MU as mu};
export {M_F as f};
export {M_E as e};
export {M_A as a};
}
@@ -0,0 +1,32 @@
// @target: ES6
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};
export {M_I as i};
export {M_C as c};
export {M_M as m};
export {M_MU as mu};
export {M_F as f};
export {M_E as e};
export {M_A as a};
}