Skip to content

Commit 61c7a4a

Browse files
committedNov 21, 2021
use RegExp string with flags as key for cached RegExp object, related to ajv-validator/ajv-keywords#220
1 parent 4cc0cad commit 61c7a4a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎lib/vocabularies/code.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ const newRegExp = _`new RegExp`
9595
export function usePattern({gen, it: {opts}}: KeywordCxt, pattern: string): Name {
9696
const u = opts.unicodeRegExp ? "u" : ""
9797
const {regExp} = opts.code
98+
const rx = regExp(pattern, u)
9899

99100
return gen.scopeValue("pattern", {
100-
key: pattern,
101-
ref: regExp(pattern, u),
101+
key: rx.toString(),
102+
ref: rx,
102103
code: _`${regExp.code === "new RegExp" ? newRegExp : useFunc(gen, regExp)}(${pattern}, ${u})`,
103104
})
104105
}

0 commit comments

Comments
 (0)
Please sign in to comment.