Gate ES2025 regex syntax (duplicate named groups, pattern modifiers) behind target - #63689
Closed
sumukhl17-lgtm wants to merge 1 commit into
Closed
Gate ES2025 regex syntax (duplicate named groups, pattern modifiers) behind target#63689sumukhl17-lgtm wants to merge 1 commit into
sumukhl17-lgtm wants to merge 1 commit into
Conversation
…behind target check Fixes microsoft#63682
Contributor
There was a problem hiding this comment.
Pull request overview
This PR ensures ES2025 regular-expression syntax is correctly gated by target, aligning duplicate named capturing groups and pattern-modifier groups ((?i:...)) with how other regex features are version-checked in the scanner.
Changes:
- Adds an ES2025-only gate (TS18062) for pattern modifier syntax when modifier text is present.
- Adds an ES2025-only gate (TS18063) for duplicate named capturing groups that are otherwise valid due to mutual exclusivity.
- Adds a new conformance test covering
es2022vses2025, and updates existing regex scanning baselines accordingly.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/cases/conformance/es2025/regexPatternModifiersAndDuplicateNamedGroups.ts | New multi-target conformance case demonstrating errors at es2022 and acceptance at es2025. |
| tests/baselines/reference/regularExpressionScanning(target=es5).errors.txt | Updates expected diagnostics to include TS18062/TS18063 under older targets. |
| tests/baselines/reference/regularExpressionScanning(target=es2015).errors.txt | Updates expected diagnostics to include TS18062/TS18063 under older targets. |
| src/compiler/scanner.ts | Implements ES2025 target gating for pattern modifiers and duplicate named groups (mutually exclusive case). |
| src/compiler/diagnosticMessages.json | Introduces TS18062 and TS18063 diagnostic messages. |
Author
|
@microsoft-github-policy-service agree |
Contributor
|
@sumukhl17-lgtm You implemented the change in the wrong repository. See https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md |
Member
|
The TypeScript repo is closed for development; PR should be in the typescript-go repo. Please see the top section of CONTRIBUTING.md and pinned issue #62963. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #63682
Both duplicate named capturing groups and pattern modifier syntax
(
(?i:...)) were being parsed and validated correctly, but weren'tgated to ES2025+ the way named capturing groups are gated to ES2018
and the
vflag is gated to ES2024.scanGroupNamenow errors (TS18063) when a capturing group nameis reused across mutually-exclusive alternatives and the target
is below ES2025 — this sits alongside the existing mutual-exclusivity
check (TS1515) rather than replacing it.
(?switch now errors(TS18062) when modifier text is present and the target is below
ES2025 — bare non-capturing groups (
(?:...)) are unaffected sinceno modifier characters are scanned in that case.
Added a new conformance test
(
tests/cases/conformance/es2025/regexPatternModifiersAndDuplicateNamedGroups.ts)targeting es2022 and es2025 to show the gate firing/not firing.
Also updated the existing
regularExpressionScanning.tsbaselines(es5, es2015), which already had test cases for both features and
now correctly produce the new errors.
I used AI assistance while working through this fix and
reviewed/tested the result myself before opening this PR.