Fix missing lib files in reused programs#63239
Fix missing lib files in reused programs#63239jakebailey wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
@typescript-bot pack this |
|
Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
There was a problem hiding this comment.
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
libFilesduring complete structure reuse soisSourceFileDefaultLibraryremains accurate. - Add a unit test covering
isSourceFileDefaultLibraryafterts.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.
| // 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"); |
There was a problem hiding this comment.
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.
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.