[utils] js_to_json: Improve

Closes #4900
This commit is contained in:
pukkandan 2022-09-23 19:21:07 +05:30
parent 32972518da
commit f55523cfdd
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39

View File

@ -3298,7 +3298,7 @@ def fix_kv(m):
return '"%d":' % i if v.endswith(':') else '%d' % i
if v in vars:
return vars[v]
return json.dumps(vars[v])
if strict:
raise ValueError(f'Unknown value: {v}')
@ -3310,6 +3310,7 @@ def create_map(mobj):
code = re.sub(r'new Map\((\[.*?\])?\)', create_map, code)
if not strict:
code = re.sub(r'new Date\((".+")\)', r'\g<1>', code)
code = re.sub(r'new \w+\((.*?)\)', lambda m: json.dumps(m.group(0)), code)
return re.sub(r'''(?sx)
"(?:[^"\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^"\\]*"|