Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ namespace ts {
...program.getSemanticDiagnostics(sourceFile, cancellationToken)
];

if (program.getCompilerOptions().declaration) {
if (getEmitDeclarations(program.getCompilerOptions())) {
addRange(diagnostics, program.getDeclarationDiagnostics(sourceFile, cancellationToken));
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -2533,15 +2533,15 @@ 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");
}
}

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) {
Expand Down Expand Up @@ -2610,16 +2610,16 @@ 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) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs"));
}

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) {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions src/services/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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!";

Original file line number Diff line number Diff line change
@@ -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!";

Original file line number Diff line number Diff line change
@@ -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) ====
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down