Dts for export * from "mod" and export { a, b as c,...} [from "mod"]

This commit is contained in:
Sheetal Nandi 2015-02-17 09:28:55 -08:00
parent 5b6a9a8517
commit fc1528f3e5
20 changed files with 652 additions and 6 deletions

View File

@ -1723,12 +1723,18 @@ module ts {
}
function setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]{
var exportSymbol: Symbol;
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
var exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
var result: Node[] = [];
buildVisibleNodeList(exportSymbol.declarations);
return result;
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
}
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent);
}
var result: Node[] = [];
if (exportSymbol) {
buildVisibleNodeList(exportSymbol.declarations);
}
return result;
function buildVisibleNodeList(declarations: Declaration[]) {
forEach(declarations, declaration => {

View File

@ -905,7 +905,7 @@ module ts {
}
else {
write("{ ");
emitCommaList((<NamedImports>node.importClause.namedBindings).elements, emitImportSpecifier, resolver.isDeclarationVisible);
emitCommaList((<NamedImports>node.importClause.namedBindings).elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible);
write(" }");
}
}
@ -916,7 +916,7 @@ module ts {
writer.writeLine();
}
function emitImportSpecifier(node: ImportSpecifier) {
function emitImportOrExportSpecifier(node: ImportOrExportSpecifier) {
if (node.propertyName) {
writeTextOfNode(currentSourceFile, node.propertyName);
write(" as ");
@ -924,6 +924,35 @@ module ts {
writeTextOfNode(currentSourceFile, node.name);
}
function emitExportSpecifier(node: ExportSpecifier) {
emitImportOrExportSpecifier(node);
// Make all the declarations visible for the export name
var nodes = resolver.setDeclarationsOfIdentifierAsVisible(node.propertyName || node.name);
// write each of these declarations asynchronously
writeAsynchronousModuleElements(nodes);
}
function emitExportDeclaration(node: ExportDeclaration) {
emitJsDocComments(node);
write("export ");
if (node.exportClause) {
write("{ ");
emitCommaList(node.exportClause.elements, emitExportSpecifier);
write(" }");
}
else {
write("*");
}
if (node.moduleSpecifier) {
write(" from ");
writeTextOfNode(currentSourceFile, node.moduleSpecifier);
}
write(";");
writer.writeLine();
}
function writeModuleDeclaration(node: ModuleDeclaration) {
emitJsDocComments(node);
emitModuleElementDeclarationFlags(node);
@ -1608,6 +1637,8 @@ module ts {
case SyntaxKind.ImportDeclaration:
// Import declaration without import clause is visible, otherwise it is not visible
return emitModuleElement(node, /*isModuleElementVisible*/!(<ImportDeclaration>node).importClause);
case SyntaxKind.ExportDeclaration:
return emitExportDeclaration(<ExportDeclaration>node);
case SyntaxKind.Constructor:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:

View File

@ -0,0 +1,20 @@
tests/cases/compiler/server.ts(2,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
==== tests/cases/compiler/server.ts (1 errors) ====
export class c {
~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
}
export interface i {
}
export module m {
export var x = 10;
}
export var x = 10;
export module uninstantiated {
}
==== tests/cases/compiler/client.ts (0 errors) ====
export * from "server";

View File

@ -0,0 +1,48 @@
//// [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;
})();
exports.c = c;
var m;
(function (m) {
m.x = 10;
})(m = exports.m || (exports.m = {}));
exports.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";

View File

@ -0,0 +1,48 @@
//// [tests/cases/compiler/es6ExportAllInEs5.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;
})();
exports.c = c;
var m;
(function (m) {
m.x = 10;
})(m = exports.m || (exports.m = {}));
exports.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";

View File

@ -0,0 +1,24 @@
=== tests/cases/compiler/server.ts ===
export class c {
>c : c
}
export interface i {
>i : i
}
export module m {
>m : typeof m
export var x = 10;
>x : number
}
export var x = 10;
>x : number
export module uninstantiated {
>uninstantiated : unknown
}
=== tests/cases/compiler/client.ts ===
export * from "server";
No type information for this code.

View File

@ -0,0 +1,22 @@
tests/cases/compiler/es6ExportClause.ts(12,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
==== tests/cases/compiler/es6ExportClause.ts (1 errors) ====
class c {
}
interface i {
}
module m {
export var x = 10;
}
var x = 10;
module uninstantiated {
}
export { c };
~~~~~~~~~~~~~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
export { c as c2 };
export { i, m as instantiatedModule };
export { uninstantiated };
export { x };

View File

@ -0,0 +1,47 @@
//// [es6ExportClause.ts]
class c {
}
interface i {
}
module m {
export var x = 10;
}
var x = 10;
module uninstantiated {
}
export { c };
export { c as c2 };
export { i, m as instantiatedModule };
export { uninstantiated };
export { x };
//// [es6ExportClause.js]
var c = (function () {
function c() {
}
return c;
})();
var m;
(function (m) {
m.x = 10;
})(m || (m = {}));
var x = 10;
//// [es6ExportClause.d.ts]
declare class c {
}
interface i {
}
declare module m {
var x: number;
}
declare var x: number;
declare module uninstantiated {
}
export { c };
export { c as c2 };
export { i, m as instantiatedModule };
export { uninstantiated };
export { x };

View File

@ -0,0 +1,51 @@
//// [es6ExportClauseInEs5.ts]
class c {
}
interface i {
}
module m {
export var x = 10;
}
var x = 10;
module uninstantiated {
}
export { c };
export { c as c2 };
export { i, m as instantiatedModule };
export { uninstantiated };
export { x };
//// [es6ExportClauseInEs5.js]
var c = (function () {
function c() {
}
return c;
})();
exports.c = c;
exports.c2 = c;
var m;
(function (m) {
m.x = 10;
})(m || (m = {}));
exports.instantiatedModule = m;
var x = 10;
exports.x = x;
//// [es6ExportClauseInEs5.d.ts]
declare class c {
}
interface i {
}
declare module m {
var x: number;
}
declare var x: number;
declare module uninstantiated {
}
export { c };
export { c as c2 };
export { i, m as instantiatedModule };
export { uninstantiated };
export { x };

View File

@ -0,0 +1,38 @@
=== tests/cases/compiler/es6ExportClauseInEs5.ts ===
class c {
>c : c
}
interface i {
>i : i
}
module m {
>m : typeof m
export var x = 10;
>x : number
}
var x = 10;
>x : number
module uninstantiated {
>uninstantiated : unknown
}
export { c };
>c : typeof c
export { c as c2 };
>c : unknown
>c2 : typeof c
export { i, m as instantiatedModule };
>i : unknown
>m : unknown
>instantiatedModule : typeof m
export { uninstantiated };
>uninstantiated : unknown
export { x };
>x : number

View File

@ -0,0 +1,24 @@
tests/cases/compiler/server.ts(2,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided.
==== tests/cases/compiler/server.ts (1 errors) ====
export class c {
~
!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided.
}
export interface i {
}
export module m {
export var x = 10;
}
export var x = 10;
export module uninstantiated {
}
==== tests/cases/compiler/client.ts (0 errors) ====
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";

View File

@ -0,0 +1,65 @@
//// [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;
})();
exports.c = c;
var m;
(function (m) {
m.x = 10;
})(m = exports.m || (exports.m = {}));
exports.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";

View File

@ -0,0 +1,65 @@
//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.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;
})();
exports.c = c;
var m;
(function (m) {
m.x = 10;
})(m = exports.m || (exports.m = {}));
exports.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";

View File

@ -0,0 +1,40 @@
=== tests/cases/compiler/server.ts ===
export class c {
>c : c
}
export interface i {
>i : i
}
export module m {
>m : typeof m
export var x = 10;
>x : number
}
export var x = 10;
>x : number
export module uninstantiated {
>uninstantiated : unknown
}
=== tests/cases/compiler/client.ts ===
export { c } from "server";
>c : typeof c
export { c as c2 } from "server";
>c : unknown
>c2 : typeof c
export { i, m as instantiatedModule } from "server";
>i : unknown
>m : unknown
>instantiatedModule : typeof instantiatedModule
export { uninstantiated } from "server";
>uninstantiated : unknown
export { x } from "server";
>x : number

View File

@ -0,0 +1,17 @@
// @target: es6
// @declaration: true
// @filename: server.ts
export class c {
}
export interface i {
}
export module m {
export var x = 10;
}
export var x = 10;
export module uninstantiated {
}
// @filename: client.ts
export * from "server";

View File

@ -0,0 +1,18 @@
// @target: es5
// @module: commonjs
// @declaration: true
// @filename: server.ts
export class c {
}
export interface i {
}
export module m {
export var x = 10;
}
export var x = 10;
export module uninstantiated {
}
// @filename: client.ts
export * from "server";

View File

@ -0,0 +1,19 @@
// @target: es6
// @declaration: true
// @filename: server.ts
class c {
}
interface i {
}
module m {
export var x = 10;
}
var x = 10;
module uninstantiated {
}
export { c };
export { c as c2 };
export { i, m as instantiatedModule };
export { uninstantiated };
export { x };

View File

@ -0,0 +1,20 @@
// @target: es5
// @module: commonjs
// @declaration: true
// @filename: server.ts
class c {
}
interface i {
}
module m {
export var x = 10;
}
var x = 10;
module uninstantiated {
}
export { c };
export { c as c2 };
export { i, m as instantiatedModule };
export { uninstantiated };
export { x };

View File

@ -0,0 +1,21 @@
// @target: es6
// @declaration: true
// @filename: server.ts
export class c {
}
export interface i {
}
export module m {
export var x = 10;
}
export var x = 10;
export module uninstantiated {
}
// @filename: 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";

View File

@ -0,0 +1,22 @@
// @target: es5
// @module: commonjs
// @declaration: true
// @filename: server.ts
export class c {
}
export interface i {
}
export module m {
export var x = 10;
}
export var x = 10;
export module uninstantiated {
}
// @filename: 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";