Skip to content

feat: merge same ImportNamespaceSpecifier for external module#4373

Merged
IWANABETHATGUY merged 2 commits intomainfrom
04-29-feat_merge_same_namespace_import_for_external_module
Jun 7, 2025
Merged

feat: merge same ImportNamespaceSpecifier for external module#4373
IWANABETHATGUY merged 2 commits intomainfrom
04-29-feat_merge_same_namespace_import_for_external_module

Conversation

@IWANABETHATGUY
Copy link
Member

@IWANABETHATGUY IWANABETHATGUY commented Apr 29, 2025

Description

  1. Closed [Feature Request]: same namespace import statements are not merged in output #4324

Summary by CodeRabbit

  • Bug Fixes

    • Prevented duplicate namespace imports when bundling external modules, ensuring each external module is only imported once as a namespace.
  • Tests

    • Added new test cases to verify correct handling of namespace imports for external modules, including scenarios with multiple imports from the same external source.
  • Chores

    • Updated test configurations to mark certain modules as external dependencies and clarify execution expectations.

@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review April 29, 2025 10:21
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@netlify
Copy link

netlify bot commented Apr 29, 2025

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 97feeb6
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/684412d830342e00086cb3ec

@IWANABETHATGUY IWANABETHATGUY force-pushed the 04-29-feat_merge_same_namespace_import_for_external_module branch 3 times, most recently from b121b2e to 1cba71a Compare April 29, 2025 10:27
@IWANABETHATGUY IWANABETHATGUY force-pushed the 04-29-feat_merge_same_namespace_import_for_external_module branch from 1cba71a to 339cf6d Compare April 29, 2025 10:32
@IWANABETHATGUY IWANABETHATGUY marked this pull request as draft April 29, 2025 10:34
@IWANABETHATGUY IWANABETHATGUY force-pushed the 04-29-feat_merge_same_namespace_import_for_external_module branch from 339cf6d to 83c426b Compare April 29, 2025 10:34
@github-actions
Copy link
Contributor

github-actions bot commented Apr 29, 2025

Benchmarks Rust

  • target: main(ee57cb6)
  • pr: 04-29-feat_merge_same_namespace_import_for_external_module(97feeb6)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     77.4±2.86ms        ? ?/sec    1.04     80.5±2.46ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     89.5±2.51ms        ? ?/sec    1.04     93.1±4.05ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00    115.8±3.60ms        ? ?/sec    1.02    118.1±2.28ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    130.5±1.81ms        ? ?/sec    1.02    133.3±2.84ms        ? ?/sec
bundle/bundle@threejs                                        1.00     41.4±0.75ms        ? ?/sec    1.03     42.6±1.94ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     48.3±0.81ms        ? ?/sec    1.01     48.6±1.15ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    443.9±6.81ms        ? ?/sec    1.02    453.5±7.94ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    518.3±4.38ms        ? ?/sec    1.04    538.5±8.70ms        ? ?/sec
scan/scan@rome_ts                                            1.00     93.0±1.90ms        ? ?/sec    1.04     96.8±1.63ms        ? ?/sec
scan/scan@threejs                                            1.00     32.0±0.93ms        ? ?/sec    1.12     36.0±4.01ms        ? ?/sec
scan/scan@threejs10x                                         1.00    330.3±5.14ms        ? ?/sec    1.01    332.7±4.53ms        ? ?/sec

@Brooooooklyn
Copy link
Member

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Apr 29, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link

coderabbitai bot commented Apr 29, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce logic to deduplicate namespace imports for external modules during the ECMAScript module formatting and import/export binding stages. A new set is used to track which external modules have already had a namespace import rendered, ensuring only one such import per module appears in the output. Additionally, the import/export binding context is updated to separately manage and link namespace imports for external modules. New test files and configuration are added to verify the deduplication behavior for specific external modules.

Changes

