@@ -371,7 +371,7 @@ function buildExtraObjectPropertiesSerializer (context, location, addComma, objV
371371 const propertyLocation = patternPropertiesLocation . getPropertyLocation ( propertyKey )
372372
373373 code += `
374- if (/ ${ propertyKey . replace ( / \\ * \/ / g , '\\/' ) } / .test(key)) {
374+ if (new RegExp( ${ JSON . stringify ( propertyKey ) } ) .test(key)) {
375375 ${ addComma }
376376 json += asString(key) + JSON_STR_COLONS
377377 ${ buildValue ( context , propertyLocation , 'value' ) }
@@ -620,10 +620,7 @@ function buildObject (context, location, input) {
620620 const functionName = generateFuncName ( context )
621621 context . functionsNamesBySchema . set ( schema , functionName )
622622
623- const schemaRef = getSafeSchemaRef ( context , location )
624-
625623 const functionCode = `
626- // ${ schemaRef }
627624 function ${ functionName } (input) {
628625 const obj = ${ toJSON ( 'input' ) }
629626 if (obj === null) return ${ nullable ? 'JSON_STR_NULL' : 'JSON_STR_EMPTY_OBJECT' }
@@ -680,17 +677,17 @@ function buildArray (context, location, input) {
680677 context . functionsNamesBySchema . set ( schema , functionName )
681678
682679 const schemaRef = getSafeSchemaRef ( context , location )
680+ const schemaRefError = JSON . stringify ( `The value of '${ schemaRef } ' does not match schema definition.` )
683681
684682 let functionCode = `
685683 function ${ functionName } (obj) {
686- // ${ schemaRef }
687684 let json = ''
688685 `
689686
690687 functionCode += `
691688 if (obj === null) return ${ nullable ? 'JSON_STR_NULL' : 'JSON_STR_EMPTY_ARRAY' }
692689 if (!Array.isArray(obj)) {
693- throw new TypeError(\`The value of ' ${ schemaRef } ' does not match schema definition.\` )
690+ throw new TypeError(${ schemaRefError } )
694691 }
695692 const arrayLength = obj.length
696693 `
@@ -768,14 +765,15 @@ function buildArray (context, location, input) {
768765 }
769766
770767 context . buildingSet . add ( schema )
771- const safeSchemaRef = getSafeSchemaRef ( context , location )
768+ const schemaRef = getSafeSchemaRef ( context , location )
769+ const schemaRefError = JSON . stringify ( `The value of '${ schemaRef } ' does not match schema definition.` )
772770 const objVar = `obj_${ context . uid ++ } `
773771 let inlinedCode = `
774772 const ${ objVar } = ${ input }
775773 if (${ objVar } === null) {
776774 json += ${ nullable ? 'JSON_STR_NULL' : 'JSON_STR_EMPTY_ARRAY' }
777775 } else if (!Array.isArray(${ objVar } )) {
778- throw new TypeError(\`The value of ' ${ safeSchemaRef } ' does not match schema definition.\` )
776+ throw new TypeError(${ schemaRefError } )
779777 } else {
780778 const arrayLength_${ objVar } = ${ objVar } .length
781779 `
@@ -976,8 +974,9 @@ function buildMultiTypeSerializer (context, location, input) {
976974 }
977975 }
978976 } )
977+ const schemaRef = getSafeSchemaRef ( context , location )
979978 code += `
980- else throw new TypeError(\ `The value of '${ getSafeSchemaRef ( context , location ) } ' does not match schema definition.\` )
979+ else throw new TypeError(${ JSON . stringify ( `The value of '${ schemaRef } ' does not match schema definition.` ) } )
981980 `
982981
983982 return code
@@ -1218,14 +1217,15 @@ function buildOneOf (context, location, input) {
12181217 context . validatorSchemaRefs . add ( schemaRef )
12191218
12201219 code += `
1221- ${ index === 0 ? 'if' : 'else if' } (validator.validate(" ${ schemaRef } " , ${ input } )) {
1220+ ${ index === 0 ? 'if' : 'else if' } (validator.validate(${ JSON . stringify ( schemaRef ) } , ${ input } )) {
12221221 ${ nestedResult }
12231222 }
12241223 `
12251224 }
12261225
1226+ const schemaRef = getSafeSchemaRef ( context , location )
12271227 code += `
1228- else throw new TypeError(\ `The value of '${ getSafeSchemaRef ( context , location ) } ' does not match schema definition.\` )
1228+ else throw new TypeError(${ JSON . stringify ( `The value of '${ schemaRef } ' does not match schema definition.` ) } )
12291229 `
12301230
12311231 return code
@@ -1268,7 +1268,7 @@ function buildIfThenElse (context, location, input) {
12681268
12691269 if ( ! elseSchema ) {
12701270 return `
1271- if (validator.validate(" ${ ifSchemaRef } " , ${ input } )) {
1271+ if (validator.validate(${ JSON . stringify ( ifSchemaRef ) } , ${ input } )) {
12721272 ${ buildValue ( context , thenMergedLocation , input ) }
12731273 } else {
12741274 ${ buildValue ( context , rootLocation , input ) }
@@ -1292,7 +1292,7 @@ function buildIfThenElse (context, location, input) {
12921292 }
12931293
12941294 return `
1295- if (validator.validate(" ${ ifSchemaRef } " , ${ input } )) {
1295+ if (validator.validate(${ JSON . stringify ( ifSchemaRef ) } , ${ input } )) {
12961296 ${ buildValue ( context , thenMergedLocation , input ) }
12971297 } else {
12981298 ${ buildValue ( context , elseMergedLocation , input ) }
0 commit comments