Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ast): rearrange impls for literal types in same order as they are defined #8425

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions crates/oxc_ast/src/ast_impl/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,41 @@ impl fmt::Display for NumericLiteral<'_> {
}
}

impl StringLiteral<'_> {
/// Static Semantics: `IsStringWellFormedUnicode`
/// test for \uD800-\uDFFF
///
/// See: <https://tc39.es/ecma262/multipage/abstract-operations.html#sec-isstringwellformedunicode>
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<str> 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 {
Expand Down Expand Up @@ -262,38 +297,3 @@ impl fmt::Display for RegExpFlags {
Ok(())
}
}

impl StringLiteral<'_> {
/// Static Semantics: `IsStringWellFormedUnicode`
/// test for \uD800-\uDFFF
///
/// See: <https://tc39.es/ecma262/multipage/abstract-operations.html#sec-isstringwellformedunicode>
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<str> 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)
}
}
Loading