Fix replacing Python constants in arrays
This commit is contained in:
parent
30fcdf5ce8
commit
582645df70
|
@ -179,7 +179,9 @@ export function repair (jsString) {
|
||||||
c = curr()
|
c = curr()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specialValues.indexOf(key) === -1) {
|
if (key in pythonConstants) {
|
||||||
|
return pythonConstants[key]
|
||||||
|
} else if (specialValues.indexOf(key) === -1) {
|
||||||
return '"' + key + '"'
|
return '"' + key + '"'
|
||||||
} else {
|
} else {
|
||||||
return key
|
return key
|
||||||
|
@ -268,6 +270,7 @@ export function repair (jsString) {
|
||||||
i++
|
i++
|
||||||
} else if (/[a-zA-Z_$]/.test(c) && ['{', ','].indexOf(lastNonWhitespace()) !== -1) {
|
} else if (/[a-zA-Z_$]/.test(c) && ['{', ','].indexOf(lastNonWhitespace()) !== -1) {
|
||||||
// an unquoted object key (like a in '{a:2}')
|
// an unquoted object key (like a in '{a:2}')
|
||||||
|
// FIXME: array values are also parsed via parseKey, work this out properly
|
||||||
chars.push(parseKey())
|
chars.push(parseKey())
|
||||||
} else if (/\w/.test(c)) {
|
} else if (/\w/.test(c)) {
|
||||||
chars.push(parseValue())
|
chars.push(parseValue())
|
||||||
|
|
|
@ -141,12 +141,14 @@ describe('util', () => {
|
||||||
' "null": None,\n' +
|
' "null": None,\n' +
|
||||||
' "true": True,\n' +
|
' "true": True,\n' +
|
||||||
' "false": False\n' +
|
' "false": False\n' +
|
||||||
|
' "array": [1, foo, None, True, False]\n' +
|
||||||
'}'
|
'}'
|
||||||
|
|
||||||
const expectedJson = '{\n' +
|
const expectedJson = '{\n' +
|
||||||
' "null": null,\n' +
|
' "null": null,\n' +
|
||||||
' "true": true,\n' +
|
' "true": true,\n' +
|
||||||
' "false": false\n' +
|
' "false": false\n' +
|
||||||
|
' "array": [1, "foo", null, true, false]\n' +
|
||||||
'}'
|
'}'
|
||||||
|
|
||||||
assert.strictEqual(repair(pythonDocument), expectedJson)
|
assert.strictEqual(repair(pythonDocument), expectedJson)
|
||||||
|
|
Loading…
Reference in New Issue