Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Oct 17, 2024
1 parent c49813c commit 5c8961b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions crates/oxc_syntax/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,39 @@ pub const SP: char = '\u{20}';
/// U+00A0 NON-BREAKING SPACE, abbreviated `<NBSP>`.
pub const NBSP: char = '\u{a0}';

pub fn is_irregular_whitespace(c: char) -> bool {
matches!(
c,
VT | FF | NBSP | ZWNBSP | '\u{85}' | '\u{1680}' | '\u{2000}'
..='\u{200a}' | '\u{202f}' | '\u{205f}' | '\u{3000}'
)
}

// U+0085 NEXT LINE, abbreviated `<NEL>`.
const NEL: char = '\u{85}';

const OGHAM_SPACE_MARK: char = '\u{1680}';

const EN_QUAD: char = '\u{2000}';

// U+200B ZERO WIDTH SPACE, abbreviated `<ZWSP>`.
const ZWSP: char = '\u{200b}';

// Narrow No-Break Space
// Narrow NO-BREAK SPACE, abbreviated `<NNBSP>`.
const NNBSP: char = '\u{202f}';

// Medium Mathematical Space
// U+205F MEDIUM MATHEMATICAL SPACE, abbreviated `<MMSP>`.
const MMSP: char = '\u{205f}';

const IDEOGRAPHIC_SPACE: char = '\u{3000}';

pub fn is_irregular_whitespace(c: char) -> bool {
matches!(
c,
VT | FF | NBSP | ZWNBSP | NEL | OGHAM_SPACE_MARK | EN_QUAD
..ZWSP | NNBSP | MMSP | IDEOGRAPHIC_SPACE
)
}

// https://github.com/microsoft/TypeScript/blob/b8e4ed8aeb0b228f544c5736908c31f136a9f7e3/src/compiler/scanner.ts#L556
// TODO: Unclear why we match `ZWSP` here, and not in `is_irregular_whitespace`.
// https://github.com/oxc-project/oxc/pull/6639
pub fn is_white_space_single_line(c: char) -> bool {
// Note: nextLine is in the Zs space, and should be considered to be a whitespace.
// It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript.
matches!(
c,
SP | TAB | VT | FF | NBSP | NEL | OGHAM_SPACE_MARK | EN_QUAD
..=ZWSP | NNBSP | MMSP | IDEOGRAPHIC_SPACE | ZWNBSP
)
matches!(c, SP | TAB | ZWSP) || is_irregular_whitespace(c)
}

// 11.3 Line Terminators
Expand Down

0 comments on commit 5c8961b

Please sign in to comment.