Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Use escapeRegExp().
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Dec 24, 2018
1 parent dad035d commit c41e001
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
24 changes: 22 additions & 2 deletions src/parse/find-indexes.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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

Expand Down
7 changes: 4 additions & 3 deletions src/util/is-own-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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*.?$"
)

Expand All @@ -41,6 +40,8 @@ function init() {
showProxy: true
}

let inspectDepth = 0

function isOwnProxy(value) {
return OwnProxy.instances.has(value) ||
isOwnProxyFallback(value)
Expand Down

0 comments on commit c41e001

Please sign in to comment.