diff --git a/crates/oxc_transformer/src/plugins/tagged_template_transform.rs b/crates/oxc_transformer/src/plugins/tagged_template_transform.rs index 6b3acb421ee82..567c33af7e136 100644 --- a/crates/oxc_transformer/src/plugins/tagged_template_transform.rs +++ b/crates/oxc_transformer/src/plugins/tagged_template_transform.rs @@ -52,6 +52,9 @@ use crate::{ state::TransformState, }; +const SCRIPT_TAG: &[u8; 8] = b" { ctx: &'ctx TransformCtx<'a>, } @@ -71,27 +74,27 @@ impl<'a, 'ctx> TaggedTemplateTransform<'a, 'ctx> { /// Check if the template literal contains a ` bool { - const SCRIPT_TAG: &[u8] = b" TaggedTemplateTransform<'a, 'ctx> { } /// Transform a tagged template expression to use the [`Helper::TaggedTemplateLiteral`] helper function - // `#[inline]` so that compiler can see `expr` should be a `TaggedTemplateExpression` and reduce redundant checks - #[inline] fn transform_tagged_template(&self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { if !matches!(expr, Expression::TaggedTemplateExpression(tagged) if Self::contains_closing_script_tag(&tagged.quasi)) { @@ -236,3 +237,24 @@ impl<'a, 'ctx> TaggedTemplateTransform<'a, 'ctx> { binding } } + +/// Check if `slice` is ` bool { + // Compiler condenses these operations to an 8-byte read, u64 AND, and u64 compare. + // https://godbolt.org/z/K8q68WGn6 + let mut bytes: [u8; 8] = slice.try_into().unwrap(); + for byte in bytes.iter_mut().skip(2) { + // `| 32` converts ASCII upper case letters to lower case. + *byte |= 32; + } + bytes == *SCRIPT_TAG +}