Skip to content

Commit 101d24e

Browse files
authored
Merge branch 'main' into feat/manifest-builtin
2 parents 0b12bd1 + 5cba000 commit 101d24e

File tree

36 files changed

+459
-359
lines changed

36 files changed

+459
-359
lines changed

Cargo.lock

Lines changed: 10 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ micromegas-perfetto = { version = "0.9.0", default-features = false }
6464
miette = { version = "7.5.0", default-features = false }
6565
mimalloc = { version = "0.2.4", package = "mimalloc-rspack", default-features = false }
6666
mime_guess = { version = "2.0.5", default-features = false, features = ["rev-mappings"] }
67-
notify = { version = "8.1.0", default-features = false }
67+
notify = { version = "8.2.0", default-features = false }
6868
num-bigint = { version = "0.4.6", default-features = false }
6969
once_cell = { version = "1.20.2", default-features = false }
7070
oneshot = { version = "0.1.8", default-features = false, features = ["std", "async"] }
@@ -78,7 +78,7 @@ proc-macro2 = { version = "1.0.92", default-features = false }
7878
prost = { version = "0.13", default-features = false }
7979
quote = { version = "1.0.38", default-features = false }
8080
rayon = { version = "1.10.0", default-features = false }
81-
regex = { version = "1.11.1", default-features = false }
81+
regex = { version = "1.12.2", default-features = false }
8282
regex-syntax = { version = "0.8.5", default-features = false, features = ["std"] }
8383
regress = { version = "0.10.4", default-features = false, features = ["pattern"] }
8484
ropey = { version = "1.6.1", default-features = false }
@@ -100,7 +100,7 @@ syn = { version = "2.0.95", default-features = false }
100100
termcolor = { version = "1.4.1", default-features = false }
101101
textwrap = { version = "0.16.1", default-features = false }
102102
thread_local = { version = "1.1.9", default-features = false }
103-
tokio = { version = "1.42.0", default-features = false, features = ["rt", "rt-multi-thread"] }
103+
tokio = { version = "1.48.0", default-features = false, features = ["rt", "rt-multi-thread"] }
104104
toml = { version = "0.8.19", default-features = false, features = ["parse", "display"] }
105105
tracing = { version = "0.1.41", default-features = false, features = ["max_level_trace", "release_max_level_trace"] }
106106
tracing-subscriber = { version = "0.3.19", default-features = false, features = ["fmt", "registry"] }

crates/rspack_core/src/compilation/make/module_executor/entry.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ impl Task<ExecutorTaskContext> for EntryTask {
4040
executed_entry_deps,
4141
} = context;
4242

