Skip to content

Commit d1d6169

Browse files
committed
Address PR feedback: expand ternary return into if block, add check to ensure proper options usage
1 parent 33c4527 commit d1d6169

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/compiler/program.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,10 @@ namespace ts {
16691669
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap"));
16701670
}
16711671
}
1672+
1673+
if(!options.declaration && options.declarationDir) {
1674+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "declarationDir", "declaration"));
1675+
}
16721676

16731677
const languageVersion = options.target || ScriptTarget.ES3;
16741678
const outFile = options.outFile || options.out;

src/compiler/utilities.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -2015,11 +2015,13 @@ namespace ts {
20152015
export function getDeclarationEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost) {
20162016
const options = host.getCompilerOptions();
20172017
const outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified
2018-
return options.declaration ? removeFileExtension(
2019-
outputDir
2018+
2019+
if (options.declaration) {
2020+
const path = outputDir
20202021
? getSourceFilePathInNewDir(sourceFile, host, outputDir)
2021-
: sourceFile.fileName
2022-
) + ".d.ts" : undefined;
2022+
: sourceFile.fileName;
2023+
return removeFileExtension(path) + ".d.ts";
2024+
}
20232025
}
20242026

20252027
export function getEmitScriptTarget(compilerOptions: CompilerOptions) {

0 commit comments

Comments
 (0)