Handle numeric literal export names in declaration emit#3919
Draft
Copilot wants to merge 4 commits into
Draft
Conversation
Add KindNumericLiteral case to emitModuleExportName in the printer, which was causing a panic when emitting declarations for CommonJS files with numeric export names like `exports[1] = 2`. Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/9f3fe2c6-afe3-4d4b-9709-13e88c7271b6 Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix tsgo printer panics when emitting declarations for CommonJS files
Handle numeric literal in emitModuleExportName
May 16, 2026
jakebailey
reviewed
May 16, 2026
Comment on lines
+20
to
+31
| //// [DtsFileErrors] | ||
|
|
||
|
|
||
| bug.d.ts(2,22): error TS2300: Duplicate identifier '(Missing)'. | ||
| bug.d.ts(2,23): error TS1003: Identifier expected. | ||
| bug.d.ts(2,25): error TS1128: Declaration or statement expected. | ||
| bug.d.ts(4,24): error TS2300: Duplicate identifier '(Missing)'. | ||
| bug.d.ts(4,25): error TS1003: Identifier expected. | ||
| bug.d.ts(4,27): error TS1128: Declaration or statement expected. | ||
| bug.d.ts(6,24): error TS2300: Duplicate identifier '(Missing)'. | ||
| bug.d.ts(6,25): error TS1003: Identifier expected. | ||
| bug.d.ts(6,27): error TS1128: Declaration or statement expected. |
Member
There was a problem hiding this comment.
@copilot Probably this indicates further brokenness, but compare to Strada.
I'd think we'd want to export as "1" etc since numeric props are just number props in disguise? Not sure. Look into it.
Contributor
Author
There was a problem hiding this comment.
You're right — numeric props are just string props in disguise. Fixed in 0019d09 by converting NumericLiteral to StringLiteral in getNameExpressionPreferringIdentifier in the declaration transformer. Now emits export { _exported as "1" } instead of the invalid export { _exported as 1 }, eliminating the parse errors from the baseline (down from 9 to just 3 duplicate identifier errors, which are expected since all 3 exports share the same name "1").
…ration emit
Numeric property names in JS are string properties; convert NumericLiteral
to StringLiteral in getNameExpressionPreferringIdentifier so declarations
emit valid syntax like `export { _exported as "1" }` instead of the
invalid `export { _exported as 1 }`.
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/0d9fa6e3-1d16-42fa-824c-c7baf31e67ee
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
Handle numeric literal in emitModuleExportName
Handle numeric literal export names in declaration emit
May 16, 2026
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.
The printer panics when emitting declarations for CommonJS files with numeric export names (e.g.
exports[1] = 2).emitModuleExportNameonly handledKindIdentifierandKindStringLiteral, missingKindNumericLiteral. Additionally, the declaration transformer passed numeric literals through unchanged, producing invalid syntax likeexport { _exported as 1 }.KindNumericLiteralcase toemitModuleExportNamein the printer to prevent the panicgetNameExpressionPreferringIdentifierin the declaration transformer, since numeric property names in JS are string properties — now emits validexport { _exported as "1" }syntaxexports[1],module.exports[1], andObject.defineProperty(exports, 1, {})