From f1055130186699275529df916fbf976f42596007 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 23 Apr 2024 12:54:18 -0400 Subject: [PATCH 1/7] Report RegExp errors in grammar check, use Annex B grammar --- src/compiler/checker.ts | 41 ++++++- src/compiler/scanner.ts | 107 +++++++++++------- .../parserRegularExpression1.errors.txt | 7 -- .../reference/parserRegularExpression1.js | 4 +- .../parserRegularExpression1.symbols | 2 +- .../reference/parserRegularExpression1.types | 2 +- ...gularExpressionDivideAmbiguity4.errors.txt | 7 +- ...parserRegularExpressionDivideAmbiguity4.js | 2 +- ...serRegularExpressionDivideAmbiguity4.types | 8 +- ...pressionScanning(target=es2015).errors.txt | 65 +---------- ...rExpressionScanning(target=es5).errors.txt | 65 +---------- ...pressionScanning(target=esnext).errors.txt | 65 +---------- ...pertyValueExpressionSuggestions.errors.txt | 6 +- .../reference/shebangError.errors.txt | 8 +- .../parserRegularExpression1.ts | 2 +- 15 files changed, 130 insertions(+), 261 deletions(-) delete mode 100644 tests/baselines/reference/parserRegularExpression1.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0e45abf93737d..883f28290e9dd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -102,6 +102,7 @@ import { countWhere, createBinaryExpressionTrampoline, createCompilerDiagnostic, + createDetachedDiagnostic, createDiagnosticCollection, createDiagnosticForFileFromMessageChain, createDiagnosticForNode, @@ -123,6 +124,7 @@ import { createPrinterWithRemoveCommentsNeverAsciiEscape, createPrinterWithRemoveCommentsOmitTrailingSemicolon, createPropertyNameNodeForIdentifierOrLiteral, + createScanner, createSymbolTable, createSyntacticTypeNodeBuilder, createTextWriter, @@ -937,6 +939,7 @@ import { rangeOfTypeParameters, ReadonlyKeyword, reduceLeft, + RegularExpressionLiteral, RelationComparisonResult, relativeComplement, removeExtension, @@ -31353,6 +31356,42 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } + function checkGrammarRegularExpressionLiteral(node: RegularExpressionLiteral) { + const sourceFile = getSourceFileOfNode(node); + if (!hasParseDiagnostics(sourceFile)) { + let lastError: DiagnosticWithLocation | undefined; + const scanner = createScanner( + sourceFile.languageVersion, + /*skipTrivia*/ true, + sourceFile.languageVariant, + sourceFile.text, + (message, length, arg0) => { + // emulate `parseErrorAtPosition` from parser.ts + const start = scanner.getTokenEnd(); + if (message.category === DiagnosticCategory.Message && lastError && start === lastError.start && length === lastError.length) { + const error = createDetachedDiagnostic(sourceFile.fileName, sourceFile.text, start, length, message, arg0); + addRelatedInfo(lastError, error); + } + else if (!lastError || start !== lastError.start) { + lastError = createFileDiagnostic(sourceFile, start, length, message, arg0); + diagnostics.add(lastError); + } + }, + node.pos, + node.end - node.pos, + ); + Debug.assert(scanner.scan() === SyntaxKind.SlashToken); + Debug.assert(scanner.reScanSlashToken(/*reportErrors*/ true) === SyntaxKind.RegularExpressionLiteral); + return !!lastError; + } + return false; + } + + function checkRegularExpressionLiteral(node: RegularExpressionLiteral) { + checkGrammarRegularExpressionLiteral(node); + return globalRegExpType; + } + function checkSpreadExpression(node: SpreadElement, checkMode?: CheckMode): Type { if (languageVersion < LanguageFeatureMinimumTarget.SpreadElements) { checkExternalEmitHelpers(node, compilerOptions.downlevelIteration ? ExternalEmitHelpers.SpreadIncludes : ExternalEmitHelpers.SpreadArray); @@ -39662,7 +39701,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.TemplateExpression: return checkTemplateExpression(node as TemplateExpression); case SyntaxKind.RegularExpressionLiteral: - return globalRegExpType; + return checkRegularExpressionLiteral(node as RegularExpressionLiteral); case SyntaxKind.ArrayLiteralExpression: return checkArrayLiteral(node as ArrayLiteralExpression, checkMode, forceTuple); case SyntaxKind.ObjectLiteralExpression: diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 01dc3b1b31494..a2f0d8f13da1b 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -76,6 +76,8 @@ export interface Scanner { getTokenFlags(): TokenFlags; reScanGreaterToken(): SyntaxKind; reScanSlashToken(): SyntaxKind; + /** @internal */ + reScanSlashToken(reportErrors?: boolean): SyntaxKind; // eslint-disable-line @typescript-eslint/unified-signatures reScanAsteriskEqualsToken(): SyntaxKind; reScanTemplateToken(isTaggedTemplate: boolean): SyntaxKind; /** @deprecated use {@link reScanTemplateToken}(false) */ @@ -1484,7 +1486,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean // | [0-3] [0-7] [0-7]? // | [4-7] [0-7] // NonOctalDecimalEscapeSequence ::= [89] - function scanEscapeSequence(shouldEmitInvalidEscapeError: boolean, isRegularExpression: boolean): string { + function scanEscapeSequence(shouldEmitInvalidEscapeError: boolean, isRegularExpression: boolean | "annex-b"): string { const start = pos; pos++; if (pos >= end) { @@ -1523,7 +1525,9 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean tokenFlags |= TokenFlags.ContainsInvalidEscape; if (isRegularExpression || shouldEmitInvalidEscapeError) { const code = parseInt(text.substring(start + 1, pos), 8); - error(Diagnostics.Octal_escape_sequences_are_not_allowed_Use_the_syntax_0, start, pos - start, "\\x" + code.toString(16).padStart(2, "0")); + if (isRegularExpression !== "annex-b") { + error(Diagnostics.Octal_escape_sequences_are_not_allowed_Use_the_syntax_0, start, pos - start, "\\x" + code.toString(16).padStart(2, "0")); + } return String.fromCharCode(code); } return text.substring(start, pos); @@ -1559,7 +1563,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean ) { // '\u{DDDDDD}' pos -= 2; - return scanExtendedUnicodeEscape(isRegularExpression || shouldEmitInvalidEscapeError); + return scanExtendedUnicodeEscape(!!isRegularExpression || shouldEmitInvalidEscapeError); } // '\uDDDD' for (; pos < start + 6; pos++) { @@ -1623,7 +1627,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean case CharacterCodes.paragraphSeparator: return ""; default: - if (isRegularExpression && (shouldEmitInvalidEscapeError || isIdentifierPart(ch, languageVersion))) { + if (isRegularExpression === true && (shouldEmitInvalidEscapeError || isIdentifierPart(ch, languageVersion))) { error(Diagnostics.This_character_cannot_be_escaped_in_a_regular_expression, pos - 2, 2); } return String.fromCharCode(ch); @@ -2386,7 +2390,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean return token = SyntaxKind.EqualsToken; } - function reScanSlashToken(): SyntaxKind { + function reScanSlashToken(reportErrors?: boolean): SyntaxKind { if (token === SyntaxKind.SlashToken || token === SyntaxKind.SlashEqualsToken) { // Quickly get to the end of regex such that we know the flags let p = tokenStart + 1; @@ -2444,44 +2448,57 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean if (!isIdentifierPart(ch, languageVersion)) { break; } - const flag = characterToRegularExpressionFlag(String.fromCharCode(ch)); - if (flag === undefined) { - error(Diagnostics.Unknown_regular_expression_flag, p, 1); - } - else if (regExpFlags & flag) { - error(Diagnostics.Duplicate_regular_expression_flag, p, 1); - } - else if (((regExpFlags | flag) & RegularExpressionFlags.UnicodeMode) === RegularExpressionFlags.UnicodeMode) { - error(Diagnostics.The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously, p, 1); - } - else { - regExpFlags |= flag; - const availableFrom = regExpFlagToFirstAvailableLanguageVersion.get(flag)!; - if (languageVersion < availableFrom) { - error(Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later, p, 1, getNameOfScriptTarget(availableFrom)); + if (reportErrors) { + const flag = characterToRegularExpressionFlag(String.fromCharCode(ch)); + if (flag === undefined) { + error(Diagnostics.Unknown_regular_expression_flag, p, 1); + } + else if (regExpFlags & flag) { + error(Diagnostics.Duplicate_regular_expression_flag, p, 1); + } + else if (((regExpFlags | flag) & RegularExpressionFlags.UnicodeMode) === RegularExpressionFlags.UnicodeMode) { + error(Diagnostics.The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously, p, 1); + } + else { + regExpFlags |= flag; + const availableFrom = regExpFlagToFirstAvailableLanguageVersion.get(flag)!; + if (languageVersion < availableFrom) { + error(Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later, p, 1, getNameOfScriptTarget(availableFrom)); + } } } p++; } - pos = tokenStart + 1; - const saveTokenPos = tokenStart; - const saveTokenFlags = tokenFlags; - scanRegularExpressionWorker(text, endOfBody, regExpFlags, isUnterminated); - if (!isUnterminated) { + if (reportErrors) { + pos = tokenStart + 1; + const saveTokenPos = tokenStart; + const saveTokenFlags = tokenFlags; + scanRegularExpressionWorker(text, endOfBody, regExpFlags, isUnterminated, /*annexB*/ true); + if (!isUnterminated) { + pos = p; + } + tokenStart = saveTokenPos; + tokenFlags = saveTokenFlags; + } + else { pos = p; } - tokenStart = saveTokenPos; - tokenFlags = saveTokenFlags; tokenValue = text.substring(tokenStart, pos); token = SyntaxKind.RegularExpressionLiteral; } return token; - function scanRegularExpressionWorker(text: string, end: number, regExpFlags: RegularExpressionFlags, isUnterminated: boolean) { - /** Grammar parameter */ - const unicodeMode = !!(regExpFlags & RegularExpressionFlags.UnicodeMode); + function scanRegularExpressionWorker(text: string, end: number, regExpFlags: RegularExpressionFlags, isUnterminated: boolean, annexB: boolean) { /** Grammar parameter */ const unicodeSetsMode = !!(regExpFlags & RegularExpressionFlags.UnicodeSets); + /** Grammar parameter */ + const unicodeMode = unicodeSetsMode || !!(regExpFlags & RegularExpressionFlags.UnicodeMode); // v always implies u + + if (unicodeMode) { + // Annex B treats any unicode mode as the strict syntax. + annexB = false; + } + /** @see {scanClassSetExpression} */ let mayContainStrings = false; @@ -2571,7 +2588,8 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean case CharacterCodes.equals: case CharacterCodes.exclamation: pos++; - isPreviousTermQuantifiable = false; + // In Annex B, `(?=Disjunction)` and `(?!Disjunciton)` are quantifiable + isPreviousTermQuantifiable = annexB; break; case CharacterCodes.lessThan: const groupNameStart = pos; @@ -2763,7 +2781,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean default: // The scanEscapeSequence call in scanCharacterEscape must return non-empty strings // since there must not be line breaks in a regex literal - Debug.assert(scanCharacterClassEscape() || scanDecimalEscape() || scanCharacterEscape()); + Debug.assert(scanCharacterClassEscape() || scanDecimalEscape() || scanCharacterEscape(/*atomEscape*/ true)); break; } } @@ -2788,7 +2806,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean // IdentityEscape ::= // | '^' | '$' | '/' | '\' | '.' | '*' | '+' | '?' | '(' | ')' | '[' | ']' | '{' | '}' | '|' // | [~UnicodeMode] (any other non-identifier characters) - function scanCharacterEscape(): string { + function scanCharacterEscape(atomEscape: boolean): string { Debug.assertEqual(text.charCodeAt(pos - 1), CharacterCodes.backslash); let ch = text.charCodeAt(pos); switch (ch) { @@ -2802,6 +2820,15 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean if (unicodeMode) { error(Diagnostics.c_must_be_followed_by_an_ASCII_letter, pos - 2, 2); } + else if (atomEscape && annexB) { + // Annex B treats + // + // ExtendedAtom : `\` [lookahead = `c`] + // + // as the single character `\` when `c` isn't followed by a valid control character + pos--; + return "\\"; + } return String.fromCharCode(ch); case CharacterCodes.caret: case CharacterCodes.$: @@ -2826,7 +2853,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean return "\\"; } pos--; - return scanEscapeSequence(/*shouldEmitInvalidEscapeError*/ unicodeMode, /*isRegularExpression*/ true); + return scanEscapeSequence(/*shouldEmitInvalidEscapeError*/ unicodeMode, /*isRegularExpression*/ annexB ? "annex-b" : true); } } @@ -2873,12 +2900,12 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean if (isClassContentExit(ch)) { return; } - if (!minCharacter) { + if (!minCharacter && !annexB) { error(Diagnostics.A_character_class_range_must_not_be_bounded_by_another_character_class, minStart, pos - 1 - minStart); } const maxStart = pos; const maxCharacter = scanClassAtom(); - if (!maxCharacter) { + if (!maxCharacter && !annexB) { error(Diagnostics.A_character_class_range_must_not_be_bounded_by_another_character_class, maxStart, pos - maxStart); continue; } @@ -3208,7 +3235,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean pos++; return String.fromCharCode(ch); default: - return scanCharacterEscape(); + return scanCharacterEscape(/*atomEscape*/ false); } } else if (ch === text.charCodeAt(pos + 1)) { @@ -3275,7 +3302,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean if (scanCharacterClassEscape()) { return ""; } - return scanCharacterEscape(); + return scanCharacterEscape(/*atomEscape*/ false); } } else { @@ -3407,7 +3434,9 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean } }); forEach(decimalEscapes, escape => { - if (escape.value > numberOfCapturingGroups) { + // in AnnexB, if a DecimalEscape is greater than the number of capturing groups then it is treated as + // either a LegacyOctalEscapeSequence or IdentityEscape + if (!annexB && escape.value > numberOfCapturingGroups) { if (numberOfCapturingGroups) { error(Diagnostics.A_decimal_escape_must_refer_to_an_existent_capturing_group_There_are_only_0_capturing_groups_in_this_regular_expression, escape.pos, escape.end - escape.pos, numberOfCapturingGroups); } diff --git a/tests/baselines/reference/parserRegularExpression1.errors.txt b/tests/baselines/reference/parserRegularExpression1.errors.txt deleted file mode 100644 index bc21ec63c5211..0000000000000 --- a/tests/baselines/reference/parserRegularExpression1.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -parserRegularExpression1.ts(1,34): error TS1516: A character class range must not be bounded by another character class. - - -==== parserRegularExpression1.ts (1 errors) ==== - return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. \ No newline at end of file diff --git a/tests/baselines/reference/parserRegularExpression1.js b/tests/baselines/reference/parserRegularExpression1.js index 61698e7a7c23b..36902cfcf3706 100644 --- a/tests/baselines/reference/parserRegularExpression1.js +++ b/tests/baselines/reference/parserRegularExpression1.js @@ -1,7 +1,7 @@ //// [tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression1.ts] //// //// [parserRegularExpression1.ts] -return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; +/(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; //// [parserRegularExpression1.js] -return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; +/(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; diff --git a/tests/baselines/reference/parserRegularExpression1.symbols b/tests/baselines/reference/parserRegularExpression1.symbols index 637fbb00f2bbc..0e3e77dceca99 100644 --- a/tests/baselines/reference/parserRegularExpression1.symbols +++ b/tests/baselines/reference/parserRegularExpression1.symbols @@ -2,4 +2,4 @@ === parserRegularExpression1.ts === -return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; +/(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; diff --git a/tests/baselines/reference/parserRegularExpression1.types b/tests/baselines/reference/parserRegularExpression1.types index e3b438be1a011..8853d983d3e11 100644 --- a/tests/baselines/reference/parserRegularExpression1.types +++ b/tests/baselines/reference/parserRegularExpression1.types @@ -1,7 +1,7 @@ //// [tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression1.ts] //// === parserRegularExpression1.ts === -return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; +/(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; >/(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g : RegExp > : ^^^^^^ diff --git a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.errors.txt b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.errors.txt index 71688b6975608..4b32921546956 100644 --- a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.errors.txt +++ b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.errors.txt @@ -1,10 +1,13 @@ parserRegularExpressionDivideAmbiguity4.ts(1,1): error TS2304: Cannot find name 'foo'. parserRegularExpressionDivideAmbiguity4.ts(1,6): error TS1161: Unterminated regular expression literal. +parserRegularExpressionDivideAmbiguity4.ts(1,17): error TS1005: ')' expected. -==== parserRegularExpressionDivideAmbiguity4.ts (2 errors) ==== +==== parserRegularExpressionDivideAmbiguity4.ts (3 errors) ==== foo(/notregexp); ~~~ !!! error TS2304: Cannot find name 'foo'. -!!! error TS1161: Unterminated regular expression literal. \ No newline at end of file +!!! error TS1161: Unterminated regular expression literal. + +!!! error TS1005: ')' expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.js b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.js index b8ec4550186b8..de84199b803ae 100644 --- a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.js +++ b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.js @@ -4,4 +4,4 @@ foo(/notregexp); //// [parserRegularExpressionDivideAmbiguity4.js] -foo(/notregexp); +foo(/notregexp);); diff --git a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.types b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.types index 49795f0955380..0c2623d2d1269 100644 --- a/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.types +++ b/tests/baselines/reference/parserRegularExpressionDivideAmbiguity4.types @@ -2,10 +2,10 @@ === parserRegularExpressionDivideAmbiguity4.ts === foo(/notregexp); ->foo(/notregexp) : any -> : ^^^ +>foo(/notregexp); : any +> : ^^^ >foo : any > : ^^^ ->/notregexp : RegExp -> : ^^^^^^ +>/notregexp); : RegExp +> : ^^^^^^ diff --git a/tests/baselines/reference/regularExpressionScanning(target=es2015).errors.txt b/tests/baselines/reference/regularExpressionScanning(target=es2015).errors.txt index 45e837e1bf737..9f93e6dacfdaf 100644 --- a/tests/baselines/reference/regularExpressionScanning(target=es2015).errors.txt +++ b/tests/baselines/reference/regularExpressionScanning(target=es2015).errors.txt @@ -17,13 +17,6 @@ regularExpressionScanning.ts(5,6): error TS1499: Unknown regular expression flag regularExpressionScanning.ts(5,7): error TS1509: This regular expression flag cannot be toggled within a subpattern. regularExpressionScanning.ts(5,10): error TS1509: This regular expression flag cannot be toggled within a subpattern. regularExpressionScanning.ts(5,11): error TS1500: Duplicate regular expression flag. -regularExpressionScanning.ts(7,9): error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. -regularExpressionScanning.ts(7,24): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. -regularExpressionScanning.ts(7,26): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. -regularExpressionScanning.ts(7,29): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x53'. -regularExpressionScanning.ts(7,37): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x03'. -regularExpressionScanning.ts(7,42): error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. -regularExpressionScanning.ts(7,43): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x05'. regularExpressionScanning.ts(8,9): error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. regularExpressionScanning.ts(8,24): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. regularExpressionScanning.ts(8,26): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. @@ -48,10 +41,7 @@ regularExpressionScanning.ts(12,40): error TS1507: There is nothing available fo regularExpressionScanning.ts(12,61): error TS1505: Incomplete quantifier. Digit expected. regularExpressionScanning.ts(14,12): error TS1517: Range out of order in character class. regularExpressionScanning.ts(14,15): error TS1517: Range out of order in character class. -regularExpressionScanning.ts(14,22): error TS1516: A character class range must not be bounded by another character class. regularExpressionScanning.ts(14,28): error TS1517: Range out of order in character class. -regularExpressionScanning.ts(14,33): error TS1516: A character class range must not be bounded by another character class. -regularExpressionScanning.ts(14,36): error TS1516: A character class range must not be bounded by another character class. regularExpressionScanning.ts(15,3): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. regularExpressionScanning.ts(15,8): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. regularExpressionScanning.ts(15,16): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. @@ -119,21 +109,12 @@ regularExpressionScanning.ts(23,19): error TS1518: Anything that would possibly regularExpressionScanning.ts(23,31): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class. regularExpressionScanning.ts(23,47): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class. regularExpressionScanning.ts(23,59): error TS1501: This regular expression flag is only available when targeting 'esnext' or later. -regularExpressionScanning.ts(25,17): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(25,23): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(26,3): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,6): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,15): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,17): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(26,20): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,23): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,3): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,10): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,17): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,21): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,24): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,39): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,43): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(28,3): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(28,7): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(28,10): error TS1535: This character cannot be escaped in a regular expression. @@ -164,9 +145,7 @@ regularExpressionScanning.ts(31,4): error TS1517: Range out of order in characte regularExpressionScanning.ts(31,8): error TS1517: Range out of order in character class. regularExpressionScanning.ts(31,34): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. regularExpressionScanning.ts(31,42): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. -regularExpressionScanning.ts(31,55): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(31,63): error TS1517: Range out of order in character class. -regularExpressionScanning.ts(31,76): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(32,4): error TS1517: Range out of order in character class. regularExpressionScanning.ts(32,8): error TS1517: Range out of order in character class. regularExpressionScanning.ts(32,19): error TS1508: Unexpected ']'. Did you mean to escape it with backslash? @@ -224,7 +203,7 @@ regularExpressionScanning.ts(42,89): error TS1518: Anything that would possibly regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag is only available when targeting 'esnext' or later. -==== regularExpressionScanning.ts (224 errors) ==== +==== regularExpressionScanning.ts (203 errors) ==== const regexes: RegExp[] = [ // Flags /foo/visualstudiocode, @@ -270,20 +249,6 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag !!! error TS1500: Duplicate regular expression flag. // Capturing groups /\2()(\12)(foo)\1\0[\0\1\01\123](\3\03)\5\005/, - ~~ -!!! error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. - ~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. - ~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. - ~~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x53'. - ~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x03'. - ~ -!!! error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. - ~~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x05'. /\2()(\12)(foo)\1\0[\0\1\01\123](\3\03)\5\005/u, ~~ !!! error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. @@ -339,14 +304,8 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag !!! error TS1517: Range out of order in character class. ~~~ !!! error TS1517: Range out of order in character class. - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. ~~~~~ !!! error TS1517: Range out of order in character class. - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. /\p{L}\p{gc=L}\p{ASCII}\p{Invalid}[\p{L}\p{gc=L}\P{ASCII}\p{Invalid}]/, ~~~~~ !!! error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. @@ -492,10 +451,6 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag !!! error TS1501: This regular expression flag is only available when targeting 'esnext' or later. // Character escapes /\c[\c0\ca\cQ\c\C]\c1\C/, - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. /\c[\c0\ca\cQ\c\C]\c1\C/u, ~~ !!! error TS1512: '\c' must be followed by an ASCII letter. @@ -510,20 +465,6 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag ~~ !!! error TS1535: This character cannot be escaped in a regular expression. /\q\\\`[\q\\\`[\Q\\\Q{\q{foo|bar|baz]\q{]\q{/, - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. /\q\\\`[\q\\\`[\Q\\\Q{\q{foo|bar|baz]\q{]\q{/u, ~~ !!! error TS1535: This character cannot be escaped in a regular expression. @@ -588,12 +529,8 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag !!! error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. ~~~~~ !!! error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. ~~~ !!! error TS1517: Range out of order in character class. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. /[a--b[--][\d++[]]&&[[&0-9--]&&[\p{L}]--\P{L}-_-]]&&&\q{foo}[0---9][&&q&&&\q{bar}&&]/u, ~~~ !!! error TS1517: Range out of order in character class. diff --git a/tests/baselines/reference/regularExpressionScanning(target=es5).errors.txt b/tests/baselines/reference/regularExpressionScanning(target=es5).errors.txt index 33da1f9c67165..94cda1ce07a09 100644 --- a/tests/baselines/reference/regularExpressionScanning(target=es5).errors.txt +++ b/tests/baselines/reference/regularExpressionScanning(target=es5).errors.txt @@ -17,13 +17,6 @@ regularExpressionScanning.ts(5,6): error TS1499: Unknown regular expression flag regularExpressionScanning.ts(5,7): error TS1509: This regular expression flag cannot be toggled within a subpattern. regularExpressionScanning.ts(5,10): error TS1509: This regular expression flag cannot be toggled within a subpattern. regularExpressionScanning.ts(5,11): error TS1500: Duplicate regular expression flag. -regularExpressionScanning.ts(7,9): error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. -regularExpressionScanning.ts(7,24): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. -regularExpressionScanning.ts(7,26): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. -regularExpressionScanning.ts(7,29): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x53'. -regularExpressionScanning.ts(7,37): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x03'. -regularExpressionScanning.ts(7,42): error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. -regularExpressionScanning.ts(7,43): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x05'. regularExpressionScanning.ts(8,9): error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. regularExpressionScanning.ts(8,24): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. regularExpressionScanning.ts(8,26): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. @@ -49,10 +42,7 @@ regularExpressionScanning.ts(12,40): error TS1507: There is nothing available fo regularExpressionScanning.ts(12,61): error TS1505: Incomplete quantifier. Digit expected. regularExpressionScanning.ts(14,12): error TS1517: Range out of order in character class. regularExpressionScanning.ts(14,15): error TS1517: Range out of order in character class. -regularExpressionScanning.ts(14,22): error TS1516: A character class range must not be bounded by another character class. regularExpressionScanning.ts(14,28): error TS1517: Range out of order in character class. -regularExpressionScanning.ts(14,33): error TS1516: A character class range must not be bounded by another character class. -regularExpressionScanning.ts(14,36): error TS1516: A character class range must not be bounded by another character class. regularExpressionScanning.ts(15,3): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. regularExpressionScanning.ts(15,8): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. regularExpressionScanning.ts(15,16): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. @@ -123,8 +113,6 @@ regularExpressionScanning.ts(23,19): error TS1518: Anything that would possibly regularExpressionScanning.ts(23,31): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class. regularExpressionScanning.ts(23,47): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class. regularExpressionScanning.ts(23,59): error TS1501: This regular expression flag is only available when targeting 'esnext' or later. -regularExpressionScanning.ts(25,17): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(25,23): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(26,3): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,6): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,15): error TS1512: '\c' must be followed by an ASCII letter. @@ -132,13 +120,6 @@ regularExpressionScanning.ts(26,17): error TS1535: This character cannot be esca regularExpressionScanning.ts(26,20): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,23): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(26,26): error TS1501: This regular expression flag is only available when targeting 'es6' or later. -regularExpressionScanning.ts(27,3): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,10): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,17): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,21): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,24): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,39): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,43): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(28,3): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(28,7): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(28,10): error TS1535: This character cannot be escaped in a regular expression. @@ -170,9 +151,7 @@ regularExpressionScanning.ts(31,4): error TS1517: Range out of order in characte regularExpressionScanning.ts(31,8): error TS1517: Range out of order in character class. regularExpressionScanning.ts(31,34): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. regularExpressionScanning.ts(31,42): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. -regularExpressionScanning.ts(31,55): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(31,63): error TS1517: Range out of order in character class. -regularExpressionScanning.ts(31,76): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(32,4): error TS1517: Range out of order in character class. regularExpressionScanning.ts(32,8): error TS1517: Range out of order in character class. regularExpressionScanning.ts(32,19): error TS1508: Unexpected ']'. Did you mean to escape it with backslash? @@ -231,7 +210,7 @@ regularExpressionScanning.ts(42,89): error TS1518: Anything that would possibly regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag is only available when targeting 'esnext' or later. -==== regularExpressionScanning.ts (231 errors) ==== +==== regularExpressionScanning.ts (210 errors) ==== const regexes: RegExp[] = [ // Flags /foo/visualstudiocode, @@ -277,20 +256,6 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag !!! error TS1500: Duplicate regular expression flag. // Capturing groups /\2()(\12)(foo)\1\0[\0\1\01\123](\3\03)\5\005/, - ~~ -!!! error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. - ~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. - ~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. - ~~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x53'. - ~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x03'. - ~ -!!! error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. - ~~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x05'. /\2()(\12)(foo)\1\0[\0\1\01\123](\3\03)\5\005/u, ~~ !!! error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. @@ -348,14 +313,8 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag !!! error TS1517: Range out of order in character class. ~~~ !!! error TS1517: Range out of order in character class. - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. ~~~~~ !!! error TS1517: Range out of order in character class. - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. /\p{L}\p{gc=L}\p{ASCII}\p{Invalid}[\p{L}\p{gc=L}\P{ASCII}\p{Invalid}]/, ~~~~~ !!! error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. @@ -507,10 +466,6 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag !!! error TS1501: This regular expression flag is only available when targeting 'esnext' or later. // Character escapes /\c[\c0\ca\cQ\c\C]\c1\C/, - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. /\c[\c0\ca\cQ\c\C]\c1\C/u, ~~ !!! error TS1512: '\c' must be followed by an ASCII letter. @@ -527,20 +482,6 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag ~ !!! error TS1501: This regular expression flag is only available when targeting 'es6' or later. /\q\\\`[\q\\\`[\Q\\\Q{\q{foo|bar|baz]\q{]\q{/, - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. /\q\\\`[\q\\\`[\Q\\\Q{\q{foo|bar|baz]\q{]\q{/u, ~~ !!! error TS1535: This character cannot be escaped in a regular expression. @@ -607,12 +548,8 @@ regularExpressionScanning.ts(42,101): error TS1501: This regular expression flag !!! error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. ~~~~~ !!! error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. ~~~ !!! error TS1517: Range out of order in character class. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. /[a--b[--][\d++[]]&&[[&0-9--]&&[\p{L}]--\P{L}-_-]]&&&\q{foo}[0---9][&&q&&&\q{bar}&&]/u, ~~~ !!! error TS1517: Range out of order in character class. diff --git a/tests/baselines/reference/regularExpressionScanning(target=esnext).errors.txt b/tests/baselines/reference/regularExpressionScanning(target=esnext).errors.txt index 75619a28c11a9..8b448d49eb491 100644 --- a/tests/baselines/reference/regularExpressionScanning(target=esnext).errors.txt +++ b/tests/baselines/reference/regularExpressionScanning(target=esnext).errors.txt @@ -14,13 +14,6 @@ regularExpressionScanning.ts(5,6): error TS1499: Unknown regular expression flag regularExpressionScanning.ts(5,7): error TS1509: This regular expression flag cannot be toggled within a subpattern. regularExpressionScanning.ts(5,10): error TS1509: This regular expression flag cannot be toggled within a subpattern. regularExpressionScanning.ts(5,11): error TS1500: Duplicate regular expression flag. -regularExpressionScanning.ts(7,9): error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. -regularExpressionScanning.ts(7,24): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. -regularExpressionScanning.ts(7,26): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. -regularExpressionScanning.ts(7,29): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x53'. -regularExpressionScanning.ts(7,37): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x03'. -regularExpressionScanning.ts(7,42): error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. -regularExpressionScanning.ts(7,43): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x05'. regularExpressionScanning.ts(8,9): error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. regularExpressionScanning.ts(8,24): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. regularExpressionScanning.ts(8,26): error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. @@ -36,10 +29,7 @@ regularExpressionScanning.ts(12,40): error TS1507: There is nothing available fo regularExpressionScanning.ts(12,61): error TS1505: Incomplete quantifier. Digit expected. regularExpressionScanning.ts(14,12): error TS1517: Range out of order in character class. regularExpressionScanning.ts(14,15): error TS1517: Range out of order in character class. -regularExpressionScanning.ts(14,22): error TS1516: A character class range must not be bounded by another character class. regularExpressionScanning.ts(14,28): error TS1517: Range out of order in character class. -regularExpressionScanning.ts(14,33): error TS1516: A character class range must not be bounded by another character class. -regularExpressionScanning.ts(14,36): error TS1516: A character class range must not be bounded by another character class. regularExpressionScanning.ts(15,3): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. regularExpressionScanning.ts(15,8): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. regularExpressionScanning.ts(15,16): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. @@ -104,21 +94,12 @@ regularExpressionScanning.ts(22,47): error TS1528: Any Unicode property that wou regularExpressionScanning.ts(23,19): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class. regularExpressionScanning.ts(23,31): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class. regularExpressionScanning.ts(23,47): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class. -regularExpressionScanning.ts(25,17): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(25,23): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(26,3): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,6): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,15): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,17): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(26,20): error TS1512: '\c' must be followed by an ASCII letter. regularExpressionScanning.ts(26,23): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,3): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,10): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,17): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,21): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,24): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,39): error TS1535: This character cannot be escaped in a regular expression. -regularExpressionScanning.ts(27,43): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(28,3): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(28,7): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(28,10): error TS1535: This character cannot be escaped in a regular expression. @@ -148,9 +129,7 @@ regularExpressionScanning.ts(31,4): error TS1517: Range out of order in characte regularExpressionScanning.ts(31,8): error TS1517: Range out of order in character class. regularExpressionScanning.ts(31,34): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. regularExpressionScanning.ts(31,42): error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. -regularExpressionScanning.ts(31,55): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(31,63): error TS1517: Range out of order in character class. -regularExpressionScanning.ts(31,76): error TS1535: This character cannot be escaped in a regular expression. regularExpressionScanning.ts(32,4): error TS1517: Range out of order in character class. regularExpressionScanning.ts(32,8): error TS1517: Range out of order in character class. regularExpressionScanning.ts(32,19): error TS1508: Unexpected ']'. Did you mean to escape it with backslash? @@ -198,7 +177,7 @@ regularExpressionScanning.ts(42,5): error TS1518: Anything that would possibly m regularExpressionScanning.ts(42,89): error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class. -==== regularExpressionScanning.ts (198 errors) ==== +==== regularExpressionScanning.ts (177 errors) ==== const regexes: RegExp[] = [ // Flags /foo/visualstudiocode, @@ -238,20 +217,6 @@ regularExpressionScanning.ts(42,89): error TS1518: Anything that would possibly !!! error TS1500: Duplicate regular expression flag. // Capturing groups /\2()(\12)(foo)\1\0[\0\1\01\123](\3\03)\5\005/, - ~~ -!!! error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. - ~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. - ~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x01'. - ~~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x53'. - ~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x03'. - ~ -!!! error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. - ~~~~ -!!! error TS1487: Octal escape sequences are not allowed. Use the syntax '\x05'. /\2()(\12)(foo)\1\0[\0\1\01\123](\3\03)\5\005/u, ~~ !!! error TS1533: A decimal escape must refer to an existent capturing group. There are only 4 capturing groups in this regular expression. @@ -289,14 +254,8 @@ regularExpressionScanning.ts(42,89): error TS1518: Anything that would possibly !!! error TS1517: Range out of order in character class. ~~~ !!! error TS1517: Range out of order in character class. - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. ~~~~~ !!! error TS1517: Range out of order in character class. - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. - ~~ -!!! error TS1516: A character class range must not be bounded by another character class. /\p{L}\p{gc=L}\p{ASCII}\p{Invalid}[\p{L}\p{gc=L}\P{ASCII}\p{Invalid}]/, ~~~~~ !!! error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. @@ -436,10 +395,6 @@ regularExpressionScanning.ts(42,89): error TS1518: Anything that would possibly !!! error TS1518: Anything that would possibly match more than a single character is invalid inside a negated character class. // Character escapes /\c[\c0\ca\cQ\c\C]\c1\C/, - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. /\c[\c0\ca\cQ\c\C]\c1\C/u, ~~ !!! error TS1512: '\c' must be followed by an ASCII letter. @@ -454,20 +409,6 @@ regularExpressionScanning.ts(42,89): error TS1518: Anything that would possibly ~~ !!! error TS1535: This character cannot be escaped in a regular expression. /\q\\\`[\q\\\`[\Q\\\Q{\q{foo|bar|baz]\q{]\q{/, - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. /\q\\\`[\q\\\`[\Q\\\Q{\q{foo|bar|baz]\q{]\q{/u, ~~ !!! error TS1535: This character cannot be escaped in a regular expression. @@ -530,12 +471,8 @@ regularExpressionScanning.ts(42,89): error TS1518: Anything that would possibly !!! error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. ~~~~~ !!! error TS1530: Unicode property value expressions are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. ~~~ !!! error TS1517: Range out of order in character class. - ~~ -!!! error TS1535: This character cannot be escaped in a regular expression. /[a--b[--][\d++[]]&&[[&0-9--]&&[\p{L}]--\P{L}-_-]]&&&\q{foo}[0---9][&&q&&&\q{bar}&&]/u, ~~~ !!! error TS1517: Range out of order in character class. diff --git a/tests/baselines/reference/regularExpressionUnicodePropertyValueExpressionSuggestions.errors.txt b/tests/baselines/reference/regularExpressionUnicodePropertyValueExpressionSuggestions.errors.txt index 18133b69068e7..9b69caf634cc5 100644 --- a/tests/baselines/reference/regularExpressionUnicodePropertyValueExpressionSuggestions.errors.txt +++ b/tests/baselines/reference/regularExpressionUnicodePropertyValueExpressionSuggestions.errors.txt @@ -8,13 +8,13 @@ regularExpressionUnicodePropertyValueExpressionSuggestions.ts(1,55): error TS150 const regex = /\p{ascii}\p{Sc=Unknown}\p{sc=unknownX}/u; ~~~~~ !!! error TS1529: Unknown Unicode property name or value. -!!! related TS1369 regularExpressionUnicodePropertyValueExpressionSuggestions.ts:1:19: Did you mean 'ASCII'? +!!! related TS1369: Did you mean 'ASCII'? ~~ !!! error TS1524: Unknown Unicode property name. -!!! related TS1369 regularExpressionUnicodePropertyValueExpressionSuggestions.ts:1:28: Did you mean 'sc'? +!!! related TS1369: Did you mean 'sc'? ~~~~~~~~ !!! error TS1526: Unknown Unicode property value. -!!! related TS1369 regularExpressionUnicodePropertyValueExpressionSuggestions.ts:1:45: Did you mean 'Unknown'? +!!! related TS1369: Did you mean 'Unknown'? ~ !!! error TS1501: This regular expression flag is only available when targeting 'es6' or later. \ No newline at end of file diff --git a/tests/baselines/reference/shebangError.errors.txt b/tests/baselines/reference/shebangError.errors.txt index ce5ecd3f555c6..43213c29fc2c1 100644 --- a/tests/baselines/reference/shebangError.errors.txt +++ b/tests/baselines/reference/shebangError.errors.txt @@ -1,23 +1,17 @@ shebangError.ts(2,1): error TS18026: '#!' can only be used at the start of a file. shebangError.ts(2,2): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -shebangError.ts(2,8): error TS1499: Unknown regular expression flag. -shebangError.ts(2,10): error TS1499: Unknown regular expression flag. shebangError.ts(2,12): error TS2304: Cannot find name 'env'. shebangError.ts(2,16): error TS1005: ';' expected. shebangError.ts(2,16): error TS2304: Cannot find name 'node'. -==== shebangError.ts (7 errors) ==== +==== shebangError.ts (5 errors) ==== var foo = 'Shebang is only allowed on the first line'; #!/usr/bin/env node ~~ !!! error TS18026: '#!' can only be used at the start of a file. ~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. - ~ -!!! error TS1499: Unknown regular expression flag. - ~ -!!! error TS1499: Unknown regular expression flag. ~~~ !!! error TS2304: Cannot find name 'env'. ~~~~ diff --git a/tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression1.ts b/tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression1.ts index 456e62f46960b..36f90d903712f 100644 --- a/tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression1.ts +++ b/tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression1.ts @@ -1 +1 @@ -return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; \ No newline at end of file +/(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g; \ No newline at end of file From 40ea4dfedd550099d82ea693235ea1f9e62c0a43 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 23 Apr 2024 17:54:04 -0400 Subject: [PATCH 2/7] Revert change to incremental parser test --- src/compiler/scanner.ts | 2 +- src/testRunner/unittests/incrementalParser.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index a2f0d8f13da1b..562c24ec8d88c 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -2492,7 +2492,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean /** Grammar parameter */ const unicodeSetsMode = !!(regExpFlags & RegularExpressionFlags.UnicodeSets); /** Grammar parameter */ - const unicodeMode = unicodeSetsMode || !!(regExpFlags & RegularExpressionFlags.UnicodeMode); // v always implies u + const unicodeMode = !!(regExpFlags & RegularExpressionFlags.UnicodeMode); if (unicodeMode) { // Annex B treats any unicode mode as the strict syntax. diff --git a/src/testRunner/unittests/incrementalParser.ts b/src/testRunner/unittests/incrementalParser.ts index 52c3f16e0c01a..a42044d0a67db 100644 --- a/src/testRunner/unittests/incrementalParser.ts +++ b/src/testRunner/unittests/incrementalParser.ts @@ -160,7 +160,7 @@ describe("unittests:: Incremental Parser", () => { const oldText = ts.ScriptSnapshot.fromString(source); const newTextAndChange = withInsert(oldText, semicolonIndex, "/"); - compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); }); it("Regular expression 2", () => { From 48d0a0a70bfec3d65d63714e11f93ccd0da28e74 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 24 Apr 2024 16:32:32 -0400 Subject: [PATCH 3/7] PR feedback --- src/compiler/checker.ts | 56 +++++++++++++++++++++++------------------ src/compiler/scanner.ts | 2 +- src/compiler/types.ts | 1 + 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 883f28290e9dd..0ddb2d3e78185 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1102,6 +1102,7 @@ import { WideningContext, WithStatement, YieldExpression, + Scanner, } from "./_namespaces/ts"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers"; import * as performance from "./_namespaces/ts.performance"; @@ -1449,6 +1450,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var requestedExternalEmitHelperNames = new Set(); var requestedExternalEmitHelpers: ExternalEmitHelpers; var externalHelpersModule: Symbol; + var scanner: Scanner | undefined; var Symbol = objectAllocator.getSymbolConstructor(); var Type = objectAllocator.getTypeConstructor(); @@ -31360,35 +31362,41 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const sourceFile = getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { let lastError: DiagnosticWithLocation | undefined; - const scanner = createScanner( - sourceFile.languageVersion, - /*skipTrivia*/ true, - sourceFile.languageVariant, - sourceFile.text, - (message, length, arg0) => { - // emulate `parseErrorAtPosition` from parser.ts - const start = scanner.getTokenEnd(); - if (message.category === DiagnosticCategory.Message && lastError && start === lastError.start && length === lastError.length) { - const error = createDetachedDiagnostic(sourceFile.fileName, sourceFile.text, start, length, message, arg0); - addRelatedInfo(lastError, error); - } - else if (!lastError || start !== lastError.start) { - lastError = createFileDiagnostic(sourceFile, start, length, message, arg0); - diagnostics.add(lastError); - } - }, - node.pos, - node.end - node.pos, - ); - Debug.assert(scanner.scan() === SyntaxKind.SlashToken); - Debug.assert(scanner.reScanSlashToken(/*reportErrors*/ true) === SyntaxKind.RegularExpressionLiteral); - return !!lastError; + scanner ??= createScanner(ScriptTarget.ESNext, /*skipTrivia*/ true); + scanner.setScriptTarget(sourceFile.languageVersion); + scanner.setLanguageVariant(sourceFile.languageVariant); + scanner.setText(sourceFile.text, node.pos, node.end - node.pos); + scanner.setOnError((message, length, arg0) => { + // emulate `parseErrorAtPosition` from parser.ts + const start = scanner!.getTokenEnd(); + if (message.category === DiagnosticCategory.Message && lastError && start === lastError.start && length === lastError.length) { + const error = createDetachedDiagnostic(sourceFile.fileName, sourceFile.text, start, length, message, arg0); + addRelatedInfo(lastError, error); + } + else if (!lastError || start !== lastError.start) { + lastError = createFileDiagnostic(sourceFile, start, length, message, arg0); + diagnostics.add(lastError); + } + }); + try { + Debug.assert(scanner.scan() === SyntaxKind.SlashToken); + Debug.assert(scanner.reScanSlashToken(/*reportErrors*/ true) === SyntaxKind.RegularExpressionLiteral); + return !!lastError; + } + finally { + scanner.setText(""); + scanner.setOnError(/*onError*/ undefined); + } } return false; } function checkRegularExpressionLiteral(node: RegularExpressionLiteral) { - checkGrammarRegularExpressionLiteral(node); + const nodeLinks = getNodeLinks(node); + if (!nodeLinks.grammarChecked) { + addLazyDiagnostic(() => checkGrammarRegularExpressionLiteral(node)); + nodeLinks.grammarChecked = true; + } return globalRegExpType; } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 562c24ec8d88c..65677ea034ada 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -2588,7 +2588,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean case CharacterCodes.equals: case CharacterCodes.exclamation: pos++; - // In Annex B, `(?=Disjunction)` and `(?!Disjunciton)` are quantifiable + // In Annex B, `(?=Disjunction)` and `(?!Disjunction)` are quantifiable isPreviousTermQuantifiable = annexB; break; case CharacterCodes.lessThan: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 70397a75908de..eaa596132eb48 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6140,6 +6140,7 @@ export interface NodeLinks { parameterInitializerContainsUndefined?: boolean; // True if this is a parameter declaration whose type annotation contains "undefined". fakeScopeForSignatureDeclaration?: "params" | "typeParams"; // If present, this is a fake scope injected into an enclosing declaration chain. assertionExpressionType?: Type; // Cached type of the expression of a type assertion + grammarChecked?: boolean; // Whether this expression has already been grammar-checked. } /** @internal */ From aa8c58597a6376f4a39526d26be5ea059a27edb6 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 24 Apr 2024 16:49:27 -0400 Subject: [PATCH 4/7] Remove overaggressive assert --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0ddb2d3e78185..dd04bcfbfe09e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -31365,7 +31365,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { scanner ??= createScanner(ScriptTarget.ESNext, /*skipTrivia*/ true); scanner.setScriptTarget(sourceFile.languageVersion); scanner.setLanguageVariant(sourceFile.languageVariant); - scanner.setText(sourceFile.text, node.pos, node.end - node.pos); scanner.setOnError((message, length, arg0) => { // emulate `parseErrorAtPosition` from parser.ts const start = scanner!.getTokenEnd(); @@ -31378,9 +31377,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { diagnostics.add(lastError); } }); + scanner.setText(sourceFile.text, node.pos, node.end - node.pos); try { - Debug.assert(scanner.scan() === SyntaxKind.SlashToken); - Debug.assert(scanner.reScanSlashToken(/*reportErrors*/ true) === SyntaxKind.RegularExpressionLiteral); + scanner.scan(); + Debug.assert(scanner.reScanSlashToken(/*reportErrors*/ true) === SyntaxKind.RegularExpressionLiteral, "Expected scanner to rescan RegularExpressionLiteral"); return !!lastError; } finally { From 19cb6ca7c3d0ea7711ec11d745f811b2f69b9316 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 24 Apr 2024 17:02:37 -0400 Subject: [PATCH 5/7] Fix format --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dd04bcfbfe09e..0e6212b0bdade 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -956,6 +956,7 @@ import { ReverseMappedType, sameMap, SatisfiesExpression, + Scanner, scanTokenAtPosition, ScriptKind, ScriptTarget, @@ -1102,7 +1103,6 @@ import { WideningContext, WithStatement, YieldExpression, - Scanner, } from "./_namespaces/ts"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers"; import * as performance from "./_namespaces/ts.performance"; From d67ab82f268e9a3c55bc8ff8f0a6b4ce1a18e288 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 24 Apr 2024 17:32:01 -0400 Subject: [PATCH 6/7] Use NodeCheckFlags.TypeChecked --- src/compiler/checker.ts | 4 ++-- src/compiler/types.ts | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0e6212b0bdade..b67b45073704d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -31393,9 +31393,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function checkRegularExpressionLiteral(node: RegularExpressionLiteral) { const nodeLinks = getNodeLinks(node); - if (!nodeLinks.grammarChecked) { + if (!(nodeLinks.flags & NodeCheckFlags.TypeChecked)) { + nodeLinks.flags |= NodeCheckFlags.TypeChecked; addLazyDiagnostic(() => checkGrammarRegularExpressionLiteral(node)); - nodeLinks.grammarChecked = true; } return globalRegExpType; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index eaa596132eb48..70397a75908de 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6140,7 +6140,6 @@ export interface NodeLinks { parameterInitializerContainsUndefined?: boolean; // True if this is a parameter declaration whose type annotation contains "undefined". fakeScopeForSignatureDeclaration?: "params" | "typeParams"; // If present, this is a fake scope injected into an enclosing declaration chain. assertionExpressionType?: Type; // Cached type of the expression of a type assertion - grammarChecked?: boolean; // Whether this expression has already been grammar-checked. } /** @internal */ From 74d995c87646091ebacddc0f4abf21f76a4d2359 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 24 Apr 2024 17:39:04 -0400 Subject: [PATCH 7/7] Add test for `/=/` --- .../reference/parserRegularExpression6.js | 10 ++++++++++ .../parserRegularExpression6.symbols | 12 +++++++++++ .../reference/parserRegularExpression6.types | 20 +++++++++++++++++++ .../parserRegularExpression6.ts | 3 +++ 4 files changed, 45 insertions(+) create mode 100644 tests/baselines/reference/parserRegularExpression6.js create mode 100644 tests/baselines/reference/parserRegularExpression6.symbols create mode 100644 tests/baselines/reference/parserRegularExpression6.types create mode 100644 tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression6.ts diff --git a/tests/baselines/reference/parserRegularExpression6.js b/tests/baselines/reference/parserRegularExpression6.js new file mode 100644 index 0000000000000..b6142fd267d3b --- /dev/null +++ b/tests/baselines/reference/parserRegularExpression6.js @@ -0,0 +1,10 @@ +//// [tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression6.ts] //// + +//// [parserRegularExpression6.ts] +declare var a; +a /= 1; // parse as infix +a = /=/; // parse as regexp + +//// [parserRegularExpression6.js] +a /= 1; // parse as infix +a = /=/; // parse as regexp diff --git a/tests/baselines/reference/parserRegularExpression6.symbols b/tests/baselines/reference/parserRegularExpression6.symbols new file mode 100644 index 0000000000000..b5cec1d8448d0 --- /dev/null +++ b/tests/baselines/reference/parserRegularExpression6.symbols @@ -0,0 +1,12 @@ +//// [tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression6.ts] //// + +=== parserRegularExpression6.ts === +declare var a; +>a : Symbol(a, Decl(parserRegularExpression6.ts, 0, 11)) + +a /= 1; // parse as infix +>a : Symbol(a, Decl(parserRegularExpression6.ts, 0, 11)) + +a = /=/; // parse as regexp +>a : Symbol(a, Decl(parserRegularExpression6.ts, 0, 11)) + diff --git a/tests/baselines/reference/parserRegularExpression6.types b/tests/baselines/reference/parserRegularExpression6.types new file mode 100644 index 0000000000000..a07adbb2dcf41 --- /dev/null +++ b/tests/baselines/reference/parserRegularExpression6.types @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression6.ts] //// + +=== parserRegularExpression6.ts === +declare var a; +>a : any + +a /= 1; // parse as infix +>a /= 1 : number +> : ^^^^^^ +>a : any +>1 : 1 +> : ^ + +a = /=/; // parse as regexp +>a = /=/ : RegExp +> : ^^^^^^ +>a : any +>/=/ : RegExp +> : ^^^^^^ + diff --git a/tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression6.ts b/tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression6.ts new file mode 100644 index 0000000000000..7180a2f6540a4 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression6.ts @@ -0,0 +1,3 @@ +declare var a; +a /= 1; // parse as infix +a = /=/; // parse as regexp \ No newline at end of file