Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): walk call for_name #9428

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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,15 @@
return;
}

if drive
.call(self, expr, evaluated_callee.identifier())
// if drive
// .call(self, expr, evaluated_callee.identifier())
// .unwrap_or_default()

if evaluated_callee
.identifier()
.call_hooks_name(self, |parser, for_name| {
return drive.call(parser, expr, for_name);

Check failure on line 1016 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
Loading