8000 feat: treeshake dynamic import chained member expression by privatenumber · Pull Request #5898 · rollup/rollup · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: treeshake dynamic import chained member expression #5898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

privatenumber
Copy link
Contributor
@privatenumber privatenumber commented Apr 2, 2025

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Here's the test-only PR demonstrating that it fails without this change:
privatenumber#2

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

This PR adds support for tree-shaking dynamic imports when the following pattern is observed:

import(specifier).then(m => m.name)

I didn't look into this deeply, but in a Vite library build, one of my libraries generates this syntax to import from a chunk. When a Vite app (which uses Rollup under the hood) consumes the library, the unused exports from the chunk isn’t tree-shaken.

I'm not sure if this is the root cause, but I thought this change would improve tree-shaking regardless at minimal cost and was worth adding.

Copy link
vercel bot commented Apr 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 12, 2025 7:11am

@privatenumber privatenumber force-pushed the dynamic-import-treeshake-member-expression branch from 9754604 to 75d2bc3 Compare April 3, 2025 02:05
@privatenumber privatenumber changed the title feat: treeshake dynamic import member expression feat: treeshake dynamic import chained member expression Apr 3, 2025
@privatenumber privatenumber marked this pull request as ready for review April 3, 2025 02:06
Copy link
Member
@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

While this is kind of a special case, it looks good to me. Technically at this point, we do have a logic that can track inclusions of object properties at this point. However, using for this purpose would require a bigger refactoring as getDeterministicImportedNames is only run once, so it would instead need to be triggered somehow from the parameter variables. Maybe we will implement it at some point. Until then, good work!

@lukastaegert lukastaegert enabled auto-merge April 8, 2025 04:58
Copy link
codecov bot commented Apr 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.55%. Comparing base (19fb519) to head (95f2779).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5898      +/-   ##
==========================================
- Coverage   98.56%   98.55%   -0.02%     
==========================================
  Files         270      270              
  Lines        8685     8692       +7     
  Branches     1487     1488       +1     
==========================================
+ Hits         8560     8566       +6     
- Misses         92       93       +1     
  Partials       33       33              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

auto-merge was automatically disabled April 8, 2025 06:46 8000

Head branch was pushed to by a user without write access

@lukastaegert lukastaegert enabled auto-merge April 12, 2025 05:42
@lukastaegert lukastaegert added this pull request to the merge queue Apr 12, 2025
auto-merge was automatically disabled April 12, 2025 06:58

Pull Request is not mergeable

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 12, 2025
@lukastaegert lukastaegert enabled auto-merge April 12, 2025 07:10
@lukastaegert lukastaegert added this pull request to the merge queue Apr 12, 2025
Merged via the queue into rollup:master with commit 4ded099 Apr 12, 2025
40 of 41 checks passed
Copy link

This PR has been released as part of rollup@4.40.0. You can test it via npm install rollup.

@privatenumber
Copy link
Contributor Author

Amazing! It's an honor to be able to contribute to Rollup—thank you for all your work.

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.

3 participants
0