Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ES2025 RegExp duplicate named capturing groups #1291

Closed
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test case
  • Loading branch information
ota-meshi committed Apr 15, 2024
commit f7a9609d438fbd560bf0b541afaf651a390062f7
1 change: 1 addition & 0 deletions test/tests-regexp-2025.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ test("/(?<x>a)|(?<x>b)|(?<x>c)/", {}, { ecmaVersion: 2025 })
test("/(?<x>a)|\\k<x>/", {}, { ecmaVersion: 2025 })
testFail("/(?<x>a)|(?<x>b)(?<x>c)/", "Invalid regular expression: /(?<x>a)|(?<x>b)(?<x>c)/: Duplicate capture group name (1:1)", { ecmaVersion: 2025 })
testFail("/(?:(?<x>a)|(?<x>b))(?<x>c)/", "Invalid regular expression: /(?:(?<x>a)|(?<x>b))(?<x>c)/: Duplicate capture group name (1:1)", { ecmaVersion: 2025 })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I try it in Safari, it's not a syntax error. I may be misunderstanding something 🤔

Copy link
Contributor Author

@ota-meshi ota-meshi Apr 15, 2024

Choose a reason for hiding this comment

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

If I try the front and back swapped /(?<x>c)(?:(?<x>a)|(?<x>b))/ in Safari, I will get a syntax error.
Is it a bug in Safari that /(?:(?<x>a)|(?<x>b))(?<x>c)/ does not result in a syntax error? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

The way I read the spec, yes, that should be a syntax error—there is no | parse node that separates either of the first two definitions of <x> from the last one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your comment!
I was relieved that my understanding was correct 😄
If the current specs are fine, I think this PR is ready for review.

testFail("/(?<x>a)(?:(?<x>b)|(?<x>c))/", "Invalid regular expression: /(?<x>a)(?:(?<x>b)|(?<x>c))/: Duplicate capture group name (1:1)", { ecmaVersion: 2025 })
testFail("/(?:(?:(?<x>a)|(?<x>b))|(?:))(?<x>c)/", "Invalid regular expression: /(?:(?:(?<x>a)|(?<x>b))|(?:))(?<x>c)/: Duplicate capture group name (1:1)", { ecmaVersion: 2025 })
Loading