Skip to content

Commit a0682b9

Browse files
authored
fix: avoid unecessary concat calls (#256)
1 parent ebbae94 commit a0682b9

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

index.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,12 @@ function addPatternProperties (location) {
405405
if (/${regex.replace(/\\*\//g, '\\/')}/.test(keys[i])) {
406406
`
407407
if (type === 'object') {
408-
code += buildObject(ppLocation, '', 'buildObjectPP' + index)
409-
code += `
408+
code += `${buildObject(ppLocation, '', 'buildObjectPP' + index)}
410409
${addComma}
411410
json += $asString(keys[i]) + ':' + buildObjectPP${index}(obj[keys[i]])
412411
`
413412
} else if (type === 'array') {
414-
code += buildArray(ppLocation, '', 'buildArrayPP' + index)
415-
code += `
413+
code += `${buildArray(ppLocation, '', 'buildArrayPP' + index)}
416414
${addComma}
417415
json += $asString(keys[i]) + ':' + buildArrayPP${index}(obj[keys[i]])
418416
`
@@ -483,14 +481,12 @@ function additionalProperty (location) {
483481
var format = ap.format
484482
var stringSerializer = getStringSerializer(format)
485483
if (type === 'object') {
486-
code += buildObject(apLocation, '', 'buildObjectAP')
487-
code += `
484+
code += `${buildObject(apLocation, '', 'buildObjectAP')}
488485
${addComma}
489486
json += $asString(keys[i]) + ':' + buildObjectAP(obj[keys[i]])
490487
`
491488
} else if (type === 'array') {
492-
code += buildArray(apLocation, '', 'buildArrayAP')
493-
code += `
489+
code += `${buildArray(apLocation, '', 'buildArrayAP')}
494490
${addComma}
495491
json += $asString(keys[i]) + ':' + buildArrayAP(obj[keys[i]])
496492
`
@@ -792,8 +788,7 @@ function buildCode (location, code, laterCode, name) {
792788
}
793789
code += `${JSON.stringify(required[i])}`
794790
}
795-
code += ']'
796-
code += `
791+
code += `]
797792
for (var i = 0; i < required.length; i++) {
798793
if (obj[required[i]] === undefined) throw new Error('"' + required[i] + '" is required!')
799794
}
@@ -932,11 +927,10 @@ function buildObject (location, code, name) {
932927
r = buildInnerObject(location, name)
933928
}
934929

935-
code += r.code
936930
laterCode = r.laterCode
937931

938932
// Removes the comma if is the last element of the string (in case there are not properties)
939-
code += `
933+
code += `${r.code}
940934
json += '}'
941935
return json
942936
}
@@ -1006,16 +1000,13 @@ function buildArray (location, code, name) {
10061000
}
10071001
${result.code}
10081002
}
1003+
json += ']'
1004+
return json
1005+
}
10091006
`
10101007

10111008
laterCode = result.laterCode
10121009

1013-
code += `
1014-
json += ']'
1015-
return json
1016-
}
1017-
`
1018-
10191010
code += laterCode
10201011

10211012
return code

0 commit comments

Comments
 (0)