Skip to content

Fix missing lib files in reused programs#63239

Open
jakebailey wants to merge 1 commit intomicrosoft:mainfrom
jakebailey:fix-63228
Open

Fix missing lib files in reused programs#63239
jakebailey wants to merge 1 commit intomicrosoft:mainfrom
jakebailey:fix-63228

Conversation

@jakebailey
Copy link
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
Member Author

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 11, 2026

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

Command Status Results
pack this ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 11, 2026

Hey @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".;

Copy link
Contributor

Copilot AI left a comment

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
File Description
tests/baselines/reference/tsserver/compileOnSave/emit-in-project.js Baseline update reflecting corrected default-lib handling in compileOnSave output
tests/baselines/reference/tsserver/compileOnSave/emit-in-project-with-module.js Baseline update reflecting corrected default-lib handling in compileOnSave output
tests/baselines/reference/tsserver/compileOnSave/configProjects-global-file-shape-changed.js Baseline update reflecting corrected default-lib handling in compileOnSave output
tests/baselines/reference/tscWatch/watchEnvironment/watchFile/using-fixed-chunk-size-polling.js Baseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/watchEnvironment/watchFile/using-dynamic-priority-polling.js Baseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/watchEnvironment/fsEvent-for-change-is-repeated.js Baseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/programUpdates/when-skipLibCheck-and-skipDefaultLibCheck-changes.js Baseline 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.js Baseline 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.js Baseline 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.js Baseline 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.js Baseline 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.js Baseline 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.js Baseline update reflecting corrected default-lib classification in incremental program updates
tests/baselines/reference/tscWatch/programUpdates/should-reflect-change-in-config-file.js Baseline update reflecting corrected default-lib classification in program updates
tests/baselines/reference/tscWatch/programUpdates/handle-recreated-files-correctly.js Baseline update reflecting corrected default-lib classification in program updates
tests/baselines/reference/tscWatch/noEmit/multiFile/semantic-errors.js Baseline update reflecting corrected default-lib classification in noEmit watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/semantic-errors-with-incremental.js Baseline update reflecting corrected default-lib classification in noEmit incremental watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/dts-errors.js Baseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/dts-errors-without-dts-enabled.js Baseline update reflecting corrected default-lib classification in watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/dts-errors-without-dts-enabled-with-incremental.js Baseline update reflecting corrected default-lib classification in incremental watch output
tests/baselines/reference/tscWatch/noEmit/multiFile/dts-errors-with-incremental.js Baseline 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.js Baseline update reflecting corrected default-lib classification in emit watch output
tests/baselines/reference/tscWatch/emit/emit-with-outFile-or-out-setting/config-has-out.js Baseline 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.js Baseline 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.js Baseline update reflecting corrected default-lib classification in configured-project emit watch output
tests/baselines/reference/tscWatch/emit/emit-file-content/handles-new-lines-lineFeed.js Baseline update reflecting corrected default-lib classification in emit watch output
tests/baselines/reference/tscWatch/emit/emit-file-content/handles-new-lines-carriageReturn-lineFeed.js Baseline 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.js Baseline update reflecting corrected default-lib classification in emit watch output
src/testRunner/unittests/reuseProgramStructure.ts Adds a unit test for isSourceFileDefaultLibrary behavior after program reuse
src/compiler/program.ts Copies 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");
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

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

3 participants