Fix panic in transformCommonJSExport for named non-default exports#3379
Draft
Fix panic in transformCommonJSExport for named non-default exports#3379
Conversation
The second branch of transformCommonJSExport (named non-default exports) was missing the getSymbolAccessibilityDiagnostic setter before calling ensureType. When type serialization triggered TrackSymbol and found an inaccessible symbol, it would call the default throwDiagnostic handler, causing a panic. Added the appropriate diagnostic handler to match the pattern used by the first (default export) and third (non-identifier name) branches. Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/d88f9257-5e67-4eef-be7b-4574b5576717 Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix LSP request failure for diagnostics during type serialization
Fix panic in transformCommonJSExport for named non-default exports
Apr 9, 2026
jakebailey
reviewed
Apr 9, 2026
Comment on lines
+1100
to
+1106
| tx.state.getSymbolAccessibilityDiagnostic = func(_ printer.SymbolAccessibilityResult) *SymbolAccessibilityDiagnostic { | ||
| return &SymbolAccessibilityDiagnostic{ | ||
| diagnosticMessage: diagnostics.Exported_variable_0_has_or_is_using_private_name_1, | ||
| errorNode: input, | ||
| typeName: name, | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
This is technically correct (I had the same change locally), but not complete, because while adding the error stops the crash, there shouldn't be an error in the first place, and stopping the error requires further changes related to JS emit and how we choose to reuse nodes / resolve things even though they're in JSDoc. I have that change locally, but it still felt hacky (hence not having sent anything yet).
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.
Named non-default CommonJS exports (e.g.
exports.foo = ...) panic with"Diagnostic emitted without context"during declaration emit when the inferred type references an inaccessible symbol.transformCommonJSExporthas three branches. The default-export and non-identifier-name branches both setgetSymbolAccessibilityDiagnosticbefore callingensureType, but the named non-default branch did not. SinceKindCommonJSExportis not incanProduceDiagnostics,ensureTypedoesn't override the handler either, leaving the initialthrowDiagnosticpanic handler active whenTrackSymbolencounters a private symbol.getSymbolAccessibilityDiagnosticwithExported_variable_0_has_or_is_using_private_name_1in the missing branch, matching the pattern of the other two branchescjsModuleExportsNamedDeclarationEmit.tsexercising named non-default CJS export declaration emit