From c8aedbf382b615059b922ba8ec6593069ad94e27 Mon Sep 17 00:00:00 2001 From: Asad Saeeduddin Date: Sat, 20 Feb 2016 17:40:39 -0500 Subject: [PATCH] Address PR feedback: expand ternary return into if block, add check to ensure proper options usage --- src/compiler/program.ts | 4 ++++ src/compiler/utilities.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d41f34df0b3..ef190df6a4f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1670,6 +1670,10 @@ namespace ts { } } + if (!options.declaration && options.declarationDir) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "declarationDir", "declaration")); + } + const languageVersion = options.target || ScriptTarget.ES3; const outFile = options.outFile || options.out; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 40b5462888e..9c598da9069 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2015,11 +2015,13 @@ namespace ts { export function getDeclarationEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost) { const options = host.getCompilerOptions(); const outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified - return options.declaration ? removeFileExtension( - outputDir + + if (options.declaration) { + const path = outputDir ? getSourceFilePathInNewDir(sourceFile, host, outputDir) - : sourceFile.fileName - ) + ".d.ts" : undefined; + : sourceFile.fileName; + return removeFileExtension(path) + ".d.ts"; + } } export function getEmitScriptTarget(compilerOptions: CompilerOptions) {