Skip to content

Commit d8e22cd

Browse files
authored
add genFuncNameCounter to context (#601)
1 parent 33e1c3b commit d8e22cd

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function build (schema, options) {
7373

7474
const context = {
7575
functions: [],
76+
functionsCounter: 0,
7677
functionsNamesBySchema: new Map(),
7778
options,
7879
refResolver: new RefResolver(),
@@ -180,7 +181,6 @@ function build (schema, options) {
180181
const contextFunc = new Function('validator', 'serializer', contextFunctionCode)
181182
const stringifyFunc = contextFunc(validator, serializer)
182183

183-
genFuncNameCounter = 0
184184
return stringifyFunc
185185
}
186186

@@ -498,7 +498,7 @@ function buildObject (context, location) {
498498
return context.functionsNamesBySchema.get(schema)
499499
}
500500

501-
const functionName = generateFuncName()
501+
const functionName = generateFuncName(context)
502502
context.functionsNamesBySchema.set(schema, functionName)
503503

504504
let schemaRef = location.getSchemaRef()
@@ -543,7 +543,7 @@ function buildArray (context, location) {
543543
return context.functionsNamesBySchema.get(schema)
544544
}
545545

546-
const functionName = generateFuncName()
546+
const functionName = generateFuncName(context)
547547
context.functionsNamesBySchema.set(schema, functionName)
548548

549549
let schemaRef = location.getSchemaRef()
@@ -670,9 +670,8 @@ function buildArrayTypeCondition (type, accessor) {
670670
return condition
671671
}
672672

673-
let genFuncNameCounter = 0
674-
function generateFuncName () {
675-
return 'anonymous' + genFuncNameCounter++
673+
function generateFuncName (context) {
674+
return 'anonymous' + context.functionsCounter++
676675
}
677676

678677
function buildMultiTypeSerializer (context, location, input) {

0 commit comments

Comments
 (0)