From 2683225190d22774a2b87a29663e1939e7ecfae6 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 29 Oct 2026 01:08:46 +0000 Subject: [PATCH] perf(str): `static_ident!` and `static_str!` macros guarantee const evaluation (#28340) `static_ident!` and `static_str!` macros are intended to evaluate at compile time. This is especially valuable for `static_ident!` as we want the hash to be calculated at compile time. Wrap both in a `const { ... }` block to ensure they are const-evaluated. --- crates/oxc_str/src/ident.rs | 3 ++- crates/oxc_str/src/str.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/oxc_str/src/ident.rs b/crates/oxc_str/src/ident.rs index fba0d9a471..14a812c3c8 100644 --- a/crates/oxc_str/src/ident.rs +++ b/crates/oxc_str/src/ident.rs @@ -581,7 +581,8 @@ pub type ArenaIdentHashSet<'alloc> = #[macro_export] macro_rules! static_ident { ($s:literal) => { - $crate::__internal::new_const_ident($s) + // `const { ... }` block guarantees evaluation at compile time + const { $crate::__internal::new_const_ident($s) } }; } diff --git a/crates/oxc_str/src/str.rs b/crates/oxc_str/src/str.rs index 30c0aac04b..fd2bbc3ed0 100644 --- a/crates/oxc_str/src/str.rs +++ b/crates/oxc_str/src/str.rs @@ -341,7 +341,8 @@ impl ESTree for Str<'_> { #[macro_export] macro_rules! static_str { ($s:literal) => { - $crate::Str::new_const($s) + // `const { ... }` block guarantees evaluation at compile time + const { $crate::Str::new_const($s) } }; }