From 0762bd31a7e33c8702b2e8031d6ec6dffdae6d07 Mon Sep 17 00:00:00 2001 From: Sjors Smits Date: Fri, 25 Aug 2023 07:48:12 +0200 Subject: [PATCH] Exterior RegExp Encode (#542) --- src/compiler/compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/compiler.ts b/src/compiler/compiler.ts index 25c463a9f..0c9d2b958 100644 --- a/src/compiler/compiler.ts +++ b/src/compiler/compiler.ts @@ -330,7 +330,7 @@ export namespace TypeCompiler { if (IsNumber(schema.minProperties)) yield `Object.getOwnPropertyNames(${value}).length >= ${schema.minProperties}` if (IsNumber(schema.maxProperties)) yield `Object.getOwnPropertyNames(${value}).length <= ${schema.maxProperties}` const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0] - const variable = CreateVariable(`new RegExp(/${patternKey}/)`) + const variable = CreateVariable(`${new RegExp(patternKey)}`) const check1 = CreateExpression(patternSchema, references, 'value') const check2 = Types.TypeGuard.TSchema(schema.additionalProperties) ? CreateExpression(schema.additionalProperties, references, value) : schema.additionalProperties === false ? 'false' : 'true' const expression = `(${variable}.test(key) ? ${check1} : ${check2})`