mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Emit export class declaration in es6 format.
Note since we havent yet changed the emitting of class declaration to es6 format, we are just exporting the constructor function Conflicts: src/compiler/emitter.ts
This commit is contained in:
parent
b091fa57ef
commit
6bcbe824aa
@ -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);
|
||||
}
|
||||
|
||||
@ -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";
|
||||
@ -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";
|
||||
@ -20,4 +20,4 @@ var A = (function () {
|
||||
};
|
||||
return A;
|
||||
})();
|
||||
A = A;
|
||||
export { A };
|
||||
|
||||
238
tests/baselines/reference/es6ModuleClassDeclaration.js
Normal file
238
tests/baselines/reference/es6ModuleClassDeclaration.js
Normal file
@ -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 = {}));
|
||||
233
tests/baselines/reference/es6ModuleClassDeclaration.types
Normal file
233
tests/baselines/reference/es6ModuleClassDeclaration.types
Normal file
@ -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
|
||||
}
|
||||
@ -20,4 +20,4 @@ var A = (function () {
|
||||
};
|
||||
return A;
|
||||
})();
|
||||
A = A;
|
||||
export { A };
|
||||
|
||||
@ -20,4 +20,4 @@ var A = (function () {
|
||||
};
|
||||
return A;
|
||||
})();
|
||||
A = A;
|
||||
export { A };
|
||||
|
||||
113
tests/cases/compiler/es6ModuleClassDeclaration.ts
Normal file
113
tests/cases/compiler/es6ModuleClassDeclaration.ts
Normal file
@ -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();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user