Fix external helper crash after module-status updates (TDD rewrite)#4022
Closed
RyanCavanaugh wants to merge 2 commits into
Closed
Fix external helper crash after module-status updates (TDD rewrite)#4022RyanCavanaugh wants to merge 2 commits into
RyanCavanaugh wants to merge 2 commits into
Conversation
Add a fourslash test that reproduces the panic in checkExternalEmitHelpers when a file transitions from script to decorated exported module. The test edits a file to add @dec and export keywords, then requests diagnostics which triggers the nil pointer dereference in resolveExternalModule. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
checkExternalEmitHelpers could panic after an incremental program update when a file changed from script to module. The reused program state could lack the synthetic tslib import specifier needed for helper resolution. Treat changes to ExternalModuleIndicator or CommonJSModuleIndicator as non-reusable in canReplaceFileInProgram. This forces rebuilt module- resolution state when helper imports may need to be synthesized. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3878
Rewrite of #3994
Analysis
\checkExternalEmitHelpers\ panics with a nil pointer dereference in \
esolveExternalModule\ (via \IsStringLiteralLike\) after an incremental program update when a file transitions from script to module. The root cause is that \canReplaceFileInProgram\ allows file reuse even when the module indicator status has changed. When a file becomes a module (e.g. by adding \�xport\), the reused program state lacks the synthetic \ slib\ import specifier needed for helper resolution, causing the nil dereference.
Fix
Add checks in \canReplaceFileInProgram\ to compare \ExternalModuleIndicator\ and \CommonJSModuleIndicator\ between old and new file versions. When either changes (nil to non-nil or vice versa), the file cannot be reused and module-resolution state is rebuilt with the correct synthetic imports.
Copilot Checklist
I successfully ran these commands at the end of my session, and they completed without error: