Skip to content

Commit

Permalink
use RegExp string with flags as key for cached RegExp object, related…
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Nov 21, 2021
1 parent 4cc0cad commit 61c7a4a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/vocabularies/code.ts
Expand Up @@ -95,10 +95,11 @@ const newRegExp = _`new RegExp`
export function usePattern({gen, it: {opts}}: KeywordCxt, pattern: string): Name {
const u = opts.unicodeRegExp ? "u" : ""
const {regExp} = opts.code
const rx = regExp(pattern, u)

return gen.scopeValue("pattern", {
key: pattern,
ref: regExp(pattern, u),
key: rx.toString(),
ref: rx,
code: _`${regExp.code === "new RegExp" ? newRegExp : useFunc(gen, regExp)}(${pattern}, ${u})`,
})
}
Expand Down

0 comments on commit 61c7a4a

Please sign in to comment.