perf(regex): remove redundant character-class and quantifier checks (#28288)

Character classes cannot contain strings outside Unicode sets mode, and
existing parser invariants already establish the removed class-string
and quantifier checks.

AI-assisted implementation.
This commit is contained in:
Boshen authored and GitHub committed 2026-10-29 16:30:16 +08:00
1 parent ec8e8d4c08
commit ab5655ae5c
8 files changed
+30 -18

No files matched your search

@@ -782,7 +782,10 @@ impl<'a> PatternParser<'a> {
let (kind, body) = self.parse_class_contents()?;
if self.reader.eat(']') {
let strings = PatternParser::may_contain_strings_in_class_contents(kind, &body);
// Without UnicodeSetsMode, ClassContents is empty or NonemptyClassRanges,
// whose MayContainStrings is always false.
let strings = self.state.unicode_sets_mode
&& PatternParser::may_contain_strings_in_class_contents(kind, &body);
// [SS:EE] CharacterClass :: [^ ClassContents ]
// It is a Syntax Error if MayContainStrings of the ClassContents is true.
@@ -1432,10 +1435,6 @@ impl<'a> PatternParser<'a> {
}
}
if body.is_empty() {
strings = true;
}
Ok((body, strings))
}
@@ -1777,7 +1776,7 @@ impl<'a> PatternParser<'a> {
self.span_factory.create(span_start, self.reader.offset()),
));
}
if MAX_QUANTIFIER < min || MAX_QUANTIFIER < max {
if MAX_QUANTIFIER < max {
return Err(diagnostics::too_large_number_in_braced_quantifier(
self.span_factory.create(span_start, self.reader.offset()),
));
@@ -0,0 +1,13 @@
const patterns = [
/[]/,
/[a-z\d]/,
/[a-z\p{Letter}]/u,
/[a-z]/v,
/[\q{}]/v,
/[\q{a|b}]/v,
/[\q{ab}]/v,
/[\p{Basic_Emoji}]/v,
/[[\q{ab}]&&[a-z]]/v,
/[[\q{ab}]--[a-z]]/v,
/[[a-z]--[\q{ab}]]/v,
];
+2 -2
View File
@@ -1,3 +1,3 @@
codegen_misc Summary:
AST Parsed : 118/118 (100.00%)
Positive Passed: 118/118 (100.00%)
AST Parsed : 119/119 (100.00%)
Positive Passed: 119/119 (100.00%)
+2 -2
View File
@@ -1,3 +1,3 @@
formatter_misc Summary:
AST Parsed : 118/118 (100.00%)
Positive Passed: 118/118 (100.00%)
AST Parsed : 119/119 (100.00%)
Positive Passed: 119/119 (100.00%)
+2 -2
View File
@@ -1,3 +1,3 @@
lexer_misc Summary:
AST Parsed : 373/373 (100.00%)
Positive Passed: 373/373 (100.00%)
AST Parsed : 374/374 (100.00%)
Positive Passed: 374/374 (100.00%)
+2 -2
View File
@@ -1,6 +1,6 @@
parser_misc Summary:
AST Parsed : 118/118 (100.00%)
Positive Passed: 118/118 (100.00%)
AST Parsed : 119/119 (100.00%)
Positive Passed: 119/119 (100.00%)
Negative Passed: 257/257 (100.00%)
× TS(1275): 'accessor' modifier can only appear on a property declaration.
+2 -2
View File
@@ -1,6 +1,6 @@
semantic_misc Summary:
AST Parsed : 118/118 (100.00%)
Positive Passed: 112/118 (94.92%)
AST Parsed : 119/119 (100.00%)
Positive Passed: 113/119 (94.96%)
semantic Error: tasks/coverage/misc/pass/declare-let-private.ts
Bindings mismatch:
after transform: ScopeId(0): ["private"]
@@ -1,3 +1,3 @@
transformer_misc Summary:
AST Parsed : 118/118 (100.00%)
Positive Passed: 118/118 (100.00%)
AST Parsed : 119/119 (100.00%)
Positive Passed: 119/119 (100.00%)