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

feat: string replace dependency #3219

Merged
merged 1 commit into from
May 25, 2023
Merged

Conversation

underfin
Copy link
Collaborator

@underfin underfin commented May 18, 2023

Related issue (if exists)

Summary

  • use ast span to muate string instead of ast path at codegen, add a new js_parse_generate to separate logic.
  • commonjs transform already implement

馃 Generated by Copilot at 5d24e95

This pull request adds new features and refactors some existing code in the rspack project, which is a Rust-based web packer. The main feature is the static import and export handling by the rspack_plugin_javascript crate, which enables tree-shaking and code generation for modules that use ES6 syntax. To support this feature, the rspack_core crate was updated with new dependency types, a new ModuleGraphModule struct, and new runtime constants. The other plugins, rspack_plugin_asset and rspack_plugin_css, were also updated to comply with the new ParseResult struct. The static-import fixture was modified and extended to test the new feature.

Walkthrough

馃 Generated by Copilot at 5d24e95

  • Add code_generatable_dependency.rs file to rspack_core crate, defining CodeReplaceSourceDependency trait and helper functions for dependencies that can modify module source code (link)
  • Add replace_const_dependency.rs file to rspack_core crate, defining ReplaceConstDependency struct that implements CodeReplaceSourceDependency trait and can replace source code range with constant string (link, link)
  • Import and re-export code_generatable_dependency.rs and replace_const_dependency.rs in dependency/mod.rs and module.rs files of rspack_core crate (link, link, link)
  • Extend Dependency trait with as_code_replace_source_dependency method that returns optional Box<dyn CodeReplaceSourceDependency> in dependency/mod.rs file of rspack_core crate (link)
  • Add module_graph_module.rs file to rspack_core crate, defining ModuleGraphModule struct that represents module in module graph with connections, dependencies, and metadata (link, link)
  • Import and re-export module_graph_module.rs in module.rs file of rspack_core crate (link)
  • Add ExportsType enum to module.rs file of rspack_core crate, defining possible types of exports that module can have (link)
  • Extend Module trait with get_string_replace_generation_dependencies method that returns optional slice of Box<dyn CodeReplaceSourceDependency> in module.rs file of rspack_core crate (link)
  • Refactor NormalModule struct in normal_module.rs file of rspack_core crate, removing HashSet type and ModuleGraphModule struct, and adding code_replace_source_dependencies field (link, link, link)
  • Initialize and assign code_replace_source_dependencies field in new, build, and build_result methods of NormalModule struct in normal_module.rs file of rspack_core crate (link, link, link)
  • Implement get_string_replace_generation_dependencies method for NormalModule struct in normal_module.rs file of rspack_core crate, returning slice of Box<dyn CodeReplaceSourceDependency> from code_replace_source_dependencies field (link)
  • Add code_replace_source_dependencies field to ParseResult struct in parser_and_generator.rs file of rspack_core crate, holding vector of Box<dyn CodeReplaceSourceDependency> for dependencies that can modify module source code (link)
  • Add MAKE_NAMESPACE_OBJECT, EXPORTS, COMPAT_GET_DEFAULT_EXPORT, and CREATE_FAKE_NAMESPACE_OBJECT constants to RuntimeGlobals enum in runtime_globals.rs file of rspack_core crate, representing runtime functions and variables for static import and export handling (link, link)
  • Initialize code_replace_source_dependencies field to empty vector in generate methods of AssetParserAndGenerator struct in lib.rs file of rspack_plugin_asset crate and CssParserAndGenerator struct in parser_and_generator/mod.rs file of rspack_plugin_css crate, indicating no dependencies that can modify module source code (link, link)
  • Add harmony_compatibility_dependency.rs file to rspack_plugin_javascript crate, defining HarmonyCompatibilityDependency struct that implements CodeReplaceSourceDependency trait and can mark module as __esModule and add runtime function call to make module namespace object (link)
  • Add harmony_evaluated_import_specifier_dependency.rs file to rspack_plugin_javascript crate, defining empty HarmonyEvaluatedImportSpecifierDependency struct as placeholder for future dependency that can handle dynamic import specifiers (link)
  • Add harmony_export_expression_dependency.rs file to rspack_plugin_javascript crate, defining HarmonyExpressionHeaderDependency struct that implements CodeReplaceSourceDependency trait and can replace export expression with variable assignment (link)
  • Change rspack fixture to only use static-import subdirectory, and comment out other fixtures, for testing purposes (link, link)
  • Change a.js, b.js, and index.js files and add c.js and e.js files in static-import fixture, to test different scenarios of static import and export handling by plugin (link, link, link, link, link)

@underfin underfin marked this pull request as draft May 18, 2023 11:25
@github-actions github-actions bot added release: feature team The issue/pr is created by the member of Rspack. labels May 18, 2023
@underfin underfin changed the title feat: string replace feat: string replace dependency May 18, 2023
@underfin underfin force-pushed the denpendcy-add-string-replace branch from 5d24e95 to 0386544 Compare May 23, 2023 09:29
@underfin
Copy link
Collaborator Author

!bench

@github-actions
Copy link
Contributor

Benchmark Results

group                                                 baseline                               pr
-----                                                 --------                               --
criterion_benchmark/ten_copy_of_threejs               1.28       2.7卤0.10s        ? ?/sec    1.00       2.1卤0.05s        ? ?/sec
high_cost_benchmark/ten_copy_of_threejs_production    1.40       9.2卤0.18s        ? ?/sec    1.00       6.6卤0.08s        ? ?/sec

@underfin underfin force-pushed the denpendcy-add-string-replace branch from 0386544 to 7e95cd7 Compare May 24, 2023 11:40
@Boshen Boshen mentioned this pull request May 25, 2023
@underfin underfin force-pushed the denpendcy-add-string-replace branch 4 times, most recently from d131ac3 to 55ad484 Compare May 25, 2023 06:27
@underfin underfin force-pushed the denpendcy-add-string-replace branch from 55ad484 to 94ede6b Compare May 25, 2023 06:47
@underfin underfin marked this pull request as ready for review May 25, 2023 06:48
@hyf0
Copy link
Collaborator

hyf0 commented May 25, 2023

!bench

@underfin underfin enabled auto-merge May 25, 2023 07:05
@underfin underfin added this pull request to the merge queue May 25, 2023
Merged via the queue into main with commit 2800d2b May 25, 2023
21 checks passed
@underfin underfin deleted the denpendcy-add-string-replace branch May 25, 2023 07:27
@github-actions
Copy link
Contributor

Benchmark Results

group                                                 baseline                               pr
-----                                                 --------                               --
criterion_benchmark/ten_copy_of_threejs               1.00       3.3卤0.10s        ? ?/sec    1.00       3.3卤0.12s        ? ?/sec
high_cost_benchmark/ten_copy_of_threejs_production    1.00      11.5卤0.17s        ? ?/sec    1.00      11.4卤0.16s        ? ?/sec

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