Skip to content
Open
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
19 changes: 14 additions & 5 deletions core/parser/src/lexer/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ impl Identifier {
/// [spec]: https://tc39.es/ecma262/#sec-names-and-keywords
pub(super) fn is_identifier_start(ch: u32) -> bool {
const ID_START: CodePointSetDataBorrowed<'static> = CodePointSetData::new::<IdStart>();
matches!(ch, 0x0024 /* $ */ | 0x005F /* _ */) || ID_START.contains32(ch)
if ch < 0x80 {
// ASCII fast path: `ID_Start` in ASCII is exactly `A-Z` and `a-z`.
#[allow(clippy::cast_possible_truncation)]
let b = ch as u8;
return b.is_ascii_alphabetic() || b == b'$' || b == b'_';
}
ID_START.contains32(ch)
}

/// Checks if a character is `IdentifierPart` as per ECMAScript standards.
Expand All @@ -47,10 +53,13 @@ impl Identifier {
fn is_identifier_part(ch: u32) -> bool {
const ID_CONTINUE: CodePointSetDataBorrowed<'static> =
CodePointSetData::new::<IdContinue>();
matches!(
ch,
0x0024 /* $ */ | 0x005F /* _ */ | 0x200C /* <ZWNJ> */ | 0x200D /* <ZWJ> */
) || ID_CONTINUE.contains32(ch)
if ch < 0x80 {
// ASCII fast path: `ID_Continue` in ASCII is exactly `0-9`, `A-Z`, `a-z` and `_`.
#[allow(clippy::cast_possible_truncation)]
let b = ch as u8;
return b.is_ascii_alphanumeric() || b == b'$' || b == b'_';
}
matches!(ch, 0x200C /* <ZWNJ> */ | 0x200D /* <ZWJ> */) || ID_CONTINUE.contains32(ch)
}
}

Expand Down