diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 011a09ee64e..b114ffda86c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4748,7 +4748,12 @@ module ts { } write(");"); emitEnd(node); - if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { + + if (isES6ModuleMemberDeclaration(node)) { + // TODO update this to emit "export class " when ES67 class emit is available + emitES6NamedExportForDeclaration(node); + } + else if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { writeLine(); emitStart(node); emitModuleMemberName(node); @@ -4757,6 +4762,7 @@ module ts { emitEnd(node); write(";"); } + if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js deleted file mode 100644 index c2cd962408b..00000000000 --- a/tests/baselines/reference/es6ExportAll.js +++ /dev/null @@ -1,49 +0,0 @@ -//// [tests/cases/compiler/es6ExportAll.ts] //// - -//// [server.ts] - -export class c { -} -export interface i { -} -export module m { - export var x = 10; -} -export var x = 10; -export module uninstantiated { -} - -//// [client.ts] -export * from "server"; - -//// [server.js] -var c = (function () { - function c() { - } - return c; -})(); -c = c; -var m; -(function (m) { - m.x = 10; -})(m || (m = {})); -export { m }; -export var x = 10; -//// [client.js] -var _server = require("server"); -for (var _a in _server) if (!exports.hasOwnProperty(_a)) exports[_a] = _server[_a]; - - -//// [server.d.ts] -export declare class c { -} -export interface i { -} -export declare module m { - var x: number; -} -export declare var x: number; -export declare module uninstantiated { -} -//// [client.d.ts] -export * from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js deleted file mode 100644 index c3dcb4095e3..00000000000 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js +++ /dev/null @@ -1,66 +0,0 @@ -//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts] //// - -//// [server.ts] - -export class c { -} -export interface i { -} -export module m { - export var x = 10; -} -export var x = 10; -export module uninstantiated { -} - -//// [client.ts] -export { c } from "server"; -export { c as c2 } from "server"; -export { i, m as instantiatedModule } from "server"; -export { uninstantiated } from "server"; -export { x } from "server"; - -//// [server.js] -var c = (function () { - function c() { - } - return c; -})(); -c = c; -var m; -(function (m) { - m.x = 10; -})(m || (m = {})); -export { m }; -export var x = 10; -//// [client.js] -var _server = require("server"); -exports.c = _server.c; -var _server_1 = require("server"); -exports.c2 = _server_1.c; -var _server_2 = require("server"); -exports.i = _server_2.i; -exports.instantiatedModule = _server_2.m; -var _server_3 = require("server"); -exports.uninstantiated = _server_3.uninstantiated; -var _server_4 = require("server"); -exports.x = _server_4.x; - - -//// [server.d.ts] -export declare class c { -} -export interface i { -} -export declare module m { - var x: number; -} -export declare var x: number; -export declare module uninstantiated { -} -//// [client.d.ts] -export { c } from "server"; -export { c as c2 } from "server"; -export { i, m as instantiatedModule } from "server"; -export { uninstantiated } from "server"; -export { x } from "server"; diff --git a/tests/baselines/reference/es6Module.js b/tests/baselines/reference/es6Module.js index 56c5264c053..6c2e87fff1d 100644 --- a/tests/baselines/reference/es6Module.js +++ b/tests/baselines/reference/es6Module.js @@ -20,4 +20,4 @@ var A = (function () { }; return A; })(); -A = A; +export { A }; diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.js b/tests/baselines/reference/es6ModuleClassDeclaration.js new file mode 100644 index 00000000000..5ad7da0e8b2 --- /dev/null +++ b/tests/baselines/reference/es6ModuleClassDeclaration.js @@ -0,0 +1,238 @@ +//// [es6ModuleClassDeclaration.ts] +export class c { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +class c2 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +new c(); +new c2(); + +export module m1 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); +} +module m2 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +} + +//// [es6ModuleClassDeclaration.js] +var c = (function () { + function c() { + this.x = 10; + this.y = 30; + } + c.prototype.method1 = function () { + }; + c.prototype.method2 = function () { + }; + c.method3 = function () { + }; + c.method4 = function () { + }; + c.k = 20; + c.l = 30; + return c; +})(); +export { c }; +var c2 = (function () { + function c2() { + this.x = 10; + this.y = 30; + } + c2.prototype.method1 = function () { + }; + c2.prototype.method2 = function () { + }; + c2.method3 = function () { + }; + c2.method4 = function () { + }; + c2.k = 20; + c2.l = 30; + return c2; +})(); +new c(); +new c2(); +var m1; +(function (m1) { + var c3 = (function () { + function c3() { + this.x = 10; + this.y = 30; + } + c3.prototype.method1 = function () { + }; + c3.prototype.method2 = function () { + }; + c3.method3 = function () { + }; + c3.method4 = function () { + }; + c3.k = 20; + c3.l = 30; + return c3; + })(); + m1.c3 = c3; + var c4 = (function () { + function c4() { + this.x = 10; + this.y = 30; + } + c4.prototype.method1 = function () { + }; + c4.prototype.method2 = function () { + }; + c4.method3 = function () { + }; + c4.method4 = function () { + }; + c4.k = 20; + c4.l = 30; + return c4; + })(); + new c(); + new c2(); + new c3(); + new c4(); +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + var c3 = (function () { + function c3() { + this.x = 10; + this.y = 30; + } + c3.prototype.method1 = function () { + }; + c3.prototype.method2 = function () { + }; + c3.method3 = function () { + }; + c3.method4 = function () { + }; + c3.k = 20; + c3.l = 30; + return c3; + })(); + m2.c3 = c3; + var c4 = (function () { + function c4() { + this.x = 10; + this.y = 30; + } + c4.prototype.method1 = function () { + }; + c4.prototype.method2 = function () { + }; + c4.method3 = function () { + }; + c4.method4 = function () { + }; + c4.k = 20; + c4.l = 30; + return c4; + })(); + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.types b/tests/baselines/reference/es6ModuleClassDeclaration.types new file mode 100644 index 00000000000..09d50c4e542 --- /dev/null +++ b/tests/baselines/reference/es6ModuleClassDeclaration.types @@ -0,0 +1,233 @@ +=== tests/cases/compiler/es6ModuleClassDeclaration.ts === +export class c { +>c : c + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } +} +class c2 { +>c2 : c2 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } +} +new c(); +>new c() : c +>c : typeof c + +new c2(); +>new c2() : c2 +>c2 : typeof c2 + +export module m1 { +>m1 : typeof m1 + + export class c3 { +>c3 : c3 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + class c4 { +>c4 : c4 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + new c(); +>new c() : c +>c : typeof c + + new c2(); +>new c2() : c2 +>c2 : typeof c2 + + new c3(); +>new c3() : c3 +>c3 : typeof c3 + + new c4(); +>new c4() : c4 +>c4 : typeof c4 +} +module m2 { +>m2 : typeof m2 + + export class c3 { +>c3 : c3 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + class c4 { +>c4 : c4 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + new c(); +>new c() : c +>c : typeof c + + new c2(); +>new c2() : c2 +>c2 : typeof c2 + + new c3(); +>new c3() : c3 +>c3 : typeof c3 + + new c4(); +>new c4() : c4 +>c4 : typeof c4 + + new m1.c3(); +>new m1.c3() : m1.c3 +>m1.c3 : typeof m1.c3 +>m1 : typeof m1 +>c3 : typeof m1.c3 +} diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js index 36df01dc237..075cc28e82c 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js @@ -20,4 +20,4 @@ var A = (function () { }; return A; })(); -A = A; +export { A }; diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js index fbcebbd9d0d..de66fd0023b 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js @@ -20,4 +20,4 @@ var A = (function () { }; return A; })(); -A = A; +export { A }; diff --git a/tests/cases/compiler/es6ModuleClassDeclaration.ts b/tests/cases/compiler/es6ModuleClassDeclaration.ts new file mode 100644 index 00000000000..3b36e53037f --- /dev/null +++ b/tests/cases/compiler/es6ModuleClassDeclaration.ts @@ -0,0 +1,113 @@ +// @target: ES6 +export class c { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +class c2 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +new c(); +new c2(); + +export module m1 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); +} +module m2 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +} \ No newline at end of file