diff --git a/src/parse.js b/src/parse.js index 9852ef6..f8775bb 100644 --- a/src/parse.js +++ b/src/parse.js @@ -738,11 +738,10 @@ function getOptimizedGroup(node) { } function isValidGroupNameOniguruma(name) { - // Although Onig group name rules are permissive, the validation here is incomplete and can be - // improved. The more restrictive rules for valid JS group names are accurately captured in - // `isValidGroupNameJs`. Note that backrefs and subroutines might contextually use `-` and `+` to - // indicate relative index or recursion level - return /^[^-+\d)][^)]*$/.test(name); + // The more restrictive rules for valid JS group names are captured in `isValidGroupNameJs`. Note + // that backrefs and subroutines might contextually use `-` and `+` to indicate relative index or + // recursion level + return /^[\p{Alpha}\p{Pc}][^)]*$/u.test(name); } // For any intersection classes that contain only a class, swap the parent with its (modded) child diff --git a/src/transform.js b/src/transform.js index 3563bf2..83986ec 100644 --- a/src/transform.js +++ b/src/transform.js @@ -179,17 +179,17 @@ const FirstPassVisitor = { CharacterSet({node, replaceWith}, {accuracy, minTargetEs2024, digitIsAscii, spaceIsAscii, wordIsAscii}) { const {kind, negate, value} = node; - // Flag D with `\d`, `\p{Digit}`, `[[:digit:]]`` + // Flag D with `\d`, `\p{Digit}`, `[[:digit:]]` if (digitIsAscii && (kind === AstCharacterSetKinds.digit || value === 'digit')) { replaceWith(createCharacterSet(AstCharacterSetKinds.digit, {negate})); return; } - // Flag S with `\s`, `\p{Space}`, `[[:space:]]`` + // Flag S with `\s`, `\p{Space}`, `[[:space:]]` if (spaceIsAscii && (kind === AstCharacterSetKinds.space || value === 'space')) { replaceWith(setNegate(parseFragment(asciiSpaceChar), negate)); return; } - // Flag W with `\w`, `\p{Word}`, `[[:word:]]`` + // Flag W with `\w`, `\p{Word}`, `[[:word:]]` if (wordIsAscii && (kind === AstCharacterSetKinds.word || value === 'word')) { replaceWith(createCharacterSet(AstCharacterSetKinds.word, {negate})); return; @@ -838,7 +838,7 @@ function isLoneGLookaround(node, options) { } function isValidGroupNameJs(name) { - // JS group names are more restrictive than Onig; see `isValidGroupNameOniguruma`, + // JS group names are more restrictive than Onig; see `isValidGroupNameOniguruma` and // return /^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(name); }