Preserve number and string representation in json-stringify parser (#18405)

Co-authored-by: Alexander Kachkaev <alexander@kachkaev.ru>
This commit is contained in:
fisker CheungandAlexander Kachkaev authored and GitHub committed 2025-12-06 14:47:35 +08:00
1 parent a7b8a4f77d
commit 74366fcf1d
8 files changed
+718 -142

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
#### Preserve number and string representation in `json-stringify` parser (#18405 by @fisker)
Previous versions of Prettier `json-stringify` parser used `JSON.stringify()` to print numbers and strings. This led to the loss of the original value representation in a few rare cases. For example, extremely large or small numbers were rounded, and some special characters were unescaped. Technically, these transformations do not change how JSON values are read, but they are not something a formatter [is concerned about](https://prettier.io/docs/rationale#strings). Prettier main now keeps the original representation, even if it can be simplified.
<!-- prettier-ignore -->
```jsonc
// Input
[
"\u00FF",
1e9999,
0.4e669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006,
-9223372036854775809,
1e3,
{
1e3: 1,
1e999999999999999999999999999999: 1,
1: 1
}
]
// Prettier stable
[
"ÿ",
null,
null,
-9223372036854776000,
1000,
{
"1000": 1,
"Infinity": 1,
"1": 1
}
]
// Prettier main
[
"\u00FF",
1e9999,
0.4e669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006,
-9223372036854775809,
1e3,
{
1e3: 1,
1e999999999999999999999999999999: 1,
"1": 1
}
]
```
+1 -1
View File
@@ -317,7 +317,7 @@ Valid options:
- `"json"` (via [@babel/parser parseExpression](https://babeljs.io/docs/babel-parser#babelparserparseexpressioncode-options)) _First available in v1.5.0_
- `"json5"` (same parser as `"json"`, but outputs as [json5](https://json5.org/)) _First available in v1.13.0_
- `"jsonc"` (same parser as `"json"`, but outputs as "JSON with Comments") _First available in v3.2.0_
- `"json-stringify"` (same parser as `"json"`, but outputs like `JSON.stringify`) _First available in v1.13.0_
- `"json-stringify"` (parse like `JSON.parse()` except it's less strict, whitespace resembles `JSON.stringify()`) _First available in v1.13.0_
- `"graphql"` (via [graphql/language](https://github.com/graphql/graphql-js/tree/master/src/language)) _First available in v1.5.0_
- `"markdown"` (via [remark-parse](https://github.com/wooorm/remark/tree/main/packages/remark-parse)) _First available in v1.8.0_
- `"mdx"` (via [remark-parse](https://github.com/wooorm/remark/tree/main/packages/remark-parse) and [@mdx-js/mdx](https://github.com/mdx-js/mdx/tree/master/packages/mdx)) _First available in v1.15.0_
+51 -10
View File
@@ -1,4 +1,5 @@
import { hardline, indent, join } from "../document/index.js";
import printString from "../utilities/print-string.js";
import UnexpectedNodeError from "../utilities/unexpected-node-error.js";
function genericPrint(path, options, print) {
@@ -44,11 +45,17 @@ function genericPrint(path, options, print) {
case "BooleanLiteral":
return node.value ? "true" : "false";
case "StringLiteral":
return JSON.stringify(node.value);
case "NumericLiteral":
return isObjectKey(path)
? JSON.stringify(String(node.value))
: JSON.stringify(node.value);
return printString(getRaw(node), options);
case "NumericLiteral": {
// Intentionally to not use `printNumber`
// We may start stop support number normalization like the string print
const raw = getRaw(node);
if (isObjectKey(path) && String(Number(raw)) === raw) {
return `"${raw}"`;
}
return raw;
}
case "Identifier":
return isObjectKey(path) ? JSON.stringify(node.name) : node.name;
case "TemplateLiteral":
@@ -62,6 +69,10 @@ function genericPrint(path, options, print) {
}
}
function getRaw(node) {
return node.extra.raw;
}
function isObjectKey(path) {
return path.key === "key" && path.parent.type === "ObjectProperty";
}
@@ -69,7 +80,6 @@ function isObjectKey(path) {
const ignoredProperties = new Set([
"start",
"end",
"extra",
"loc",
"comments",
"leadingComments",
@@ -82,19 +92,45 @@ const ignoredProperties = new Set([
function clean(original, cloned /* , parent*/) {
const { type } = original;
// We print quoted key
if (type === "ObjectProperty") {
const { key } = original;
if (key.type === "Identifier") {
cloned.key = { type: "StringLiteral", value: key.name };
const { name } = key;
cloned.key = {
type: "StringLiteral",
value: name,
extra: { rawValue: name },
};
} else if (key.type === "NumericLiteral") {
cloned.key = { type: "StringLiteral", value: String(key.value) };
const raw = getRaw(key);
if (String(Number(raw)) === raw) {
cloned.key = {
type: "StringLiteral",
value: raw,
extra: { rawValue: raw },
};
}
}
return;
}
if (type === "StringLiteral") {
// We only remove `\` before `"`, but it's hard to detect if it's escaped
delete cloned.extra.raw;
}
if (type === "UnaryExpression" && original.operator === "+") {
return cloned.argument;
}
if (type === "ArrayExpression" || type === "ObjectExpression") {
cloned.extra ??= {};
if (original.extra?.trailingComma) {
delete cloned.extra.trailingComma;
}
}
// We print holes in array as `null`
if (type === "ArrayExpression") {
for (const [index, element] of original.elements.entries()) {
@@ -106,7 +142,12 @@ function clean(original, cloned /* , parent*/) {
}
// We print `TemplateLiteral` as string
if (type === "TemplateLiteral") {
return { type: "StringLiteral", value: original.quasis[0].value.cooked };
const value = original.quasis[0].value.cooked;
return {
type: "StringLiteral",
value,
extra: { rawValue: value },
};
}
}
+1
View File
@@ -15,6 +15,7 @@ function printString(raw, options) {
const enclosingQuote =
options.parser === "json" ||
options.parser === "jsonc" ||
options.parser === "json-stringify" ||
// This was added before we have the `jsonc` parser
// If `{quoteProps: "preserve"}` and `{singleQuote: false}` (default value),
// and `{parser: "json5"}`, double quotes are always used for strings.
@@ -56,11 +56,16 @@ runFormatTest(
...[...characters, LINE_FEED].map((character) => ({
name: `json-stringify(\\${characterCode(character)})`,
code: SINGLE_QUOTE + BACKSLASH + character + SINGLE_QUOTE,
output:
character === UNDERSCORE || character === SPACE
? DOUBLE_QUOTE + character + DOUBLE_QUOTE + LINE_FEED
: DOUBLE_QUOTE + DOUBLE_QUOTE + LINE_FEED,
output: DOUBLE_QUOTE + BACKSLASH + character + DOUBLE_QUOTE + LINE_FEED,
})),
...[...characters, LINE_FEED].map((character) => {
const code = DOUBLE_QUOTE + BACKSLASH + character + DOUBLE_QUOTE;
return {
name: `json-stringify(\\${characterCode(character)})`,
code,
output: code + LINE_FEED,
};
}),
...characters.map((character) => ({
name: `json-stringify(\\\\${characterCode(character)})`,
code: SINGLE_QUOTE + BACKSLASH + BACKSLASH + character + SINGLE_QUOTE,
@@ -1,5 +1,443 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`snippet: i_number_double_huge_neg_exp.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[123.456e-789]
=====================================output=====================================
[123.456e-789]
================================================================================
`;
exports[`snippet: i_number_double_huge_neg_exp.json format 2`] = `
====================================options=====================================
parsers: ["jsonc"]
printWidth: 80
| printWidth
=====================================input======================================
[123.456e-789]
=====================================output=====================================
[123.456e-789]
================================================================================
`;
exports[`snippet: i_number_double_huge_neg_exp.json format 3`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[123.456e-789]
=====================================output=====================================
[123.456e-789]
================================================================================
`;
exports[`snippet: i_number_double_huge_neg_exp.json format 4`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[123.456e-789]
=====================================output=====================================
[
123.456e-789
]
================================================================================
`;
exports[`snippet: i_number_huge_exp.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
=====================================output=====================================
[
0.4e669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006
]
================================================================================
`;
exports[`snippet: i_number_huge_exp.json format 2`] = `
====================================options=====================================
parsers: ["jsonc"]
printWidth: 80
| printWidth
=====================================input======================================
[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
=====================================output=====================================
[
0.4e669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006,
]
================================================================================
`;
exports[`snippet: i_number_huge_exp.json format 3`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
=====================================output=====================================
[
0.4e669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006,
]
================================================================================
`;
exports[`snippet: i_number_huge_exp.json format 4`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
=====================================output=====================================
[
0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006
]
================================================================================
`;
exports[`snippet: i_number_neg_int_huge_exp.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[-1e+9999]
=====================================output=====================================
[-1e9999]
================================================================================
`;
exports[`snippet: i_number_neg_int_huge_exp.json format 2`] = `
====================================options=====================================
parsers: ["jsonc"]
printWidth: 80
| printWidth
=====================================input======================================
[-1e+9999]
=====================================output=====================================
[-1e9999]
================================================================================
`;
exports[`snippet: i_number_neg_int_huge_exp.json format 3`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[-1e+9999]
=====================================output=====================================
[-1e9999]
================================================================================
`;
exports[`snippet: i_number_neg_int_huge_exp.json format 4`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[-1e+9999]
=====================================output=====================================
[
-1e+9999
]
================================================================================
`;
exports[`snippet: i_number_pos_double_huge_exp.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[1.5e+9999]
=====================================output=====================================
[1.5e9999]
================================================================================
`;
exports[`snippet: i_number_pos_double_huge_exp.json format 2`] = `
====================================options=====================================
parsers: ["jsonc"]
printWidth: 80
| printWidth
=====================================input======================================
[1.5e+9999]
=====================================output=====================================
[1.5e9999]
================================================================================
`;
exports[`snippet: i_number_pos_double_huge_exp.json format 3`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[1.5e+9999]
=====================================output=====================================
[1.5e9999]
================================================================================
`;
exports[`snippet: i_number_pos_double_huge_exp.json format 4`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[1.5e+9999]
=====================================output=====================================
[
1.5e+9999
]
================================================================================
`;
exports[`snippet: i_number_real_neg_overflow.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[-123123e100000]
=====================================output=====================================
[-123123e100000]
================================================================================
`;
exports[`snippet: i_number_real_neg_overflow.json format 2`] = `
====================================options=====================================
parsers: ["jsonc"]
printWidth: 80
| printWidth
=====================================input======================================
[-123123e100000]
=====================================output=====================================
[-123123e100000]
================================================================================
`;
exports[`snippet: i_number_real_neg_overflow.json format 3`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[-123123e100000]
=====================================output=====================================
[-123123e100000]
================================================================================
`;
exports[`snippet: i_number_real_neg_overflow.json format 4`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[-123123e100000]
=====================================output=====================================
[
-123123e100000
]
================================================================================
`;
exports[`snippet: i_number_real_pos_overflow.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[123123e100000]
=====================================output=====================================
[123123e100000]
================================================================================
`;
exports[`snippet: i_number_real_pos_overflow.json format 2`] = `
====================================options=====================================
parsers: ["jsonc"]
printWidth: 80
| printWidth
=====================================input======================================
[123123e100000]
=====================================output=====================================
[123123e100000]
================================================================================
`;
exports[`snippet: i_number_real_pos_overflow.json format 3`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[123123e100000]
=====================================output=====================================
[123123e100000]
================================================================================
`;
exports[`snippet: i_number_real_pos_overflow.json format 4`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[123123e100000]
=====================================output=====================================
[
123123e100000
]
================================================================================
`;
exports[`snippet: i_number_real_underflow.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[123e-10000000]
=====================================output=====================================
[123e-10000000]
================================================================================
`;
exports[`snippet: i_number_real_underflow.json format 2`] = `
====================================options=====================================
parsers: ["jsonc"]
printWidth: 80
| printWidth
=====================================input======================================
[123e-10000000]
=====================================output=====================================
[123e-10000000]
================================================================================
`;
exports[`snippet: i_number_real_underflow.json format 3`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[123e-10000000]
=====================================output=====================================
[123e-10000000]
================================================================================
`;
exports[`snippet: i_number_real_underflow.json format 4`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[123e-10000000]
=====================================output=====================================
[
123e-10000000
]
================================================================================
`;
exports[`snippet: i_number_too_big_neg_int.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[-123123123123123123123123123123]
=====================================output=====================================
[-123123123123123123123123123123]
================================================================================
`;
exports[`snippet: i_number_too_big_neg_int.json format 2`] = `
====================================options=====================================
parsers: ["jsonc"]
printWidth: 80
| printWidth
=====================================input======================================
[-123123123123123123123123123123]
=====================================output=====================================
[-123123123123123123123123123123]
================================================================================
`;
exports[`snippet: i_number_too_big_neg_int.json format 3`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[-123123123123123123123123123123]
=====================================output=====================================
[-123123123123123123123123123123]
================================================================================
`;
exports[`snippet: i_number_too_big_neg_int.json format 4`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[-123123123123123123123123123123]
=====================================output=====================================
[
-123123123123123123123123123123
]
================================================================================
`;
exports[`snippet: i_number_too_big_pos_int.json format 1`] = `
====================================options=====================================
parsers: ["json"]
@@ -54,6 +492,60 @@ printWidth: 80
================================================================================
`;
exports[`snippet: i_number_very_big_negative_int.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[-237462374673276894279832749832423479823246327846]
=====================================output=====================================
[-237462374673276894279832749832423479823246327846]
================================================================================
`;
exports[`snippet: i_number_very_big_negative_int.json format 2`] = `
====================================options=====================================
parsers: ["jsonc"]
printWidth: 80
| printWidth
=====================================input======================================
[-237462374673276894279832749832423479823246327846]
=====================================output=====================================
[-237462374673276894279832749832423479823246327846]
================================================================================
`;
exports[`snippet: i_number_very_big_negative_int.json format 3`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[-237462374673276894279832749832423479823246327846]
=====================================output=====================================
[-237462374673276894279832749832423479823246327846]
================================================================================
`;
exports[`snippet: i_number_very_big_negative_int.json format 4`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[-237462374673276894279832749832423479823246327846]
=====================================output=====================================
[
-237462374673276894279832749832423479823246327846
]
================================================================================
`;
exports[`snippet: i_object_key_lone_2nd_surrogate.json format 1`] = `
====================================options=====================================
parsers: ["json"]
@@ -102,7 +594,7 @@ printWidth: 80
{"\\uDFAA":0}
=====================================output=====================================
{
"\\udfaa": 0
"\\uDFAA": 0
}
================================================================================
@@ -156,7 +648,7 @@ printWidth: 80
["\\uDADA"]
=====================================output=====================================
[
"\\udada"
"\\uDADA"
]
================================================================================
@@ -210,7 +702,7 @@ printWidth: 80
["\\uD888\\u1234"]
=====================================output=====================================
[
"\\ud888ሴ"
"\\uD888\\u1234"
]
================================================================================
@@ -372,7 +864,7 @@ printWidth: 80
["\\uD800\\n"]
=====================================output=====================================
[
"\\ud800\\n"
"\\uD800\\n"
]
================================================================================
@@ -426,7 +918,7 @@ printWidth: 80
["\\uDd1ea"]
=====================================output=====================================
[
"\\udd1ea"
"\\uDd1ea"
]
================================================================================
@@ -480,7 +972,7 @@ printWidth: 80
["\\uD800\\uD800\\n"]
=====================================output=====================================
[
"\\ud800\\ud800\\n"
"\\uD800\\uD800\\n"
]
================================================================================
@@ -696,7 +1188,7 @@ printWidth: 80
["\\uDd1e\\uD834"]
=====================================output=====================================
[
"\\udd1e\\ud834"
"\\uDd1e\\uD834"
]
================================================================================
@@ -804,7 +1296,7 @@ printWidth: 80
["\\uDFAA"]
=====================================output=====================================
[
"\\udfaa"
"\\uDFAA"
]
================================================================================
@@ -1280,7 +1772,7 @@ printWidth: 80
=====================================output=====================================
[
-9223372036854776000
-9223372036854775808
]
================================================================================
@@ -1296,7 +1788,7 @@ printWidth: 80
=====================================output=====================================
[
-9223372036854776000
-9223372036854775809
]
================================================================================
@@ -1354,7 +1846,7 @@ printWidth: 80
=====================================output=====================================
[
1
1.0
]
================================================================================
@@ -1412,7 +1904,7 @@ printWidth: 80
=====================================output=====================================
[
1
1.000000000000000005
]
================================================================================
@@ -1470,7 +1962,7 @@ printWidth: 80
=====================================output=====================================
[
0
1E-999
]
================================================================================
@@ -1528,7 +2020,7 @@ printWidth: 80
=====================================output=====================================
[
1000000
1E6
]
================================================================================
@@ -1686,7 +2178,7 @@ printWidth: 80
=====================================output=====================================
[
9223372036854776000
9223372036854775807
]
================================================================================
@@ -1702,7 +2194,7 @@ printWidth: 80
=====================================output=====================================
[
9223372036854776000
9223372036854775808
]
================================================================================
@@ -1760,7 +2252,7 @@ printWidth: 80
=====================================output=====================================
[
10000000000000000000
10000000000000000999
]
================================================================================
@@ -2093,7 +2585,7 @@ printWidth: 80
["\\uD800"]
=====================================output=====================================
[
"\\ud800"
"\\uD800"
]
================================================================================
@@ -2201,7 +2693,7 @@ printWidth: 80
["\\uD800\\uD800"]
=====================================output=====================================
[
"\\ud800\\ud800"
"\\uD800\\uD800"
]
================================================================================
@@ -2309,7 +2801,7 @@ printWidth: 80
["\\uD800\\uD800\\uD800"]
=====================================output=====================================
[
"\\ud800\\ud800\\ud800"
"\\uD800\\uD800\\uD800"
]
================================================================================
@@ -3074,7 +3566,7 @@ printWidth: 80
[123e65]
=====================================output=====================================
[
1.23e+67
123e65
]
================================================================================
@@ -3128,7 +3620,7 @@ printWidth: 80
[0e+1]
=====================================output=====================================
[
0
0e+1
]
================================================================================
@@ -3182,7 +3674,7 @@ printWidth: 80
[0e1]
=====================================output=====================================
[
0
0e1
]
================================================================================
@@ -3300,7 +3792,7 @@ printWidth: 80
=====================================output=====================================
[
-1e-78
-0.000000000000000000000000000000000000000000000000000000000000000000000000000001
]
================================================================================
@@ -3354,7 +3846,7 @@ printWidth: 80
[20e1]
=====================================output=====================================
[
200
20e1
]
================================================================================
@@ -3624,7 +4116,7 @@ printWidth: 80
[1E22]
=====================================output=====================================
[
1e+22
1E22
]
================================================================================
@@ -3678,7 +4170,7 @@ printWidth: 80
[1E-2]
=====================================output=====================================
[
0.01
1E-2
]
================================================================================
@@ -3732,7 +4224,7 @@ printWidth: 80
[1E+2]
=====================================output=====================================
[
100
1E+2
]
================================================================================
@@ -3786,7 +4278,7 @@ printWidth: 80
[123e45]
=====================================output=====================================
[
1.23e+47
123e45
]
================================================================================
@@ -3840,7 +4332,7 @@ printWidth: 80
[123.456e78]
=====================================output=====================================
[
1.23456e+80
123.456e78
]
================================================================================
@@ -3894,7 +4386,7 @@ printWidth: 80
[1e-2]
=====================================output=====================================
[
0.01
1e-2
]
================================================================================
@@ -3948,7 +4440,7 @@ printWidth: 80
[1e+2]
=====================================output=====================================
[
100
1e+2
]
================================================================================
@@ -4489,8 +4981,8 @@ printWidth: 80
{ "min": -1.0e+28, "max": 1.0e+28 }
=====================================output=====================================
{
"min": -1e+28,
"max": 1e+28
"min": -1.0e+28,
"max": 1.0e+28
}
================================================================================
@@ -4672,7 +5164,7 @@ printWidth: 80
{"title":"\\u041f\\u043e\\u043b\\u0442\\u043e\\u0440\\u0430 \\u0417\\u0435\\u043c\\u043b\\u0435\\u043a\\u043e\\u043f\\u0430" }
=====================================output=====================================
{
"title": "Полтора Землекопа"
"title": "\\u041f\\u043e\\u043b\\u0442\\u043e\\u0440\\u0430 \\u0417\\u0435\\u043c\\u043b\\u0435\\u043a\\u043e\\u043f\\u0430"
}
================================================================================
@@ -4794,7 +5286,7 @@ printWidth: 80
["\\u0060\\u012a\\u12AB"]
=====================================output=====================================
[
"\`Īካ"
"\\u0060\\u012a\\u12AB"
]
================================================================================
@@ -4848,7 +5340,7 @@ printWidth: 80
["\\uD801\\udc37"]
=====================================output=====================================
[
"𐐷"
"\\uD801\\udc37"
]
================================================================================
@@ -4902,7 +5394,7 @@ printWidth: 80
["\\ud83d\\ude39\\ud83d\\udc8d"]
=====================================output=====================================
[
"😹💍"
"\\ud83d\\ude39\\ud83d\\udc8d"
]
================================================================================
@@ -4956,7 +5448,7 @@ printWidth: 80
["\\"\\\\\\/\\b\\f\\n\\r\\t"]
=====================================output=====================================
[
"\\"\\\\/\\b\\f\\n\\r\\t"
"\\"\\\\\\/\\b\\f\\n\\r\\t"
]
================================================================================
@@ -5334,7 +5826,7 @@ printWidth: 80
["\\uFFFF"]
=====================================output=====================================
[
"￿"
"\\uFFFF"
]
================================================================================
@@ -5496,7 +5988,7 @@ printWidth: 80
["\\uDBFF\\uDFFF"]
=====================================output=====================================
[
"􏿿"
"\\uDBFF\\uDFFF"
]
================================================================================
@@ -5550,7 +6042,7 @@ printWidth: 80
["new\\u00A0line"]
=====================================output=====================================
[
"new line"
"new\\u00A0line"
]
================================================================================
@@ -5766,7 +6258,7 @@ printWidth: 80
["\\u002c"]
=====================================output=====================================
[
","
"\\u002c"
]
================================================================================
@@ -6034,7 +6526,7 @@ printWidth: 80
["\\uD834\\uDd1e"]
=====================================output=====================================
[
"𝄞"
"\\uD834\\uDd1e"
]
================================================================================
@@ -6088,7 +6580,7 @@ printWidth: 80
["\\u0821"]
=====================================output=====================================
[
"ࠡ"
"\\u0821"
]
================================================================================
@@ -6142,7 +6634,7 @@ printWidth: 80
["\\u0123"]
=====================================output=====================================
[
"ģ"
"\\u0123"
]
================================================================================
@@ -6304,7 +6796,7 @@ printWidth: 80
["\\u0061\\u30af\\u30EA\\u30b9"]
=====================================output=====================================
[
"aクリス"
"\\u0061\\u30af\\u30EA\\u30b9"
]
================================================================================
@@ -6358,7 +6850,7 @@ printWidth: 80
["new\\u000Aline"]
=====================================output=====================================
[
"new\\nline"
"new\\u000Aline"
]
================================================================================
@@ -6466,7 +6958,7 @@ printWidth: 80
["\\uA66D"]
=====================================output=====================================
[
"ꙭ"
"\\uA66D"
]
================================================================================
@@ -6574,7 +7066,7 @@ printWidth: 80
["\\uD83F\\uDFFE"]
=====================================output=====================================
[
"🿾"
"\\uD83F\\uDFFE"
]
================================================================================
@@ -6628,7 +7120,7 @@ printWidth: 80
["\\uDBFF\\uDFFE"]
=====================================output=====================================
[
"􏿾"
"\\uDBFF\\uDFFE"
]
================================================================================
@@ -6682,7 +7174,7 @@ printWidth: 80
["\\u200B"]
=====================================output=====================================
[
"​"
"\\u200B"
]
================================================================================
@@ -6736,7 +7228,7 @@ printWidth: 80
["\\u2064"]
=====================================output=====================================
[
"⁤"
"\\u2064"
]
================================================================================
@@ -6790,7 +7282,7 @@ printWidth: 80
["\\uFDD0"]
=====================================output=====================================
[
"﷐"
"\\uFDD0"
]
================================================================================
@@ -6844,7 +7336,7 @@ printWidth: 80
["\\uFFFE"]
=====================================output=====================================
[
"￾"
"\\uFFFE"
]
================================================================================
@@ -6898,7 +7390,7 @@ printWidth: 80
["\\u0022"]
=====================================output=====================================
[
"\\""
"\\u0022"
]
================================================================================
@@ -6952,7 +7444,7 @@ printWidth: 80
["\\u005C"]
=====================================output=====================================
[
"\\\\"
"\\u005C"
]
================================================================================
@@ -10,21 +10,9 @@ const SKIP = new Set([
"i_structure_500_nested_arrays.json",
]);
const BUGS = new Set([
"i_number_neg_int_huge_exp.json",
"i_number_real_neg_overflow.json",
"i_number_double_huge_neg_exp.json",
"i_number_huge_exp.json",
"i_number_pos_double_huge_exp.json",
"i_number_real_pos_overflow.json",
"i_number_real_underflow.json",
"i_number_too_big_neg_int.json",
"i_number_very_big_negative_int.json",
]);
const cases = [...parsing, ...transform]
.map(({ name, input, error }) => {
if (error || SKIP.has(name) || BUGS.has(name)) {
if (error || SKIP.has(name)) {
return;
}
@@ -594,15 +594,16 @@ No \\\\n's!",
},
{
"//": "JSON5 numbers",
"hexadecimal": 912559,
"leadingDecimalPoint": 0.8675309,
"andTrailing": 8675309,
"hexadecimal": 0xdecaf,
"leadingDecimalPoint": .8675309,
"andTrailing": 8675309.,
"positiveSign": 1
},
{
"//": "JSON5 strings",
"singleQuotes": "I can use \\"double quotes\\" here",
"lineBreaks": "Look, Mom! No \\\\n's!"
"lineBreaks": "Look, Mom! \\
No \\\\n's!"
}
]
@@ -1237,35 +1238,35 @@ printWidth: 80
{
"//": "String escapes ",
"data": [
"\\u0000",
"ÿ",
"ÿ",
"\\0",
"\\xFF",
"\\u00FF",
"🐉"
]
},
{
"//": "Numbers",
"data": [
83,
42,
100000,
123456,
3740122863,
83,
0o123,
0b101010,
1e5,
123_456,
0xDeeD_Beef,
0123,
-Infinity,
-NaN,
1,
-1,
83,
42,
100000,
123456,
3740122863,
-83,
-42,
-100000,
-123456,
-3740122863
0o123,
0b101010,
1e5,
123_456,
0xDeeD_Beef,
-0o123,
-0b101010,
-1e5,
-123_456,
-0xDeeD_Beef
]
},
{
@@ -1537,8 +1538,8 @@ printWidth: 80
1,
2,
"3",
10000000000,
0.001
1e10,
1e-3
]
}
}
@@ -2460,23 +2461,23 @@ printWidth: 80
null,
{
"integer": 1234567890,
"real": -9876.54321,
"e": 1.23456789e-13,
"E": 1.23456789e+34,
"": 2.3456789012e+76,
"real": -9876.543210,
"e": 0.123456789e-12,
"E": 1.234567890E+34,
"": 23456789012E66,
"zero": 0,
"one": 1,
"space": " ",
"quote": "\\"",
"backslash": "\\\\",
"controls": "\\b\\f\\n\\r\\t",
"slash": "/ & /",
"slash": "/ & \\/",
"alpha": "abcdefghijklmnopqrstuvwyz",
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
"digit": "0123456789",
"0123456789": "digit",
"special": "\`1~!@#$%^&*()_+-={':[,]}|;.</>?",
"hex": "ģ䕧覫췯ꯍ",
"hex": "\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A",
"true": true,
"false": false,
"null": null,
@@ -2505,19 +2506,19 @@ printWidth: 80
7
],
"jsontext": "{\\"object with 1 member\\":[\\"array with 1 element\\"]}",
"quotes": "&#34; \\" %22 0x22 034 &#x22;",
"/\\\\\\"쫾몾ꮘﳞ볚\\b\\f\\n\\r\\t\`1~!@#$%^&*()_+-=[]{}|;:',./<>?": "A key can be any string"
"quotes": "&#34; \\u0022 %22 0x22 034 &#x22;",
"\\/\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t\`1~!@#$%^&*()_+-=[]{}|;:',./<>?": "A key can be any string"
},
0.5,
98.6,
99.44,
1066,
10,
1,
0.1,
1,
2,
2,
1e1,
0.1e1,
1e-1,
1e00,
2e+00,
2e-00,
"rosebud"
]
@@ -2956,23 +2957,23 @@ printWidth: 80
"true": "",
"string": "",
"0": "",
"100": "",
"100": "",
"10": "",
"0.01": "",
"0.001": "",
"10": "",
"1": "",
"1": "",
1e2: "",
1.0e+2: "",
.10e+2: "",
1e-2: "",
.1e-2: "",
0.1e+2: "",
1.0: "",
1.00000: "",
.1: "",
.100000: "",
"0.1": "",
"0.1": "",
"0.1": "",
"0.1": "",
"1e+30": "",
"1e-30": "",
"1e-30": "",
"Infinity": "",
"123": ""
0.100000: "",
999999999999999999999999999999: "",
.000000000000000000000000000001: "",
0.000000000000000000000000000001: "",
1e999999999999999999999999999999: "",
1_2_3: ""
}
================================================================================
@@ -3073,8 +3074,8 @@ printWidth: 80
1,
2,
"3",
10000000000,
0.001
1e10,
1e-3
]
}
}