Skip to content

Commit 92e3202

Browse files
committed
Fix the compilerRunner when compiling resulting d.ts file when --out is specified
1 parent 16d1cfd commit 92e3202

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/harness/compilerRunner.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,40 @@ class CompilerBaselineRunner extends RunnerBase {
183183

184184
// if the .d.ts is non-empty, confirm it compiles correctly as well
185185
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) {
186-
function getDtsFile(file: { unitName: string; content: string }) {
186+
function addDtsFile(file: { unitName: string; content: string }, dtsFiles: { unitName: string; content: string }[]) {
187187
if (Harness.Compiler.isDTS(file.unitName)) {
188-
return file;
189-
} else {
190-
var declFile = ts.forEach(result.declFilesCode,
191-
declFile => declFile.fileName === (file.unitName.substr(0, file.unitName.length - ".ts".length) + ".d.ts")
188+
dtsFiles.push(file);
189+
}
190+
else {
191+
var declFile = findResultCodeFile(file.unitName);
192+
// Look if there is --out file corresponding to this ts file
193+
if (!declFile && options.out) {
194+
declFile = findResultCodeFile(options.out);
195+
if (!declFile || findUnit(declFile.fileName, declToBeCompiled) ||
196+
findUnit(declFile.fileName, declOtherFiles)) {
197+
return;
198+
}
199+
}
200+
201+
if (declFile) {
202+
dtsFiles.push({ unitName: declFile.fileName, content: declFile.code });
203+
return;
204+
}
205+
}
206+
207+
function findResultCodeFile(fileName: string) {
208+
return ts.forEach(result.declFilesCode,
209+
declFile => declFile.fileName === (fileName.substr(0, fileName.length - ".ts".length) + ".d.ts")
192210
? declFile : undefined);
193-
return { unitName: declFile.fileName, content: declFile.code };
211+
}
212+
213+
function findUnit(fileName: string, units: { unitName: string; content: string }[]) {
214+
return ts.forEach(units, unit => unit.unitName === fileName ? unit : undefined);
194215
}
195216
}
196217

197-
ts.forEach(toBeCompiled, file => { declToBeCompiled.push(getDtsFile(file)); });
198-
ts.forEach(otherFiles, file => { declOtherFiles.push(getDtsFile(file)); });
218+
ts.forEach(toBeCompiled, file => addDtsFile(file, declToBeCompiled));
219+
ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));
199220
harnessCompiler.compileFiles(declToBeCompiled, declOtherFiles, function (compileResult) {
200221
declResult = compileResult;
201222
}, function (settings) {

0 commit comments

Comments
 (0)