Merge pull request #27196 from Microsoft/declarationAndComposite

Ensure all the usages of compilerOptions.declaration take into account compilerOptions.composite if needed
This commit is contained in:
Sheetal Nandi 2018-09-18 14:33:13 -07:00 committed by GitHub
commit 86f8ab127e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 20 deletions

View file

@ -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.

View file

@ -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();
}

View file

@ -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;

View file

@ -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!";

View file

@ -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!";

View file

@ -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) ====

View file

@ -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 {