Skip to content

Commit 86f8ab1

Browse files
authored
Merge pull request #27196 from Microsoft/declarationAndComposite
Ensure all the usages of compilerOptions.declaration take into account compilerOptions.composite if needed
2 parents c57ff08 + 4c04725 commit 86f8ab1

7 files changed

+24
-20
lines changed

src/compiler/program.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ namespace ts {
207207
...program.getSemanticDiagnostics(sourceFile, cancellationToken)
208208
];
209209

210-
if (program.getCompilerOptions().declaration) {
210+
if (getEmitDeclarations(program.getCompilerOptions())) {
211211
addRange(diagnostics, program.getDeclarationDiagnostics(sourceFile, cancellationToken));
212212
}
213213

@@ -817,9 +817,9 @@ namespace ts {
817817
// If a rootDir is specified use it as the commonSourceDirectory
818818
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory);
819819
}
820-
else if (options.composite) {
820+
else if (options.composite && options.configFilePath) {
821821
// Project compilations never infer their root from the input source paths
822-
commonSourceDirectory = getDirectoryPath(normalizeSlashes(options.configFilePath!)); // TODO: GH#18217
822+
commonSourceDirectory = getDirectoryPath(normalizeSlashes(options.configFilePath));
823823
checkSourceFilesBelongToPath(emittedFiles, commonSourceDirectory);
824824
}
825825
else {
@@ -1388,7 +1388,7 @@ namespace ts {
13881388
...program.getSemanticDiagnostics(sourceFile, cancellationToken)
13891389
];
13901390

1391-
if (diagnostics.length === 0 && program.getCompilerOptions().declaration) {
1391+
if (diagnostics.length === 0 && getEmitDeclarations(program.getCompilerOptions())) {
13921392
declarationDiagnostics = program.getDeclarationDiagnostics(/*sourceFile*/ undefined, cancellationToken);
13931393
}
13941394

@@ -2407,8 +2407,8 @@ namespace ts {
24072407
}
24082408

24092409
if (options.isolatedModules) {
2410-
if (options.declaration) {
2411-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules");
2410+
if (getEmitDeclarations(options)) {
2411+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, getEmitDeclarationOptionName(options), "isolatedModules");
24122412
}
24132413

24142414
if (options.noEmitOnError) {
@@ -2533,15 +2533,15 @@ namespace ts {
25332533

25342534
if (options.declarationDir) {
25352535
if (!getEmitDeclarations(options)) {
2536-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "declarationDir", "declaration");
2536+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "declarationDir", "declaration", "composite");
25372537
}
25382538
if (options.out || options.outFile) {
25392539
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declarationDir", options.out ? "out" : "outFile");
25402540
}
25412541
}
25422542

25432543
if (options.declarationMap && !getEmitDeclarations(options)) {
2544-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "declarationMap", "declaration");
2544+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "declarationMap", "declaration", "composite");
25452545
}
25462546

25472547
if (options.lib && options.noLib) {
@@ -2610,16 +2610,16 @@ namespace ts {
26102610
}
26112611

26122612
if (!options.noEmit && options.allowJs && getEmitDeclarations(options)) {
2613-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", options.declaration ? "declaration" : "composite");
2613+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", getEmitDeclarationOptionName(options));
26142614
}
26152615

26162616
if (options.checkJs && !options.allowJs) {
26172617
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs"));
26182618
}
26192619

26202620
if (options.emitDeclarationOnly) {
2621-
if (!options.declaration) {
2622-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration");
2621+
if (!getEmitDeclarations(options)) {
2622+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "emitDeclarationOnly", "declaration", "composite");
26232623
}
26242624

26252625
if (options.noEmit) {
@@ -2877,6 +2877,9 @@ namespace ts {
28772877
return resolveConfigFileProjectName(passedInRef.path);
28782878
}
28792879

2880+
function getEmitDeclarationOptionName(options: CompilerOptions) {
2881+
return options.declaration ? "declaration" : "composite";
2882+
}
28802883
/* @internal */
28812884
/**
28822885
* Returns a DiagnosticMessage if we won't include a resolved module due to its extension.

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ namespace ts {
13821382
// Therefore only get diagnostics for given file.
13831383

13841384
const semanticDiagnostics = program.getSemanticDiagnostics(targetSourceFile, cancellationToken);
1385-
if (!program.getCompilerOptions().declaration) {
1385+
if (!getEmitDeclarations(program.getCompilerOptions())) {
13861386
return semanticDiagnostics.slice();
13871387
}
13881388

src/services/transpile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace ts {
4848
options.paths = undefined;
4949
options.rootDirs = undefined;
5050
options.declaration = undefined;
51+
options.composite = undefined;
5152
options.declarationDir = undefined;
5253
options.out = undefined;
5354
options.outFile = undefined;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'.
1+
error TS5069: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration' or option 'composite'.
22

33

4-
!!! error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'.
4+
!!! error TS5069: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration' or option 'composite'.
55
==== tests/cases/compiler/hello.ts (0 errors) ====
66
var hello = "yo!";
77

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'.
21
error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'.
2+
error TS5069: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration' or option 'composite'.
33

44

5-
!!! error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'.
65
!!! error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'.
6+
!!! error TS5069: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration' or option 'composite'.
77
==== tests/cases/compiler/hello.ts (0 errors) ====
88
var hello = "yo!";
99

tests/baselines/reference/declarationEmitToDeclarationDirWithoutCompositeAndDeclarationOptions.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/foo/tsconfig.json(2,26): error TS5052: Option 'declarationDir' cannot be specified without specifying option 'declaration'.
1+
/foo/tsconfig.json(2,26): error TS5069: Option 'declarationDir' cannot be specified without specifying option 'declaration' or option 'composite'.
22

33

44
==== /foo/tsconfig.json (1 errors) ====
55
{
66
"compilerOptions": { "declarationDir": "out" }
77
~~~~~~~~~~~~~~~~
8-
!!! error TS5052: Option 'declarationDir' cannot be specified without specifying option 'declaration'.
8+
!!! error TS5069: Option 'declarationDir' cannot be specified without specifying option 'declaration' or option 'composite'.
99
}
1010

1111
==== /foo/test.ts (0 errors) ====

tests/baselines/reference/declarationMapsWithoutDeclaration.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error TS5052: Option 'declarationMap' cannot be specified without specifying option 'declaration'.
1+
error TS5069: Option 'declarationMap' cannot be specified without specifying option 'declaration' or option 'composite'.
22

33

4-
!!! error TS5052: Option 'declarationMap' cannot be specified without specifying option 'declaration'.
4+
!!! error TS5069: Option 'declarationMap' cannot be specified without specifying option 'declaration' or option 'composite'.
55
==== tests/cases/compiler/declarationMapsWithoutDeclaration.ts (0 errors) ====
66
module m2 {
77
export interface connectModule {

0 commit comments

Comments
 (0)