fix: migrate more string replace dependency for test #3341
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue (if exists)
Summary
馃 Generated by Copilot at ecba181
This pull request enhances the code generation logic for various dependency types in the
rspack_plugin_javascript
crate, and adds support for async modules,require.resolve
, andnew URL
expressions. It also refactors some common code to theruntime_template
module and fixes some syntax errors.Walkthrough
馃 Generated by Copilot at ecba181
module_id
andHarmonyExportImportedSpecifierDependency
functions from thecrates/rspack_plugin_javascript/src/dependency
modules to thecrates/rspack_core/src/dependency/runtime_template.rs
file, as they are used by multiple dependencies and not specific to esm or commonjs (link, link, link)get_reexport_var
to thecrates/rspack_core/src/dependency/runtime_template.rs
file, which returns a string representing the re-exported variable from an imported variable and an export name (link)update
to theimport_statement
function in thecrates/rspack_core/src/dependency/runtime_template.rs
file, which indicates whether a new variable should be created or the existing one updated for the import, and use it to conditionally add thevar
declaration to the import variables (link, link, link)module_id
function in thecrates/rspack_core/src/dependency/runtime_template.rs
file to handle the case when the dependency is weak and does not have a module identifier or id, and return a placeholder string in that case (link)import_var_default
expression in thecrates/rspack_core/src/dependency/runtime_template.rs
file, as they are not needed and may cause parsing errors (link)module_id
function to generate code for the module id in various dependencies, such asCommonJSRequireDependency
,HarmonyImportDependency
,HarmonyAcceptDependency
,ImportMetaHotAcceptDependency
,ImportMetaHotDeclineDependency
,ModuleHotAcceptDependency
,ModuleHotDeclineDependency
, andNewURLDependency
, and pass the appropriate value for theweak
parameter (link, link, link, link, link, link, link, link)import_statement
function to generate code for the import statements in various dependencies, such asHarmonyImportDependency
andHarmonyAcceptDependency
, and pass the appropriate value for theupdate
parameter (link, link)get_import_var
function to get the import variable name from the request in theHarmonyImportDependency
struct (link)export_from_import
function to generate code for the re-exports in theHarmonyExportImportedSpecifierDependency
struct, and add a new fieldmodule_identifier
to store the module identifier of the dependency (link)HarmonyImportDependency
andHarmonyCompatibilityDependency
structs, and add theRuntimeGlobals::MODULE
andRuntimeGlobals::ASYNC_MODULE
to theruntime_requirements
(link, link)export
field from theHarmonyImportSpecifierDependency
struct and its methods, as it is no longer needed, and remove the code that generates code for re-exporting the imported specifier (link, link, link, link, link)require_resolve_dependency
andRequireResolveDependency
, which represent a dependency for therequire.resolve
expression, and generate code for it using themodule_id
function (link, link)new_url_dependency
andNewURLDependency
, which represent a dependency for thenew URL
expression, and generate code for it using themodule_id
andRuntimeGlobals::REQUIRE
functions (link, link)require.context
andimport
expressions, which take a function argument, by inserting a(
character after thecallee_end
position in theCommonJSRequireContextDependency
andImportContextDependency
structs (link, link)// todo module_arguments
to theapply
method of theModuleIdDependency
struct, to indicate that the code needs to be updated to use the module arguments instead of the hardcoded"module.id"
string (link)render_init_fragments
to thecrates/rspack_plugin_javascript/src/runtime.rs
file, which takes a source code and a list of init fragments, and inserts the fragments to the source code according to their stage and order, and use it in thegenerate
method of theStringReplace
struct (link, link, link, link)