Fully include dynamic imports in a try-catch#6254
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where dynamic imports in try-catch blocks result in empty objects. When try-catch deoptimization is enabled, Rollup passes INCLUDE_PARAMETERS (the string 'variables') instead of false to the try block, but the ImportExpression's include method wasn't handling this case properly.
Changes:
- Added logic to include all exports from dynamic imports when
includeChildrenRecursivelyis truthy - Added a test case to verify dynamic imports in try-catch blocks work correctly
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/ast/nodes/ImportExpression.ts | Added check to call includeAllExports() when includeChildrenRecursively is truthy in the include method |
| test/function/samples/try-catch-dynamic-import/main.js | Test entry point with dynamic import in try-catch using .then() |
| test/function/samples/try-catch-dynamic-import/dep.js | Test dependency file exporting a value |
| test/function/samples/try-catch-dynamic-import/_config.js | Test configuration verifying the imported value is accessible |
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#try-catch-dynamic-importNotice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust. or load it into the REPL: |
Performance report
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6254 +/- ##
=======================================
Coverage 98.83% 98.83%
=======================================
Files 273 273
Lines 10700 10702 +2
Branches 2854 2855 +1
=======================================
+ Hits 10575 10577 +2
Misses 82 82
Partials 43 43 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This PR has been released as part of rollup@4.57.1. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
Inclusion works differently within a try-catch, so we need to take extra care to just include the entire import target in those cases.