Skip to content

Commit

Permalink
RegExp syntax checking performance (#58339)
Browse files Browse the repository at this point in the history
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
  • Loading branch information
rbuckton and jakebailey committed Apr 29, 2024
1 parent d2ad3ca commit cd566ba
Show file tree
Hide file tree
Showing 7 changed files with 1,035 additions and 977 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Expand Up @@ -31379,7 +31379,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function checkGrammarRegularExpressionLiteral(node: RegularExpressionLiteral) {
const sourceFile = getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
if (!hasParseDiagnostics(sourceFile) && !node.isUnterminated) {
let lastError: DiagnosticWithLocation | undefined;
scanner ??= createScanner(ScriptTarget.ESNext, /*skipTrivia*/ true);
scanner.setScriptTarget(sourceFile.languageVersion);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Expand Up @@ -1733,7 +1733,7 @@
"category": "Error",
"code": 1519
},
"Expected a class set oprand.": {
"Expected a class set operand.": {
"category": "Error",
"code": 1520
},
Expand Down
1,947 changes: 1,002 additions & 945 deletions src/compiler/scanner.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/compiler/types.ts
Expand Up @@ -7630,6 +7630,7 @@ export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptio
// dprint-ignore
/** @internal */
export const enum CharacterCodes {
EOF = -1,
nullCharacter = 0,
maxAsciiCharacter = 0x7F,

Expand Down
Expand Up @@ -157,24 +157,24 @@ regularExpressionScanning.ts(37,61): error TS1508: Unexpected '}'. Did you mean
regularExpressionScanning.ts(37,63): error TS1517: Range out of order in character class.
regularExpressionScanning.ts(37,76): error TS1535: This character cannot be escaped in a regular expression.
regularExpressionScanning.ts(38,8): error TS1005: '--' expected.
regularExpressionScanning.ts(38,9): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,11): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,9): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,11): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,12): error TS1005: '--' expected.
regularExpressionScanning.ts(38,15): error TS1522: A character class must not contain a reserved double punctuator. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,20): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,28): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,40): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,47): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,49): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,50): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,50): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,55): error TS1511: '\q' is only available inside character class.
regularExpressionScanning.ts(38,57): error TS1508: Unexpected '{'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,61): error TS1508: Unexpected '}'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,66): error TS1508: Unexpected '-'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,67): error TS1005: '--' expected.
regularExpressionScanning.ts(38,70): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,70): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,75): error TS1508: Unexpected '&'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,85): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,85): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,87): error TS1501: This regular expression flag is only available when targeting 'esnext' or later.
regularExpressionScanning.ts(39,56): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(39,67): error TS1005: '&&' expected.
Expand Down Expand Up @@ -561,9 +561,9 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag

!!! error TS1005: '--' expected.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.

!!! error TS1005: '--' expected.
~~
Expand All @@ -579,7 +579,7 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
~
!!! error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.
~~
!!! error TS1511: '\q' is only available inside character class.
~
Expand All @@ -591,11 +591,11 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag

!!! error TS1005: '--' expected.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.
~
!!! error TS1508: Unexpected '&'. Did you mean to escape it with backslash?

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.
~
!!! error TS1501: This regular expression flag is only available when targeting 'esnext' or later.
/[[^\P{Decimal_Number}&&[0-9]]&&\p{L}&&\p{ID_Continue}--\p{ASCII}\p{CWCF}]/v,
Expand Down
Expand Up @@ -164,24 +164,24 @@ regularExpressionScanning.ts(37,63): error TS1517: Range out of order in charact
regularExpressionScanning.ts(37,76): error TS1535: This character cannot be escaped in a regular expression.
regularExpressionScanning.ts(37,87): error TS1501: This regular expression flag is only available when targeting 'es6' or later.
regularExpressionScanning.ts(38,8): error TS1005: '--' expected.
regularExpressionScanning.ts(38,9): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,11): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,9): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,11): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,12): error TS1005: '--' expected.
regularExpressionScanning.ts(38,15): error TS1522: A character class must not contain a reserved double punctuator. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,20): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,28): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,40): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,47): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,49): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,50): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,50): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,55): error TS1511: '\q' is only available inside character class.
regularExpressionScanning.ts(38,57): error TS1508: Unexpected '{'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,61): error TS1508: Unexpected '}'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,66): error TS1508: Unexpected '-'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,67): error TS1005: '--' expected.
regularExpressionScanning.ts(38,70): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,70): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,75): error TS1508: Unexpected '&'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,85): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,85): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,87): error TS1501: This regular expression flag is only available when targeting 'esnext' or later.
regularExpressionScanning.ts(39,56): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(39,67): error TS1005: '&&' expected.
Expand Down Expand Up @@ -582,9 +582,9 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag

