Skip to content

Fix missing lib files in reused programs - #63239

Merged
Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
jakebailey:fix-63228
Mar 12, 2026
Merged

Fix missing lib files in reused programs#63239
Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
jakebailey:fix-63228

Conversation

@jakebailey

Copy link
Copy Markdown
Member

Fixes#63228

I should have noticed this in the baselines from my original change, but I did not.

This should be cherry-picked to 6.0.

@jakebailey

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
pack this✅ Started✅ Results

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Hey Jake Bailey (@jakebailey), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
"devDependencies": {
"typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/167413/artifacts?artifactName=tgz&fileId=9172AA0B40779F1AC39448730BC86E547DE9294E1DF8B85C9C1E2347B88C9CF202&fileName=/typescript-6.0.0-insiders.20260311.tgz"
}
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@6.0.0-pr-63239-2".;

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a regression in program-structure reuse where default library files were not being tracked as default libs in the reused program, leading to incorrect behavior in APIs like isSourceFileDefaultLibrary and downstream watch/tsserver outputs (issue #63228).

Changes:

  • Re-populate libFiles during complete structure reuse so isSourceFileDefaultLibrary remains accurate.
  • Add a unit test covering isSourceFileDefaultLibrary after ts.createProgram(..., oldProgram) reuse.
  • Update multiple tsserver/tsc-watch baselines to reflect corrected default-lib classification.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
tests/baselines/reference/tsserver/compileOnSave/emit-in-project.jsBaseline update reflecting corrected default-lib handling in compileOnSave output
tests/baselines/reference/tsserver/compileOnSave/emit-in-project-with-module.jsBaseline update reflecting corrected default-lib handling in compileOnSave output
tests/baselines/reference/tsserver/compileOnSave/configProjects-global-file-shape-changed.jsBaseline update reflecting corrected default-lib handling in compileOnSave output
tests/baselines/reference/tscWatch/watchEnvironment/watchFile/using-fixed-chunk-size-polling.jsBaseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/watchEnvironment/watchFile/using-dynamic-priority-polling.jsBaseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/watchEnvironment/fsEvent-for-change-is-repeated.jsBaseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/programUpdates/when-skipLibCheck-and-skipDefaultLibCheck-changes.jsBaseline update reflecting corrected default-lib handling when check options change
tests/baselines/reference/tscWatch/programUpdates/updates-errors-in-lib-file/when-non-module-file-changes/with-skipLibCheck.jsBaseline update reflecting corrected default-lib classification in incremental program updates
tests/baselines/reference/tscWatch/programUpdates/updates-errors-in-lib-file/when-non-module-file-changes/with-skipDefaultLibCheck.jsBaseline update reflecting corrected default-lib classification in incremental program updates
tests/baselines/reference/tscWatch/programUpdates/updates-errors-in-lib-file/when-non-module-file-changes/with-default-options.jsBaseline update reflecting corrected default-lib classification in incremental program updates
tests/baselines/reference/tscWatch/programUpdates/updates-errors-in-lib-file/when-module-file-with-global-definitions-changes/with-skipLibCheck.jsBaseline update reflecting corrected default-lib classification in incremental program updates
tests/baselines/reference/tscWatch/programUpdates/updates-errors-in-lib-file/when-module-file-with-global-definitions-changes/with-skipDefaultLibCheck.jsBaseline update reflecting corrected default-lib classification in incremental program updates
tests/baselines/reference/tscWatch/programUpdates/updates-errors-in-lib-file/when-module-file-with-global-definitions-changes/with-default-options.jsBaseline update reflecting corrected default-lib classification in incremental program updates
tests/baselines/reference/tscWatch/programUpdates/should-reflect-change-in-config-file.jsBaseline update reflecting corrected default-lib classification in program updates
tests/baselines/reference/tscWatch/programUpdates/handle-recreated-files-correctly.jsBaseline update reflecting corrected default-lib classification in program updates
tests/baselines/reference/tscWatch/noEmit/multiFile/semantic-errors.jsBaseline update reflecting corrected default-lib classification in noEmit watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/semantic-errors-with-incremental.jsBaseline update reflecting corrected default-lib classification in noEmit incremental watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/dts-errors.jsBaseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/dts-errors-without-dts-enabled.jsBaseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/dts-errors-without-dts-enabled-with-incremental.jsBaseline update reflecting corrected default-lib classification in incremental watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/dts-errors-with-incremental.jsBaseline update reflecting corrected default-lib classification in incremental watch output
tests/baselines/reference/tscWatch/emit/when-module-emit-is-specified-as-node/when-instead-of-filechanged-recursive-directory-watcher-is-invoked.jsBaseline update reflecting corrected default-lib classification in emit watch output
tests/baselines/reference/tscWatch/emit/emit-with-outFile-or-out-setting/config-has-out.jsBaseline update reflecting corrected default-lib classification in emit watch output
tests/baselines/reference/tscWatch/emit/emit-with-outFile-or-out-setting/config-does-not-have-out-or-outFile.jsBaseline update reflecting corrected default-lib classification in emit watch output
tests/baselines/reference/tscWatch/emit/emit-for-configured-projects/should-return-all-files-if-a-global-file-changed-shape.jsBaseline update reflecting corrected default-lib classification in configured-project emit watch output
tests/baselines/reference/tscWatch/emit/emit-file-content/handles-new-lines-lineFeed.jsBaseline update reflecting corrected default-lib classification in emit watch output
tests/baselines/reference/tscWatch/emit/emit-file-content/handles-new-lines-carriageReturn-lineFeed.jsBaseline update reflecting corrected default-lib classification in emit watch output
tests/baselines/reference/tscWatch/emit/emit-file-content/file-is-deleted-and-created-as-part-of-change.jsBaseline update reflecting corrected default-lib classification in emit watch output
src/testRunner/unittests/reuseProgramStructure.tsAdds a unit test for isSourceFileDefaultLibrary behavior after program reuse
src/compiler/program.tsCopies default-lib membership (libFiles) during complete structure reuse

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +791 to +799
// 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");

CopilotAIMar 11, 2026

Copy link

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.
@github-project-automationgithub-project-automationBot moved this from Not started to Needs merge in PR BacklogMar 12, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queueMar 12, 2026
Merged via the queue into microsoft:main with commit 9059e5bMar 12, 2026
27 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the fix-63228 branch March 12, 2026 15:55
@github-project-automationgithub-project-automationBot moved this from Needs merge to Done in PR BacklogMar 12, 2026
@jakebailey

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) cherry-pick this to release-6.0

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
cherry-pick this to release-6.0❌ Error: HttpError: Unexpected inputs provided: ["source_owner", "source_repo"] - https://docs.github.com/rest/actions/workflows#create-a-workflow-dispatch-event

@jakebailey

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) cherry-pick this to release-6.0

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
cherry-pick this to release-6.0✅ Started✅ Results

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey, Jake Bailey (@jakebailey)! I've created #63246 for you.

Ryan Cavanaugh (RyanCavanaugh) pushed a commit that referenced this pull request Mar 13, 2026
…e-6.0 (#63246)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

TypeScript 6 API Bug - isSourceFileDefaultLibrary false negative on program structure reuse

4 participants

@jakebailey@typescript-bot@RyanCavanaugh