From ea6b79659927596fadae44535b34776a2b7ab47a Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 24 Feb 2026 16:04:12 +0000 Subject: [PATCH] feat(parser): add `LexerConfig::TOKENS_METHOD_IS_STATIC` const (#19683) Add a const to `LexerConfig` trait indicating whether the config is static or runtime. This will be useful optimization in a later PR. --- crates/oxc_parser/src/config.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/oxc_parser/src/config.rs b/crates/oxc_parser/src/config.rs index ac70ce9dc3bec..065916b470cac 100644 --- a/crates/oxc_parser/src/config.rs +++ b/crates/oxc_parser/src/config.rs @@ -114,6 +114,16 @@ pub trait LexerConfig: Default { /// Byte handlers table type. type ByteHandlers: Index>; + /// `true` if [`tokens`] method returns a static value. + /// + /// This const is useful in situations where code can be more efficient + /// when the return value of [`tokens`] method is known at compile time. + /// + /// Implementors of this trait MUST only set this const to `true` if [`tokens`] method returns a static value. + /// + /// [`tokens`]: LexerConfig::tokens + const TOKENS_METHOD_IS_STATIC: bool; + /// Returns `true` if tokens are enabled. fn tokens(&self) -> bool; @@ -128,6 +138,8 @@ pub struct NoTokensLexerConfig; impl LexerConfig for NoTokensLexerConfig { type ByteHandlers = ByteHandlers; + const TOKENS_METHOD_IS_STATIC: bool = true; + #[inline(always)] fn tokens(&self) -> bool { false @@ -146,6 +158,8 @@ pub struct TokensLexerConfig; impl LexerConfig for TokensLexerConfig { type ByteHandlers = ByteHandlers; + const TOKENS_METHOD_IS_STATIC: bool = true; + #[inline(always)] fn tokens(&self) -> bool { true @@ -174,6 +188,8 @@ impl RuntimeLexerConfig { impl LexerConfig for RuntimeLexerConfig { type ByteHandlers = ByteHandlers; + const TOKENS_METHOD_IS_STATIC: bool = false; + #[inline(always)] fn tokens(&self) -> bool { self.tokens