diff --git a/lib/utils.js b/lib/utils.js index 2cf88ca..0516ccd 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -103,7 +103,7 @@ function findPossibleIndexes(code, identifiers, filter) { } const pattern = new RegExp( - "\\b(?:" + identifiers.join("|") + ")\\b", + "\\b(?:" + identifiers.map(escapeRegExp).join("|") + ")\\b", "g" ); @@ -118,6 +118,11 @@ function findPossibleIndexes(code, identifiers, filter) { return possibleIndexes; } +// RegExp.escape() polyfill, since Node 22.x doesn't have it +function escapeRegExp (regexp) { + return regexp.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +}; + exports.findPossibleIndexes = findPossibleIndexes; function findLikelyIndexes(code, identifiers) {