Skip to content

Fix emit for export {...} with ES6 target and non-ES6 modules #5176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3785,7 +3785,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(";");
}
}
if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) {
if (modulekind !== ModuleKind.ES6 && node.parent === currentSourceFile) {
forEach(node.declarationList.declarations, emitExportVariableAssignments);
}
}
Expand Down Expand Up @@ -4011,7 +4011,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}

emitSignatureAndBody(node);
if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) {
if (modulekind !== ModuleKind.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) {
emitExportMemberAssignments((<FunctionDeclaration>node).name);
}

Expand Down Expand Up @@ -4687,6 +4687,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
else {
emitClassLikeDeclarationForES6AndHigher(node);
}
if (modulekind !== ModuleKind.ES6 && node.parent === currentSourceFile && node.name) {
emitExportMemberAssignments(node.name);
}
}

function emitClassLikeDeclarationForES6AndHigher(node: ClassLikeDeclaration) {
Expand Down Expand Up @@ -4934,10 +4937,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
if (node.kind === SyntaxKind.ClassDeclaration) {
emitExportMemberAssignment(<ClassDeclaration>node);
}

if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile && node.name) {
emitExportMemberAssignments(node.name);
}
}

function emitClassMemberPrefix(node: ClassLikeDeclaration, member: Node) {
Expand Down Expand Up @@ -5509,7 +5508,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emitEnd(node);
write(";");
}
if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) {
if (modulekind !== ModuleKind.ES6 && node.parent === currentSourceFile) {
if (modulekind === ModuleKind.System && (node.flags & NodeFlags.Export)) {
// write the call to exporter for enum
writeLine();
Expand Down
73 changes: 73 additions & 0 deletions tests/baselines/reference/exportsAndImports1-es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//// [tests/cases/conformance/es6/modules/exportsAndImports1-es6.ts] ////

//// [t1.ts]

var v = 1;
function f() { }
class C {
}
interface I {
}
enum E {
A, B, C
}
const enum D {
A, B, C
}
module M {
export var x;
}
module N {
export interface I {
}
}
type T = number;
import a = M.x;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add in a reassignment to v (ie, v = 10) here. Observe that we emit v = 10 but no corresponding exports.v = v. I'm not sure lifting all the exports from where the export statement is to wherever the variable's declaration is is correct for this export form.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an orthogonal issue already being discussed in #4101.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, okay, didn't know about the old issue.

export { v, f, C, I, E, D, M, N, T, a };

//// [t2.ts]
export { v, f, C, I, E, D, M, N, T, a } from "./t1";

//// [t3.ts]
import { v, f, C, I, E, D, M, N, T, a } from "./t1";
export { v, f, C, I, E, D, M, N, T, a };


//// [t1.js]
var v = 1;
exports.v = v;
function f() { }
exports.f = f;
class C {
}
exports.C = C;
var E;
(function (E) {
E[E["A"] = 0] = "A";
E[E["B"] = 1] = "B";
E[E["C"] = 2] = "C";
})(E || (E = {}));
exports.E = E;
var M;
(function (M) {
})(M || (M = {}));
exports.M = M;
var a = M.x;
exports.a = a;
//// [t2.js]
var t1_1 = require("./t1");
exports.v = t1_1.v;
exports.f = t1_1.f;
exports.C = t1_1.C;
exports.E = t1_1.E;
exports.M = t1_1.M;
exports.a = t1_1.a;
//// [t3.js]
var t1_1 = require("./t1");
exports.v = t1_1.v;
exports.f = t1_1.f;
exports.C = t1_1.C;
exports.E = t1_1.E;
exports.M = t1_1.M;
exports.a = t1_1.a;
101 changes: 101 additions & 0 deletions tests/baselines/reference/exportsAndImports1-es6.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
=== tests/cases/conformance/es6/modules/t1.ts ===

var v = 1;
>v : Symbol(v, Decl(t1.ts, 1, 3))

function f() { }
>f : Symbol(f, Decl(t1.ts, 1, 10))

class C {
>C : Symbol(C, Decl(t1.ts, 2, 16))
}
interface I {
>I : Symbol(I, Decl(t1.ts, 4, 1))
}
enum E {
>E : Symbol(E, Decl(t1.ts, 6, 1))

A, B, C
>A : Symbol(E.A, Decl(t1.ts, 7, 8))
>B : Symbol(E.B, Decl(t1.ts, 8, 6))
>C : Symbol(E.C, Decl(t1.ts, 8, 9))
}
const enum D {
>D : Symbol(D, Decl(t1.ts, 9, 1))

A, B, C
>A : Symbol(D.A, Decl(t1.ts, 10, 14))
>B : Symbol(D.B, Decl(t1.ts, 11, 6))
>C : Symbol(D.C, Decl(t1.ts, 11, 9))
}
module M {
>M : Symbol(M, Decl(t1.ts, 12, 1))

export var x;
>x : Symbol(x, Decl(t1.ts, 14, 14))
}
module N {
>N : Symbol(N, Decl(t1.ts, 15, 1))

export interface I {
>I : Symbol(I, Decl(t1.ts, 16, 10))
}
}
type T = number;
>T : Symbol(T, Decl(t1.ts, 19, 1))

import a = M.x;
>a : Symbol(a, Decl(t1.ts, 20, 16))
>M : Symbol(M, Decl(t1.ts, 12, 1))
>x : Symbol(a, Decl(t1.ts, 14, 14))

export { v, f, C, I, E, D, M, N, T, a };
>v : Symbol(v, Decl(t1.ts, 23, 8))
>f : Symbol(f, Decl(t1.ts, 23, 11))
>C : Symbol(C, Decl(t1.ts, 23, 14))
>I : Symbol(I, Decl(t1.ts, 23, 17))
>E : Symbol(E, Decl(t1.ts, 23, 20))
>D : Symbol(D, Decl(t1.ts, 23, 23))
>M : Symbol(M, Decl(t1.ts, 23, 26))
>N : Symbol(N, Decl(t1.ts, 23, 29))
>T : Symbol(T, Decl(t1.ts, 23, 32))
>a : Symbol(a, Decl(t1.ts, 23, 35))

=== tests/cases/conformance/es6/modules/t2.ts ===
export { v, f, C, I, E, D, M, N, T, a } from "./t1";
>v : Symbol(v, Decl(t2.ts, 0, 8))
>f : Symbol(f, Decl(t2.ts, 0, 11))
>C : Symbol(C, Decl(t2.ts, 0, 14))
>I : Symbol(I, Decl(t2.ts, 0, 17))
>E : Symbol(E, Decl(t2.ts, 0, 20))
>D : Symbol(D, Decl(t2.ts, 0, 23))
>M : Symbol(M, Decl(t2.ts, 0, 26))
>N : Symbol(N, Decl(t2.ts, 0, 29))
>T : Symbol(T, Decl(t2.ts, 0, 32))
>a : Symbol(a, Decl(t2.ts, 0, 35))

=== tests/cases/conformance/es6/modules/t3.ts ===
import { v, f, C, I, E, D, M, N, T, a } from "./t1";
>v : Symbol(v, Decl(t3.ts, 0, 8))
>f : Symbol(f, Decl(t3.ts, 0, 11))
>C : Symbol(C, Decl(t3.ts, 0, 14))
>I : Symbol(I, Decl(t3.ts, 0, 17))
>E : Symbol(E, Decl(t3.ts, 0, 20))
>D : Symbol(D, Decl(t3.ts, 0, 23))
>M : Symbol(M, Decl(t3.ts, 0, 26))
>N : Symbol(N, Decl(t3.ts, 0, 29))
>T : Symbol(T, Decl(t3.ts, 0, 32))
>a : Symbol(a, Decl(t3.ts, 0, 35))

export { v, f, C, I, E, D, M, N, T, a };
>v : Symbol(v, Decl(t3.ts, 1, 8))
>f : Symbol(f, Decl(t3.ts, 1, 11))
>C : Symbol(C, Decl(t3.ts, 1, 14))
>I : Symbol(I, Decl(t3.ts, 1, 17))
>E : Symbol(E, Decl(t3.ts, 1, 20))
>D : Symbol(D, Decl(t3.ts, 1, 23))
>M : Symbol(M, Decl(t3.ts, 1, 26))
>N : Symbol(N, Decl(t3.ts, 1, 29))
>T : Symbol(T, Decl(t3.ts, 1, 32))
>a : Symbol(a, Decl(t3.ts, 1, 35))

102 changes: 102 additions & 0 deletions tests/baselines/reference/exportsAndImports1-es6.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
=== tests/cases/conformance/es6/modules/t1.ts ===

var v = 1;
>v : number
>1 : number

function f() { }
>f : () => void

class C {
>C : C
}
interface I {
>I : I
}
enum E {
>E : E

A, B, C
>A : E
>B : E
>C : E
}
const enum D {
>D : D

A, B, C
>A : D
>B : D
>C : D
}
module M {
>M : typeof M

export var x;
>x : any
}
module N {
>N : any

export interface I {
>I : I
}
}
type T = number;
>T : number

import a = M.x;
>a : any
>M : typeof M
>x : any

export { v, f, C, I, E, D, M, N, T, a };
>v : number
>f : () => void
>C : typeof C
>I : any
>E : typeof E
>D : typeof D
>M : typeof M
>N : any
>T : any
>a : any

=== tests/cases/conformance/es6/modules/t2.ts ===
export { v, f, C, I, E, D, M, N, T, a } from "./t1";
>v : number
>f : () => void
>C : typeof C
>I : any
>E : typeof E
>D : typeof D
>M : typeof M
>N : any
>T : any
>a : any

=== tests/cases/conformance/es6/modules/t3.ts ===
import { v, f, C, I, E, D, M, N, T, a } from "./t1";
>v : number
>f : () => void
>C : typeof C
>I : any
>E : typeof E
>D : typeof D
>M : typeof M
>N : any
>T : any
>a : any

export { v, f, C, I, E, D, M, N, T, a };
>v : number
>f : () => void
>C : typeof C
>I : any
>E : typeof E
>D : typeof D
>M : typeof M
>N : any
>T : any
>a : any

26 changes: 26 additions & 0 deletions tests/baselines/reference/exportsAndImports2-es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//// [tests/cases/conformance/es6/modules/exportsAndImports2-es6.ts] ////

//// [t1.ts]

export var x = "x";
export var y = "y";

//// [t2.ts]
export { x as y, y as x } from "./t1";

//// [t3.ts]
import { x, y } from "./t1";
export { x as y, y as x };


//// [t1.js]
exports.x = "x";
exports.y = "y";
//// [t2.js]
var t1_1 = require("./t1");
exports.y = t1_1.x;
exports.x = t1_1.y;
//// [t3.js]
var t1_1 = require("./t1");
exports.y = t1_1.x;
exports.x = t1_1.y;
26 changes: 26 additions & 0 deletions tests/baselines/reference/exportsAndImports2-es6.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== tests/cases/conformance/es6/modules/t1.ts ===

export var x = "x";
>x : Symbol(x, Decl(t1.ts, 1, 10))

export var y = "y";
>y : Symbol(y, Decl(t1.ts, 2, 10))

=== tests/cases/conformance/es6/modules/t2.ts ===
export { x as y, y as x } from "./t1";
>x : Symbol(y, Decl(t2.ts, 0, 8))
>y : Symbol(y, Decl(t2.ts, 0, 8))
>y : Symbol(x, Decl(t2.ts, 0, 16))
>x : Symbol(x, Decl(t2.ts, 0, 16))

=== tests/cases/conformance/es6/modules/t3.ts ===
import { x, y } from "./t1";
>x : Symbol(x, Decl(t3.ts, 0, 8))
>y : Symbol(y, Decl(t3.ts, 0, 11))

export { x as y, y as x };
>x : Symbol(y, Decl(t3.ts, 1, 8))
>y : Symbol(y, Decl(t3.ts, 1, 8))
>y : Symbol(x, Decl(t3.ts, 1, 16))
>x : Symbol(x, Decl(t3.ts, 1, 16))

Loading