diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c9d8a45fedb23..d4ac082e25195 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -207,7 +207,7 @@ namespace ts { ...program.getSemanticDiagnostics(sourceFile, cancellationToken) ]; - if (program.getCompilerOptions().declaration) { + if (getEmitDeclarations(program.getCompilerOptions())) { addRange(diagnostics, program.getDeclarationDiagnostics(sourceFile, cancellationToken)); } @@ -817,9 +817,9 @@ namespace ts { // If a rootDir is specified use it as the commonSourceDirectory commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory); } - else if (options.composite) { + else if (options.composite && options.configFilePath) { // Project compilations never infer their root from the input source paths - commonSourceDirectory = getDirectoryPath(normalizeSlashes(options.configFilePath!)); // TODO: GH#18217 + commonSourceDirectory = getDirectoryPath(normalizeSlashes(options.configFilePath)); checkSourceFilesBelongToPath(emittedFiles, commonSourceDirectory); } else { @@ -1388,7 +1388,7 @@ namespace ts { ...program.getSemanticDiagnostics(sourceFile, cancellationToken) ]; - if (diagnostics.length === 0 && program.getCompilerOptions().declaration) { + if (diagnostics.length === 0 && getEmitDeclarations(program.getCompilerOptions())) { declarationDiagnostics = program.getDeclarationDiagnostics(/*sourceFile*/ undefined, cancellationToken); } @@ -2407,8 +2407,8 @@ namespace ts { } if (options.isolatedModules) { - if (options.declaration) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules"); + if (getEmitDeclarations(options)) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, getEmitDeclarationOptionName(options), "isolatedModules"); } if (options.noEmitOnError) { @@ -2533,7 +2533,7 @@ namespace ts { if (options.declarationDir) { if (!getEmitDeclarations(options)) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "declarationDir", "declaration"); + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "declarationDir", "declaration", "composite"); } if (options.out || options.outFile) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declarationDir", options.out ? "out" : "outFile"); @@ -2541,7 +2541,7 @@ namespace ts { } if (options.declarationMap && !getEmitDeclarations(options)) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "declarationMap", "declaration"); + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "declarationMap", "declaration", "composite"); } if (options.lib && options.noLib) { @@ -2610,7 +2610,7 @@ namespace ts { } if (!options.noEmit && options.allowJs && getEmitDeclarations(options)) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", options.declaration ? "declaration" : "composite"); + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", getEmitDeclarationOptionName(options)); } if (options.checkJs && !options.allowJs) { @@ -2618,8 +2618,8 @@ namespace ts { } if (options.emitDeclarationOnly) { - if (!options.declaration) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDeclarationOnly", "declaration"); + if (!getEmitDeclarations(options)) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "emitDeclarationOnly", "declaration", "composite"); } if (options.noEmit) { @@ -2877,6 +2877,9 @@ namespace ts { return resolveConfigFileProjectName(passedInRef.path); } + function getEmitDeclarationOptionName(options: CompilerOptions) { + return options.declaration ? "declaration" : "composite"; + } /* @internal */ /** * Returns a DiagnosticMessage if we won't include a resolved module due to its extension. diff --git a/src/services/services.ts b/src/services/services.ts index 5a035a92bcda2..a9dfdc2d0afd3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1382,7 +1382,7 @@ namespace ts { // Therefore only get diagnostics for given file. const semanticDiagnostics = program.getSemanticDiagnostics(targetSourceFile, cancellationToken); - if (!program.getCompilerOptions().declaration) { + if (!getEmitDeclarations(program.getCompilerOptions())) { return semanticDiagnostics.slice(); } diff --git a/src/services/transpile.ts b/src/services/transpile.ts index 70ca5b6431438..030d2273b6274 100644 --- a/src/services/transpile.ts +++ b/src/services/transpile.ts @@ -48,6 +48,7 @@ namespace ts { options.paths = undefined; options.rootDirs = undefined; options.declaration = undefined; + options.composite = undefined; options.declarationDir = undefined; options.out = undefined; options.outFile = undefined; diff --git a/tests/baselines/reference/declFileEmitDeclarationOnlyError1.errors.txt b/tests/baselines/reference/declFileEmitDeclarationOnlyError1.errors.txt index 62447a4a91152..968b2a09b00be 100644 --- a/tests/baselines/reference/declFileEmitDeclarationOnlyError1.errors.txt +++ b/tests/baselines/reference/declFileEmitDeclarationOnlyError1.errors.txt @@ -1,7 +1,7 @@ -error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'. +error TS5069: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration' or option 'composite'. -!!! error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'. +!!! error TS5069: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration' or option 'composite'. ==== tests/cases/compiler/hello.ts (0 errors) ==== var hello = "yo!"; \ No newline at end of file diff --git a/tests/baselines/reference/declFileEmitDeclarationOnlyError2.errors.txt b/tests/baselines/reference/declFileEmitDeclarationOnlyError2.errors.txt index 37be20aa132e1..0b1ea1409c5b6 100644 --- a/tests/baselines/reference/declFileEmitDeclarationOnlyError2.errors.txt +++ b/tests/baselines/reference/declFileEmitDeclarationOnlyError2.errors.txt @@ -1,9 +1,9 @@ -error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'. error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'. +error TS5069: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration' or option 'composite'. -!!! error TS5052: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration'. !!! error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'. +!!! error TS5069: Option 'emitDeclarationOnly' cannot be specified without specifying option 'declaration' or option 'composite'. ==== tests/cases/compiler/hello.ts (0 errors) ==== var hello = "yo!"; \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitToDeclarationDirWithoutCompositeAndDeclarationOptions.errors.txt b/tests/baselines/reference/declarationEmitToDeclarationDirWithoutCompositeAndDeclarationOptions.errors.txt index e2a5a20452c0d..63ba628173240 100644 --- a/tests/baselines/reference/declarationEmitToDeclarationDirWithoutCompositeAndDeclarationOptions.errors.txt +++ b/tests/baselines/reference/declarationEmitToDeclarationDirWithoutCompositeAndDeclarationOptions.errors.txt @@ -1,11 +1,11 @@ -/foo/tsconfig.json(2,26): error TS5052: Option 'declarationDir' cannot be specified without specifying option 'declaration'. +/foo/tsconfig.json(2,26): error TS5069: Option 'declarationDir' cannot be specified without specifying option 'declaration' or option 'composite'. ==== /foo/tsconfig.json (1 errors) ==== { "compilerOptions": { "declarationDir": "out" } ~~~~~~~~~~~~~~~~ -!!! error TS5052: Option 'declarationDir' cannot be specified without specifying option 'declaration'. +!!! error TS5069: Option 'declarationDir' cannot be specified without specifying option 'declaration' or option 'composite'. } ==== /foo/test.ts (0 errors) ==== diff --git a/tests/baselines/reference/declarationMapsWithoutDeclaration.errors.txt b/tests/baselines/reference/declarationMapsWithoutDeclaration.errors.txt index c432f44513058..8574b7d338836 100644 --- a/tests/baselines/reference/declarationMapsWithoutDeclaration.errors.txt +++ b/tests/baselines/reference/declarationMapsWithoutDeclaration.errors.txt @@ -1,7 +1,7 @@ -error TS5052: Option 'declarationMap' cannot be specified without specifying option 'declaration'. +error TS5069: Option 'declarationMap' cannot be specified without specifying option 'declaration' or option 'composite'. -!!! error TS5052: Option 'declarationMap' cannot be specified without specifying option 'declaration'. +!!! error TS5069: Option 'declarationMap' cannot be specified without specifying option 'declaration' or option 'composite'. ==== tests/cases/compiler/declarationMapsWithoutDeclaration.ts (0 errors) ==== module m2 { export interface connectModule {