Repository navigation
Conversation
Since #59580, a `u` regex with a named backreference directly followed by a digit fails Hermes compilation with `Invalid regular expression: Invalid escape`. `@babel/plugin-transform-named-capturing-groups-regex` rewrites `\k<name>` as a numbered backreference without guarding a following digit, so `/(?<a>.)\k<a>1/u` becomes `/(.)\11/u`, a reference to group 11. Without the `u` flag, `\11` reads as a legacy octal escape, so non-`u` regexes compile but silently match the wrong thing. Hermes V1 supports named capturing groups natively, so the Hermes profiles stop lowering them, except for regexes that repeat a group name across alternatives, which Hermes doesn't support. Those still go through `@babel/plugin-transform-duplicate-named-capturing-groups-regex`. The `hermes-legacy` and `default` profiles keep the transform. Changelog: [General][Fixed] - Babel preset: Hermes V1 profiles no longer lower named capturing groups, fixing named backreferences followed by a digit
robhogan
marked this pull request as draft
October 29, 2026 10:39
Visual regression13 visual difference(s) at android
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




























Summary
Since #59580, a
uregex with a named backreference directly followed by a digit fails Hermes compilation withInvalid regular expression: Invalid escape.The cause is
@babel/plugin-transform-named-capturing-groups-regex, which rewrites\k<name>as a numbered backreference without guarding a following digit:\11is then a reference to group 11, a syntax error inumode. Before #59580 the unicode transform also dropped theuflag, and without it\11reads as a legacy octal escape (a tab) - so these regexes compiled, but silently matched the wrong thing. Non-uregexes still have that miscompile onmain.Hermes V1 supports named capturing groups natively, so this stops lowering them for the Hermes profiles. The exception is a name repeated across alternatives (
/(?<y>\d{4})-\d\d|\d\d-(?<y>\d{4})/), which Hermes doesn't support, so those regexes alone still go through@babel/plugin-transform-duplicate-named-capturing-groups-regex. Native groups also drop the_wrapRegExphelper, aRegExpsubclass with aWeakMaplookup on every match.The
hermes-legacyanddefaultprofiles keep the transform, and the bug, which is inregexpu-core(still present in 6.5.3).Test plan
exec,@@replace,@@matchAll,matchAll,replaceAlland match indices tests (413 run, no failures).hermes-stableoutput withhermescand compared against Node 26 for\k<a>1with and withoutu, a repeated-name regex,.groupsand$<name>replacement - all match. Before this change, theucase failed to compile and the non-ucase matched"x\t"instead of"xx1".Changelog
[General][Fixed] - Babel preset: Hermes V1 profiles no longer lower named capturing groups, fixing named backreferences followed by a digit