43+
if tracker.is_module_building(&meta.origin_module_identifier) {
44+
execute_task.finish_with_error(rspack_error::error!(
45+
"Nested calls to importModule are not supported. MetaInfo: {:?}",
46+
meta
47+
));
48+
return Ok(vec![]);
49+
}
50+
4351
let mut res = vec![];
4452
let (dep_id, is_new) = match entries.entry(meta.clone()) {
4553
Entry::Vacant(v) => {
@@ -90,7 +98,7 @@ impl Task<ExecutorTaskContext> for EntryTask {
9098
// mark as executed
9199
executed_entry_deps.insert(dep_id);
92100

93-
if tracker.is_running(&dep_id) {
101+
if tracker.is_entry_running(&dep_id) {
94102
let mg = origin_context.artifact.get_module_graph();
95103
// the module in module executor need to check.
96104
if mg

crates/rspack_core/src/compilation/make/module_executor/module_tracker.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,16 @@ impl ModuleTracker {
197197
}
198198
}
199199

200-
/// Check if a dep_id is running
201-
pub fn is_running(&self, dep_id: &DependencyId) -> bool {
200+
/// Check if a entry dep_id is running
201+
pub fn is_entry_running(&self, dep_id: &DependencyId) -> bool {
202202
self.entry_finish_tasks.contains_key(dep_id)
203203
}
204+
205+
/// Check if a module is building
206+
pub fn is_module_building(&self, mid: &ModuleIdentifier) -> bool {
207+
let Some(child) = self.unfinished_module.get(mid) else {
208+
return false;
209+
};
210+
child == &usize::MAX
211+
}
204212
}

crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ impl JavascriptParserPlugin for CommonJsExportsParserPlugin {
402402
&self,
403403
parser: &mut JavascriptParser,
404404
expr: &swc_core::ecma::ast::ThisExpr,
405+
_for_name: &str,
405406
) -> Option<bool> {
406407
if self.should_skip_handler(parser) {
407408
return None;

crates/rspack_plugin_javascript/src/parser_plugin/drive.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,10 @@ impl JavascriptParserPlugin for JavaScriptParserPluginDrive {
454454
&self,
455455
parser: &mut JavascriptParser,
456456
expr: &swc_core::ecma::ast::ThisExpr,
457+
for_name: &str,
457458
) -> Option<bool> {
458459
for plugin in &self.plugins {
459-
let res = plugin.this(parser, expr);
460+
let res = plugin.this(parser, expr, for_name);
460461
// `SyncBailHook`
461462
if res.is_some() {
462463
return res;

crates/rspack_plugin_javascript/src/parser_plugin/esm_top_level_this_plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ impl JavascriptParserPlugin for ESMTopLevelThisParserPlugin {
1010
&self,
1111
parser: &mut JavascriptParser,
1212
expr: &swc_core::ecma::ast::ThisExpr,
13+
_for_name: &str,
1314
) -> Option<bool> {
1415
(parser.is_esm && parser.is_top_level_this()).then(|| {
1516
parser.add_presentational_dependency(Box::new(ConstDependency::new(

crates/rspack_plugin_javascript/src/parser_plugin/inner_graph/plugin.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use crate::{
2020
is_pure_class, is_pure_class_member, is_pure_expression, is_pure_function,
2121
},
2222
visitors::{
23-
JavascriptParser, Statement, TagInfoData, VariableDeclaration, scope_info::VariableInfoFlags,
23+
ExportedVariableInfo, JavascriptParser, Statement, TagInfoData, VariableDeclaration,
24+
scope_info::VariableInfoFlags,
2425
},
2526
};
2627

@@ -639,19 +640,42 @@ impl JavascriptParserPlugin for InnerGraphPlugin {
639640
fn class_body_element(
640641
&self,
641642
parser: &mut JavascriptParser,
642-
_element: &swc_core::ecma::ast::ClassMember,
643+
element: &ClassMember,
643644
class_decl_or_expr: crate::visitors::ClassDeclOrExpr,
644645
) -> Option<bool> {
645646
if !parser.inner_graph.is_enabled() || !parser.is_top_level_scope() {
646647
return None;
647648
}
648-
649-
if parser
649+
if let Some(top_level_symbol) = parser
650650
.inner_graph
651651
.class_with_top_level_symbol
652-
.contains_key(&class_decl_or_expr.span())
652+
.get(&class_decl_or_expr.span())
653653
{
654+
let top_level_symbol_variable_name = top_level_symbol.name.clone();
654655
parser.inner_graph.set_top_level_symbol(None);
656+
/*
657+
* ```js
658+
* var A = class B {
659+
* static {
660+
* this;
661+
* B;
662+
* }
663+
* }
664+
* ```
665+
* Alias `this` and `B` (class ident) to top level symbol `A` here, so `A` is used if `this` or `B`
666+
* is used in static block (`add_usage` in identifier hook and this hook), even `A` is not used in
667+
* any other place.
668+
*/
669+
if let ClassMember::StaticBlock(_) = element {
670+
let class_var = parser
671+
.get_variable_info(&top_level_symbol_variable_name)
672+
.map(|info| ExportedVariableInfo::VariableInfo(info.id()))
673+
.unwrap_or(ExportedVariableInfo::Name(top_level_symbol_variable_name));
674+
if let Some(class_ident) = class_decl_or_expr.ident() {
675+
parser.set_variable(class_ident.sym.clone(), class_var.clone());
676+
}
677+
parser.set_variable("this".into(), class_var);
678+
}
655679
}
656680

657681
None
@@ -804,4 +828,14 @@ impl JavascriptParserPlugin for InnerGraphPlugin {
804828
Self::for_each_expression(parser, for_name);
805829
None
806830
}
831+
832+
fn this(
833+
&self,
834+
parser: &mut JavascriptParser,
835+
_expr: &swc_core::ecma::ast::ThisExpr,
836+
for_name: &str,
837+
) -> Option<bool> {
838+
Self::for_each_expression(parser, for_name);
839+
None
840+
}
807841
}

crates/rspack_plugin_javascript/src/parser_plugin/side_effects_parser_plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ pub fn is_pure_class(
454454
}
455455
ClassMember::TsIndexSignature(_) => unreachable!(),
456456
ClassMember::Empty(_) => true,
457-
ClassMember::StaticBlock(_) => true,
458-
ClassMember::AutoAccessor(_) => true,
457+
ClassMember::StaticBlock(_) => false, // TODO: support is pure analyze for statements
458+
ClassMember::AutoAccessor(_) => false,
459459
}
460460
})
461461
}

crates/rspack_plugin_javascript/src/parser_plugin/trait.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,12 @@ pub trait JavascriptParserPlugin {
302302
None
303303
}
304304

305-
fn this(&self, _parser: &mut JavascriptParser, _expr: &ThisExpr) -> Option<bool> {
305+
fn this(
306+
&self,
307+
_parser: &mut JavascriptParser,
308+
_expr: &ThisExpr,
309+
_for_name: &str,
310+
) -> Option<bool> {
306311
None
307312
}
308313

0 commit comments

Comments
 (0)