From fdd97f4fbe287ea45eeb619be2cdc979c490aae1 Mon Sep 17 00:00:00 2001 From: graphemecluster Date: Tue, 28 May 2024 11:12:34 +0800 Subject: [PATCH] Clarify why nested character classes should not be considered in the first pass --- src/compiler/scanner.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 3d1af3309e943..ad6928331f26d 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -2456,6 +2456,9 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean let namedCaptureGroups = false; // Although nested character classes are allowed in Unicode Sets mode, // an unescaped slash is nevertheless invalid even in a character class in any Unicode mode. + // This is indicated by Section 12.9.5 Regular Expression Literals of the specification, + // where nested character classes are not considered at all. (A `[` RegularExpressionClassChar + // does nothing in a RegularExpressionClass, and a `]` always closes the class.) // Additionally, parsing nested character classes will misinterpret regexes like `/[[]/` // as unterminated, consuming characters beyond the slash. (This even applies to `/[[]/v`, // which should be parsed as a well-terminated regex with an incomplete character class.)