Skip to content

Commit 65d728b

Browse files
committed
include query and fragment in request pattern
1 parent cf5594a commit 65d728b

File tree

2 files changed

+76
-6
lines changed

2 files changed

+76
-6
lines changed

turbopack/crates/turbopack-core/src/resolve/parse.rs

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -698,16 +698,68 @@ impl Request {
698698
#[turbo_tasks::function]
699699
pub async fn request_pattern(self: Vc<Self>) -> Result<Vc<Pattern>> {
700700
Ok(match &*self.await? {
701-
Request::Raw { path, .. } => path.clone(),
702-
Request::Relative { path, .. } => path.clone(),
703-
Request::Module { module, path, .. } => {
701+
Request::Raw {
702+
path,
703+
query,
704+
fragment,
705+
..
706+
} => {
707+
let mut path = path.clone();
708+
path.push(Pattern::Constant(query.owned().await?));
709+
path.push(Pattern::Constant(fragment.owned().await?));
710+
path.normalize();
711+
path
712+
}
713+
Request::Relative {
714+
path,
715+
query,
716+
fragment,
717+
..
718+
} => {
719+
let mut path = path.clone();
720+
path.push(Pattern::Constant(query.owned().await?));
721+
path.push(Pattern::Constant(fragment.owned().await?));
722+
path.normalize();
723+
path
724+
}
725+
Request::Module {
726+
module,
727+
path,
728+
query,
729+
fragment,
730+
..
731+
} => {
704732
let mut path = path.clone();
705733
path.push_front(Pattern::Constant(module.clone()));
734+
path.push(Pattern::Constant(query.owned().await?));
735+
path.push(Pattern::Constant(fragment.owned().await?));
736+
path.normalize();
737+
path
738+
}
739+
Request::ServerRelative {
740+
path,
741+
query,
742+
fragment,
743+
..
744+
} => {
745+
let mut path = path.clone();
746+
path.push(Pattern::Constant(query.owned().await?));
747+
path.push(Pattern::Constant(fragment.owned().await?));
748+
path.normalize();
749+
path
750+
}
751+
Request::Windows {
752+
path,
753+
query,
754+
fragment,
755+
..
756+
} => {
757+
let mut path = path.clone();
758+
path.push(Pattern::Constant(query.owned().await?));
759+
path.push(Pattern::Constant(fragment.owned().await?));
706760
path.normalize();
707761
path
708762
}
709-
Request::ServerRelative { path, .. } => path.clone(),
710-
Request::Windows { path, .. } => path.clone(),
711763
Request::Empty => Pattern::Constant("".into()),
712764
Request::PackageInternal { path } => path.clone(),
713765
Request::DataUri {
@@ -722,8 +774,12 @@ impl Request {
722774
Request::Uri {
723775
protocol,
724776
remainder,
777+
query,
778+
fragment,
725779
..
726-
} => Pattern::Constant(format!("{protocol}{remainder}").into()),
780+
} => Pattern::Constant(
781+
format!("{protocol}{remainder}{}{}", query.await?, fragment.await?).into(),
782+
),
727783
Request::Unknown { path } => path.clone(),
728784
Request::Dynamic => Pattern::Dynamic,
729785
Request::Alternatives { requests } => Pattern::Alternatives(

turbopack/crates/turbopack-core/src/resolve/pattern.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ impl Pattern {
142142
}
143143
}
144144

145+
pub fn is_empty_constant(&self) -> bool {
146+
if let Pattern::Constant(c) = self {
147+
c.is_empty()
148+
} else {
149+
false
150+
}
151+
}
152+
145153
pub fn constant_prefix(&self) -> &str {
146154
// The normalized pattern is an Alternative of maximally merged
147155
// Concatenations, so extracting the first/only Concatenation child
@@ -367,6 +375,9 @@ impl Pattern {
367375

368376
/// Appends something to end the pattern.
369377
pub fn push(&mut self, pat: Pattern) {
378+
if pat.is_empty_constant() {
379+
return;
380+
}
370381
match (self, pat) {
371382
(Pattern::Concatenation(list), Pattern::Concatenation(more)) => {
372383
concatenation_extend_or_merge_items(list, more.into_iter());
@@ -391,6 +402,9 @@ impl Pattern {
391402

392403
/// Prepends something to front of the pattern.
393404
pub fn push_front(&mut self, pat: Pattern) {
405+
if pat.is_empty_constant() {
406+
return;
407+
}
394408
match (self, pat) {
395409
(Pattern::Concatenation(list), Pattern::Concatenation(mut more)) => {
396410
concatenation_extend_or_merge_items(&mut more, take(list).into_iter());

0 commit comments

Comments
 (0)