-
-
Notifications
You must be signed in to change notification settings - Fork 736
chore: add import_meta_property_in_destructuring parser hook
#12255
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new parser hook import_meta_property_in_destructuring to enable interoperation between the ImportMetaPlugin and NodeStuffPlugin for handling import.meta.filename/dirname in destructuring contexts.
Key Changes
- Introduces a plugin interop hook mechanism to the JavaScript parser trait
- Adds
import_meta_property_in_destructuringmethod to handle special import.meta properties during destructuring - Implements the hook call chain through the plugin drive system
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rspack_plugin_javascript/src/parser_plugin/trait.rs | Adds the new import_meta_property_in_destructuring trait method with documentation, and imports DestructuringAssignmentProperty type |
| crates/rspack_plugin_javascript/src/parser_plugin/node_stuff_plugin.rs | Implements stub for the new hook method (marked as TODO), and adds necessary import for DestructuringAssignmentProperty |
| crates/rspack_plugin_javascript/src/parser_plugin/import_meta_plugin.rs | Calls the new hook when processing destructuring of import.meta, allowing other plugins to handle specific properties before falling back to default behavior |
| crates/rspack_plugin_javascript/src/parser_plugin/drive.rs | Implements the plugin drive logic to invoke the hook across all registered plugins using SyncBailHook pattern, and adds necessary imports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📦 Binary Size-limit
❌ Size increased by 2.25KB from 47.63MB to 47.63MB (⬆️0.00%) |
CodSpeed Performance ReportMerging #12255 will not alter performanceComparing Summary
|
|
Can this PR meet your needs? @magic-akari |
Summary
As discussed in #10573, to support the parsing of
import.meta.filename/dirnamein theNodeStuffPlugin, interop with theImportMetaPluginis required.Since webpack's parser plugins are implemented in the compiler plugins, compilation hooks can be added on the compiler plugin. However, rspack's parser plugins are implemented in javascript parser, and also the compilation id cannot be obtained inside. It needs to be passed in step by step from the outside. Moreover, the processing of the parser and the execution of hooks are synchronous, but on rspack's Rust side, only asynchronous hooks are retained, and synchronous hooks are only privately implemented inside the parser hook.
Therefore, a hook is added to the parser hook for interop between the
ImportMetaPluginand theNodeStuffPlugin, and the name is changed toimport_meta_property_in_desctructuringto indicate that it is a plugin interop hook.Related links
Checklist