Fix replacing Python constants in arrays

This commit is contained in:
jos 2020-02-16 10:11:12 +01:00
parent 30fcdf5ce8
commit 582645df70
2 changed files with 6 additions and 1 deletions

View File

@ -179,7 +179,9 @@ export function repair (jsString) {
c = curr()
}
if (specialValues.indexOf(key) === -1) {
if (key in pythonConstants) {
return pythonConstants[key]
} else if (specialValues.indexOf(key) === -1) {
return '"' + key + '"'
} else {
return key
@ -268,6 +270,7 @@ export function repair (jsString) {
i++
} else if (/[a-zA-Z_$]/.test(c) && ['{', ','].indexOf(lastNonWhitespace()) !== -1) {
// an unquoted object key (like a in '{a:2}')
// FIXME: array values are also parsed via parseKey, work this out properly
chars.push(parseKey())
} else if (/\w/.test(c)) {
chars.push(parseValue())

View File

@ -141,12 +141,14 @@ describe('util', () => {
' "null": None,\n' +
' "true": True,\n' +
' "false": False\n' +
' "array": [1, foo, None, True, False]\n' +
'}'
const expectedJson = '{\n' +
' "null": null,\n' +
' "true": true,\n' +
' "false": false\n' +
' "array": [1, "foo", null, true, false]\n' +
'}'
assert.strictEqual(repair(pythonDocument), expectedJson)