Skip to content

Commit

Permalink
fix(transformer): RegExp transform handle Term::Quantifier
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Sep 5, 2024
1 parent a96866d commit c0cebaa
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions crates/oxc_transformer/src/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,27 +197,33 @@ impl<'a> RegExp<'a> {
///
/// Based on parsed regular expression pattern.
fn has_unsupported_regular_expression_pattern(&self, pattern: &Pattern<'a>) -> bool {
let terms_contains_unsupported = |terms: &[Term]| {
terms.iter().any(|term| match term {
Term::CapturingGroup(_) => self.named_capture_groups,
Term::UnicodePropertyEscape(_) => self.unicode_property_escapes,
pattern.body.body.iter().any(|alternative| {
alternative.body.iter().any(|term| self.term_contains_unsupported(term))
})
}

fn term_contains_unsupported(&self, mut term: &Term) -> bool {
// Loop because `Term::Quantifier` contains a nested `Term`
loop {
match term {
Term::CapturingGroup(_) => return self.named_capture_groups,
Term::UnicodePropertyEscape(_) => return self.unicode_property_escapes,
Term::CharacterClass(character_class) => {
self.unicode_property_escapes
return self.unicode_property_escapes
&& character_class_has_unicode_property_escape(character_class)
}
Term::LookAroundAssertion(assertion) => {
self.look_behind_assertions
return self.look_behind_assertions
&& matches!(
assertion.kind,
LookAroundAssertionKind::Lookbehind
| LookAroundAssertionKind::NegativeLookbehind
)
}
_ => false,
})
};

pattern.body.body.iter().any(|alternative| terms_contains_unsupported(&alternative.body))
Term::Quantifier(quantifier) => term = &quantifier.body,
_ => return false,
}
}
}
}

Expand Down

0 comments on commit c0cebaa

Please sign in to comment.