Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,9 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
Debug.assert(newSourceFiles.length === oldProgram.getSourceFiles().length);
for (const newSourceFile of newSourceFiles) {
filesByName.set(newSourceFile.path, newSourceFile);
if (oldProgram.isSourceFileDefaultLibrary(newSourceFile)) {
libFiles.add(newSourceFile.path);
}
}
const oldFilesByNameMap = oldProgram.getFilesByNameMap();
oldFilesByNameMap.forEach((oldFile, path) => {
Expand Down
29 changes: 29 additions & 0 deletions src/testRunner/unittests/reuseProgramStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,35 @@ describe("unittests:: reuseProgramStructure:: General", () => {
baselineDiagnostics(baselines, program4);
runBaseline("handles file preprocessing dignostics when diagnostics are not queried", baselines);
});

it("isSourceFileDefaultLibrary is preserved after program reuse", () => {
const libFile = { name: "/lib.d.ts", text: SourceText.New("", "", "declare var console: any;") };
const mainFile = { name: "/main.ts", text: SourceText.New("", "", "var x = 1;") };
const files = [libFile, mainFile];

const host = createTestCompilerHost(files, target);
host.getDefaultLibFileName = () => "/lib.d.ts";

const options: ts.CompilerOptions = { target };
const program1 = ts.createProgram(["/main.ts"], options, host) as ProgramWithSourceTexts;
program1.sourceTexts = files;
program1.host = host;
program1.version = 1;

const libSourceFile1 = program1.getSourceFile("/lib.d.ts")!;
assert.isDefined(libSourceFile1, "lib file should exist in program 1");
assert.isTrue(program1.isSourceFileDefaultLibrary(libSourceFile1), "lib file should be a default library in program 1");

// Update main file only (code change) -> should trigger complete structure reuse
mainFile.text = mainFile.text.updateProgram("var x = 2;");
const host2 = createTestCompilerHost(files, target, program1);
host2.getDefaultLibFileName = () => "/lib.d.ts";
const program2 = ts.createProgram(["/main.ts"], options, host2, program1);

const libSourceFile2 = program2.getSourceFile("/lib.d.ts")!;
assert.isDefined(libSourceFile2, "lib file should exist in program 2");
assert.isTrue(program2.isSourceFileDefaultLibrary(libSourceFile2), "lib file should still be a default library in program 2 after reuse");
Comment on lines +791 to +799
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test intends to validate behavior specifically after program structure reuse, but it doesn’t currently assert that reuse actually happened. If reuse heuristics change (e.g. structure falls back to SafeModules/Not), the test could pass without exercising the regression. Consider asserting program2.structureIsReused is Completely (or at least asserting the lib SourceFile object was reused) before checking isSourceFileDefaultLibrary.

Copilot generated this review using guidance from repository custom instructions.
});
});

describe("unittests:: reuseProgramStructure:: host is optional", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,5 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/username/projects/project/app/file.ts (computed .d.ts)
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,5 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/a/app.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,5 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/a/app.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/a/b/globalfile3.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)
/home/src/projects/a/b/modulefile1.ts (computed .d.ts)
/home/src/projects/a/b/file1consumer1.ts (computed .d.ts)
/home/src/projects/a/b/file1consumer2.ts (computed .d.ts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/a/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)
/home/src/projects/a/b.ts (computed .d.ts)

exitCode:: ExitStatus.undefined
Expand Down Expand Up @@ -200,7 +199,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/a/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)
/home/src/projects/a/b.ts (computed .d.ts)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ No cached semantic diagnostics in the builder::

Shape signatures in builder refreshed for::
/home/src/projects/a/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)
/home/src/projects/a/b.ts (computed .d.ts)

exitCode:: ExitStatus.undefined
Expand Down Expand Up @@ -211,7 +210,6 @@ No cached semantic diagnostics in the builder::

Shape signatures in builder refreshed for::
/home/src/projects/a/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)
/home/src/projects/a/b.ts (computed .d.ts)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ No cached semantic diagnostics in the builder::

Shape signatures in builder refreshed for::
/home/src/projects/a/rootfolder/project/scripts/typescript.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)
/home/src/projects/a/rootfolder/project/scripts/javascript.js (computed .d.ts)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -547,7 +546,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -448,7 +447,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -262,7 +261,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -295,7 +294,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -486,7 +485,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -272,7 +271,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/home/src/projects/project/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/user/username/workspace/solution/projects/project/commonfile2.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)
/user/username/workspace/solution/projects/project/commonfile1.ts (computed .d.ts)

exitCode:: ExitStatus.undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/user/username/workspace/solution/projects/project/commonfile2.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)
/user/username/workspace/solution/projects/project/commonfile1.ts (computed .d.ts)

exitCode:: ExitStatus.undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -170,6 +169,5 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,10 @@ Program files::
/user/username/projects/myproject/a.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
/user/username/projects/myproject/a.ts

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -168,11 +166,9 @@ Program files::
/user/username/projects/myproject/a.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
/user/username/projects/myproject/a.ts

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,10 @@ Program files::
/user/username/projects/myproject/a.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
/user/username/projects/myproject/a.ts

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -168,11 +166,9 @@ Program files::
/user/username/projects/myproject/a.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
/user/username/projects/myproject/a.ts

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -171,6 +170,5 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,10 @@ Program files::
/user/username/projects/myproject/a.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
/user/username/projects/myproject/a.ts

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -169,11 +167,9 @@ Program files::
/user/username/projects/myproject/a.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
/user/username/projects/myproject/a.ts

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,10 @@ Program files::
/user/username/projects/myproject/a.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
/user/username/projects/myproject/a.ts

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down Expand Up @@ -169,11 +167,9 @@ Program files::
/user/username/projects/myproject/a.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
/user/username/projects/myproject/a.ts

Shape signatures in builder refreshed for::
/user/username/projects/myproject/a.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ Program files::
/user/username/projects/myproject/b.d.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts

No shapes updated in the builder::

Expand Down Expand Up @@ -297,6 +298,7 @@ Program files::
/user/username/projects/myproject/b.d.ts

Semantic diagnostics in builder refreshed for::
/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts

No shapes updated in the builder::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ main.ts

Shape signatures in builder refreshed for::
/user/username/projects/project/main.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/a/username/projects/project/typescript.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)

exitCode:: ExitStatus.undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ Semantic diagnostics in builder refreshed for::

Shape signatures in builder refreshed for::
/user/username/projects/project/commonfile1.ts (computed .d.ts)
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version)
/user/username/projects/project/commonfile2.ts (computed .d.ts)

exitCode:: ExitStatus.undefined
Expand Down
Loading
Loading