diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1ac305cf05..0f309bc380 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -766,6 +766,18 @@ module ts { } } + function emitImportDeclaration(node: ImportDeclaration) { + // TODO(shkamat): Do the changes so that we emit only if declaration is visible + emitJsDocComments(node); + if (node.flags & NodeFlags.Export) { + write("export "); + } + write("import "); + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + write(";"); + writer.writeLine(); + } + function emitModuleDeclaration(node: ModuleDeclaration) { if (resolver.isDeclarationVisible(node)) { emitJsDocComments(node); @@ -1483,6 +1495,8 @@ module ts { return emitImportEqualsDeclaration(node); case SyntaxKind.ExportAssignment: return emitExportAssignment(node); + case SyntaxKind.ImportDeclaration: + return emitImportDeclaration(node); case SyntaxKind.SourceFile: return emitSourceFile(node); } diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index 43d21885c2..b5eb7a1ba0 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -5,9 +5,16 @@ export var a = 10; //// [es6ImportWithoutFromClause_1.ts] -import "es6ImportWithoutFromClause_0"; +import "es6ImportWithoutFromClause_0"; + //// [es6ImportWithoutFromClause_0.js] exports.a = 10; //// [es6ImportWithoutFromClause_1.js] require("es6ImportWithoutFromClause_0"); + + +//// [es6ImportWithoutFromClause_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClause_1.d.ts] +import "es6ImportWithoutFromClause_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.types b/tests/baselines/reference/es6ImportWithoutFromClause.types index 1cd7df9962..3cc5067891 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.types +++ b/tests/baselines/reference/es6ImportWithoutFromClause.types @@ -5,4 +5,5 @@ export var a = 10; === tests/cases/compiler/es6ImportWithoutFromClause_1.ts === import "es6ImportWithoutFromClause_0"; +No type information for this code. No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js new file mode 100644 index 0000000000..0464794ea8 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js @@ -0,0 +1,37 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts] //// + +//// [es6ImportWithoutFromClauseAmd_0.ts] + +export var a = 10; + +//// [es6ImportWithoutFromClauseAmd_1.ts] +export var b = 10; + +//// [es6ImportWithoutFromClauseAmd_2.ts] +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +var _b = 10; + +//// [es6ImportWithoutFromClauseAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [es6ImportWithoutFromClauseAmd_1.js] +define(["require", "exports"], function (require, exports) { + exports.b = 10; +}); +//// [es6ImportWithoutFromClauseAmd_2.js] +define(["require", "exports", "es6ImportWithoutFromClauseAmd_0", "es6ImportWithoutFromClauseAmd_2"], function (require, exports, _c, _d) { + var _a = 10; + var _b = 10; +}); + + +//// [es6ImportWithoutFromClauseAmd_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseAmd_1.d.ts] +export declare var b: number; +//// [es6ImportWithoutFromClauseAmd_2.d.ts] +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types new file mode 100644 index 0000000000..c3d0938891 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_1.ts === +export var b = 10; +>b : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_2.ts === +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +>_a : number + +var _b = 10; +>_b : number + diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js index f6610ac5ad..9495bc1ffb 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -11,3 +11,9 @@ import "es6ImportWithoutFromClauseInEs5_0"; exports.a = 10; //// [es6ImportWithoutFromClauseInEs5_1.js] require("es6ImportWithoutFromClauseInEs5_0"); + + +//// [es6ImportWithoutFromClauseInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseInEs5_1.d.ts] +import "es6ImportWithoutFromClauseInEs5_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js new file mode 100644 index 0000000000..1c75b15c7d --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts] //// + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.ts] + +export interface i { +} + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.ts] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.js] +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.js] +require("es6ImportWithoutFromClauseNonInstantiatedModule_0"); + + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.d.ts] +export interface i { +} +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.d.ts] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types new file mode 100644 index 0000000000..2be3f67f1e --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_0.ts === + +export interface i { +>i : i +} + +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_1.ts === +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClause.ts b/tests/cases/compiler/es6ImportWithoutFromClause.ts index 70a15a9bc5..d43aac9b63 100644 --- a/tests/cases/compiler/es6ImportWithoutFromClause.ts +++ b/tests/cases/compiler/es6ImportWithoutFromClause.ts @@ -1,8 +1,9 @@ // @target: es6 // @module: commonjs +// @declaration: true // @filename: es6ImportWithoutFromClause_0.ts export var a = 10; // @filename: es6ImportWithoutFromClause_1.ts -import "es6ImportWithoutFromClause_0"; \ No newline at end of file +import "es6ImportWithoutFromClause_0"; diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts b/tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts new file mode 100644 index 0000000000..8c43a19e40 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts @@ -0,0 +1,14 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportWithoutFromClauseAmd_0.ts +export var a = 10; + +// @filename: es6ImportWithoutFromClauseAmd_1.ts +export var b = 10; + +// @filename: es6ImportWithoutFromClauseAmd_2.ts +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +var _b = 10; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts index 339880ee09..08c21c2364 100644 --- a/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts +++ b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts @@ -1,5 +1,6 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportWithoutFromClauseInEs5_0.ts export var a = 10; diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts b/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts new file mode 100644 index 0000000000..8d364f75a9 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @module: commonjs +// @declaration: true + +// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_0.ts +export interface i { +} + +// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_1.ts +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; \ No newline at end of file