Skip to content

Commit 70e26fc

Browse files
Merge pull request #27447 from mattmccutchen/issue-27117
Don't complain about `modules` and `outFile` options when `emitDeclarationOnly` is set.
2 parents 29dd67e + 32e75e7 commit 70e26fc

10 files changed

+103
-2
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,7 @@ namespace ts {
25792579
}
25802580

25812581
// Cannot specify module gen that isn't amd or system with --out
2582-
if (outFile) {
2582+
if (outFile && !options.emitDeclarationOnly) {
25832583
if (options.module && !(options.module === ModuleKind.AMD || options.module === ModuleKind.System)) {
25842584
createDiagnosticForOptionName(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile", "module");
25852585
}

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3265,7 +3265,7 @@ namespace ts {
32653265
const isSourceFileFromExternalLibrary = (file: SourceFile) => host.isSourceFileFromExternalLibrary(file);
32663266
if (options.outFile || options.out) {
32673267
const moduleKind = getEmitModuleKind(options);
3268-
const moduleEmitEnabled = moduleKind === ModuleKind.AMD || moduleKind === ModuleKind.System;
3268+
const moduleEmitEnabled = options.emitDeclarationOnly || moduleKind === ModuleKind.AMD || moduleKind === ModuleKind.System;
32693269
// Can emit only sources that are not declaration file and are either non module code or module with --module or --target es6 specified
32703270
return filter(host.getSourceFiles(), sourceFile =>
32713271
(moduleEmitEnabled || !isExternalModule(sourceFile)) && sourceFileMayBeEmitted(sourceFile, options, isSourceFileFromExternalLibrary));
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [tests/cases/compiler/outModuleConcatCommonjsDeclarationOnly.ts] ////
2+
3+
//// [a.ts]
4+
export class A { }
5+
6+
//// [b.ts]
7+
import {A} from "./ref/a";
8+
export class B extends A { }
9+
10+
11+
12+
//// [all.d.ts]
13+
declare module "ref/a" {
14+
export class A {
15+
}
16+
}
17+
declare module "b" {
18+
import { A } from "ref/a";
19+
export class B extends A {
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/ref/a.ts ===
2+
export class A { }
3+
>A : Symbol(A, Decl(a.ts, 0, 0))
4+
5+
=== tests/cases/compiler/b.ts ===
6+
import {A} from "./ref/a";
7+
>A : Symbol(A, Decl(b.ts, 0, 8))
8+
9+
export class B extends A { }
10+
>B : Symbol(B, Decl(b.ts, 0, 26))
11+
>A : Symbol(A, Decl(b.ts, 0, 8))
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/ref/a.ts ===
2+
export class A { }
3+
>A : A
4+
5+
=== tests/cases/compiler/b.ts ===
6+
import {A} from "./ref/a";
7+
>A : typeof A
8+
9+
export class B extends A { }
10+
>B : B
11+
>A : A
12+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/compiler/outModuleConcatUnspecifiedModuleKindDeclarationOnly.ts] ////
2+
3+
//// [a.ts]
4+
export class A { } // module
5+
6+
//// [b.ts]
7+
var x = 0; // global
8+
9+
10+
11+
//// [out.d.ts]
12+
declare module "a" {
13+
export class A {
14+
}
15+
}
16+
declare var x: number;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/a.ts ===
2+
export class A { } // module
3+
>A : Symbol(A, Decl(a.ts, 0, 0))
4+
5+
=== tests/cases/compiler/b.ts ===
6+
var x = 0; // global
7+
>x : Symbol(x, Decl(b.ts, 0, 3))
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/a.ts ===
2+
export class A { } // module
3+
>A : A
4+
5+
=== tests/cases/compiler/b.ts ===
6+
var x = 0; // global
7+
>x : number
8+
>0 : 0
9+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @target: ES5
2+
// @sourcemap: true
3+
// @declaration: true
4+
// @emitDeclarationOnly: true
5+
// @module: commonjs
6+
// @outFile: all.js
7+
8+
// @Filename: ref/a.ts
9+
export class A { }
10+
11+
// @Filename: b.ts
12+
import {A} from "./ref/a";
13+
export class B extends A { }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @target: ES5
2+
// @outFile: out.js
3+
// @declaration: true
4+
// @emitDeclarationOnly: true
5+
6+
// @Filename: a.ts
7+
export class A { } // module
8+
9+
// @Filename: b.ts
10+
var x = 0; // global

0 commit comments

Comments
 (0)