Skip to content

Commit 7820021

Browse files
authored
fix(core): fix module external not treated as async (#9247)
* fix(core): fix module external not treated as async * fix: enable async only when module is false * chore: fix clippy * reafctor: align build_info.module
1 parent 03cc6cf commit 7820021

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

crates/rspack_core/src/external_module.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,16 +533,23 @@ impl Module for ExternalModule {
533533

534534
async fn build(
535535
&mut self,
536-
_build_context: BuildContext,
536+
build_context: BuildContext,
537537
_: Option<&Compilation>,
538538
) -> Result<BuildResult> {
539+
self.build_info.module = build_context.compiler_options.output.module;
539540
let resolved_external_type = self.resolve_external_type();
540541

541542
// TODO add exports_type for request
542543
match resolved_external_type {
543544
"this" => self.build_info.strict = false,
544545
"system" => self.build_meta.exports_type = BuildMetaExportsType::Namespace,
545-
"module" => self.build_meta.exports_type = BuildMetaExportsType::Namespace,
546+
"module" => {
547+
self.build_meta.exports_type = BuildMetaExportsType::Namespace;
548+
// align with https://github.com/webpack/webpack/blob/3919c844eca394d73ca930e4fc5506fb86e2b094/lib/ExternalModule.js#L597
549+
if !self.build_info.module {
550+
self.build_meta.has_top_level_await = true;
551+
}
552+
}
546553
"script" | "promise" => self.build_meta.has_top_level_await = true,
547554
"import" => {
548555
self.build_meta.has_top_level_await = true;

crates/rspack_core/src/module.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub struct BuildInfo {
6868
pub top_level_declarations: Option<HashSet<Atom>>,
6969
pub module_concatenation_bailout: Option<String>,
7070
pub assets: HashMap<String, CompilationAsset>,
71+
pub module: bool,
7172
}
7273

7374
impl Default for BuildInfo {
@@ -87,6 +88,7 @@ impl Default for BuildInfo {
8788
top_level_declarations: None,
8889
module_concatenation_bailout: None,
8990
assets: Default::default(),
91+
module: false,
9092
}
9193
}
9294
}
@@ -168,6 +170,7 @@ impl Display for ExportsArgument {
168170
#[serde(rename_all = "camelCase")]
169171
pub struct BuildMeta {
170172
pub strict_esm_module: bool,
173+
// same as is_async https://github.com/webpack/webpack/blob/3919c844eca394d73ca930e4fc5506fb86e2b094/lib/Module.js#L107
171174
pub has_top_level_await: bool,
172175
pub esm: bool,
173176
pub exports_type: BuildMetaExportsType,

0 commit comments

Comments
 (0)