Skip to content

Commit 076ae1f

Browse files
committed
Retain native error for \k with bare integer in patterns that use atomic groups
1 parent 96b912c commit 076ae1f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/atomic-groups.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ export function atomicGroupsPostprocessor(pattern) {
4141
} else if (m === ')' && inAG) {
4242
if (!numGroupsOpenInAG) {
4343
aGCount++;
44-
// Replace pattern and use `\k<…>` as a temporary shield for the backref since numbered
45-
// backrefs are prevented separately
46-
pattern = `${pattern.slice(0, aGPos)}${emulatedAGDelim}${pattern.slice(aGPos + aGDelim.length, pos)}))\\k<${aGCount + capturingGroupCount}>)${pattern.slice(pos + 1)}`;
44+
// Replace pattern and use `\k<$$N>` as a temporary shield for the backref since
45+
// numbered backrefs are prevented separately
46+
pattern = `${pattern.slice(0, aGPos)}${emulatedAGDelim}${
47+
pattern.slice(aGPos + aGDelim.length, pos)
48+
}))\\k<$$${aGCount + capturingGroupCount}>)${pattern.slice(pos + 1)}`;
4749
hasProcessedAG = true;
4850
break;
4951
}
@@ -62,10 +64,10 @@ export function atomicGroupsPostprocessor(pattern) {
6264
// Start over from the beginning of the last atomic group's contents, in case the processed group
6365
// contains additional atomic groups
6466
} while (hasProcessedAG);
65-
// Replace `\k<>` added as a shield from the check for invalid numbered backrefs
67+
// Replace `\k<$$N>` added as a shield from the check for invalid numbered backrefs
6668
pattern = replaceUnescaped(
6769
pattern,
68-
String.raw`\\k<(?<backrefNum>\d+)>`,
70+
String.raw`\\k<\$\$(?<backrefNum>\d+)>`,
6971
({groups: {backrefNum}}) => `\\${backrefNum}`,
7072
Context.DEFAULT
7173
);

0 commit comments

Comments
 (0)