Skip to content

Commit 216ed1b

Browse files
committed
Get dts content from sourceFile if present
1 parent 50d98ae commit 216ed1b

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

src/compiler/program.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,11 @@ namespace ts {
14571457
if (!out) continue;
14581458

14591459
const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true);
1460-
const node = createInputFiles(path => host.readFile(path), jsFilePath!, sourceMapFilePath, declarationFilePath!, declarationMapPath);
1460+
const node = createInputFiles(fileName => {
1461+
const path = toPath(fileName);
1462+
const sourceFile = getSourceFileByPath(path);
1463+
return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
1464+
}, jsFilePath! , sourceMapFilePath, declarationFilePath! , declarationMapPath);
14611465
nodes.push(node);
14621466
}
14631467
}

src/testRunner/unittests/tsbuild.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -495,36 +495,35 @@ export const b = new A();`);
495495
Harness.Baseline.runBaseline("outfile-concat.js", patch ? vfs.formatPatch(patch) : null);
496496
});
497497
it("verify readFile calls", () => {
498-
const expectedMap = createMap<number>();
499-
// Configs
500-
expectedMap.set("/src/third/tsconfig.json", 1);
501-
expectedMap.set("/src/second/tsconfig.json", 1);
502-
expectedMap.set("/src/first/tsconfig.json", 1);
503-
504-
// Source files
505-
expectedMap.set("/src/third/third_part1.ts", 1);
506-
expectedMap.set("/src/second/second_part1.ts", 1);
507-
expectedMap.set("/src/second/second_part2.ts", 1);
508-
expectedMap.set("/src/first/first_PART1.ts", 1);
509-
expectedMap.set("/src/first/first_part2.ts", 1);
510-
expectedMap.set("/src/first/first_part3.ts", 1);
511-
512-
// outputs
513-
expectedMap.set("/src/first/bin/first-output.js", 1);
514-
expectedMap.set("/src/first/bin/first-output.js.map", 1);
515-
// 1 for reading source File, 1 for emit
516-
expectedMap.set("/src/first/bin/first-output.d.ts", 2);
517-
expectedMap.set("/src/first/bin/first-output.d.ts.map", 1);
518-
expectedMap.set("/src/2/second-output.js", 1);
519-
expectedMap.set("/src/2/second-output.js.map", 1);
520-
// 1 for reading source File, 1 for emit
521-
expectedMap.set("/src/2/second-output.d.ts", 2);
522-
expectedMap.set("/src/2/second-output.d.ts.map", 1);
523-
524-
assert.equal(actualReadFileMap.size, expectedMap.size, `Expected: ${JSON.stringify(arrayFrom(expectedMap.entries()))} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`);
525-
actualReadFileMap.forEach((value, key) => {
526-
const expected = expectedMap.get(key);
527-
assert.equal(value, expected, `Expected: ${JSON.stringify(arrayFrom(expectedMap.entries()))} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`);
498+
const expected = [
499+
// Configs
500+
"/src/third/tsconfig.json",
501+
"/src/second/tsconfig.json",
502+
"/src/first/tsconfig.json",
503+
504+
// Source files
505+
"/src/third/third_part1.ts",
506+
"/src/second/second_part1.ts",
507+
"/src/second/second_part2.ts",
508+
"/src/first/first_PART1.ts",
509+
"/src/first/first_part2.ts",
510+
"/src/first/first_part3.ts",
511+
512+
// outputs
513+
"/src/first/bin/first-output.js",
514+
"/src/first/bin/first-output.js.map",
515+
"/src/first/bin/first-output.d.ts",
516+
"/src/first/bin/first-output.d.ts.map",
517+
"/src/2/second-output.js",
518+
"/src/2/second-output.js.map",
519+
"/src/2/second-output.d.ts",
520+
"/src/2/second-output.d.ts.map"
521+
];
522+
523+
assert.equal(actualReadFileMap.size, expected.length, `Expected: ${JSON.stringify(expected)} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`);
524+
expected.forEach(expectedValue => {
525+
const actual = actualReadFileMap.get(expectedValue);
526+
assert.equal(actual, 1, `Mismatch in read file call number for: ${expectedValue}\nExpected: ${JSON.stringify(expected)} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`);
528527
});
529528
});
530529
});

0 commit comments

Comments
 (0)