Skip to content

Commit

Permalink
Use emulation groups with recursion when relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Dec 19, 2024
1 parent d9688b0 commit 38699b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,6 @@ Notice that nearly every feature below has at least subtle differences from Java
<td align="middle">✅</td>
<td>
✔ Unnamed captures and numbered calls allowed when using named capture<br>
✔ Allows numbered subroutine refs to duplicate group names<br>
</td>
</tr>
</table>
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ function toDetails(pattern, options) {
bestEffortTarget: opts.target,
});
const generated = generate(regexAst, opts);
pattern = possessive(recursion(generated.pattern));
const atomized = atomic(pattern, {useEmulationGroups: !opts.avoidSubclass});
const useEmulationGroups = atomized !== pattern && !opts.avoidSubclass;
pattern = atomized;
const pluginData = {useEmulationGroups: !opts.avoidSubclass};
const result = {
pattern,
pattern: atomic(possessive(recursion(generated.pattern, pluginData)), pluginData),
flags: `${opts.hasIndices ? 'd' : ''}${opts.global ? 'g' : ''}${generated.flags}${generated.options.disable.v ? 'u' : 'v'}`,
};
// See <github.com/slevithan/regex/blob/main/src/subclass.js>
const emulationGroupMarker = '$E$';
const useEmulationGroups = result.pattern.includes(emulationGroupMarker) && !opts.avoidSubclass;
if (useEmulationGroups || regexAst._strategy) {
result.subclass = {
useEmulationGroups,
Expand Down

0 comments on commit 38699b2

Please sign in to comment.