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: align parser.walk_expression to webpack, which put into context_dependency_helper #6963

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix index
  • Loading branch information
CPunisher committed Jun 28, 2024
commit 774975a21cf6c922dcda450c07fe5b3f001df856
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;

use itertools::Either;
use itertools::Itertools;
use rspack_core::parse_resource;
use rspack_core::SpanExt;
Expand Down Expand Up @@ -61,10 +62,16 @@ pub fn create_context_dependency(
.parts()
.into_iter()
.enumerate()
.partition(|&(index, _)| index % 2 == 0);
.partition_map(|(index, part)| {
if index % 2 == 0 {
Either::Left(part)
} else {
Either::Right(part)
}
});
let last_index = even_parts.len() - 1;

for (i, part) in even_parts {
for (i, part) in even_parts.into_iter().enumerate() {
if i == 0 {
let value = format!(
"{}{prefix}",
Expand All @@ -88,7 +95,7 @@ pub fn create_context_dependency(
}

let mut walker = ExprSpanFinder {
targets: odd_parts.into_iter().map(|(_, part)| part).collect_vec(),
targets: odd_parts,
on_visit: |n| parser.walk_expression(n),
};
expr.visit_with(&mut walker);
Expand Down