Skip to content

Handle numeric literal export names in declaration emit#3919

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-tsgo-printer-panics
Draft

Handle numeric literal export names in declaration emit#3919
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-tsgo-printer-panics

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

The printer panics when emitting declarations for CommonJS files with numeric export names (e.g. exports[1] = 2). emitModuleExportName only handled KindIdentifier and KindStringLiteral, missing KindNumericLiteral. Additionally, the declaration transformer passed numeric literals through unchanged, producing invalid syntax like export { _exported as 1 }.

  • Added KindNumericLiteral case to emitModuleExportName in the printer to prevent the panic
  • Added numeric-to-string conversion in getNameExpressionPreferringIdentifier in the declaration transformer, since numeric property names in JS are string properties — now emits valid export { _exported as "1" } syntax
  • Added test case covering exports[1], module.exports[1], and Object.defineProperty(exports, 1, {})

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
Copilot AI requested a review from jakebailey May 16, 2026 19:56
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copilot AI requested a review from jakebailey May 16, 2026 20:45
Copy link
Copy Markdown
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems plausible

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.

tsgo printer panics when emitting declarations for CommonJS files with numeric export names

2 participants