Skip to content

Commit

Permalink
fix(parser): walk call for_name
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Feb 21, 2025
1 parent 6c8b2c4 commit 6d345e6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rspack_core::{ConstDependency, RuntimeGlobals, SpanExt};
use rspack_util::atom::Atom;
use swc_core::ecma::ast::{CallExpr, Expr, MemberExpr};
use swc_core::{common::Spanned, ecma::ast::UnaryExpr};

Expand Down Expand Up @@ -175,6 +176,7 @@ impl JavascriptParserPlugin for AMDParserPlugin {
Some(true),
start,
end,
Some(vec![Atom::from("amd")]),
));
}

Expand All @@ -185,6 +187,7 @@ impl JavascriptParserPlugin for AMDParserPlugin {
Some(true),
start,
end,
Some(vec![Atom::from("amd")]),
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rspack_core::{
};
use rspack_core::{ContextNameSpaceObject, ContextOptions};
use rspack_error::{DiagnosticExt, Severity};
use rspack_util::atom::Atom;
use swc_core::common::{Span, Spanned};
use swc_core::ecma::ast::{CallExpr, Expr, ExprOrSpread, Ident, MemberExpr, NewExpr, UnaryExpr};

Expand Down Expand Up @@ -386,15 +387,15 @@ impl CommonJsImportsParserPlugin {

impl JavascriptParserPlugin for CommonJsImportsParserPlugin {
fn can_rename(&self, parser: &mut JavascriptParser, str: &str) -> Option<bool> {

Check failure on line 389 in crates/rspack_plugin_javascript/src/parser_plugin/common_js_imports_parse_plugin.rs

View workflow job for this annotation

GitHub Actions / Rust check

unused variable: `parser`
if str == expr_name::REQUIRE && parser.is_unresolved_ident(str) {
if str == expr_name::REQUIRE {
Some(true)
} else {
None
}
}

fn rename(&self, parser: &mut JavascriptParser, expr: &Expr, str: &str) -> Option<bool> {
if str == expr_name::REQUIRE && parser.is_unresolved_ident(str) {
if str == expr_name::REQUIRE {
parser
.presentational_dependencies
.push(Box::new(ConstDependency::new(
Expand Down Expand Up @@ -441,20 +442,23 @@ impl JavascriptParserPlugin for CommonJsImportsParserPlugin {
Some(true),
start,
end,
Some(vec![]),
)),
expr_name::REQUIRE_RESOLVE => Some(eval::evaluate_to_identifier(
expr_name::REQUIRE_RESOLVE.to_string(),
expr_name::REQUIRE.to_string(),
Some(true),
start,
end,
Some(vec![Atom::from("resolve")]),
)),
expr_name::REQUIRE_RESOLVE_WEAK => Some(eval::evaluate_to_identifier(
expr_name::REQUIRE_RESOLVE_WEAK.to_string(),
expr_name::REQUIRE.to_string(),
Some(true),
start,
end,
Some(vec![Atom::from("resolveWeak")]),
)),
_ => None,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl JavascriptParserPlugin for ModuleHotReplacementParserPlugin {
Some(true),
start,
end,
Some(vec![Atom::from("hot")]),
))
} else {
None
Expand Down Expand Up @@ -199,6 +200,7 @@ impl JavascriptParserPlugin for ImportMetaHotReplacementParserPlugin {
Some(true),
start,
end,
Some(vec![Atom::from("webpackHot")]),
))
} else {
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use rspack_core::{
ContextMode, ContextNameSpaceObject, ContextOptions, DependencyCategory, SpanExt,
};
use rspack_regex::RspackRegex;
use rspack_util::atom::Atom;
use swc_core::common::Spanned;
use swc_core::ecma::ast::{CallExpr, Lit};

Expand Down Expand Up @@ -121,6 +122,7 @@ impl JavascriptParserPlugin for ImportMetaContextDependencyParserPlugin {
Some(true),
start,
end,
Some(vec![Atom::from("webpackContext")]),
))
} else {
None
Expand Down
3 changes: 2 additions & 1 deletion crates/rspack_plugin_javascript/src/utils/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,13 @@ pub fn evaluate_to_identifier(
truthy: Option<bool>,
start: u32,
end: u32,
get_members: Option<Vec<Atom>>,
) -> BasicEvaluatedExpression {
let mut eval = BasicEvaluatedExpression::with_range(start, end);
eval.set_identifier(
identifier,
ExportedVariableInfo::Name(root_info),
None,
get_members,
None,
None,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,17 @@ impl JavascriptParser<'_> {
return;
}

if drive
.call(self, expr, evaluated_callee.identifier())
dbg!(&evaluated_callee);

Check failure on line 1009 in crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs

View workflow job for this annotation

GitHub Actions / Rust check

the `dbg!` macro is intended as a debugging tool
// if drive
// .call(self, expr, evaluated_callee.identifier())
// .unwrap_or_default()

if evaluated_callee
.identifier()
.call_hooks_name(self, |parser, for_name| {
dbg!(evaluated_callee.identifier(), for_name);

Check failure on line 1017 in crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs

View workflow job for this annotation

GitHub Actions / Rust check

the `dbg!` macro is intended as a debugging tool
return drive.call(parser, expr, for_name);

Check failure on line 1018 in crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs

View workflow job for this annotation

GitHub Actions / Rust check

unneeded `return` statement
})
.unwrap_or_default()
{
/* result2 */
Expand Down

0 comments on commit 6d345e6

Please sign in to comment.