Files / Paths Change Summary
crates/rolldown/src/ecmascript/format/esm.rs Added a set to track rendered external namespace imports, skipping duplicates during output generation.
crates/rolldown/src/stages/link_stage/bind_imports_and_exports.rs Added a map to track and link namespace imports for external modules separately; updated binding logic accordingly.
crates/rolldown/tests/rolldown/issues/4324/_config.json Added test configuration marking "node:http" and "node:net" as external, with execution not expected.
crates/rolldown/tests/rolldown/issues/4324/file.js
crates/rolldown/tests/rolldown/issues/4324/file2.js
Added test files importing the same external module as a namespace and a named import, then logging their values.
crates/rolldown/tests/rolldown/issues/4324/main.js Added a test entry file importing the above test files.

Sequence Diagram(s)

sequenceDiagram
    participant File1 as file.js
    participant File2 as file2.js
    participant Main as main.js
    participant Formatter as ESM Formatter
    participant Binder as Import/Export Binder

    File1->>Binder: Import * as what from "node:http"
    File2->>Binder: Import * as hello from "node:http"
    Binder->>Binder: Track namespace imports per module
    Binder->>Formatter: Provide deduplicated import info
    Formatter->>Formatter: Render only one namespace import per external module
    Formatter-->>Main: Output merged import statements
Loading

Assessment against linked issues

Objective Addressed Explanation
Merge same namespace import statements in output (#4324)
Ensure only one namespace import per external module is generated (#4324)
Separate tracking and linking of namespace imports for external modules in binding logic (#4324)
Prevent duplicate namespace imports and related panics (#4324)

Poem

In the warren of code, imports would multiply,
But now with sharp paws, we rabbits deduplicate and try!
Only one namespace per module, neat and spry,
No more import clutter hopping by.
With a twitch of the nose and a flick of the ear,
Our bundle is tidy—springtime is here!
🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@IWANABETHATGUY IWANABETHATGUY force-pushed the 04-29-feat_merge_same_namespace_import_for_external_module branch from 83c426b to cb46411 Compare April 29, 2025 14:25
@IWANABETHATGUY IWANABETHATGUY force-pushed the 04-29-feat_merge_same_namespace_import_for_external_module branch from 4853b6a to 5dbbc61 Compare June 7, 2025 07:38
@IWANABETHATGUY IWANABETHATGUY force-pushed the 04-29-feat_merge_same_namespace_import_for_external_module branch 4 times, most recently from 127c45e to a6b2879 Compare June 7, 2025 10:13
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review June 7, 2025 10:14
@IWANABETHATGUY IWANABETHATGUY force-pushed the 04-29-feat_merge_same_namespace_import_for_external_module branch from a6b2879 to 97feeb6 Compare June 7, 2025 10:22
@IWANABETHATGUY IWANABETHATGUY changed the title feat: merge same namespace import for external module feat: merge same ImportNamespaceSpecifier for external module Jun 7, 2025
@IWANABETHATGUY IWANABETHATGUY added this pull request to the merge queue Jun 7, 2025
Merged via the queue into main with commit f547642 Jun 7, 2025
24 checks passed
@IWANABETHATGUY IWANABETHATGUY deleted the 04-29-feat_merge_same_namespace_import_for_external_module branch June 7, 2025 10:48
@github-actions github-actions bot mentioned this pull request Jun 7, 2025
Boshen pushed a commit that referenced this pull request Jun 7, 2025
## [1.0.0-beta.13] - 2025-06-07

### 🚀 Features

- feat: merge same `ImportNamespaceSpecifier` for external module by
@IWANABETHATGUY in
[#4373](#4373)

### 🐛 Bug Fixes

- ci: disable `generate_release_notes` by @Boshen

### 📚 Documentation

- docs: add MAINTENANCE.md; remove rolldown.rs/contrib-guide/release by
@Boshen in [#4854](#4854)

### ⚙️ Miscellaneous Tasks

- add input description to prepare-release.yml by @Boshen
- fix prepare-release.yml by @Boshen
- CHANGELOG.md: ci(CHANGELOG.md): use git-cliff to generate changelogs
by @Boshen in [#4858](#4858)
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.

[Feature Request]: same namespace import statements are not merged in output

4 participants