!!! error TS1005: '--' expected.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.

!!! error TS1005: '--' expected.
~~
Expand All @@ -600,7 +600,7 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
~
!!! error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.
~~
!!! error TS1511: '\q' is only available inside character class.
~
Expand All @@ -612,11 +612,11 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag

!!! error TS1005: '--' expected.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.
~
!!! error TS1508: Unexpected '&'. Did you mean to escape it with backslash?

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.
~
!!! error TS1501: This regular expression flag is only available when targeting 'esnext' or later.
/[[^\P{Decimal_Number}&&[0-9]]&&\p{L}&&\p{ID_Continue}--\p{ASCII}\p{CWCF}]/v,
Expand Down
Expand Up @@ -141,24 +141,24 @@ regularExpressionScanning.ts(37,61): error TS1508: Unexpected '}'. Did you mean
regularExpressionScanning.ts(37,63): error TS1517: Range out of order in character class.
regularExpressionScanning.ts(37,76): error TS1535: This character cannot be escaped in a regular expression.
regularExpressionScanning.ts(38,8): error TS1005: '--' expected.
regularExpressionScanning.ts(38,9): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,11): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,9): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,11): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,12): error TS1005: '--' expected.
regularExpressionScanning.ts(38,15): error TS1522: A character class must not contain a reserved double punctuator. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,20): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,28): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,40): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,47): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,49): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(38,50): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,50): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,55): error TS1511: '\q' is only available inside character class.
regularExpressionScanning.ts(38,57): error TS1508: Unexpected '{'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,61): error TS1508: Unexpected '}'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,66): error TS1508: Unexpected '-'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,67): error TS1005: '--' expected.
regularExpressionScanning.ts(38,70): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,70): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(38,75): error TS1508: Unexpected '&'. Did you mean to escape it with backslash?
regularExpressionScanning.ts(38,85): error TS1520: Expected a class set oprand.
regularExpressionScanning.ts(38,85): error TS1520: Expected a class set operand.
regularExpressionScanning.ts(39,56): error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
regularExpressionScanning.ts(39,67): error TS1005: '&&' expected.
regularExpressionScanning.ts(41,5): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class.
Expand Down Expand Up @@ -503,9 +503,9 @@ regularExpressionScanning.ts(47,89): error TS1518: Anything that would possibly

!!! error TS1005: '--' expected.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.

!!! error TS1005: '--' expected.
~~
Expand All @@ -521,7 +521,7 @@ regularExpressionScanning.ts(47,89): error TS1518: Anything that would possibly
~
!!! error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.
~~
!!! error TS1511: '\q' is only available inside character class.
~
Expand All @@ -533,11 +533,11 @@ regularExpressionScanning.ts(47,89): error TS1518: Anything that would possibly

!!! error TS1005: '--' expected.

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.
~
!!! error TS1508: Unexpected '&'. Did you mean to escape it with backslash?

!!! error TS1520: Expected a class set oprand.
!!! error TS1520: Expected a class set operand.
/[[^\P{Decimal_Number}&&[0-9]]&&\p{L}&&\p{ID_Continue}--\p{ASCII}\p{CWCF}]/v,
~~
!!! error TS1519: Operators must not be mixed within a character class. Wrap it in a nested class instead.
Expand Down

0 comments on commit cd566ba

Please sign in to comment.