Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrate more string replace dependency for test #3341

Merged
merged 1 commit into from
May 30, 2023

Conversation

underfin
Copy link
Collaborator

@underfin underfin commented May 29, 2023

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, and new URL expressions. It also refactors some common code to the runtime_template module and fixes some syntax errors.

Walkthrough

馃 Generated by Copilot at ecba181

  • Move the module_id and HarmonyExportImportedSpecifierDependency functions from the crates/rspack_plugin_javascript/src/dependency modules to the crates/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)
  • Add a new function get_reexport_var to the crates/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)
  • Add a new parameter update to the import_statement function in the crates/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 the var declaration to the import variables (link, link, link)
  • Modify the module_id function in the crates/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)
  • Remove the parentheses from the import_var_default expression in the crates/rspack_core/src/dependency/runtime_template.rs file, as they are not needed and may cause parsing errors (link)
  • Use the module_id function to generate code for the module id in various dependencies, such as CommonJSRequireDependency, HarmonyImportDependency, HarmonyAcceptDependency, ImportMetaHotAcceptDependency, ImportMetaHotDeclineDependency, ModuleHotAcceptDependency, ModuleHotDeclineDependency, and NewURLDependency, and pass the appropriate value for the weak parameter (link, link, link, link, link, link, link, link)
  • Use the import_statement function to generate code for the import statements in various dependencies, such as HarmonyImportDependency and HarmonyAcceptDependency, and pass the appropriate value for the update parameter (link, link)
  • Use the get_import_var function to get the import variable name from the request in the HarmonyImportDependency struct (link)
  • Use the export_from_import function to generate code for the re-exports in the HarmonyExportImportedSpecifierDependency struct, and add a new field module_identifier to store the module identifier of the dependency (link)
  • Add code to handle the case when the imported module is async and needs to be awaited in the HarmonyImportDependency and HarmonyCompatibilityDependency structs, and add the RuntimeGlobals::MODULE and RuntimeGlobals::ASYNC_MODULE to the runtime_requirements (link, link)
  • Remove the export field from the HarmonyImportSpecifierDependency 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)
  • Add a new module and struct require_resolve_dependency and RequireResolveDependency, which represent a dependency for the require.resolve expression, and generate code for it using the module_id function (link, link)
  • Add a new module and struct new_url_dependency and NewURLDependency, which represent a dependency for the new URL expression, and generate code for it using the module_id and RuntimeGlobals::REQUIRE functions (link, link)
  • Fix a syntax error when generating code for the require.context and import expressions, which take a function argument, by inserting a ( character after the callee_end position in the CommonJSRequireContextDependency and ImportContextDependency structs (link, link)
  • Add a comment // todo module_arguments to the apply method of the ModuleIdDependency struct, to indicate that the code needs to be updated to use the module arguments instead of the hardcoded "module.id" string (link)
  • Add a function render_init_fragments to the crates/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 the generate method of the StringReplace struct (link, link, link, link)

@underfin underfin changed the title fix: migrate more dependency for test fix: migrate more string replace dependency for test May 29, 2023
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label May 29, 2023
@underfin underfin marked this pull request as draft May 29, 2023 12:16
@underfin underfin marked this pull request as ready for review May 30, 2023 09:38
@underfin underfin added this pull request to the merge queue May 30, 2023
function() { return module; }
__webpack_require__.d(getter, { a: getter });
return getter;
// var getter = module && module.__esModule ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

This may affect live-binding for ESM module

Merged via the queue into main with commit 54487ef May 30, 2023
12 checks passed
@underfin underfin deleted the add-more-string-replace branch May 30, 2023 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants