Skip to content

Gate ES2025 regex syntax (duplicate named groups, pattern modifiers) behind target - #63689

Closed
sumukhl17-lgtm wants to merge 1 commit into
microsoft:mainfrom
sumukhl17-lgtm:fix-63682-regex-es2025-gating
Closed

Gate ES2025 regex syntax (duplicate named groups, pattern modifiers) behind target#63689
sumukhl17-lgtm wants to merge 1 commit into
microsoft:mainfrom
sumukhl17-lgtm:fix-63682-regex-es2025-gating

Conversation

@sumukhl17-lgtm

Copy link
Copy Markdown

Fixes #63682

Both duplicate named capturing groups and pattern modifier syntax
((?i:...)) were being parsed and validated correctly, but weren't
gated to ES2025+ the way named capturing groups are gated to ES2018
and the v flag is gated to ES2024.

  • scanGroupName now errors (TS18063) when a capturing group name
    is reused across mutually-exclusive alternatives and the target
    is below ES2025 — this sits alongside the existing mutual-exclusivity
    check (TS1515) rather than replacing it.
  • The pattern-modifier scan site in the (? switch now errors
    (TS18062) when modifier text is present and the target is below
    ES2025 — bare non-capturing groups ((?:...)) are unaffected since
    no 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.ts baselines
(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.

Copilot AI review requested due to automatic review settings July 29, 2026 10:17
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Jul 29, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Jul 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 es2022 vs es2025, 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.

@sumukhl17-lgtm

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@MartinJohns

Copy link
Copy Markdown
Contributor

@sumukhl17-lgtm You implemented the change in the wrong repository. See https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md

@RyanCavanaugh

Copy link
Copy Markdown
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.

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ES2025 regex syntax (duplicate named groups, pattern modifiers) is not gated by target

4 participants