From 76dd2086a4984d8858d558b44c01967417fef588 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 20 Apr 2016 11:22:52 -0700 Subject: [PATCH 1/3] Report error if user specified --out and we are defaulting to commonjs emit --- src/compiler/program.ts | 5 +- .../reference/isolatedModulesOut.errors.txt | 2 + .../typeReferenceDirectives11.errors.txt | 17 +++++ .../reference/typeReferenceDirectives11.js | 27 ------- .../typeReferenceDirectives11.symbols | 23 ------ .../reference/typeReferenceDirectives11.types | 26 ------- .../typeReferenceDirectives12.errors.txt | 36 +++++++++ .../reference/typeReferenceDirectives12.js | 63 ---------------- .../typeReferenceDirectives12.symbols | 68 ----------------- .../reference/typeReferenceDirectives12.types | 73 ------------------- 10 files changed, 59 insertions(+), 281 deletions(-) create mode 100644 tests/baselines/reference/typeReferenceDirectives11.errors.txt delete mode 100644 tests/baselines/reference/typeReferenceDirectives11.js delete mode 100644 tests/baselines/reference/typeReferenceDirectives11.symbols delete mode 100644 tests/baselines/reference/typeReferenceDirectives11.types create mode 100644 tests/baselines/reference/typeReferenceDirectives12.errors.txt delete mode 100644 tests/baselines/reference/typeReferenceDirectives12.js delete mode 100644 tests/baselines/reference/typeReferenceDirectives12.symbols delete mode 100644 tests/baselines/reference/typeReferenceDirectives12.types diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 1ef5d6bfba1..bf5b7cb5727 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2076,7 +2076,10 @@ namespace ts { } // Cannot specify module gen that isn't amd or system with --out - if (outFile && options.module && !(options.module === ModuleKind.AMD || options.module === ModuleKind.System)) { + // Report this error if user specified --module moduleKind + // or if there is external module in compilation which defaults to commonjs + const emitModuleKind = getEmitModuleKind(options); + if (outFile && (options.module || firstExternalModuleSourceFile) && !(emitModuleKind === ModuleKind.AMD || emitModuleKind === ModuleKind.System)) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); } diff --git a/tests/baselines/reference/isolatedModulesOut.errors.txt b/tests/baselines/reference/isolatedModulesOut.errors.txt index 7d16ac94666..7df16139bfe 100644 --- a/tests/baselines/reference/isolatedModulesOut.errors.txt +++ b/tests/baselines/reference/isolatedModulesOut.errors.txt @@ -1,8 +1,10 @@ error TS5053: Option 'out' cannot be specified with option 'isolatedModules'. +error TS6082: Only 'amd' and 'system' modules are supported alongside --out. tests/cases/compiler/file2.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. !!! error TS5053: Option 'out' cannot be specified with option 'isolatedModules'. +!!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out. ==== tests/cases/compiler/file1.ts (0 errors) ==== export var x; diff --git a/tests/baselines/reference/typeReferenceDirectives11.errors.txt b/tests/baselines/reference/typeReferenceDirectives11.errors.txt new file mode 100644 index 00000000000..2acecc8de4c --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives11.errors.txt @@ -0,0 +1,17 @@ +error TS6082: Only 'amd' and 'system' modules are supported alongside --out. + + +!!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out. +==== /mod2.ts (0 errors) ==== + + import {foo} from "./mod1"; + export const bar = foo(); +==== /types/lib/index.d.ts (0 errors) ==== + + + interface Lib { x } + +==== /mod1.ts (0 errors) ==== + + export function foo(): Lib { return {x: 1} } + \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives11.js b/tests/baselines/reference/typeReferenceDirectives11.js deleted file mode 100644 index cb41c843adc..00000000000 --- a/tests/baselines/reference/typeReferenceDirectives11.js +++ /dev/null @@ -1,27 +0,0 @@ -//// [tests/cases/compiler/typeReferenceDirectives11.ts] //// - -//// [index.d.ts] - - -interface Lib { x } - -//// [mod1.ts] - -export function foo(): Lib { return {x: 1} } - -//// [mod2.ts] - -import {foo} from "./mod1"; -export const bar = foo(); - -//// [output.js] - - -//// [output.d.ts] -/// -declare module "mod1" { - export function foo(): Lib; -} -declare module "mod2" { - export const bar: Lib; -} diff --git a/tests/baselines/reference/typeReferenceDirectives11.symbols b/tests/baselines/reference/typeReferenceDirectives11.symbols deleted file mode 100644 index 875bb2a0900..00000000000 --- a/tests/baselines/reference/typeReferenceDirectives11.symbols +++ /dev/null @@ -1,23 +0,0 @@ -=== /mod2.ts === - -import {foo} from "./mod1"; ->foo : Symbol(foo, Decl(mod2.ts, 1, 8)) - -export const bar = foo(); ->bar : Symbol(bar, Decl(mod2.ts, 2, 12)) ->foo : Symbol(foo, Decl(mod2.ts, 1, 8)) - -=== /types/lib/index.d.ts === - - -interface Lib { x } ->Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) ->x : Symbol(Lib.x, Decl(index.d.ts, 2, 15)) - -=== /mod1.ts === - -export function foo(): Lib { return {x: 1} } ->foo : Symbol(foo, Decl(mod1.ts, 0, 0)) ->Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) ->x : Symbol(x, Decl(mod1.ts, 1, 37)) - diff --git a/tests/baselines/reference/typeReferenceDirectives11.types b/tests/baselines/reference/typeReferenceDirectives11.types deleted file mode 100644 index 93d80b7988a..00000000000 --- a/tests/baselines/reference/typeReferenceDirectives11.types +++ /dev/null @@ -1,26 +0,0 @@ -=== /mod2.ts === - -import {foo} from "./mod1"; ->foo : () => Lib - -export const bar = foo(); ->bar : Lib ->foo() : Lib ->foo : () => Lib - -=== /types/lib/index.d.ts === - - -interface Lib { x } ->Lib : Lib ->x : any - -=== /mod1.ts === - -export function foo(): Lib { return {x: 1} } ->foo : () => Lib ->Lib : Lib ->{x: 1} : { x: number; } ->x : number ->1 : number - diff --git a/tests/baselines/reference/typeReferenceDirectives12.errors.txt b/tests/baselines/reference/typeReferenceDirectives12.errors.txt new file mode 100644 index 00000000000..1a1668ecfcd --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives12.errors.txt @@ -0,0 +1,36 @@ +error TS6082: Only 'amd' and 'system' modules are supported alongside --out. + + +!!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out. +==== /mod2.ts (0 errors) ==== + import { Cls } from "./main"; + import "./mod1"; + + export const cls = Cls; + export const foo = new Cls().foo(); + export const bar = Cls.bar(); +==== /types/lib/index.d.ts (0 errors) ==== + + + interface Lib { x } + +==== /main.ts (0 errors) ==== + export class Cls { + x + } + +==== /mod1.ts (0 errors) ==== + /// + + import {Cls} from "./main"; + Cls.prototype.foo = function() { return undefined; } + + declare module "./main" { + interface Cls { + foo(): Lib; + } + namespace Cls { + function bar(): Lib; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives12.js b/tests/baselines/reference/typeReferenceDirectives12.js deleted file mode 100644 index c9c4a912da1..00000000000 --- a/tests/baselines/reference/typeReferenceDirectives12.js +++ /dev/null @@ -1,63 +0,0 @@ -//// [tests/cases/compiler/typeReferenceDirectives12.ts] //// - -//// [index.d.ts] - - -interface Lib { x } - -//// [main.ts] -export class Cls { - x -} - -//// [mod1.ts] -/// - -import {Cls} from "./main"; -Cls.prototype.foo = function() { return undefined; } - -declare module "./main" { - interface Cls { - foo(): Lib; - } - namespace Cls { - function bar(): Lib; - } -} - -//// [mod2.ts] -import { Cls } from "./main"; -import "./mod1"; - -export const cls = Cls; -export const foo = new Cls().foo(); -export const bar = Cls.bar(); - -//// [output.js] -/// - - -//// [output.d.ts] -/// -declare module "main" { - export class Cls { - x: any; - } -} -declare module "mod1" { - module "main" { - interface Cls { - foo(): Lib; - } - namespace Cls { - function bar(): Lib; - } - } -} -declare module "mod2" { - import { Cls } from "main"; - import "mod1"; - export const cls: typeof Cls; - export const foo: Lib; - export const bar: Lib; -} diff --git a/tests/baselines/reference/typeReferenceDirectives12.symbols b/tests/baselines/reference/typeReferenceDirectives12.symbols deleted file mode 100644 index 30b24c39284..00000000000 --- a/tests/baselines/reference/typeReferenceDirectives12.symbols +++ /dev/null @@ -1,68 +0,0 @@ -=== /mod2.ts === -import { Cls } from "./main"; ->Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) - -import "./mod1"; - -export const cls = Cls; ->cls : Symbol(cls, Decl(mod2.ts, 3, 12)) ->Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) - -export const foo = new Cls().foo(); ->foo : Symbol(foo, Decl(mod2.ts, 4, 12)) ->new Cls().foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) ->Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) ->foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) - -export const bar = Cls.bar(); ->bar : Symbol(bar, Decl(mod2.ts, 5, 12)) ->Cls.bar : Symbol(Cls.bar, Decl(mod1.ts, 9, 19)) ->Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) ->bar : Symbol(Cls.bar, Decl(mod1.ts, 9, 19)) - -=== /types/lib/index.d.ts === - - -interface Lib { x } ->Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) ->x : Symbol(Lib.x, Decl(index.d.ts, 2, 15)) - -=== /main.ts === -export class Cls { ->Cls : Symbol(Cls, Decl(main.ts, 0, 0), Decl(mod1.ts, 5, 25), Decl(mod1.ts, 8, 5)) - - x ->x : Symbol(Cls.x, Decl(main.ts, 0, 18)) -} - -=== /mod1.ts === -/// - -import {Cls} from "./main"; ->Cls : Symbol(Cls, Decl(mod1.ts, 2, 8)) - -Cls.prototype.foo = function() { return undefined; } ->Cls.prototype.foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) ->Cls.prototype : Symbol(Cls.prototype) ->Cls : Symbol(Cls, Decl(mod1.ts, 2, 8)) ->prototype : Symbol(Cls.prototype) ->foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) ->undefined : Symbol(undefined) - -declare module "./main" { - interface Cls { ->Cls : Symbol(Cls, Decl(main.ts, 0, 0), Decl(mod1.ts, 5, 25), Decl(mod1.ts, 8, 5)) - - foo(): Lib; ->foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) ->Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) - } - namespace Cls { ->Cls : Symbol(Cls, Decl(main.ts, 0, 0), Decl(mod1.ts, 5, 25), Decl(mod1.ts, 8, 5)) - - function bar(): Lib; ->bar : Symbol(bar, Decl(mod1.ts, 9, 19)) ->Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) - } -} - diff --git a/tests/baselines/reference/typeReferenceDirectives12.types b/tests/baselines/reference/typeReferenceDirectives12.types deleted file mode 100644 index bd429b91f1c..00000000000 --- a/tests/baselines/reference/typeReferenceDirectives12.types +++ /dev/null @@ -1,73 +0,0 @@ -=== /mod2.ts === -import { Cls } from "./main"; ->Cls : typeof Cls - -import "./mod1"; - -export const cls = Cls; ->cls : typeof Cls ->Cls : typeof Cls - -export const foo = new Cls().foo(); ->foo : Lib ->new Cls().foo() : Lib ->new Cls().foo : () => Lib ->new Cls() : Cls ->Cls : typeof Cls ->foo : () => Lib - -export const bar = Cls.bar(); ->bar : Lib ->Cls.bar() : Lib ->Cls.bar : () => Lib ->Cls : typeof Cls ->bar : () => Lib - -=== /types/lib/index.d.ts === - - -interface Lib { x } ->Lib : Lib ->x : any - -=== /main.ts === -export class Cls { ->Cls : Cls - - x ->x : any -} - -=== /mod1.ts === -/// - -import {Cls} from "./main"; ->Cls : typeof Cls - -Cls.prototype.foo = function() { return undefined; } ->Cls.prototype.foo = function() { return undefined; } : () => any ->Cls.prototype.foo : () => Lib ->Cls.prototype : Cls ->Cls : typeof Cls ->prototype : Cls ->foo : () => Lib ->function() { return undefined; } : () => any ->undefined : undefined - -declare module "./main" { - interface Cls { ->Cls : Cls - - foo(): Lib; ->foo : () => Lib ->Lib : Lib - } - namespace Cls { ->Cls : typeof Cls - - function bar(): Lib; ->bar : () => Lib ->Lib : Lib - } -} - From 11cd54a7e151cc587a91462c1554aaa193aac305 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 20 Apr 2016 11:25:41 -0700 Subject: [PATCH 2/3] Change the tests for typereference directive tests 11 and 12 to use module gen amd so they can emit correctly Fixes #8182 --- .../typeReferenceDirectives11.errors.txt | 17 ---- .../reference/typeReferenceDirectives11.js | 36 ++++++++ .../typeReferenceDirectives11.symbols | 23 ++++++ .../typeReferenceDirectives11.trace.json | 3 +- .../reference/typeReferenceDirectives11.types | 26 ++++++ .../typeReferenceDirectives12.errors.txt | 36 -------- .../reference/typeReferenceDirectives12.js | 82 +++++++++++++++++++ .../typeReferenceDirectives12.symbols | 68 +++++++++++++++ .../typeReferenceDirectives12.trace.json | 9 +- .../reference/typeReferenceDirectives12.types | 73 +++++++++++++++++ .../compiler/typeReferenceDirectives11.ts | 1 + .../compiler/typeReferenceDirectives12.ts | 1 + 12 files changed, 314 insertions(+), 61 deletions(-) delete mode 100644 tests/baselines/reference/typeReferenceDirectives11.errors.txt create mode 100644 tests/baselines/reference/typeReferenceDirectives11.js create mode 100644 tests/baselines/reference/typeReferenceDirectives11.symbols create mode 100644 tests/baselines/reference/typeReferenceDirectives11.types delete mode 100644 tests/baselines/reference/typeReferenceDirectives12.errors.txt create mode 100644 tests/baselines/reference/typeReferenceDirectives12.js create mode 100644 tests/baselines/reference/typeReferenceDirectives12.symbols create mode 100644 tests/baselines/reference/typeReferenceDirectives12.types diff --git a/tests/baselines/reference/typeReferenceDirectives11.errors.txt b/tests/baselines/reference/typeReferenceDirectives11.errors.txt deleted file mode 100644 index 2acecc8de4c..00000000000 --- a/tests/baselines/reference/typeReferenceDirectives11.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -error TS6082: Only 'amd' and 'system' modules are supported alongside --out. - - -!!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out. -==== /mod2.ts (0 errors) ==== - - import {foo} from "./mod1"; - export const bar = foo(); -==== /types/lib/index.d.ts (0 errors) ==== - - - interface Lib { x } - -==== /mod1.ts (0 errors) ==== - - export function foo(): Lib { return {x: 1} } - \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives11.js b/tests/baselines/reference/typeReferenceDirectives11.js new file mode 100644 index 00000000000..b75ce8b4762 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives11.js @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/typeReferenceDirectives11.ts] //// + +//// [index.d.ts] + + +interface Lib { x } + +//// [mod1.ts] + +export function foo(): Lib { return {x: 1} } + +//// [mod2.ts] + +import {foo} from "./mod1"; +export const bar = foo(); + +//// [output.js] +define("mod1", ["require", "exports"], function (require, exports) { + "use strict"; + function foo() { return { x: 1 }; } + exports.foo = foo; +}); +define("mod2", ["require", "exports", "mod1"], function (require, exports, mod1_1) { + "use strict"; + exports.bar = mod1_1.foo(); +}); + + +//// [output.d.ts] +/// +declare module "mod1" { + export function foo(): Lib; +} +declare module "mod2" { + export const bar: Lib; +} diff --git a/tests/baselines/reference/typeReferenceDirectives11.symbols b/tests/baselines/reference/typeReferenceDirectives11.symbols new file mode 100644 index 00000000000..875bb2a0900 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives11.symbols @@ -0,0 +1,23 @@ +=== /mod2.ts === + +import {foo} from "./mod1"; +>foo : Symbol(foo, Decl(mod2.ts, 1, 8)) + +export const bar = foo(); +>bar : Symbol(bar, Decl(mod2.ts, 2, 12)) +>foo : Symbol(foo, Decl(mod2.ts, 1, 8)) + +=== /types/lib/index.d.ts === + + +interface Lib { x } +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) +>x : Symbol(Lib.x, Decl(index.d.ts, 2, 15)) + +=== /mod1.ts === + +export function foo(): Lib { return {x: 1} } +>foo : Symbol(foo, Decl(mod1.ts, 0, 0)) +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) +>x : Symbol(x, Decl(mod1.ts, 1, 37)) + diff --git a/tests/baselines/reference/typeReferenceDirectives11.trace.json b/tests/baselines/reference/typeReferenceDirectives11.trace.json index be060569d83..c21e8989f4a 100644 --- a/tests/baselines/reference/typeReferenceDirectives11.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives11.trace.json @@ -5,8 +5,7 @@ "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving module './mod1' from '/mod2.ts'. ========", - "Module resolution kind is not specified, using 'NodeJs'.", - "Loading module as file / folder, candidate module location '/mod1'.", + "Module resolution kind is not specified, using 'Classic'.", "File '/mod1.ts' exist - use it as a name resolution result.", "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives11.types b/tests/baselines/reference/typeReferenceDirectives11.types new file mode 100644 index 00000000000..93d80b7988a --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives11.types @@ -0,0 +1,26 @@ +=== /mod2.ts === + +import {foo} from "./mod1"; +>foo : () => Lib + +export const bar = foo(); +>bar : Lib +>foo() : Lib +>foo : () => Lib + +=== /types/lib/index.d.ts === + + +interface Lib { x } +>Lib : Lib +>x : any + +=== /mod1.ts === + +export function foo(): Lib { return {x: 1} } +>foo : () => Lib +>Lib : Lib +>{x: 1} : { x: number; } +>x : number +>1 : number + diff --git a/tests/baselines/reference/typeReferenceDirectives12.errors.txt b/tests/baselines/reference/typeReferenceDirectives12.errors.txt deleted file mode 100644 index 1a1668ecfcd..00000000000 --- a/tests/baselines/reference/typeReferenceDirectives12.errors.txt +++ /dev/null @@ -1,36 +0,0 @@ -error TS6082: Only 'amd' and 'system' modules are supported alongside --out. - - -!!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out. -==== /mod2.ts (0 errors) ==== - import { Cls } from "./main"; - import "./mod1"; - - export const cls = Cls; - export const foo = new Cls().foo(); - export const bar = Cls.bar(); -==== /types/lib/index.d.ts (0 errors) ==== - - - interface Lib { x } - -==== /main.ts (0 errors) ==== - export class Cls { - x - } - -==== /mod1.ts (0 errors) ==== - /// - - import {Cls} from "./main"; - Cls.prototype.foo = function() { return undefined; } - - declare module "./main" { - interface Cls { - foo(): Lib; - } - namespace Cls { - function bar(): Lib; - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives12.js b/tests/baselines/reference/typeReferenceDirectives12.js new file mode 100644 index 00000000000..8d64e1dba9b --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives12.js @@ -0,0 +1,82 @@ +//// [tests/cases/compiler/typeReferenceDirectives12.ts] //// + +//// [index.d.ts] + + +interface Lib { x } + +//// [main.ts] +export class Cls { + x +} + +//// [mod1.ts] +/// + +import {Cls} from "./main"; +Cls.prototype.foo = function() { return undefined; } + +declare module "./main" { + interface Cls { + foo(): Lib; + } + namespace Cls { + function bar(): Lib; + } +} + +//// [mod2.ts] +import { Cls } from "./main"; +import "./mod1"; + +export const cls = Cls; +export const foo = new Cls().foo(); +export const bar = Cls.bar(); + +//// [output.js] +define("main", ["require", "exports"], function (require, exports) { + "use strict"; + var Cls = (function () { + function Cls() { + } + return Cls; + }()); + exports.Cls = Cls; +}); +/// +define("mod1", ["require", "exports", "main"], function (require, exports, main_1) { + "use strict"; + main_1.Cls.prototype.foo = function () { return undefined; }; +}); +define("mod2", ["require", "exports", "main", "mod1"], function (require, exports, main_2) { + "use strict"; + exports.cls = main_2.Cls; + exports.foo = new main_2.Cls().foo(); + exports.bar = main_2.Cls.bar(); +}); + + +//// [output.d.ts] +/// +declare module "main" { + export class Cls { + x: any; + } +} +declare module "mod1" { + module "main" { + interface Cls { + foo(): Lib; + } + namespace Cls { + function bar(): Lib; + } + } +} +declare module "mod2" { + import { Cls } from "main"; + import "mod1"; + export const cls: typeof Cls; + export const foo: Lib; + export const bar: Lib; +} diff --git a/tests/baselines/reference/typeReferenceDirectives12.symbols b/tests/baselines/reference/typeReferenceDirectives12.symbols new file mode 100644 index 00000000000..30b24c39284 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives12.symbols @@ -0,0 +1,68 @@ +=== /mod2.ts === +import { Cls } from "./main"; +>Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) + +import "./mod1"; + +export const cls = Cls; +>cls : Symbol(cls, Decl(mod2.ts, 3, 12)) +>Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) + +export const foo = new Cls().foo(); +>foo : Symbol(foo, Decl(mod2.ts, 4, 12)) +>new Cls().foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) +>Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) +>foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) + +export const bar = Cls.bar(); +>bar : Symbol(bar, Decl(mod2.ts, 5, 12)) +>Cls.bar : Symbol(Cls.bar, Decl(mod1.ts, 9, 19)) +>Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) +>bar : Symbol(Cls.bar, Decl(mod1.ts, 9, 19)) + +=== /types/lib/index.d.ts === + + +interface Lib { x } +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) +>x : Symbol(Lib.x, Decl(index.d.ts, 2, 15)) + +=== /main.ts === +export class Cls { +>Cls : Symbol(Cls, Decl(main.ts, 0, 0), Decl(mod1.ts, 5, 25), Decl(mod1.ts, 8, 5)) + + x +>x : Symbol(Cls.x, Decl(main.ts, 0, 18)) +} + +=== /mod1.ts === +/// + +import {Cls} from "./main"; +>Cls : Symbol(Cls, Decl(mod1.ts, 2, 8)) + +Cls.prototype.foo = function() { return undefined; } +>Cls.prototype.foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) +>Cls.prototype : Symbol(Cls.prototype) +>Cls : Symbol(Cls, Decl(mod1.ts, 2, 8)) +>prototype : Symbol(Cls.prototype) +>foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) +>undefined : Symbol(undefined) + +declare module "./main" { + interface Cls { +>Cls : Symbol(Cls, Decl(main.ts, 0, 0), Decl(mod1.ts, 5, 25), Decl(mod1.ts, 8, 5)) + + foo(): Lib; +>foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) + } + namespace Cls { +>Cls : Symbol(Cls, Decl(main.ts, 0, 0), Decl(mod1.ts, 5, 25), Decl(mod1.ts, 8, 5)) + + function bar(): Lib; +>bar : Symbol(bar, Decl(mod1.ts, 9, 19)) +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/typeReferenceDirectives12.trace.json b/tests/baselines/reference/typeReferenceDirectives12.trace.json index f4fc0937325..ff27d63ef50 100644 --- a/tests/baselines/reference/typeReferenceDirectives12.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives12.trace.json @@ -1,12 +1,10 @@ [ "======== Resolving module './main' from '/mod2.ts'. ========", - "Module resolution kind is not specified, using 'NodeJs'.", - "Loading module as file / folder, candidate module location '/main'.", + "Module resolution kind is not specified, using 'Classic'.", "File '/main.ts' exist - use it as a name resolution result.", "======== Module name './main' was successfully resolved to '/main.ts'. ========", "======== Resolving module './mod1' from '/mod2.ts'. ========", - "Module resolution kind is not specified, using 'NodeJs'.", - "Loading module as file / folder, candidate module location '/mod1'.", + "Module resolution kind is not specified, using 'Classic'.", "File '/mod1.ts' exist - use it as a name resolution result.", "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/mod1.ts', root directory '/'. ========", @@ -15,8 +13,7 @@ "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving module './main' from '/mod1.ts'. ========", - "Module resolution kind is not specified, using 'NodeJs'.", - "Loading module as file / folder, candidate module location '/main'.", + "Module resolution kind is not specified, using 'Classic'.", "File '/main.ts' exist - use it as a name resolution result.", "======== Module name './main' was successfully resolved to '/main.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives12.types b/tests/baselines/reference/typeReferenceDirectives12.types new file mode 100644 index 00000000000..bd429b91f1c --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives12.types @@ -0,0 +1,73 @@ +=== /mod2.ts === +import { Cls } from "./main"; +>Cls : typeof Cls + +import "./mod1"; + +export const cls = Cls; +>cls : typeof Cls +>Cls : typeof Cls + +export const foo = new Cls().foo(); +>foo : Lib +>new Cls().foo() : Lib +>new Cls().foo : () => Lib +>new Cls() : Cls +>Cls : typeof Cls +>foo : () => Lib + +export const bar = Cls.bar(); +>bar : Lib +>Cls.bar() : Lib +>Cls.bar : () => Lib +>Cls : typeof Cls +>bar : () => Lib + +=== /types/lib/index.d.ts === + + +interface Lib { x } +>Lib : Lib +>x : any + +=== /main.ts === +export class Cls { +>Cls : Cls + + x +>x : any +} + +=== /mod1.ts === +/// + +import {Cls} from "./main"; +>Cls : typeof Cls + +Cls.prototype.foo = function() { return undefined; } +>Cls.prototype.foo = function() { return undefined; } : () => any +>Cls.prototype.foo : () => Lib +>Cls.prototype : Cls +>Cls : typeof Cls +>prototype : Cls +>foo : () => Lib +>function() { return undefined; } : () => any +>undefined : undefined + +declare module "./main" { + interface Cls { +>Cls : Cls + + foo(): Lib; +>foo : () => Lib +>Lib : Lib + } + namespace Cls { +>Cls : typeof Cls + + function bar(): Lib; +>bar : () => Lib +>Lib : Lib + } +} + diff --git a/tests/cases/compiler/typeReferenceDirectives11.ts b/tests/cases/compiler/typeReferenceDirectives11.ts index c955a5daffc..d199277ac62 100644 --- a/tests/cases/compiler/typeReferenceDirectives11.ts +++ b/tests/cases/compiler/typeReferenceDirectives11.ts @@ -4,6 +4,7 @@ // @traceResolution: true // @types: lib // @out: output.js +// @module: amd // @filename: /types/lib/index.d.ts diff --git a/tests/cases/compiler/typeReferenceDirectives12.ts b/tests/cases/compiler/typeReferenceDirectives12.ts index ef3c8d9755f..df449dc0ef9 100644 --- a/tests/cases/compiler/typeReferenceDirectives12.ts +++ b/tests/cases/compiler/typeReferenceDirectives12.ts @@ -3,6 +3,7 @@ // @typesRoot: / // @traceResolution: true // @out: output.js +// @module: amd // @filename: /types/lib/index.d.ts From 1814569cc5d1c7f8b8617124d2659085ccff088f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 20 Apr 2016 11:28:04 -0700 Subject: [PATCH 3/3] Test case when --out is specified for compiling module but --module isnt specified --- .../reference/optionsOutAndNoModuleGen.errors.txt | 7 +++++++ tests/cases/compiler/optionsOutAndNoModuleGen.ts | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 tests/baselines/reference/optionsOutAndNoModuleGen.errors.txt create mode 100644 tests/cases/compiler/optionsOutAndNoModuleGen.ts diff --git a/tests/baselines/reference/optionsOutAndNoModuleGen.errors.txt b/tests/baselines/reference/optionsOutAndNoModuleGen.errors.txt new file mode 100644 index 00000000000..b4d00619993 --- /dev/null +++ b/tests/baselines/reference/optionsOutAndNoModuleGen.errors.txt @@ -0,0 +1,7 @@ +error TS6082: Only 'amd' and 'system' modules are supported alongside --out. + + +!!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out. +==== tests/cases/compiler/optionsOutAndNoModuleGen.ts (0 errors) ==== + + export var x = 10; \ No newline at end of file diff --git a/tests/cases/compiler/optionsOutAndNoModuleGen.ts b/tests/cases/compiler/optionsOutAndNoModuleGen.ts new file mode 100644 index 00000000000..b0a7cf22d21 --- /dev/null +++ b/tests/cases/compiler/optionsOutAndNoModuleGen.ts @@ -0,0 +1,3 @@ +// @out: output.js + +export var x = 10; \ No newline at end of file