From b29655f7d9c042027f06ef330dd29d47fb72d68b Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 10 Jan 2025 22:40:17 +0000 Subject: [PATCH] refactor(ast): rearrange impls for literal types in same order as they are defined (#8425) Pure refactor. Just move `impl StringLiteral` higher up in `ast_impl/literal.rs`, so the order of impls in `ast_impl/literal.rs` matches the order of type defs in `ast/literal.rs`. --- crates/oxc_ast/src/ast_impl/literal.rs | 70 +++++++++++++------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/crates/oxc_ast/src/ast_impl/literal.rs b/crates/oxc_ast/src/ast_impl/literal.rs index 392bdacab7a2e..676a4734b5c98 100644 --- a/crates/oxc_ast/src/ast_impl/literal.rs +++ b/crates/oxc_ast/src/ast_impl/literal.rs @@ -100,6 +100,41 @@ impl fmt::Display for NumericLiteral<'_> { } } +impl StringLiteral<'_> { + /// Static Semantics: `IsStringWellFormedUnicode` + /// test for \uD800-\uDFFF + /// + /// See: + pub fn is_string_well_formed_unicode(&self) -> bool { + let mut chars = self.value.chars(); + while let Some(c) = chars.next() { + if c == '\\' && chars.next() == Some('u') { + let hex = &chars.as_str()[..4]; + if let Ok(hex) = u32::from_str_radix(hex, 16) { + if (0xd800..=0xdfff).contains(&hex) { + return false; + } + }; + } + } + true + } +} + +impl AsRef for StringLiteral<'_> { + #[inline] + fn as_ref(&self) -> &str { + self.value.as_ref() + } +} + +impl fmt::Display for StringLiteral<'_> { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.value.fmt(f) + } +} + impl BigIntLiteral<'_> { /// Is this BigInt literal zero? (`0n`). pub fn is_zero(&self) -> bool { @@ -262,38 +297,3 @@ impl fmt::Display for RegExpFlags { Ok(()) } } - -impl StringLiteral<'_> { - /// Static Semantics: `IsStringWellFormedUnicode` - /// test for \uD800-\uDFFF - /// - /// See: - pub fn is_string_well_formed_unicode(&self) -> bool { - let mut chars = self.value.chars(); - while let Some(c) = chars.next() { - if c == '\\' && chars.next() == Some('u') { - let hex = &chars.as_str()[..4]; - if let Ok(hex) = u32::from_str_radix(hex, 16) { - if (0xd800..=0xdfff).contains(&hex) { - return false; - } - }; - } - } - true - } -} - -impl AsRef for StringLiteral<'_> { - #[inline] - fn as_ref(&self) -> &str { - self.value.as_ref() - } -} - -impl fmt::Display for StringLiteral<'_> { - #[inline] - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.value.fmt(f) - } -}