Skip to content

Commit fb4f944

Browse files
authored
avoid intermediate strings. use const and let (#596)
1 parent 07a9bcc commit fb4f944

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,14 @@ function buildInnerObject (location) {
326326
}
327327

328328
const sanitized = JSON.stringify(key)
329-
const asString = JSON.stringify(sanitized)
330329

331330
// Using obj['key'] !== undefined instead of obj.hasOwnProperty(prop) for perf reasons,
332331
// see https://github.com/mcollina/fast-json-stringify/pull/3 for discussion.
333332

334333
code += `
335334
if (obj[${sanitized}] !== undefined) {
336335
${addComma}
337-
json += ${asString} + ':'
336+
json += ${JSON.stringify(sanitized + ':')}
338337
`
339338

340339
code += buildValue(propertyLocation, `obj[${sanitized}]`)
@@ -344,7 +343,7 @@ function buildInnerObject (location) {
344343
code += `
345344
} else {
346345
${addComma}
347-
json += ${asString} + ':' + ${JSON.stringify(JSON.stringify(defaultValue))}
346+
json += ${JSON.stringify(sanitized + ':' + JSON.stringify(defaultValue))}
348347
`
349348
} else if (required.includes(key)) {
350349
code += `
@@ -526,15 +525,14 @@ function buildObject (location) {
526525
`
527526

528527
functionCode += `
529-
var obj = ${toJSON('input')}
530-
var json = '{'
531-
var addComma = false
528+
const obj = ${toJSON('input')}
529+
let json = '{'
530+
let addComma = false
532531
`
533532

534533
functionCode += buildInnerObject(location)
535534
functionCode += `
536-
json += '}'
537-
return json
535+
return json + '}'
538536
}
539537
`
540538

0 commit comments

Comments
 (0)