feat: add dynamic_import_vars plugin#1732
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
|
Thanks for the PR. We will review this when we plan to implement this feature. |
| *expr = self.ast_builder.expression_call( | ||
| import_expr.span, | ||
| self.ast_builder.vec1( | ||
| self.ast_builder.argument_expression(clone_expr(self.ast_builder, &import_expr.source)), |
There was a problem hiding this comment.
Here the &import_expr.source is not be used again, you could take it out form import_expr to avoid clone.
There was a problem hiding this comment.
The import_expr is a reference, thus it can't be moved into Argument 🤔
There was a problem hiding this comment.
Here it is a &mut import_expr, i will using to move it out.
std::mem::replace(
&mut import_expr.source,
self.ast_builder.expression_null_literal(SPAN),
)
Yeah. It is our internal implementation for For other to do list, we could add some TODO comment at code, it will leave something todo for others. Thank you. |
|
The tests still fail - Other TODOs mentioned above are now in code comments. |
I will see it, thank you. |
|
@underfin This pull request has been opened for about one week, maybe we could merge it first if it has no big issue? And polish it in the future? |
|
I could see it at next, please wait a while. |
|
Thank your awesome contribute. |
Here because the global import plugin not handle nested call expression, i using |
Head branch was pushed to by a user without write access
Listed in #819.
This PR implements Vite's dynamic-import-vars plugin as a built-in Rolldown plugin.
Todos
The tests still fail because
import.meta.globin the source code can be transformed, but those generated by dynamic_import_vars_plugin cannot. I don't know how to address this.This PR has to copy nodes, but I can't find the right way to do this in Rust (related to
CloneIntrait for AST nodes oxc-project/oxc#4284?). Currently, the AST is first generated to JS and then parsed, in order to be cloned.Other TODOs are rather less important and have comments starting with
TODO:in the source code.Notes
In Vite, the raw import expression is first resolved as a path and then converted to a glob pattern. However, because the raw import expression is in AST form in Rolldown, it is first converted to a glob pattern and then resolved as a path.