From 4d515cd780a750c7d7a42435c4b0422ba893456d Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 5 Sep 2024 18:31:55 +0100 Subject: [PATCH] fix(transformer): RegExp transform only set span on final expression --- crates/oxc_transformer/src/regexp/mod.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/oxc_transformer/src/regexp/mod.rs b/crates/oxc_transformer/src/regexp/mod.rs index 68aac4ffafe457..64cd91e12396c9 100644 --- a/crates/oxc_transformer/src/regexp/mod.rs +++ b/crates/oxc_transformer/src/regexp/mod.rs @@ -48,7 +48,7 @@ use oxc_regular_expression::ast::{ CharacterClass, CharacterClassContents, LookAroundAssertionKind, Pattern, Term, }; use oxc_semantic::ReferenceFlags; -use oxc_span::Atom; +use oxc_span::{Atom, SPAN}; use oxc_traverse::{Traverse, TraverseCtx}; use crate::context::Ctx; @@ -164,7 +164,7 @@ impl<'a> Traverse<'a> for RegExp<'a> { let callee = { let symbol_id = ctx.scopes().find_binding(ctx.current_scope_id(), "RegExp"); let ident = ctx.create_reference_id( - regexp.span, + SPAN, Atom::from("RegExp"), symbol_id, ReferenceFlags::read(), @@ -174,14 +174,11 @@ impl<'a> Traverse<'a> for RegExp<'a> { let mut arguments = ctx.ast.vec_with_capacity(2); arguments.push( - ctx.ast.argument_expression( - ctx.ast.expression_string_literal(regexp.span, pattern_source), - ), + ctx.ast.argument_expression(ctx.ast.expression_string_literal(SPAN, pattern_source)), ); let flags = regexp.regex.flags.to_string(); - let flags = - ctx.ast.argument_expression(ctx.ast.expression_string_literal(regexp.span, flags)); + let flags = ctx.ast.argument_expression(ctx.ast.expression_string_literal(SPAN, flags)); arguments.push(flags); *expr = ctx.ast.expression_new(