Skip to content

Fix external helper crash after module-status updates (TDD rewrite)#4022

Closed
RyanCavanaugh wants to merge 2 commits into
microsoft:mainfrom
RyanCavanaugh:fix/external-helper-crash-tdd-rewrite
Closed

Fix external helper crash after module-status updates (TDD rewrite)#4022
RyanCavanaugh wants to merge 2 commits into
microsoft:mainfrom
RyanCavanaugh:fix/external-helper-crash-tdd-rewrite

Conversation

@RyanCavanaugh
Copy link
Copy Markdown
Member

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:

  • npx hereby build
  • npx hereby test
  • npx hereby lint
  • npx hereby format

RyanCavanaugh and others added 2 commits May 21, 2026 09:58
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>
Copilot AI review requested due to automatic review settings May 21, 2026 17:06
@RyanCavanaugh RyanCavanaugh review requested due to automatic review settings May 21, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash via checkExternalEmitHelpers

1 participant