diff --git a/src/parse/find-indexes.js b/src/parse/find-indexes.js index 7e23bdf3f..cfcf07df5 100644 --- a/src/parse/find-indexes.js +++ b/src/parse/find-indexes.js @@ -1,5 +1,6 @@ import CHAR_CODE from "../constant/char-code.js" +import escapeRegExp from "../util/escape-regexp.js" import shared from "../shared.js" function init() { @@ -9,12 +10,31 @@ function init() { function findIndexes(code, identifiers) { const indexes = [] + const { length } = identifiers - if (identifiers.length === 0) { + if (length === 0) { return indexes } - const pattern = new RegExp("\\b(?:" + identifiers.join("|") + ")\\b", "g") + const lastIndex = length - 1 + + const pattern = new RegExp( + "\\b(?:" + + (() => { + let i = -1 + let source = "" + + while (++i < length) { + source += + escapeRegExp(identifiers[i]) + + (i === lastIndex ? "" : "|") + } + + return source + })() + + ")\\b", + "g" + ) let match diff --git a/src/util/is-own-proxy.js b/src/util/is-own-proxy.js index 283ead6ab..3333a4b23 100644 --- a/src/util/is-own-proxy.js +++ b/src/util/is-own-proxy.js @@ -2,6 +2,7 @@ import ESM from "../constant/esm.js" import OwnProxy from "../own/proxy.js" +import escapeRegExp from "../util/escape-regexp.js" import { inspect } from "../safe/util.js" import isObjectLike from "./is-object-like.js" import shared from "../shared.js" @@ -11,11 +12,9 @@ function init() { PACKAGE_PREFIX } = ESM - let inspectDepth = 0 - const endMarkerRegExp = new RegExp( "[\\[\"']" + - PACKAGE_PREFIX + + escapeRegExp(PACKAGE_PREFIX) + ":proxy['\"\\]]\\s*:\\s*1\\s*\\}\\s*.?$" ) @@ -41,6 +40,8 @@ function init() { showProxy: true } + let inspectDepth = 0 + function isOwnProxy(value) { return OwnProxy.instances.has(value) || isOwnProxyFallback(value)