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

feat: add support for ES2025 duplicate named capturing groups #195

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ota-meshi
Copy link
Member

@ota-meshi ota-meshi commented Apr 13, 2024

close #194

@RunDevelopment
Copy link

How does this handle backreferences? The resolved field points to the referenced capturing group, but this is no longer unique.

@ota-meshi
Copy link
Member Author

ota-meshi commented Apr 14, 2024

Thank you for letting me know! I think we need to change the node.
That should be treated as a breaking change, right?

BREAKING CHANGE: add support for ES2025 duplicate named capturing groups
@RunDevelopment
Copy link

That should be treated as a breaking change, right?

Maybe. You currently implemented resolved: CapturingGroup[] which is a breaking change. However, we could also use the same trick you used for Unicode set character classes in v-flag regexes. So we could do something like this:

type Backreference = AmbiguousBackreference | UnambiguousBackreference
interface BaseBackreference {
  type: "Backreference"
  // other props
  ambiguous: boolean
  resolved: CaptruingGroup | CaptruingGroup[]
}
interface AmbiguousBackreference extends BaseBackreference {
  ambiguous: true
  resolved: CaptruingGroup[]
}
interface UnambiguousBackreference extends BaseBackreference {
  ambiguous: false
  resolved: CaptruingGroup
}

The interface/property names could use some work, but I hope I communicated the idea. This wouldn't be a breaking change, because regexes without duplicate group names produce the same AST as before (except for the additional ambiguous: false property).

However, I'm not sure whether this AST is ideal. It's backwards compatible, but it's also a bit more tricky to understand.

@ota-meshi
Copy link
Member Author

Thank you! That's a good idea!
I think it's a good thing that it avoids breaking changes since it is additional information that is not related to the AST.

@ota-meshi ota-meshi removed the BREAKING CHANGE This change will require a major version bump label Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for duplicate named capturing groups
2 participants