From 6e80e03bb6d6af47aba2b339f160e4895ab5afba Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 6 Oct 2022 12:12:36 +0200 Subject: Refactor to share identifier methods --- src/util/identifier.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/util/identifier.rs (limited to 'src/util/identifier.rs') diff --git a/src/util/identifier.rs b/src/util/identifier.rs new file mode 100644 index 0000000..4887e02 --- /dev/null +++ b/src/util/identifier.rs @@ -0,0 +1,15 @@ +//! Info on JavaScript identifiers. + +use unicode_id::UnicodeID; + +/// Check if a character can start a JS identifier. +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. +pub fn id_cont(char: char, jsx: bool) -> bool { + UnicodeID::is_id_continue(char) + || matches!(char, '\u{200c}' | '\u{200d}') + || (jsx && char == '-') +} -- cgit