Skip to content

Commit a1978eb

Browse files
committed
add test
1 parent 6df6127 commit a1978eb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/testRunner/unittests/reuseProgramStructure.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,29 @@ namespace ts {
399399
assert.isDefined(program2.getSourceFile("/a.ts")!.resolvedModules!.get("a"), "'a' is not an unresolved module after re-use");
400400
});
401401

402+
it("works with updated SourceFiles", () => {
403+
const files = [
404+
{ name: "/a.ts", text: SourceText.New("", "", 'import * as a from "a";a;') },
405+
{ name: "/types/zzz/index.d.ts", text: SourceText.New("", "", 'declare module "a" { }') },
406+
];
407+
const host = createTestCompilerHost(files, target);
408+
const options: CompilerOptions = { target, typeRoots: ["/types"] };
409+
const program1 = createProgram(["/a.ts"], options, host);
410+
let sourceFile = program1.getSourceFile("/a.ts")!;
411+
assert.isDefined(sourceFile, "'/a.ts' is included in the program");
412+
sourceFile = updateSourceFile(sourceFile, "'use strict';" + sourceFile.text, { newLength: "'use strict';".length, span: { start: 0, length: 0 } });
413+
assert.strictEqual(sourceFile.statements[2].getSourceFile(), sourceFile, "parent pointers are updated");
414+
const updateHost: TestCompilerHost = {
415+
...host,
416+
getSourceFile(fileName) {
417+
return fileName === sourceFile.fileName ? sourceFile : program1.getSourceFile(fileName);
418+
}
419+
};
420+
const program2 = createProgram(["/a.ts"], options, updateHost, program1);
421+
assert.isDefined(program2.getSourceFile("/a.ts")!.resolvedModules!.get("a"), "'a' is not an unresolved module after re-use");
422+
assert.strictEqual(sourceFile.statements[2].getSourceFile(), sourceFile, "parent pointers are not altered");
423+
});
424+
402425
it("resolved type directives cache follows type directives", () => {
403426
const files = [
404427
{ name: "/a.ts", text: SourceText.New("/// <reference types='typedefs'/>", "", "var x = $") },

0 commit comments

Comments
 (0)