From 235ca3bd2580a25a767c1f57a4fa22b905f41c8a Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 30 Oct 2026 17:17:33 +0800 Subject: [PATCH] perf(semantic): skip escape checks for unescaped strings (#28507) Account for both quotes when comparing raw and cooked string lengths, skipping escape scans for unescaped strict strings. AI-assisted (Codex). --- crates/oxc_semantic/src/checker/javascript.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index cd3468dd74..9f8677ec93 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -419,7 +419,9 @@ pub fn check_string_literal(lit: &StringLiteral, ctx: &SemanticBuilder<'_>) { } let raw = lit.span.source_text(ctx.source_text); let raw_len = raw.len(); - if raw_len != lit.value.len() { + // Quotes contribute two bytes, and every escape contracts the cooked WTF-8 value. + // Equal content lengths therefore prove that there are no escapes to check. + if raw_len != lit.value.len() + 2 { if raw_len >= MIN_STRING_SIZE_FOR_BATCH_CHECK { let raw_bytes = raw.as_bytes(); // Exclude the last byte (closing quote) from the search haystack.