fix: handle function overloads in .d.ts bundling#210
Open
hugs7 wants to merge 1 commit into
Open
Conversation
When tsc emits multiple `export declare function` declarations with the same name (function overloads), Rolldown's parser rejected them as duplicate exports. The fake-js transform now detects overload signatures, merges their deps/params/children into the primary declaration for proper identifier renaming, and restores all overloads in the correct order during renderChunk. Fixes sxzz#209 Amp-Thread-ID: https://ampcode.com/threads/T-019d0682-c080-7508-81b0-e69e1b444bb7 Co-authored-by: Amp <amp@ampcode.com>
3 tasks
e355f38 to
6affa5a
Compare
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.
fix: handle function overloads in
.d.tsbundlingFixes #209
Problem
When
isolatedDeclarationsis not enabled,rolldown-plugin-dtsusestscto generate.d.tsfiles. For function overloads,tsccorrectly emits multipleexport declare functiondeclarations with the same name:During the
transformphase, the fake-js plugin converts each declaration into avar useConfig = [id, deps, children]assignment. With overloads, this produces twoexport var useConfigstatements, which Rolldown's parser rejects as duplicate exports.Solution
The fake-js plugin now detects function overload signatures during
transformand merges them into the primary declaration:Transform phase: When a
TSDeclareFunctionis encountered whose binding name has already been processed, the overload's declaration, deps, params, and children are stored on the existingDeclarationInforather than emitting a new runtime variable. The overload's deps/params/children are appended to the primary's arrays so they go through Rolldown's identifier renaming pipeline.RenderChunk phase: When restoring a declaration that has overloads, all overload signatures are emitted alongside the primary declaration in original source order, with proper identifier renaming applied via the merged arrays.
Test
Added a
function-overloadstest fixture that verifies both overload signatures appear in the bundled output: