Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,14 @@
"category": "Error",
"code": 1515
},
"Regular expression pattern modifiers are only available when targeting '{0}' or later.": {
"category": "Error",
"code": 18062
},
"Duplicate named capturing groups are only available when targeting '{0}' or later.": {
"category": "Error",
"code": 18063
},
"A character class range must not be bounded by another character class.": {
"category": "Error",
"code": 1516
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,9 @@ export function createScanner(
error(Diagnostics.Subpattern_flags_must_be_present_when_there_is_a_minus_sign, start, pos - start);
}
}
if (pos !== start && languageVersion < ScriptTarget.ES2025) {
error(Diagnostics.Regular_expression_pattern_modifiers_are_only_available_when_targeting_0_or_later, start, pos - start, getNameOfScriptTarget(ScriptTarget.ES2025));
}
scanExpectedChar(CharacterCodes.colon);
isPreviousTermQuantifiable = true;
break;
Expand Down Expand Up @@ -3008,6 +3011,9 @@ export function createScanner(
error(Diagnostics.Named_capturing_groups_with_the_same_name_must_be_mutually_exclusive_to_each_other, tokenStart, pos - tokenStart);
}
else {
if (groupSpecifiers?.has(tokenValue) && languageVersion < ScriptTarget.ES2025) {
error(Diagnostics.Duplicate_named_capturing_groups_are_only_available_when_targeting_0_or_later, tokenStart, pos - tokenStart, getNameOfScriptTarget(ScriptTarget.ES2025));
}
topNamedCapturingGroupsScope ??= new Set();
topNamedCapturingGroupsScope.add(tokenValue);
groupSpecifiers ??= new Set();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
regexPatternModifiersAndDuplicateNamedGroups.ts(1,47): error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
regexPatternModifiersAndDuplicateNamedGroups.ts(2,22): error TS18062: Regular expression pattern modifiers are only available when targeting 'es2025' or later.


==== regexPatternModifiersAndDuplicateNamedGroups.ts (2 errors) ====
const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
~
!!! error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
const modifiers = /(?i:abc)/;
~
!!! error TS18062: Regular expression pattern modifiers are only available when targeting 'es2025' or later.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/conformance/es2025/regexPatternModifiersAndDuplicateNamedGroups.ts] ////

//// [regexPatternModifiersAndDuplicateNamedGroups.ts]
const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
const modifiers = /(?i:abc)/;

//// [regexPatternModifiersAndDuplicateNamedGroups.js]
"use strict";
const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
const modifiers = /(?i:abc)/;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [tests/cases/conformance/es2025/regexPatternModifiersAndDuplicateNamedGroups.ts] ////

=== regexPatternModifiersAndDuplicateNamedGroups.ts ===
const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
>dupNames : Symbol(dupNames, Decl(regexPatternModifiersAndDuplicateNamedGroups.ts, 0, 5))

const modifiers = /(?i:abc)/;
>modifiers : Symbol(modifiers, Decl(regexPatternModifiersAndDuplicateNamedGroups.ts, 1, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/conformance/es2025/regexPatternModifiersAndDuplicateNamedGroups.ts] ////

=== regexPatternModifiersAndDuplicateNamedGroups.ts ===
const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
>dupNames : RegExp
> : ^^^^^^
>/(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/ : RegExp
> : ^^^^^^

const modifiers = /(?i:abc)/;
>modifiers : RegExp
> : ^^^^^^
>/(?i:abc)/ : RegExp
> : ^^^^^^

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/conformance/es2025/regexPatternModifiersAndDuplicateNamedGroups.ts] ////

//// [regexPatternModifiersAndDuplicateNamedGroups.ts]
const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
const modifiers = /(?i:abc)/;

//// [regexPatternModifiersAndDuplicateNamedGroups.js]
"use strict";
const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
const modifiers = /(?i:abc)/;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [tests/cases/conformance/es2025/regexPatternModifiersAndDuplicateNamedGroups.ts] ////

=== regexPatternModifiersAndDuplicateNamedGroups.ts ===
const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
>dupNames : Symbol(dupNames, Decl(regexPatternModifiersAndDuplicateNamedGroups.ts, 0, 5))

const modifiers = /(?i:abc)/;
>modifiers : Symbol(modifiers, Decl(regexPatternModifiersAndDuplicateNamedGroups.ts, 1, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/conformance/es2025/regexPatternModifiersAndDuplicateNamedGroups.ts] ////

=== regexPatternModifiersAndDuplicateNamedGroups.ts ===
const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
>dupNames : RegExp
> : ^^^^^^
>/(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/ : RegExp
> : ^^^^^^

const modifiers = /(?i:abc)/;
>modifiers : RegExp
> : ^^^^^^
>/(?i:abc)/ : RegExp
> : ^^^^^^

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ regularExpressionScanning.ts(3,19): error TS1499: Unknown regular expression fla
regularExpressionScanning.ts(3,20): error TS1499: Unknown regular expression flag.
regularExpressionScanning.ts(3,21): error TS1500: Duplicate regular expression flag.
regularExpressionScanning.ts(3,22): error TS1499: Unknown regular expression flag.
regularExpressionScanning.ts(5,5): error TS18062: Regular expression pattern modifiers are only available when targeting 'es2025' or later.
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.
Expand Down Expand Up @@ -45,11 +46,14 @@ regularExpressionScanning.ts(14,5): error TS1503: Named capturing groups are onl
regularExpressionScanning.ts(14,14): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(14,29): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(14,45): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(14,46): error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
regularExpressionScanning.ts(14,57): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(14,58): error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
regularExpressionScanning.ts(15,15): error TS1532: There is no capturing group named 'absent' in this regular expression.
regularExpressionScanning.ts(15,24): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(15,36): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(15,45): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(15,46): error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
regularExpressionScanning.ts(15,58): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(15,59): error TS1515: Named capturing groups with the same name must be mutually exclusive to each other.
regularExpressionScanning.ts(17,31): error TS1507: There is nothing available for repetition.
Expand Down Expand Up @@ -219,7 +223,7 @@ regularExpressionScanning.ts(47,89): error TS1518: Anything that would possibly
regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag is only available when targeting 'es2024' or later.


==== regularExpressionScanning.ts (219 errors) ====
==== regularExpressionScanning.ts (223 errors) ====
const regexes: RegExp[] = [
// Flags
/foo/visualstudiocode,
Expand Down Expand Up @@ -255,6 +259,8 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
!!! error TS1499: Unknown regular expression flag.
// Pattern modifiers
/(?med-ium:bar)/,
~~~~~~~
!!! error TS18062: Regular expression pattern modifiers are only available when targeting 'es2025' or later.
~
!!! error TS1499: Unknown regular expression flag.
~
Expand Down Expand Up @@ -328,8 +334,12 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~~~
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~
!!! error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
~~~~~
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~
!!! error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
/(\k<bar>)\k<absent>(?<foo>foo)|(?<bar>)((?<foo>)|(bar(?<bar>bar)))/,
~~~~~~
!!! error TS1532: There is no capturing group named 'absent' in this regular expression.
Expand All @@ -339,6 +349,8 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~~~
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~
!!! error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
~~~~~
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ regularExpressionScanning.ts(3,19): error TS1499: Unknown regular expression fla
regularExpressionScanning.ts(3,20): error TS1499: Unknown regular expression flag.
regularExpressionScanning.ts(3,21): error TS1500: Duplicate regular expression flag.
regularExpressionScanning.ts(3,22): error TS1499: Unknown regular expression flag.
regularExpressionScanning.ts(5,5): error TS18062: Regular expression pattern modifiers are only available when targeting 'es2025' or later.
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.
Expand Down Expand Up @@ -47,11 +48,14 @@ regularExpressionScanning.ts(14,5): error TS1503: Named capturing groups are onl
regularExpressionScanning.ts(14,14): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(14,29): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(14,45): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(14,46): error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
regularExpressionScanning.ts(14,57): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(14,58): error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
regularExpressionScanning.ts(15,15): error TS1532: There is no capturing group named 'absent' in this regular expression.
regularExpressionScanning.ts(15,24): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(15,36): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(15,45): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(15,46): error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
regularExpressionScanning.ts(15,58): error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
regularExpressionScanning.ts(15,59): error TS1515: Named capturing groups with the same name must be mutually exclusive to each other.
regularExpressionScanning.ts(17,31): error TS1507: There is nothing available for repetition.
Expand Down Expand Up @@ -228,7 +232,7 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag


!!! error TS5107: Option 'target=ES5' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
==== regularExpressionScanning.ts (226 errors) ====
==== regularExpressionScanning.ts (230 errors) ====
const regexes: RegExp[] = [
// Flags
/foo/visualstudiocode,
Expand Down Expand Up @@ -264,6 +268,8 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
!!! error TS1499: Unknown regular expression flag.
// Pattern modifiers
/(?med-ium:bar)/,
~~~~~~~
!!! error TS18062: Regular expression pattern modifiers are only available when targeting 'es2025' or later.
~
!!! error TS1499: Unknown regular expression flag.
~
Expand Down Expand Up @@ -339,8 +345,12 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~~~
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~
!!! error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
~~~~~
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~
!!! error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
/(\k<bar>)\k<absent>(?<foo>foo)|(?<bar>)((?<foo>)|(bar(?<bar>bar)))/,
~~~~~~
!!! error TS1532: There is no capturing group named 'absent' in this regular expression.
Expand All @@ -350,6 +360,8 @@ regularExpressionScanning.ts(47,101): error TS1501: This regular expression flag
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~~~
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~
!!! error TS18063: Duplicate named capturing groups are only available when targeting 'es2025' or later.
~~~~~
!!! error TS1503: Named capturing groups are only available when targeting 'ES2018' or later.
~~~
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @target: es2022,es2025

const dupNames = /(?<y>\d{4})-\d{2}|\d{2}\/(?<y>\d{4})/;
const modifiers = /(?i:abc)/;