Skip to content

JavaScript identifier handling: differences to spec #191

@gandaro

Description

@gandaro

The code for JavaScript identifiers:

/// Check if a character can start a JS identifier.
#[must_use]
pub fn id_start(char: char) -> bool {
UnicodeID::is_id_start(char) || matches!(char, '$' | '_')
}
/// Check if a character can continue a JS (or JSX) identifier.
#[must_use]
pub fn id_cont(char: char, jsx: bool) -> bool {
UnicodeID::is_id_continue(char)
|| matches!(char, '\u{200c}' | '\u{200d}')
|| (jsx && char == '-')
}

... has some issues:

  1. It does not seem to recognize the literal string \u1234 or \u{1234} (see UnicodeEscapeSequence production in ECMAScript) as a valid character in starting/continuing characters—though I am not sure if this is the case; you might convert such instances to Unicode characters beforehand, I do not know.
  2. It does not recognize "$" within a JS identifier (see IdentifierPartChar production in ECMAScript).
  3. I don't know why you allow U+200C and U+200D in id_cont; those are not "special" in the productions I looked at in JSX or ECMAScript.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions