diff --git a/src/subroutines.js b/src/subroutines.js index f1cdf10..9817226 100644 --- a/src/subroutines.js +++ b/src/subroutines.js @@ -74,7 +74,7 @@ function processSubroutines(expression, namedGroups) { // `unclosedGroupCount`. If there are any backrefs in the expression, wrap with '()' // instead of '(?:)' so that backrefs line up, in case there are backrefs inside the // subroutine that refer to their parent capturing group - const subroutineValue = `${hasBackrefs ? '(' : '(?:'}${contents})`; + const subroutineValue = `(${hasBackrefs ? '' : '?:'}${contents})`; openSubroutinesMap.set(subroutineName, { contents, unclosedGroupCount: countSubgroups(subroutineValue), @@ -245,7 +245,7 @@ function countCapturesBeforeGroupName(expression, groupName) { */ function countSubgroups(expression) { let num = 0; - forEachUnescaped(expression, String.raw`\(`, () => num++, Context.DEFAULT); + forEachUnescaped(expression, '\\(', () => num++, Context.DEFAULT); return num; } diff --git a/src/utils.js b/src/utils.js index d1da0d5..77a681c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -67,7 +67,7 @@ export function escapeV(str, context) { // followed by the same unescaped symbol outside an interpolation, and since it won't be wrapped, // the second symbol wouldn't be sandboxed from the one following it. export function sandboxLoneDoublePunctuatorChar(str) { - return str.replace(new RegExp(String.raw`^([${doublePunctuatorChars}])(?!\1)`), (m, _, pos) => { + return str.replace(new RegExp(`^([${doublePunctuatorChars}])(?!\\1)`), (m, _, pos) => { return `\\${m}${pos + 1 === str.length ? '' : m}`; }); }