Skip to content
Merged
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
21 changes: 13 additions & 8 deletions crates/oxc_transformer/src/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,20 @@ impl<'a, 'ctx> RegExp<'a, 'ctx> {
}

impl<'a> Traverse<'a> for RegExp<'a, '_> {
fn enter_expression(
&mut self,
expr: &mut Expression<'a>,
ctx: &mut oxc_traverse::TraverseCtx<'a>,
) {
// `#[inline]` to avoid cost of function call for all `Expression`s which aren't `RegExpLiteral`s
#[inline]
fn enter_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
if matches!(expr, Expression::RegExpLiteral(_)) {
self.transform_regexp(expr, ctx);
}
}
}

impl<'a> RegExp<'a, '_> {
/// If `RegExpLiteral` contains unsupported syntax or flags, transform to `new RegExp(...)`.
fn transform_regexp(&self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
let Expression::RegExpLiteral(regexp) = expr else {
return;
unreachable!();
};
let regexp = regexp.as_mut();

Expand Down Expand Up @@ -192,9 +199,7 @@ impl<'a> Traverse<'a> for RegExp<'a, '_> {

*expr = ctx.ast.expression_new(regexp.span, callee, arguments, NONE);
}
}

impl<'a> RegExp<'a, '_> {
/// Check if the regular expression contains any unsupported syntax.
///
/// Based on parsed regular expression pattern.
Expand Down
Loading