Skip to content

Commit 4ff1f03

Browse files
committed
check for normalization
1 parent 0799810 commit 4ff1f03

File tree

1 file changed

+19
-0
lines changed
  • turbopack/crates/turbopack-core/src/resolve

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,20 @@ impl Pattern {
524524
Some(new)
525525
}
526526

527+
pub fn is_normalized(&self) -> bool {
528+
match self {
529+
Pattern::Constant(_) => true,
530+
Pattern::Dynamic => true,
531+
Pattern::Alternatives(list) => list
532+
.iter()
533+
.all(|alt| !matches!(alt, Pattern::Alternatives(_)) && alt.is_normalized()),
534+
Pattern::Concatenation(list) => list.iter().all(|alt| {
535+
!matches!(alt, Pattern::Alternatives(_) | Pattern::Concatenation(_))
536+
&& alt.is_normalized()
537+
}),
538+
}
539+
}
540+
527541
/// Order into Alternatives -> Concatenation -> Constant/Dynamic
528542
/// Merge when possible
529543
pub fn normalize(&mut self) {
@@ -669,6 +683,7 @@ impl Pattern {
669683
}
670684
}
671685
}
686+
debug_assert!(self.is_normalized());
672687
}
673688

674689
pub fn filter_could_match(&self, value: &str) -> Option<Pattern> {
@@ -1366,6 +1381,10 @@ pub async fn read_matches(
13661381
force_in_lookup_dir: bool,
13671382
pattern: Vc<Pattern>,
13681383
) -> Result<Vc<PatternMatches>> {
1384+
#[cfg(debug_assertions)]
1385+
if !pattern.await?.is_normalized() {
1386+
panic!("Pattern must be normalized {:?}", pattern.await?);
1387+
}
13691388
let mut prefix = prefix.to_string();
13701389
let pat = pattern.await?;
13711390
let mut results = Vec::new();

0 commit comments

Comments
 (0)