Conversation
5e0c702 to
f237df6
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds support for preserving top-level await (TLA) expressions in ESM library output and enables scope hoisting for async modules. The main issue being addressed is that when using TLA, available modules optimization was incorrectly removing dependencies from child chunks, even though those modules weren't actually loaded yet when the child chunk was being loaded.
Changes:
- Tracks top-level await context through a new
in_top_level_awaitfield in the JavaScript parser - Propagates the TLA flag through dependency blocks and import dependencies
- Modifies build chunk graph logic to skip available modules optimization when dependencies are within TLA expressions
- Removes the async module bailout from ESM library plugin to enable scope hoisting for async modules
- Refactors re-export logic from
ChunkLinkContextmethods to standalone functions inlink.rs
Reviewed changes
Copilot reviewed 52 out of 53 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.vscode/settings.json |
Adds Rust formatter configuration (unrelated to PR purpose) |
crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs |
Adds logic to skip available modules merging for TLA dependencies |
crates/rspack_core/src/compilation/build_chunk_graph/mod.rs |
Adds hook system for controlling TLA behavior and makes function async |
crates/rspack_core/src/compilation/build_chunk_graph/pass.rs |
Updates to call async build_chunk_graph |
crates/rspack_core/src/compilation/mod.rs |
Minor formatting change |
crates/rspack_core/src/context_module.rs |
Adds in_top_level_await field to ContextOptions and passes to blocks |
crates/rspack_core/src/dependencies_block.rs |
Adds in_top_level_await parameter to AsyncDependenciesBlock |
crates/rspack_core/src/plugin/context.rs |
Adds build_chunk_graph_hooks to ApplyContext |
crates/rspack_core/src/plugin/plugin_driver.rs |
Registers build_chunk_graph_hooks |
crates/rspack_plugin_esm_library/src/chunk_link.rs |
Removes re-export methods (moved to link.rs) and adds re_exports_mut accessor |
crates/rspack_plugin_esm_library/src/lib.rs |
Renames module from ensure_entry_exports to optimize_chunks |
crates/rspack_plugin_esm_library/src/link.rs |
Refactors export tracking to use ExportsContext struct and moves re-export methods here |
crates/rspack_plugin_esm_library/src/optimize_chunks.rs |
File rename from ensure_entry_exports.rs |
crates/rspack_plugin_esm_library/src/plugin.rs |
Removes async module bailout and adds ignore_top_level_await hook returning false |
crates/rspack_plugin_javascript/src/dependency/esm/import_dependency.rs |
Adds in_top_level_await field and accessor method |
crates/rspack_plugin_javascript/src/parser_plugin/*.rs |
Updates all dependency/block creation sites to pass in_top_level_await |
crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs |
Adds in_top_level_await field to JavascriptParser |
crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs |
Tracks TLA state when walking await expressions |
crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk_pre.rs |
Tracks TLA state when pre-walking for-await-of statements |
crates/rspack_plugin_lazy_compilation/src/module.rs |
Adds in_top_level_await field and passes to blocks |
crates/rspack_plugin_lazy_compilation/src/plugin.rs |
Extracts TLA flag from ImportDependency |
crates/rspack_plugin_mf/src/*.rs |
Updates AsyncDependenciesBlock calls to pass false for TLA |
crates/rspack_plugin_rstest/src/parser_plugin.rs |
Updates dependency/block creation to pass in_top_level_await |
tests/rspack-test/esmOutputCases/basic/async-modules/__snapshots__/esm.snap.txt |
Updated snapshot showing scope-hoisted async modules |
tests/rspack-test/esmOutputCases/top-level-await/* |
New test cases for TLA scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs
Outdated
Show resolved
Hide resolved
crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk_pre.rs
Outdated
Show resolved
Hide resolved
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
d3774a6 to
de0916b
Compare
crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs
Outdated
Show resolved
Hide resolved
crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs
Outdated
Show resolved
Hide resolved
📦 Binary Size-limit
❌ Size increased by 1.75KB from 48.56MB to 48.56MB (⬆️0.00%) |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
de0916b to
dc3b5fb
Compare
dc3b5fb to
49e7b1d
Compare
49e7b1d to
aed151a
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Preserve top level await expr as is, support scope hoist async modules.
Related links
Checklist