From 61c7a4a6504540c35f3e4246de9bbd97680195b2 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 21 Nov 2021 18:40:18 +0000 Subject: [PATCH] use RegExp string with flags as key for cached RegExp object, related to ajv-validator/ajv-keywords#220 --- lib/vocabularies/code.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vocabularies/code.ts b/lib/vocabularies/code.ts index 93d522926..92cdd5b04 100644 --- a/lib/vocabularies/code.ts +++ b/lib/vocabularies/code.ts @@ -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})`, }) }