From 76dd2086a4984d8858d558b44c01967417fef588 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 20 Apr 2016 11:22:52 -0700 Subject: [PATCH] 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 1ef5d6bfba..bf5b7cb572 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 7d16ac9466..7df16139bf 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 0000000000..2acecc8de4 --- /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 cb41c843ad..0000000000 --- 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 875bb2a090..0000000000 --- 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 93d80b7988..0000000000 --- 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 0000000000..1a1668ecfc --- /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 c9c4a912da..0000000000 --- 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 30b24c3928..0000000000 --- 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 bd429b91f1..0000000000 --- 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 - } -} -