@@ -207,7 +207,7 @@ namespace ts {
207
207
...program . getSemanticDiagnostics ( sourceFile , cancellationToken )
208
208
] ;
209
209
210
- if ( program . getCompilerOptions ( ) . declaration ) {
210
+ if ( getEmitDeclarations ( program . getCompilerOptions ( ) ) ) {
211
211
addRange ( diagnostics , program . getDeclarationDiagnostics ( sourceFile , cancellationToken ) ) ;
212
212
}
213
213
@@ -817,9 +817,9 @@ namespace ts {
817
817
// If a rootDir is specified use it as the commonSourceDirectory
818
818
commonSourceDirectory = getNormalizedAbsolutePath ( options . rootDir , currentDirectory ) ;
819
819
}
820
- else if ( options . composite ) {
820
+ else if ( options . composite && options . configFilePath ) {
821
821
// 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 ) ) ;
823
823
checkSourceFilesBelongToPath ( emittedFiles , commonSourceDirectory ) ;
824
824
}
825
825
else {
@@ -1388,7 +1388,7 @@ namespace ts {
1388
1388
...program . getSemanticDiagnostics ( sourceFile , cancellationToken )
1389
1389
] ;
1390
1390
1391
- if ( diagnostics . length === 0 && program . getCompilerOptions ( ) . declaration ) {
1391
+ if ( diagnostics . length === 0 && getEmitDeclarations ( program . getCompilerOptions ( ) ) ) {
1392
1392
declarationDiagnostics = program . getDeclarationDiagnostics ( /*sourceFile*/ undefined , cancellationToken ) ;
1393
1393
}
1394
1394
@@ -2407,8 +2407,8 @@ namespace ts {
2407
2407
}
2408
2408
2409
2409
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" ) ;
2412
2412
}
2413
2413
2414
2414
if ( options . noEmitOnError ) {
@@ -2533,15 +2533,15 @@ namespace ts {
2533
2533
2534
2534
if ( options . declarationDir ) {
2535
2535
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 ") ;
2537
2537
}
2538
2538
if ( options . out || options . outFile ) {
2539
2539
createDiagnosticForOptionName ( Diagnostics . Option_0_cannot_be_specified_with_option_1 , "declarationDir" , options . out ? "out" : "outFile" ) ;
2540
2540
}
2541
2541
}
2542
2542
2543
2543
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 ") ;
2545
2545
}
2546
2546
2547
2547
if ( options . lib && options . noLib ) {
@@ -2610,16 +2610,16 @@ namespace ts {
2610
2610
}
2611
2611
2612
2612
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 ) ) ;
2614
2614
}
2615
2615
2616
2616
if ( options . checkJs && ! options . allowJs ) {
2617
2617
programDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Option_0_cannot_be_specified_without_specifying_option_1 , "checkJs" , "allowJs" ) ) ;
2618
2618
}
2619
2619
2620
2620
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 ") ;
2623
2623
}
2624
2624
2625
2625
if ( options . noEmit ) {
@@ -2877,6 +2877,9 @@ namespace ts {
2877
2877
return resolveConfigFileProjectName ( passedInRef . path ) ;
2878
2878
}
2879
2879
2880
+ function getEmitDeclarationOptionName ( options : CompilerOptions ) {
2881
+ return options . declaration ? "declaration" : "composite" ;
2882
+ }
2880
2883
/* @internal */
2881
2884
/**
2882
2885
* Returns a DiagnosticMessage if we won't include a resolved module due to its extension.
0 commit comments