Skip to content

feat: preserve tla expr for EsmLibrary#12942

Merged
JSerFeng merged 1 commit intomainfrom
feat/esm-tla
Feb 6, 2026
Merged

feat: preserve tla expr for EsmLibrary#12942
JSerFeng merged 1 commit intomainfrom
feat/esm-tla

Conversation

@JSerFeng
Copy link
Contributor

@JSerFeng JSerFeng commented Feb 4, 2026

Summary

Preserve top level await expr as is, support scope hoist async modules.

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings February 4, 2026 11:54
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Feb 4, 2026
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Feb 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_await field 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 ChunkLinkContext methods to standalone functions in link.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.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 825.4 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.2 MB 0

Generated by Rsdoctor GitHub Action

@JSerFeng JSerFeng force-pushed the feat/esm-tla branch 3 times, most recently from d3774a6 to de0916b Compare February 4, 2026 12:10
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

📦 Binary Size-limit

Comparing aed151a to refactor: use runtime template for context module codegen (#12957) by Gengkun

❌ Size increased by 1.75KB from 48.56MB to 48.56MB (⬆️0.00%)

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 4, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing feat/esm-tla (aed151a) with main (0f251ee)

Summary

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@JSerFeng
Copy link
Contributor Author

JSerFeng commented Feb 6, 2026

@codex review

@JSerFeng JSerFeng merged commit 17557bf into main Feb 6, 2026
74 of 76 checks passed
@JSerFeng JSerFeng deleted the feat/esm-tla branch February 6, 2026 09:56
@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 🚀

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants