From 92e3202604bc7ac3bbc3c43aaa2408c2f1d1d27a Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 21 Aug 2014 17:13:27 -0700 Subject: [PATCH] Fix the compilerRunner when compiling resulting d.ts file when --out is specified --- src/harness/compilerRunner.ts | 37 +++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index a3357826142..bab1200d74c 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -183,19 +183,40 @@ class CompilerBaselineRunner extends RunnerBase { // if the .d.ts is non-empty, confirm it compiles correctly as well if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) { - function getDtsFile(file: { unitName: string; content: string }) { + function addDtsFile(file: { unitName: string; content: string }, dtsFiles: { unitName: string; content: string }[]) { if (Harness.Compiler.isDTS(file.unitName)) { - return file; - } else { - var declFile = ts.forEach(result.declFilesCode, - declFile => declFile.fileName === (file.unitName.substr(0, file.unitName.length - ".ts".length) + ".d.ts") + dtsFiles.push(file); + } + else { + var declFile = findResultCodeFile(file.unitName); + // Look if there is --out file corresponding to this ts file + if (!declFile && options.out) { + declFile = findResultCodeFile(options.out); + if (!declFile || findUnit(declFile.fileName, declToBeCompiled) || + findUnit(declFile.fileName, declOtherFiles)) { + return; + } + } + + if (declFile) { + dtsFiles.push({ unitName: declFile.fileName, content: declFile.code }); + return; + } + } + + function findResultCodeFile(fileName: string) { + return ts.forEach(result.declFilesCode, + declFile => declFile.fileName === (fileName.substr(0, fileName.length - ".ts".length) + ".d.ts") ? declFile : undefined); - return { unitName: declFile.fileName, content: declFile.code }; + } + + function findUnit(fileName: string, units: { unitName: string; content: string }[]) { + return ts.forEach(units, unit => unit.unitName === fileName ? unit : undefined); } } - ts.forEach(toBeCompiled, file => { declToBeCompiled.push(getDtsFile(file)); }); - ts.forEach(otherFiles, file => { declOtherFiles.push(getDtsFile(file)); }); + ts.forEach(toBeCompiled, file => addDtsFile(file, declToBeCompiled)); + ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles)); harnessCompiler.compileFiles(declToBeCompiled, declOtherFiles, function (compileResult) { declResult = compileResult; }, function (settings) {