From 956d7a82f337f50b8778fbc1578abf8897ceccd6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 12:18:38 -0700 Subject: [PATCH 1/6] Fixing emit for import d, * as foo from "foo" case --- src/compiler/emitter.ts | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 03d4cc74fa..299ac0a2b6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5004,10 +5004,6 @@ module ts { } } - function isNakedImport(node: ImportDeclaration | ImportEqualsDeclaration) { - return node.kind === SyntaxKind.ImportDeclaration && !(node).importClause; - } - function emitExportImportAssignments(node: Node) { if (isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { emitExportMemberAssignments((node).name); @@ -5017,29 +5013,47 @@ module ts { function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { if (contains(externalImports, node)) { - let exportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; + let isExportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; let namespaceDeclaration = getNamespaceDeclarationNode(node); if (compilerOptions.module !== ModuleKind.AMD) { emitLeadingComments(node); emitStart(node); - if (namespaceDeclaration) { - if (!exportedImport) write("var "); + let isDefaultImport = node.kind === SyntaxKind.ImportDeclaration && (node).importClause && !!(node).importClause.name; + if (namespaceDeclaration && !isDefaultImport) { + // import x = require("foo") + // import * as x from "foo" + if (!isExportedImport) write("var "); emitModuleMemberName(namespaceDeclaration); write(" = "); } - else if (!isNakedImport(node)) { - write("var "); - write(resolver.getGeneratedNameForNode(node)); - write(" = "); + else { + // import "foo" + // import x from "foo" + // import { x, y } from "foo" + // import d, * as x from "foo" + // import d, { x, y } from "foo" + let isNakedImport = SyntaxKind.ImportDeclaration && !(node).importClause; + if (!isNakedImport) { + write("var "); + write(resolver.getGeneratedNameForNode(node)); + write(" = "); + } } emitRequire(getExternalModuleName(node)); + if (namespaceDeclaration && isDefaultImport) { + // import d, * as x from "foo" + write(", "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(resolver.getGeneratedNameForNode(node)); + } write(";"); emitEnd(node); emitExportImportAssignments(node); emitTrailingComments(node); } else { - if (exportedImport) { + if (isExportedImport) { emitModuleMemberName(namespaceDeclaration); write(" = "); emit(namespaceDeclaration.name); From e63854b40e6e2bfa53ab9571ebd7f49662f63904 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 12:18:56 -0700 Subject: [PATCH 2/6] Adding basic tests --- .../cases/compiler/es6ExportEqualsInterop.ts | 206 ++++++++++++++++++ .../conformance/es6/modules/exportStar-amd.ts | 28 +++ .../conformance/es6/modules/exportStar.ts | 28 +++ .../es6/modules/exportsAndImports1-amd.ts | 33 +++ .../es6/modules/exportsAndImports1.ts | 33 +++ .../es6/modules/exportsAndImports2-amd.ts | 12 + .../es6/modules/exportsAndImports2.ts | 12 + .../es6/modules/exportsAndImports3-amd.ts | 33 +++ .../es6/modules/exportsAndImports3.ts | 33 +++ .../es6/modules/exportsAndImports4-amd.ts | 38 ++++ .../es6/modules/exportsAndImports4.ts | 38 ++++ 11 files changed, 494 insertions(+) create mode 100644 tests/cases/compiler/es6ExportEqualsInterop.ts create mode 100644 tests/cases/conformance/es6/modules/exportStar-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportStar.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports1-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports1.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports2-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports2.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports3.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports4.ts diff --git a/tests/cases/compiler/es6ExportEqualsInterop.ts b/tests/cases/compiler/es6ExportEqualsInterop.ts new file mode 100644 index 0000000000..7b1f6700dd --- /dev/null +++ b/tests/cases/compiler/es6ExportEqualsInterop.ts @@ -0,0 +1,206 @@ +// @module: commonjs + +// @filename: modules.d.ts +declare module "interface" { + interface Foo { + x: number; + y: number; + } + export = Foo; +} + +declare module "variable" { + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "interface-variable" { + interface Foo { + x: number; + y: number; + } + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "module" { + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +declare module "interface-module" { + interface Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +declare module "variable-module" { + module Foo { + interface Bar { + x: number; + y: number; + } + } + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "function" { + function foo(); + export = foo; +} + +declare module "function-module" { + function foo(); + module foo { + export var a: number; + export var b: number; + } + export = foo; +} + +declare module "class" { + class Foo { + x: number; + y: number; + } + export = Foo; +} + +declare module "class-module" { + class Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +// @filename: main.ts +/// + +// import-equals +import z1 = require("interface"); +import z2 = require("variable"); +import z3 = require("interface-variable"); +import z4 = require("module"); +import z5 = require("interface-module"); +import z6 = require("variable-module"); +import z7 = require("function"); +import z8 = require("function-module"); +import z9 = require("class"); +import z0 = require("class-module"); + +z1.a; +z2.a; +z3.a; +z4.a; +z5.a; +z6.a; +z7.a; +z8.a; +z9.a; +z0.a; + +// default import +import x1 from "interface"; +import x2 from "variable"; +import x3 from "interface-variable"; +import x4 from "module"; +import x5 from "interface-module"; +import x6 from "variable-module"; +import x7 from "function"; +import x8 from "function-module"; +import x9 from "class"; +import x0 from "class-module"; + +// namespace import +import * as y1 from "interface"; +import * as y2 from "variable"; +import * as y3 from "interface-variable"; +import * as y4 from "module"; +import * as y5 from "interface-module"; +import * as y6 from "variable-module"; +import * as y7 from "function"; +import * as y8 from "function-module"; +import * as y9 from "class"; +import * as y0 from "class-module"; + +y1.a; +y2.a; +y3.a; +y4.a; +y5.a; +y6.a; +y7.a; +y8.a; +y9.a; +y0.a; + +// named import +import { a as a1 } from "interface"; +import { a as a2 } from "variable"; +import { a as a3 } from "interface-variable"; +import { a as a4 } from "module"; +import { a as a5 } from "interface-module"; +import { a as a6 } from "variable-module"; +import { a as a7 } from "function"; +import { a as a8 } from "function-module"; +import { a as a9 } from "class"; +import { a as a0 } from "class-module"; + +a1; +a2; +a3; +a4; +a5; +a6; +a7; +a8; +a9; +a0; + +// named export +export { a as a1 } from "interface"; +export { a as a2 } from "variable"; +export { a as a3 } from "interface-variable"; +export { a as a4 } from "module"; +export { a as a5 } from "interface-module"; +export { a as a6 } from "variable-module"; +export { a as a7 } from "function"; +export { a as a8 } from "function-module"; +export { a as a9 } from "class"; +export { a as a0 } from "class-module"; + +// export-star +export * from "interface"; +export * from "variable"; +export * from "interface-variable"; +export * from "module"; +export * from "interface-module"; +export * from "variable-module"; +export * from "function"; +export * from "function-module"; +export * from "class"; +export * from "class-module"; diff --git a/tests/cases/conformance/es6/modules/exportStar-amd.ts b/tests/cases/conformance/es6/modules/exportStar-amd.ts new file mode 100644 index 0000000000..ffa8b0a7f1 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportStar-amd.ts @@ -0,0 +1,28 @@ +// @module: amd + +// @filename: t1.ts +export var x = 1; +export var y = 2; + +// @filename: t2.ts +export default "hello"; +export function foo() { } + +// @filename: t3.ts +var x = "x"; +var y = "y"; +var z = "z"; +export { x, y, z }; + +// @filename: t4.ts +export * from "./t1"; +export * from "./t2"; +export * from "./t3"; + +// @filename: main.ts +import hello, { x, y, z, foo } from "./t4"; +hello; +x; +y; +z; +foo; diff --git a/tests/cases/conformance/es6/modules/exportStar.ts b/tests/cases/conformance/es6/modules/exportStar.ts new file mode 100644 index 0000000000..6d820d9c42 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportStar.ts @@ -0,0 +1,28 @@ +// @module: commonjs + +// @filename: t1.ts +export var x = 1; +export var y = 2; + +// @filename: t2.ts +export default "hello"; +export function foo() { } + +// @filename: t3.ts +var x = "x"; +var y = "y"; +var z = "z"; +export { x, y, z }; + +// @filename: t4.ts +export * from "./t1"; +export * from "./t2"; +export * from "./t3"; + +// @filename: main.ts +import hello, { x, y, z, foo } from "./t4"; +hello; +x; +y; +z; +foo; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports1-amd.ts b/tests/cases/conformance/es6/modules/exportsAndImports1-amd.ts new file mode 100644 index 0000000000..0c4d1de1e6 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports1-amd.ts @@ -0,0 +1,33 @@ +// @module: amd + +// @filename: 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; + +export { v, f, C, I, E, D, M, N, T, a }; + +// @filename: t2.ts +export { v, f, C, I, E, D, M, N, T, a } from "./t1"; + +// @filename: 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 }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports1.ts b/tests/cases/conformance/es6/modules/exportsAndImports1.ts new file mode 100644 index 0000000000..5b91d1d6cc --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports1.ts @@ -0,0 +1,33 @@ +// @module: commonjs + +// @filename: 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; + +export { v, f, C, I, E, D, M, N, T, a }; + +// @filename: t2.ts +export { v, f, C, I, E, D, M, N, T, a } from "./t1"; + +// @filename: 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 }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports2-amd.ts b/tests/cases/conformance/es6/modules/exportsAndImports2-amd.ts new file mode 100644 index 0000000000..72e462f0ee --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports2-amd.ts @@ -0,0 +1,12 @@ +// @module: amd + +// @filename: t1.ts +export var x = "x"; +export var y = "y"; + +// @filename: t2.ts +export { x as y, y as x } from "./t1"; + +// @filename: t3.ts +import { x, y } from "./t1"; +export { x as y, y as x }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports2.ts b/tests/cases/conformance/es6/modules/exportsAndImports2.ts new file mode 100644 index 0000000000..719f74ede5 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports2.ts @@ -0,0 +1,12 @@ +// @module: commonjs + +// @filename: t1.ts +export var x = "x"; +export var y = "y"; + +// @filename: t2.ts +export { x as y, y as x } from "./t1"; + +// @filename: t3.ts +import { x, y } from "./t1"; +export { x as y, y as x }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts b/tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts new file mode 100644 index 0000000000..b634f6f776 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts @@ -0,0 +1,33 @@ +// @module: amd + +// @filename: t1.ts +export var v = 1; +export function f() { } +export class C { +} +export interface I { +} +export enum E { + A, B, C +} +export const enum D { + A, B, C +} +export module M { + export var x; +} +export module N { + export interface I { + } +} +export type T = number; +export import a = M.x; + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; + +// @filename: t2.ts +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; + +// @filename: t3.ts +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports3.ts b/tests/cases/conformance/es6/modules/exportsAndImports3.ts new file mode 100644 index 0000000000..806a5e2779 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports3.ts @@ -0,0 +1,33 @@ +// @module: commonjs + +// @filename: t1.ts +export var v = 1; +export function f() { } +export class C { +} +export interface I { +} +export enum E { + A, B, C +} +export const enum D { + A, B, C +} +export module M { + export var x; +} +export module N { + export interface I { + } +} +export type T = number; +export import a = M.x; + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; + +// @filename: t2.ts +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; + +// @filename: t3.ts +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts b/tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts new file mode 100644 index 0000000000..d542a5ae71 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts @@ -0,0 +1,38 @@ +// @module: amd + +// @filename: t1.ts +export default "hello"; + +// @filename: t2.ts +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +import "./t1"; + +// @filename: t3.ts +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +export { a, b, c, d, e1, e2, f1, f2 }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports4.ts b/tests/cases/conformance/es6/modules/exportsAndImports4.ts new file mode 100644 index 0000000000..f077067419 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports4.ts @@ -0,0 +1,38 @@ +// @module: commonjs + +// @filename: t1.ts +export default "hello"; + +// @filename: t2.ts +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +import "./t1"; + +// @filename: t3.ts +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +export { a, b, c, d, e1, e2, f1, f2 }; From df03c686c438125a5e30ae50bd814f4f469d2c78 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 12:19:38 -0700 Subject: [PATCH 3/6] Accepting new baselines --- .../baselines/reference/APISample_compile.js | 2 +- .../reference/APISample_compile.types | 4 +- tests/baselines/reference/APISample_linter.js | 2 +- .../reference/APISample_linter.types | 4 +- .../reference/APISample_transform.js | 2 +- .../reference/APISample_transform.types | 4 +- .../baselines/reference/APISample_watcher.js | 2 +- .../reference/APISample_watcher.types | 4 +- .../es6ExportEqualsInterop.errors.txt | 304 ++++++++++++++++++ .../reference/es6ExportEqualsInterop.js | 301 +++++++++++++++++ .../reference/exportStar-amd.errors.txt | 33 ++ tests/baselines/reference/exportStar-amd.js | 69 ++++ .../baselines/reference/exportStar.errors.txt | 33 ++ tests/baselines/reference/exportStar.js | 60 ++++ .../reference/exportsAndImports1-amd.js | 82 +++++ .../reference/exportsAndImports1-amd.types | 101 ++++++ .../baselines/reference/exportsAndImports1.js | 78 +++++ .../reference/exportsAndImports1.types | 101 ++++++ .../reference/exportsAndImports2-amd.js | 30 ++ .../reference/exportsAndImports2-amd.types | 26 ++ .../baselines/reference/exportsAndImports2.js | 26 ++ .../reference/exportsAndImports2.types | 26 ++ .../reference/exportsAndImports3-amd.js | 84 +++++ .../reference/exportsAndImports3-amd.types | 131 ++++++++ .../baselines/reference/exportsAndImports3.js | 80 +++++ .../reference/exportsAndImports3.types | 131 ++++++++ .../reference/exportsAndImports4-amd.js | 64 ++++ .../reference/exportsAndImports4-amd.types | 68 ++++ .../baselines/reference/exportsAndImports4.js | 66 ++++ .../reference/exportsAndImports4.types | 68 ++++ 30 files changed, 1974 insertions(+), 12 deletions(-) create mode 100644 tests/baselines/reference/es6ExportEqualsInterop.errors.txt create mode 100644 tests/baselines/reference/es6ExportEqualsInterop.js create mode 100644 tests/baselines/reference/exportStar-amd.errors.txt create mode 100644 tests/baselines/reference/exportStar-amd.js create mode 100644 tests/baselines/reference/exportStar.errors.txt create mode 100644 tests/baselines/reference/exportStar.js create mode 100644 tests/baselines/reference/exportsAndImports1-amd.js create mode 100644 tests/baselines/reference/exportsAndImports1-amd.types create mode 100644 tests/baselines/reference/exportsAndImports1.js create mode 100644 tests/baselines/reference/exportsAndImports1.types create mode 100644 tests/baselines/reference/exportsAndImports2-amd.js create mode 100644 tests/baselines/reference/exportsAndImports2-amd.types create mode 100644 tests/baselines/reference/exportsAndImports2.js create mode 100644 tests/baselines/reference/exportsAndImports2.types create mode 100644 tests/baselines/reference/exportsAndImports3-amd.js create mode 100644 tests/baselines/reference/exportsAndImports3-amd.types create mode 100644 tests/baselines/reference/exportsAndImports3.js create mode 100644 tests/baselines/reference/exportsAndImports3.types create mode 100644 tests/baselines/reference/exportsAndImports4-amd.js create mode 100644 tests/baselines/reference/exportsAndImports4-amd.types create mode 100644 tests/baselines/reference/exportsAndImports4.js create mode 100644 tests/baselines/reference/exportsAndImports4.types diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 84ee9ef859..86cd5b5ff4 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -936,7 +936,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - isValueExportDeclaration(node: Node): boolean; + isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index d6ac61eb94..33b0ab2228 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2998,8 +2998,8 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - isValueExportDeclaration(node: Node): boolean; ->isValueExportDeclaration : (node: Node) => boolean + isValueAliasDeclaration(node: Node): boolean; +>isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 931d9473a1..6c57165bdb 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -967,7 +967,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - isValueExportDeclaration(node: Node): boolean; + isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 6f7da4147f..f6ed3b80ea 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3144,8 +3144,8 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - isValueExportDeclaration(node: Node): boolean; ->isValueExportDeclaration : (node: Node) => boolean + isValueAliasDeclaration(node: Node): boolean; +>isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 3f739c9931..b18b0e385c 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -968,7 +968,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - isValueExportDeclaration(node: Node): boolean; + isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index ba8cde8001..55064457fa 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3094,8 +3094,8 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - isValueExportDeclaration(node: Node): boolean; ->isValueExportDeclaration : (node: Node) => boolean + isValueAliasDeclaration(node: Node): boolean; +>isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 1328ce98e6..b61ed3fdc9 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1005,7 +1005,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - isValueExportDeclaration(node: Node): boolean; + isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 7a82d70523..aaba39c6b8 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3267,8 +3267,8 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - isValueExportDeclaration(node: Node): boolean; ->isValueExportDeclaration : (node: Node) => boolean + isValueAliasDeclaration(node: Node): boolean; +>isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt new file mode 100644 index 0000000000..6351a3ee89 --- /dev/null +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -0,0 +1,304 @@ +tests/cases/compiler/main.ts(15,1): error TS2304: Cannot find name 'z1'. +tests/cases/compiler/main.ts(21,4): error TS2339: Property 'a' does not exist on type '() => any'. +tests/cases/compiler/main.ts(23,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'. +tests/cases/compiler/main.ts(27,8): error TS1192: External module '"interface"' has no default export. +tests/cases/compiler/main.ts(28,8): error TS1192: External module '"variable"' has no default export. +tests/cases/compiler/main.ts(29,8): error TS1192: External module '"interface-variable"' has no default export. +tests/cases/compiler/main.ts(30,8): error TS1192: External module '"module"' has no default export. +tests/cases/compiler/main.ts(31,8): error TS1192: External module '"interface-module"' has no default export. +tests/cases/compiler/main.ts(32,8): error TS1192: External module '"variable-module"' has no default export. +tests/cases/compiler/main.ts(33,8): error TS1192: External module '"function"' has no default export. +tests/cases/compiler/main.ts(34,8): error TS1192: External module '"function-module"' has no default export. +tests/cases/compiler/main.ts(35,8): error TS1192: External module '"class"' has no default export. +tests/cases/compiler/main.ts(36,8): error TS1192: External module '"class-module"' has no default export. +tests/cases/compiler/main.ts(39,21): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(45,21): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(47,21): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(62,25): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(68,25): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(70,25): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(85,25): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(91,25): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(93,25): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(97,15): error TS2497: External module '"interface"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(98,15): error TS2497: External module '"variable"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(99,15): error TS2497: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(100,15): error TS2497: External module '"module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(101,15): error TS2497: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(102,15): error TS2497: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(103,15): error TS2497: External module '"function"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(104,15): error TS2497: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(105,15): error TS2497: External module '"class"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. + + +==== tests/cases/compiler/main.ts (32 errors) ==== + /// + + // import-equals + import z1 = require("interface"); + import z2 = require("variable"); + import z3 = require("interface-variable"); + import z4 = require("module"); + import z5 = require("interface-module"); + import z6 = require("variable-module"); + import z7 = require("function"); + import z8 = require("function-module"); + import z9 = require("class"); + import z0 = require("class-module"); + + z1.a; + ~~ +!!! error TS2304: Cannot find name 'z1'. + z2.a; + z3.a; + z4.a; + z5.a; + z6.a; + z7.a; + ~ +!!! error TS2339: Property 'a' does not exist on type '() => any'. + z8.a; + z9.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'typeof Foo'. + z0.a; + + // default import + import x1 from "interface"; + ~~ +!!! error TS1192: External module '"interface"' has no default export. + import x2 from "variable"; + ~~ +!!! error TS1192: External module '"variable"' has no default export. + import x3 from "interface-variable"; + ~~ +!!! error TS1192: External module '"interface-variable"' has no default export. + import x4 from "module"; + ~~ +!!! error TS1192: External module '"module"' has no default export. + import x5 from "interface-module"; + ~~ +!!! error TS1192: External module '"interface-module"' has no default export. + import x6 from "variable-module"; + ~~ +!!! error TS1192: External module '"variable-module"' has no default export. + import x7 from "function"; + ~~ +!!! error TS1192: External module '"function"' has no default export. + import x8 from "function-module"; + ~~ +!!! error TS1192: External module '"function-module"' has no default export. + import x9 from "class"; + ~~ +!!! error TS1192: External module '"class"' has no default export. + import x0 from "class-module"; + ~~ +!!! error TS1192: External module '"class-module"' has no default export. + + // namespace import + import * as y1 from "interface"; + ~~~~~~~~~~~ +!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. + import * as y2 from "variable"; + import * as y3 from "interface-variable"; + import * as y4 from "module"; + import * as y5 from "interface-module"; + import * as y6 from "variable-module"; + import * as y7 from "function"; + ~~~~~~~~~~ +!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. + import * as y8 from "function-module"; + import * as y9 from "class"; + ~~~~~~~ +!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. + import * as y0 from "class-module"; + + y1.a; + y2.a; + y3.a; + y4.a; + y5.a; + y6.a; + y7.a; + y8.a; + y9.a; + y0.a; + + // named import + import { a as a1 } from "interface"; + ~~~~~~~~~~~ +!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. + import { a as a2 } from "variable"; + import { a as a3 } from "interface-variable"; + import { a as a4 } from "module"; + import { a as a5 } from "interface-module"; + import { a as a6 } from "variable-module"; + import { a as a7 } from "function"; + ~~~~~~~~~~ +!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. + import { a as a8 } from "function-module"; + import { a as a9 } from "class"; + ~~~~~~~ +!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. + import { a as a0 } from "class-module"; + + a1; + a2; + a3; + a4; + a5; + a6; + a7; + a8; + a9; + a0; + + // named export + export { a as a1 } from "interface"; + ~~~~~~~~~~~ +!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. + export { a as a2 } from "variable"; + export { a as a3 } from "interface-variable"; + export { a as a4 } from "module"; + export { a as a5 } from "interface-module"; + export { a as a6 } from "variable-module"; + export { a as a7 } from "function"; + ~~~~~~~~~~ +!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. + export { a as a8 } from "function-module"; + export { a as a9 } from "class"; + ~~~~~~~ +!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. + export { a as a0 } from "class-module"; + + // export-star + export * from "interface"; + ~~~~~~~~~~~ +!!! error TS2497: External module '"interface"' uses 'export =' and cannot be used with 'export *'. + export * from "variable"; + ~~~~~~~~~~ +!!! error TS2497: External module '"variable"' uses 'export =' and cannot be used with 'export *'. + export * from "interface-variable"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2497: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. + export * from "module"; + ~~~~~~~~ +!!! error TS2497: External module '"module"' uses 'export =' and cannot be used with 'export *'. + export * from "interface-module"; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2497: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. + export * from "variable-module"; + ~~~~~~~~~~~~~~~~~ +!!! error TS2497: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. + export * from "function"; + ~~~~~~~~~~ +!!! error TS2497: External module '"function"' uses 'export =' and cannot be used with 'export *'. + export * from "function-module"; + ~~~~~~~~~~~~~~~~~ +!!! error TS2497: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. + export * from "class"; + ~~~~~~~ +!!! error TS2497: External module '"class"' uses 'export =' and cannot be used with 'export *'. + export * from "class-module"; + ~~~~~~~~~~~~~~ +!!! error TS2497: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. + +==== tests/cases/compiler/modules.d.ts (0 errors) ==== + + declare module "interface" { + interface Foo { + x: number; + y: number; + } + export = Foo; + } + + declare module "variable" { + var Foo: { + a: number; + b: number; + } + export = Foo; + } + + declare module "interface-variable" { + interface Foo { + x: number; + y: number; + } + var Foo: { + a: number; + b: number; + } + export = Foo; + } + + declare module "module" { + module Foo { + export var a: number; + export var b: number; + } + export = Foo; + } + + declare module "interface-module" { + interface Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; + } + + declare module "variable-module" { + module Foo { + interface Bar { + x: number; + y: number; + } + } + var Foo: { + a: number; + b: number; + } + export = Foo; + } + + declare module "function" { + function foo(); + export = foo; + } + + declare module "function-module" { + function foo(); + module foo { + export var a: number; + export var b: number; + } + export = foo; + } + + declare module "class" { + class Foo { + x: number; + y: number; + } + export = Foo; + } + + declare module "class-module" { + class Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; + } + \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportEqualsInterop.js b/tests/baselines/reference/es6ExportEqualsInterop.js new file mode 100644 index 0000000000..6775bb8c6b --- /dev/null +++ b/tests/baselines/reference/es6ExportEqualsInterop.js @@ -0,0 +1,301 @@ +//// [tests/cases/compiler/es6ExportEqualsInterop.ts] //// + +//// [modules.d.ts] + +declare module "interface" { + interface Foo { + x: number; + y: number; + } + export = Foo; +} + +declare module "variable" { + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "interface-variable" { + interface Foo { + x: number; + y: number; + } + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "module" { + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +declare module "interface-module" { + interface Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +declare module "variable-module" { + module Foo { + interface Bar { + x: number; + y: number; + } + } + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "function" { + function foo(); + export = foo; +} + +declare module "function-module" { + function foo(); + module foo { + export var a: number; + export var b: number; + } + export = foo; +} + +declare module "class" { + class Foo { + x: number; + y: number; + } + export = Foo; +} + +declare module "class-module" { + class Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +//// [main.ts] +/// + +// import-equals +import z1 = require("interface"); +import z2 = require("variable"); +import z3 = require("interface-variable"); +import z4 = require("module"); +import z5 = require("interface-module"); +import z6 = require("variable-module"); +import z7 = require("function"); +import z8 = require("function-module"); +import z9 = require("class"); +import z0 = require("class-module"); + +z1.a; +z2.a; +z3.a; +z4.a; +z5.a; +z6.a; +z7.a; +z8.a; +z9.a; +z0.a; + +// default import +import x1 from "interface"; +import x2 from "variable"; +import x3 from "interface-variable"; +import x4 from "module"; +import x5 from "interface-module"; +import x6 from "variable-module"; +import x7 from "function"; +import x8 from "function-module"; +import x9 from "class"; +import x0 from "class-module"; + +// namespace import +import * as y1 from "interface"; +import * as y2 from "variable"; +import * as y3 from "interface-variable"; +import * as y4 from "module"; +import * as y5 from "interface-module"; +import * as y6 from "variable-module"; +import * as y7 from "function"; +import * as y8 from "function-module"; +import * as y9 from "class"; +import * as y0 from "class-module"; + +y1.a; +y2.a; +y3.a; +y4.a; +y5.a; +y6.a; +y7.a; +y8.a; +y9.a; +y0.a; + +// named import +import { a as a1 } from "interface"; +import { a as a2 } from "variable"; +import { a as a3 } from "interface-variable"; +import { a as a4 } from "module"; +import { a as a5 } from "interface-module"; +import { a as a6 } from "variable-module"; +import { a as a7 } from "function"; +import { a as a8 } from "function-module"; +import { a as a9 } from "class"; +import { a as a0 } from "class-module"; + +a1; +a2; +a3; +a4; +a5; +a6; +a7; +a8; +a9; +a0; + +// named export +export { a as a1 } from "interface"; +export { a as a2 } from "variable"; +export { a as a3 } from "interface-variable"; +export { a as a4 } from "module"; +export { a as a5 } from "interface-module"; +export { a as a6 } from "variable-module"; +export { a as a7 } from "function"; +export { a as a8 } from "function-module"; +export { a as a9 } from "class"; +export { a as a0 } from "class-module"; + +// export-star +export * from "interface"; +export * from "variable"; +export * from "interface-variable"; +export * from "module"; +export * from "interface-module"; +export * from "variable-module"; +export * from "function"; +export * from "function-module"; +export * from "class"; +export * from "class-module"; + + +//// [main.js] +/// +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +var z2 = require("variable"); +var z3 = require("interface-variable"); +var z4 = require("module"); +var z5 = require("interface-module"); +var z6 = require("variable-module"); +var z7 = require("function"); +var z8 = require("function-module"); +var z9 = require("class"); +var z0 = require("class-module"); +z1.a; +z2.a; +z3.a; +z4.a; +z5.a; +z6.a; +z7.a; +z8.a; +z9.a; +z0.a; +// namespace import +var y1 = require("interface"); +var y2 = require("variable"); +var y3 = require("interface-variable"); +var y4 = require("module"); +var y5 = require("interface-module"); +var y6 = require("variable-module"); +var y7 = require("function"); +var y8 = require("function-module"); +var y9 = require("class"); +var y0 = require("class-module"); +y1.a; +y2.a; +y3.a; +y4.a; +y5.a; +y6.a; +y7.a; +y8.a; +y9.a; +y0.a; +// named import +var _interface_2 = require("interface"); +var _variable_2 = require("variable"); +var _interface_variable_2 = require("interface-variable"); +var _module_2 = require("module"); +var _interface_module_2 = require("interface-module"); +var _variable_module_2 = require("variable-module"); +var _function_2 = require("function"); +var _function_module_2 = require("function-module"); +var _class_2 = require("class"); +var _class_module_2 = require("class-module"); +_interface_2.a; +_variable_2.a; +_interface_variable_2.a; +_module_2.a; +_interface_module_2.a; +_variable_module_2.a; +_function_2.a; +_function_module_2.a; +_class_2.a; +_class_module_2.a; +// named export +var _variable_3 = require("variable"); +exports.a2 = _variable_3.a; +var _interface_variable_3 = require("interface-variable"); +exports.a3 = _interface_variable_3.a; +var _module_3 = require("module"); +exports.a4 = _module_3.a; +var _interface_module_3 = require("interface-module"); +exports.a5 = _interface_module_3.a; +var _variable_module_3 = require("variable-module"); +exports.a6 = _variable_module_3.a; +var _function_module_3 = require("function-module"); +exports.a8 = _function_module_3.a; +var _class_module_3 = require("class-module"); +exports.a0 = _class_module_3.a; +// export-star +__export(require("interface")); +__export(require("variable")); +__export(require("interface-variable")); +__export(require("module")); +__export(require("interface-module")); +__export(require("variable-module")); +__export(require("function")); +__export(require("function-module")); +__export(require("class")); +__export(require("class-module")); diff --git a/tests/baselines/reference/exportStar-amd.errors.txt b/tests/baselines/reference/exportStar-amd.errors.txt new file mode 100644 index 0000000000..87e4c4740a --- /dev/null +++ b/tests/baselines/reference/exportStar-amd.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/es6/modules/main.ts(1,8): error TS1192: External module '"tests/cases/conformance/es6/modules/t4"' has no default export. + + +==== tests/cases/conformance/es6/modules/t1.ts (0 errors) ==== + + export var x = 1; + export var y = 2; + +==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== + export default "hello"; + export function foo() { } + +==== tests/cases/conformance/es6/modules/t3.ts (0 errors) ==== + var x = "x"; + var y = "y"; + var z = "z"; + export { x, y, z }; + +==== tests/cases/conformance/es6/modules/t4.ts (0 errors) ==== + export * from "./t1"; + export * from "./t2"; + export * from "./t3"; + +==== tests/cases/conformance/es6/modules/main.ts (1 errors) ==== + import hello, { x, y, z, foo } from "./t4"; + ~~~~~ +!!! error TS1192: External module '"tests/cases/conformance/es6/modules/t4"' has no default export. + hello; + x; + y; + z; + foo; + \ No newline at end of file diff --git a/tests/baselines/reference/exportStar-amd.js b/tests/baselines/reference/exportStar-amd.js new file mode 100644 index 0000000000..36d0904a18 --- /dev/null +++ b/tests/baselines/reference/exportStar-amd.js @@ -0,0 +1,69 @@ +//// [tests/cases/conformance/es6/modules/exportStar-amd.ts] //// + +//// [t1.ts] + +export var x = 1; +export var y = 2; + +//// [t2.ts] +export default "hello"; +export function foo() { } + +//// [t3.ts] +var x = "x"; +var y = "y"; +var z = "z"; +export { x, y, z }; + +//// [t4.ts] +export * from "./t1"; +export * from "./t2"; +export * from "./t3"; + +//// [main.ts] +import hello, { x, y, z, foo } from "./t4"; +hello; +x; +y; +z; +foo; + + +//// [t1.js] +define(["require", "exports"], function (require, exports) { + exports.x = 1; + exports.y = 2; +}); +//// [t2.js] +define(["require", "exports"], function (require, exports) { + exports.default = "hello"; + function foo() { + } + exports.foo = foo; +}); +//// [t3.js] +define(["require", "exports"], function (require, exports) { + var x = "x"; + exports.x = x; + var y = "y"; + exports.y = y; + var z = "z"; + exports.z = z; +}); +//// [t4.js] +define(["require", "exports", "./t1", "./t2", "./t3"], function (require, exports, _t1, _t2, _t3) { + function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + } + __export(_t1); + __export(_t2); + __export(_t3); +}); +//// [main.js] +define(["require", "exports", "./t4"], function (require, exports, _t4) { + _t4.default; + _t4.x; + _t4.y; + _t4.z; + _t4.foo; +}); diff --git a/tests/baselines/reference/exportStar.errors.txt b/tests/baselines/reference/exportStar.errors.txt new file mode 100644 index 0000000000..87e4c4740a --- /dev/null +++ b/tests/baselines/reference/exportStar.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/es6/modules/main.ts(1,8): error TS1192: External module '"tests/cases/conformance/es6/modules/t4"' has no default export. + + +==== tests/cases/conformance/es6/modules/t1.ts (0 errors) ==== + + export var x = 1; + export var y = 2; + +==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== + export default "hello"; + export function foo() { } + +==== tests/cases/conformance/es6/modules/t3.ts (0 errors) ==== + var x = "x"; + var y = "y"; + var z = "z"; + export { x, y, z }; + +==== tests/cases/conformance/es6/modules/t4.ts (0 errors) ==== + export * from "./t1"; + export * from "./t2"; + export * from "./t3"; + +==== tests/cases/conformance/es6/modules/main.ts (1 errors) ==== + import hello, { x, y, z, foo } from "./t4"; + ~~~~~ +!!! error TS1192: External module '"tests/cases/conformance/es6/modules/t4"' has no default export. + hello; + x; + y; + z; + foo; + \ No newline at end of file diff --git a/tests/baselines/reference/exportStar.js b/tests/baselines/reference/exportStar.js new file mode 100644 index 0000000000..070dd90b1d --- /dev/null +++ b/tests/baselines/reference/exportStar.js @@ -0,0 +1,60 @@ +//// [tests/cases/conformance/es6/modules/exportStar.ts] //// + +//// [t1.ts] + +export var x = 1; +export var y = 2; + +//// [t2.ts] +export default "hello"; +export function foo() { } + +//// [t3.ts] +var x = "x"; +var y = "y"; +var z = "z"; +export { x, y, z }; + +//// [t4.ts] +export * from "./t1"; +export * from "./t2"; +export * from "./t3"; + +//// [main.ts] +import hello, { x, y, z, foo } from "./t4"; +hello; +x; +y; +z; +foo; + + +//// [t1.js] +exports.x = 1; +exports.y = 2; +//// [t2.js] +exports.default = "hello"; +function foo() { +} +exports.foo = foo; +//// [t3.js] +var x = "x"; +exports.x = x; +var y = "y"; +exports.y = y; +var z = "z"; +exports.z = z; +//// [t4.js] +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +__export(require("./t1")); +__export(require("./t2")); +__export(require("./t3")); +//// [main.js] +var _t4 = require("./t4"); +_t4.default; +_t4.x; +_t4.y; +_t4.z; +_t4.foo; diff --git a/tests/baselines/reference/exportsAndImports1-amd.js b/tests/baselines/reference/exportsAndImports1-amd.js new file mode 100644 index 0000000000..ac0d56769b --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1-amd.js @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports1-amd.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; + +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] +define(["require", "exports"], function (require, exports) { + var v = 1; + exports.v = v; + function f() { + } + exports.f = f; + var C = (function () { + function C() { + } + return 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.x; + })(M || (M = {})); + exports.M = M; + var a = M.x; + exports.a = a; +}); +//// [t2.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.v = _t1.v; + exports.f = _t1.f; + exports.C = _t1.C; + exports.E = _t1.E; + exports.M = _t1.M; + exports.a = _t1.a; +}); +//// [t3.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.v = _t1.v; + exports.f = _t1.f; + exports.C = _t1.C; + exports.E = _t1.E; + exports.M = _t1.M; + exports.a = _t1.a; +}); diff --git a/tests/baselines/reference/exportsAndImports1-amd.types b/tests/baselines/reference/exportsAndImports1-amd.types new file mode 100644 index 0000000000..0b35b04e22 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1-amd.types @@ -0,0 +1,101 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +var v = 1; +>v : 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 : unknown + + 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 : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>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 : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>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 : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + diff --git a/tests/baselines/reference/exportsAndImports1.js b/tests/baselines/reference/exportsAndImports1.js new file mode 100644 index 0000000000..2e396c1c72 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1.js @@ -0,0 +1,78 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports1.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; + +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; +var C = (function () { + function C() { + } + return 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.x; +})(M || (M = {})); +exports.M = M; +var a = M.x; +exports.a = a; +//// [t2.js] +var _t1 = require("./t1"); +exports.v = _t1.v; +exports.f = _t1.f; +exports.C = _t1.C; +exports.E = _t1.E; +exports.M = _t1.M; +exports.a = _t1.a; +//// [t3.js] +var _t1 = require("./t1"); +exports.v = _t1.v; +exports.f = _t1.f; +exports.C = _t1.C; +exports.E = _t1.E; +exports.M = _t1.M; +exports.a = _t1.a; diff --git a/tests/baselines/reference/exportsAndImports1.types b/tests/baselines/reference/exportsAndImports1.types new file mode 100644 index 0000000000..0b35b04e22 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1.types @@ -0,0 +1,101 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +var v = 1; +>v : 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 : unknown + + 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 : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>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 : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>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 : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + diff --git a/tests/baselines/reference/exportsAndImports2-amd.js b/tests/baselines/reference/exportsAndImports2-amd.js new file mode 100644 index 0000000000..a958c5dd77 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports2-amd.js @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports2-amd.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] +define(["require", "exports"], function (require, exports) { + exports.x = "x"; + exports.y = "y"; +}); +//// [t2.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.y = _t1.x; + exports.x = _t1.y; +}); +//// [t3.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.y = _t1.x; + exports.x = _t1.y; +}); diff --git a/tests/baselines/reference/exportsAndImports2-amd.types b/tests/baselines/reference/exportsAndImports2-amd.types new file mode 100644 index 0000000000..ebfc097da5 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports2-amd.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +export var x = "x"; +>x : string + +export var y = "y"; +>y : string + +=== tests/cases/conformance/es6/modules/t2.ts === +export { x as y, y as x } from "./t1"; +>x : string +>y : string +>y : string +>x : string + +=== tests/cases/conformance/es6/modules/t3.ts === +import { x, y } from "./t1"; +>x : string +>y : string + +export { x as y, y as x }; +>x : string +>y : string +>y : string +>x : string + diff --git a/tests/baselines/reference/exportsAndImports2.js b/tests/baselines/reference/exportsAndImports2.js new file mode 100644 index 0000000000..3773dc624c --- /dev/null +++ b/tests/baselines/reference/exportsAndImports2.js @@ -0,0 +1,26 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports2.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 = require("./t1"); +exports.y = _t1.x; +exports.x = _t1.y; +//// [t3.js] +var _t1 = require("./t1"); +exports.y = _t1.x; +exports.x = _t1.y; diff --git a/tests/baselines/reference/exportsAndImports2.types b/tests/baselines/reference/exportsAndImports2.types new file mode 100644 index 0000000000..ebfc097da5 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports2.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +export var x = "x"; +>x : string + +export var y = "y"; +>y : string + +=== tests/cases/conformance/es6/modules/t2.ts === +export { x as y, y as x } from "./t1"; +>x : string +>y : string +>y : string +>x : string + +=== tests/cases/conformance/es6/modules/t3.ts === +import { x, y } from "./t1"; +>x : string +>y : string + +export { x as y, y as x }; +>x : string +>y : string +>y : string +>x : string + diff --git a/tests/baselines/reference/exportsAndImports3-amd.js b/tests/baselines/reference/exportsAndImports3-amd.js new file mode 100644 index 0000000000..443358eafd --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3-amd.js @@ -0,0 +1,84 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts] //// + +//// [t1.ts] + +export var v = 1; +export function f() { } +export class C { +} +export interface I { +} +export enum E { + A, B, C +} +export const enum D { + A, B, C +} +export module M { + export var x; +} +export module N { + export interface I { + } +} +export type T = number; +export import a = M.x; + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; + +//// [t2.ts] +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; + +//// [t3.ts] +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; + + +//// [t1.js] +define(["require", "exports"], function (require, exports) { + exports.v = 1; + exports.v1 = exports.v; + function f() { + } + exports.f = f; + exports.f1 = exports.f; + var C = (function () { + function C() { + } + return C; + })(); + exports.C = C; + exports.C1 = exports.C; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(exports.E || (exports.E = {})); + var E = exports.E; + exports.E1 = exports.E; + var M; + (function (M) { + M.x; + })(M = exports.M || (exports.M = {})); + exports.M1 = exports.M; + exports.a = M.x; + exports.a1 = exports.a; +}); +//// [t2.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.v = _t1.v1; + exports.f = _t1.f1; + exports.C = _t1.C1; + exports.E = _t1.E1; + exports.M = _t1.M1; + exports.a = _t1.a1; +}); +//// [t3.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.v = _t1.v1; + exports.f = _t1.f1; + exports.C = _t1.C1; + exports.E = _t1.E1; + exports.M = _t1.M1; + exports.a = _t1.a1; +}); diff --git a/tests/baselines/reference/exportsAndImports3-amd.types b/tests/baselines/reference/exportsAndImports3-amd.types new file mode 100644 index 0000000000..86e21cfd08 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3-amd.types @@ -0,0 +1,131 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +export var v = 1; +>v : number + +export function f() { } +>f : () => void + +export class C { +>C : C +} +export interface I { +>I : I +} +export enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E +} +export const enum D { +>D : D + + A, B, C +>A : D +>B : D +>C : D +} +export module M { +>M : typeof M + + export var x; +>x : any +} +export module N { +>N : unknown + + export interface I { +>I : I + } +} +export type T = number; +>T : number + +export import a = M.x; +>a : any +>M : typeof M +>x : any + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; +>v : number +>v1 : number +>f : () => void +>f1 : () => void +>C : typeof C +>C1 : typeof C +>I : unknown +>I1 : unknown +>E : typeof E +>E1 : typeof E +>D : typeof D +>D1 : typeof D +>M : typeof M +>M1 : typeof M +>N : unknown +>N1 : unknown +>T : unknown +>T1 : unknown +>a : any +>a1 : any + +=== tests/cases/conformance/es6/modules/t2.ts === +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +>v1 : number +>v : number +>f1 : () => void +>f : () => void +>C1 : typeof C +>C : typeof C +>I1 : unknown +>I : unknown +>E1 : typeof E +>E : typeof E +>D1 : typeof D +>D : typeof D +>M1 : typeof M +>M : typeof M +>N1 : unknown +>N : unknown +>T1 : unknown +>T : unknown +>a1 : any +>a : any + +=== tests/cases/conformance/es6/modules/t3.ts === +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +>v1 : number +>v : number +>f1 : () => void +>f : () => void +>C1 : typeof C +>C : typeof C +>I1 : unknown +>I : unknown +>E1 : typeof E +>E : typeof E +>D1 : typeof D +>D : typeof D +>M1 : typeof M +>M : typeof M +>N1 : unknown +>N : unknown +>T1 : unknown +>T : unknown +>a1 : any +>a : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + diff --git a/tests/baselines/reference/exportsAndImports3.js b/tests/baselines/reference/exportsAndImports3.js new file mode 100644 index 0000000000..d4ebe982f8 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3.js @@ -0,0 +1,80 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports3.ts] //// + +//// [t1.ts] + +export var v = 1; +export function f() { } +export class C { +} +export interface I { +} +export enum E { + A, B, C +} +export const enum D { + A, B, C +} +export module M { + export var x; +} +export module N { + export interface I { + } +} +export type T = number; +export import a = M.x; + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; + +//// [t2.ts] +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; + +//// [t3.ts] +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; + + +//// [t1.js] +exports.v = 1; +exports.v1 = exports.v; +function f() { +} +exports.f = f; +exports.f1 = exports.f; +var C = (function () { + function C() { + } + return C; +})(); +exports.C = C; +exports.C1 = exports.C; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; +})(exports.E || (exports.E = {})); +var E = exports.E; +exports.E1 = exports.E; +var M; +(function (M) { + M.x; +})(M = exports.M || (exports.M = {})); +exports.M1 = exports.M; +exports.a = M.x; +exports.a1 = exports.a; +//// [t2.js] +var _t1 = require("./t1"); +exports.v = _t1.v1; +exports.f = _t1.f1; +exports.C = _t1.C1; +exports.E = _t1.E1; +exports.M = _t1.M1; +exports.a = _t1.a1; +//// [t3.js] +var _t1 = require("./t1"); +exports.v = _t1.v1; +exports.f = _t1.f1; +exports.C = _t1.C1; +exports.E = _t1.E1; +exports.M = _t1.M1; +exports.a = _t1.a1; diff --git a/tests/baselines/reference/exportsAndImports3.types b/tests/baselines/reference/exportsAndImports3.types new file mode 100644 index 0000000000..86e21cfd08 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3.types @@ -0,0 +1,131 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +export var v = 1; +>v : number + +export function f() { } +>f : () => void + +export class C { +>C : C +} +export interface I { +>I : I +} +export enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E +} +export const enum D { +>D : D + + A, B, C +>A : D +>B : D +>C : D +} +export module M { +>M : typeof M + + export var x; +>x : any +} +export module N { +>N : unknown + + export interface I { +>I : I + } +} +export type T = number; +>T : number + +export import a = M.x; +>a : any +>M : typeof M +>x : any + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; +>v : number +>v1 : number +>f : () => void +>f1 : () => void +>C : typeof C +>C1 : typeof C +>I : unknown +>I1 : unknown +>E : typeof E +>E1 : typeof E +>D : typeof D +>D1 : typeof D +>M : typeof M +>M1 : typeof M +>N : unknown +>N1 : unknown +>T : unknown +>T1 : unknown +>a : any +>a1 : any + +=== tests/cases/conformance/es6/modules/t2.ts === +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +>v1 : number +>v : number +>f1 : () => void +>f : () => void +>C1 : typeof C +>C : typeof C +>I1 : unknown +>I : unknown +>E1 : typeof E +>E : typeof E +>D1 : typeof D +>D : typeof D +>M1 : typeof M +>M : typeof M +>N1 : unknown +>N : unknown +>T1 : unknown +>T : unknown +>a1 : any +>a : any + +=== tests/cases/conformance/es6/modules/t3.ts === +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +>v1 : number +>v : number +>f1 : () => void +>f : () => void +>C1 : typeof C +>C : typeof C +>I1 : unknown +>I : unknown +>E1 : typeof E +>E : typeof E +>D1 : typeof D +>D : typeof D +>M1 : typeof M +>M : typeof M +>N1 : unknown +>N : unknown +>T1 : unknown +>T : unknown +>a1 : any +>a : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + diff --git a/tests/baselines/reference/exportsAndImports4-amd.js b/tests/baselines/reference/exportsAndImports4-amd.js new file mode 100644 index 0000000000..d915f4786a --- /dev/null +++ b/tests/baselines/reference/exportsAndImports4-amd.js @@ -0,0 +1,64 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts] //// + +//// [t1.ts] + +export default "hello"; + +//// [t2.ts] +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +import "./t1"; + +//// [t3.ts] +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +export { a, b, c, d, e1, e2, f1, f2 }; + + +//// [t1.js] +define(["require", "exports"], function (require, exports) { + exports.default = "hello"; +}); +//// [t3.js] +define(["require", "exports", "./t1", "./t1", "./t1", "./t1", "./t1", "./t1"], function (require, exports, a, _t1, c, _t1_2, e2, _t1_4) { + exports.a = a; + a.default; + exports.b = _t1.default; + _t1.default; + exports.c = c; + c.default; + exports.d = _t1_2.default; + _t1_2.default; + exports.e1 = _t1_3.default; + exports.e2 = e2; + _t1_3.default; + e2.default; + exports.f1 = _t1_4.default; + exports.f2 = _t1_4.default; + _t1_4.default; + _t1_4.default; +}); diff --git a/tests/baselines/reference/exportsAndImports4-amd.types b/tests/baselines/reference/exportsAndImports4-amd.types new file mode 100644 index 0000000000..4bd6f8c0e1 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports4-amd.types @@ -0,0 +1,68 @@ +=== tests/cases/conformance/es6/modules/t3.ts === +import a = require("./t1"); +>a : typeof a + +a.default; +>a.default : string +>a : typeof a +>default : string + +import b from "./t1"; +>b : string + +b; +>b : string + +import * as c from "./t1"; +>c : typeof a + +c.default; +>c.default : string +>c : typeof a +>default : string + +import { default as d } from "./t1"; +>default : string +>d : string + +d; +>d : string + +import e1, * as e2 from "./t1"; +>e1 : string +>e2 : typeof a + +e1; +>e1 : string + +e2.default; +>e2.default : string +>e2 : typeof a +>default : string + +import f1, { default as f2 } from "./t1"; +>f1 : string +>default : string +>f2 : string + +f1; +>f1 : string + +f2; +>f2 : string + +export { a, b, c, d, e1, e2, f1, f2 }; +>a : typeof a +>b : string +>c : typeof a +>d : string +>e1 : string +>e2 : typeof a +>f1 : string +>f2 : string + +=== tests/cases/conformance/es6/modules/t1.ts === + +No type information for this code.export default "hello"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports4.js b/tests/baselines/reference/exportsAndImports4.js new file mode 100644 index 0000000000..05f0285472 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports4.js @@ -0,0 +1,66 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports4.ts] //// + +//// [t1.ts] + +export default "hello"; + +//// [t2.ts] +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +import "./t1"; + +//// [t3.ts] +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +export { a, b, c, d, e1, e2, f1, f2 }; + + +//// [t1.js] +exports.default = "hello"; +//// [t3.js] +var a = require("./t1"); +exports.a = a; +a.default; +var _t1 = require("./t1"); +exports.b = _t1.default; +_t1.default; +var c = require("./t1"); +exports.c = c; +c.default; +var _t1_2 = require("./t1"); +exports.d = _t1_2.default; +_t1_2.default; +var _t1_3 = require("./t1"), e2 = _t1_3; +exports.e1 = _t1_3.default; +exports.e2 = e2; +_t1_3.default; +e2.default; +var _t1_4 = require("./t1"); +exports.f1 = _t1_4.default; +exports.f2 = _t1_4.default; +_t1_4.default; +_t1_4.default; diff --git a/tests/baselines/reference/exportsAndImports4.types b/tests/baselines/reference/exportsAndImports4.types new file mode 100644 index 0000000000..4bd6f8c0e1 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports4.types @@ -0,0 +1,68 @@ +=== tests/cases/conformance/es6/modules/t3.ts === +import a = require("./t1"); +>a : typeof a + +a.default; +>a.default : string +>a : typeof a +>default : string + +import b from "./t1"; +>b : string + +b; +>b : string + +import * as c from "./t1"; +>c : typeof a + +c.default; +>c.default : string +>c : typeof a +>default : string + +import { default as d } from "./t1"; +>default : string +>d : string + +d; +>d : string + +import e1, * as e2 from "./t1"; +>e1 : string +>e2 : typeof a + +e1; +>e1 : string + +e2.default; +>e2.default : string +>e2 : typeof a +>default : string + +import f1, { default as f2 } from "./t1"; +>f1 : string +>default : string +>f2 : string + +f1; +>f1 : string + +f2; +>f2 : string + +export { a, b, c, d, e1, e2, f1, f2 }; +>a : typeof a +>b : string +>c : typeof a +>d : string +>e1 : string +>e2 : typeof a +>f1 : string +>f2 : string + +=== tests/cases/conformance/es6/modules/t1.ts === + +No type information for this code.export default "hello"; +No type information for this code. +No type information for this code. \ No newline at end of file From b2656b0d78465501256ce942534b44571f6050b1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 14:32:42 -0700 Subject: [PATCH 4/6] Deleting unused code --- src/compiler/checker.ts | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index facf729775..ee4f5d85e7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10117,30 +10117,6 @@ module ts { return emptyArray; } - //function hasExportedMembers(moduleSymbol: Symbol) { - // let declarations = moduleSymbol.declarations; - // for (let current of declarations) { - // let statements = getModuleStatements(current); - // for (let node of statements) { - // if (node.kind === SyntaxKind.ExportDeclaration) { - // let exportClause = (node).exportClause; - // if (!exportClause) { - // return true; - // } - // let specifiers = exportClause.elements; - // for (let specifier of specifiers) { - // if (!(specifier.propertyName && specifier.name && specifier.name.text === "default")) { - // return true; - // } - // } - // } - // else if (node.kind !== SyntaxKind.ExportAssignment && node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { - // return true; - // } - // } - // } - //} - function hasExportedMembers(moduleSymbol: Symbol) { for (var id in moduleSymbol.exports) { if (id !== "export=") { From 3f0cfe3619ac05d0f349de6b36b69bb85cdb1be3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 15:35:08 -0700 Subject: [PATCH 5/6] Adding a few comments --- src/compiler/checker.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ee4f5d85e7..fa7706cb82 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -531,6 +531,24 @@ module ts { } } + // This function creates a synthetic symbol that combines the value side of one symbol with the + // type/namespace side of another symbol. Consider this example: + // + // declare module graphics { + // interface Point { + // x: number; + // y: number; + // } + // } + // declare var graphics: { + // Point: new (x: number, y: number) => graphics.Point; + // } + // declare module "graphics" { + // export = graphics; + // } + // + // An 'import { Point } from "graphics"' needs to create a symbol that combines the value side 'Point' + // property with the type/namespace side interface 'Point'. function combineValueAndTypeSymbols(valueSymbol: Symbol, typeSymbol: Symbol): Symbol { if (valueSymbol.flags & (SymbolFlags.Type | SymbolFlags.Namespace)) { return valueSymbol; @@ -776,10 +794,15 @@ module ts { error(moduleReferenceLiteral, Diagnostics.Cannot_find_external_module_0, moduleName); } + // An external module with an 'export =' declaration resolves to the target of the 'export =' declaration, + // and an external module with no 'export =' declaration resolves to the module itself. function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol { return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol; } + // An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export =' + // references a symbol that is at least declared as a module or a variable. The target of the 'export =' may + // combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable). function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression): Symbol { let symbol = resolveExternalModuleSymbol(moduleSymbol); if (symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) { From 6074b3ea24077ab36ea4ce731d0512e752c32c8f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 23 Mar 2015 11:05:03 -0700 Subject: [PATCH 6/6] Consistently error on more than one 'export default' --- src/compiler/binder.ts | 4 ++-- src/compiler/checker.ts | 4 ++-- src/compiler/utilities.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 008bb5b319..ae0bb3a030 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -531,11 +531,11 @@ module ts { case SyntaxKind.ExportAssignment: if ((node).expression.kind === SyntaxKind.Identifier) { // An export default clause with an identifier exports all meanings of that identifier - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); + declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); } else { // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); } bindChildren(node, 0, /*isBlockScopeContainer*/ false); break; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fa7706cb82..a84d0a6a8c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -613,7 +613,7 @@ module ts { return resolveEntityName(node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); } - function getTargetOfImportDeclaration(node: Declaration): Symbol { + function getTargetOfAliasDeclaration(node: Declaration): Symbol { switch (node.kind) { case SyntaxKind.ImportEqualsDeclaration: return getTargetOfImportEqualsDeclaration(node); @@ -640,7 +640,7 @@ module ts { if (!links.target) { links.target = resolvingSymbol; let node = getDeclarationOfAliasSymbol(symbol); - let target = getTargetOfImportDeclaration(node); + let target = getTargetOfAliasDeclaration(node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bf9c38188d..3c61ad66f8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -848,7 +848,7 @@ module ts { node.kind === SyntaxKind.NamespaceImport || node.kind === SyntaxKind.ImportSpecifier || node.kind === SyntaxKind.ExportSpecifier || - node.kind === SyntaxKind.ExportAssignment; + node.kind === SyntaxKind.ExportAssignment && (node).expression.kind === SyntaxKind.Identifier; } export function getClassBaseTypeNode(node: ClassDeclaration) {