oxc-project / oxc

⚓ A collection of JavaScript tools written in Rust.
https://oxc.rs
MIT License
12.5k stars 458 forks source link

regular_expression: Improve ES2025 proposal-duplicate-named-capturing-groups logic #6358

Open leaysgur opened 3 months ago

leaysgur commented 3 months ago

Done in #6847 , but there is room for performance improvement.

We want to keep the code as simple as possible and process the current 2 loops in 1 loop for duplicates detection.


https://github.com/tc39/proposal-duplicate-named-capturing-groups https://tc39.es/ecma262/#sec-mightbothparticipate

For now, /(?<a>.)(?<a>.)/ is invalid syntax, name a is duplicated.

With this change, we can use the same name if they are splitted by | and in the same Disjunction like /(?<a>.)|(?<a>.)/.

But it still not allowed in some cases like /(?<n>|(?<n>))/, /(?<n>(?<n>)|)/, /((?<n>)|(?<n>))(?<n>)/, etc...

You need to track nesting level and | to mange scope.

TODOs

preyneyv commented 1 month ago

I'd like to take a stab at this!

Boshen commented 1 month ago

@preyneyv You may continue with https://github.com/oxc-project/oxc/pull/6847