Support JSON6 (#10456)

* Add test

* Support JSON6

* Test

* Print `null` instead of holes

* More tests

* Update changelog

* Style

* Minor refactor

* Fix AST clean

* Fix `Identifier` clean

* Fix AST compare

* Style

* Reword changelog

Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>
This commit is contained in:
fisker CheungandGeorgii Dolzhykov authored and GitHub committed 2021-03-04 19:37:42 +02:00
1 parent 37aa31e929
commit 8a1ee9ad1b
7 files changed
+772 -232

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
#### Stricter JSON parser (#10346, #10443 by @fisker)
#### Stricter JSON parser (#10346, #10443, #10456 by @fisker)
Previously we allow all kinds of JavaScript expressions in `json` and `json5` parser, now they are stricter.
Prettier internally uses a JavaScript expression parser to parse JSON. That's why the `json` and `json5` parsers used to be very forgiving and allowed all kinds of JavaScript expressions. Now they are much stricter, although some simple non-standard syntax is still allowed (e.g., [JSON6](https://github.com/d3x0r/JSON6) is supported, except for multiple minus signs: `----123`).
<!-- prettier-ignore -->
```js
+23 -6
View File
@@ -45,11 +45,9 @@ function assertJsonNode(node) {
switch (node.type) {
case "ArrayExpression":
for (const element of node.elements) {
if (element === null) {
throw createJsonError(node, "Sparse array");
if (element !== null) {
assertJsonNode(element);
}
assertJsonNode(element);
}
return;
@@ -84,16 +82,35 @@ function assertJsonNode(node) {
return;
case "Identifier":
// JSON5 https://spec.json5.org/#numbers
if (node.name !== "Infinity" && node.name !== "NaN") {
if (
// JSON5 https://spec.json5.org/#numbers
node.name !== "Infinity" &&
node.name !== "NaN" &&
// JSON6 https://github.com/d3x0r/JSON6
node.name !== "undefined"
) {
throw createJsonError(node, `Identifier '${node.name}'`);
}
return;
case "TemplateLiteral":
if (isNonEmptyArray(node.expressions)) {
throw createJsonError(
node.expressions[0],
"'TemplateLiteral' with expression"
);
}
for (const element of node.quasis) {
assertJsonNode(element);
}
return;
case "NullLiteral":
case "BooleanLiteral":
case "NumericLiteral":
case "StringLiteral":
case "TemplateElement":
return;
default:
throw createJsonError(node, `'${node.type}'`);
+43 -14
View File
@@ -10,18 +10,24 @@ function genericPrint(path, options, print) {
switch (node.type) {
case "JsonRoot":
return [path.call(print, "node"), hardline];
case "ArrayExpression":
return node.elements.length === 0
? "[]"
: [
"[",
indent([
hardline,
join([",", hardline], path.map(print, "elements")),
]),
hardline,
"]",
];
case "ArrayExpression": {
if (node.elements.length === 0) {
return "[]";
}
const printed = path.map(
(elementPath) =>
path.getValue() === null ? "null" : print(elementPath),
"elements"
);
return [
"[",
indent([hardline, join([",", hardline], printed)]),
hardline,
"]",
];
}
case "ObjectExpression":
return node.properties.length === 0
? "{}"
@@ -55,6 +61,11 @@ function genericPrint(path, options, print) {
}
return node.name;
}
case "TemplateLiteral":
// There is only one `TemplateElement`
return path.call(print, "quasis", 0);
case "TemplateElement":
return JSON.stringify(node.value.cooked);
default:
/* istanbul ignore next */
throw new Error("unknown type: " + JSON.stringify(node.type));
@@ -67,18 +78,36 @@ const ignoredProperties = new Set([
"extra",
"loc",
"comments",
"leadingComments",
"trailingComments",
"innerComments",
"errors",
"range",
]);
function clean(node, newNode /*, parent*/) {
const { type } = node;
if (type === "Identifier") {
return { type: "StringLiteral", value: node.name };
// We print quoted key
if (type === "ObjectProperty" && node.key.type === "Identifier") {
newNode.key = { type: "StringLiteral", value: node.key.name };
return;
}
if (type === "UnaryExpression" && node.operator === "+") {
return newNode.argument;
}
// We print holes in array as `null`
if (type === "ArrayExpression") {
for (const [index, element] of node.elements.entries()) {
if (element === null) {
newNode.elements.splice(index, 0, { type: "NullLiteral" });
}
}
return;
}
// We print `TemplateLiteral` as string
if (type === "TemplateLiteral") {
return { type: "StringLiteral", value: node.quasis[0].value.cooked };
}
}
clean.ignoredProperties = ignoredProperties;
@@ -505,6 +505,474 @@ No \\\\n's!",
================================================================================
`;
exports[`json6.json - {"trailingComma":"all"} format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
[
{'//': 'Keyword \`undefined\`',
"data": [
{undefined: undefined},
undefined,
[undefined, ]
]
},
{'//': 'back-tick quoted strings',
"data": [
\`\`,
\`foo\`,
\`
multiple-line
\`,
\`\\u{1F409}\\\`'"\\\${}\`,
{'as-object-value': \`foo\`}
]
},
{'//': 'String escapes ',
"data": [
'\\0', '\\xFF', '\\u00FF', \`\\u{1F409}\`
]
},
{'//': 'Numbers',
"data": [
0o123, 0b101010, 1e5, 123_456, 0xDeeD_Beef,
0123,
-Infinity, -NaN,
]
},
{'//': 'empty members',
data: [
[,],
[1, , 2,,,,],
[1, , 2],
[1, , 2,]
]
}
]
=====================================output=====================================
[
{
"//": "Keyword \`undefined\`",
"data": [{ "undefined": undefined }, undefined, [undefined]]
},
{
"//": "back-tick quoted strings",
"data": [
\`\`,
\`foo\`,
\`
multiple-line
\`,
\`\\u{1F409}\\\`'"\\\${}\`,
{ "as-object-value": \`foo\` }
]
},
{ "//": "String escapes ", "data": ["\\0", "\\xFF", "\\u00FF", \`\\u{1F409}\`] },
{
"//": "Numbers",
"data": [0o123, 0b101010, 1e5, 123_456, 0xdeed_beef, 0123, -Infinity, -NaN]
},
{ "//": "empty members", "data": [[,], [1, , 2, , , ,], [1, , 2], [1, , 2]] }
]
================================================================================
`;
exports[`json6.json - {"trailingComma":"all"} format 2`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
[
{'//': 'Keyword \`undefined\`',
"data": [
{undefined: undefined},
undefined,
[undefined, ]
]
},
{'//': 'back-tick quoted strings',
"data": [
\`\`,
\`foo\`,
\`
multiple-line
\`,
\`\\u{1F409}\\\`'"\\\${}\`,
{'as-object-value': \`foo\`}
]
},
{'//': 'String escapes ',
"data": [
'\\0', '\\xFF', '\\u00FF', \`\\u{1F409}\`
]
},
{'//': 'Numbers',
"data": [
0o123, 0b101010, 1e5, 123_456, 0xDeeD_Beef,
0123,
-Infinity, -NaN,
]
},
{'//': 'empty members',
data: [
[,],
[1, , 2,,,,],
[1, , 2],
[1, , 2,]
]
}
]
=====================================output=====================================
[
{
"//": "Keyword \`undefined\`",
data: [{ undefined: undefined }, undefined, [undefined]],
},
{
"//": "back-tick quoted strings",
data: [
\`\`,
\`foo\`,
\`
multiple-line
\`,
\`\\u{1F409}\\\`'"\\\${}\`,
{ "as-object-value": \`foo\` },
],
},
{ "//": "String escapes ", data: ["\\0", "\\xFF", "\\u00FF", \`\\u{1F409}\`] },
{
"//": "Numbers",
data: [0o123, 0b101010, 1e5, 123_456, 0xdeed_beef, 0123, -Infinity, -NaN],
},
{ "//": "empty members", data: [[,], [1, , 2, , , ,], [1, , 2], [1, , 2]] },
]
================================================================================
`;
exports[`json6.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
=====================================input======================================
[
{'//': 'Keyword \`undefined\`',
"data": [
{undefined: undefined},
undefined,
[undefined, ]
]
},
{'//': 'back-tick quoted strings',
"data": [
\`\`,
\`foo\`,
\`
multiple-line
\`,
\`\\u{1F409}\\\`'"\\\${}\`,
{'as-object-value': \`foo\`}
]
},
{'//': 'String escapes ',
"data": [
'\\0', '\\xFF', '\\u00FF', \`\\u{1F409}\`
]
},
{'//': 'Numbers',
"data": [
0o123, 0b101010, 1e5, 123_456, 0xDeeD_Beef,
0123,
-Infinity, -NaN,
]
},
{'//': 'empty members',
data: [
[,],
[1, , 2,,,,],
[1, , 2],
[1, , 2,]
]
}
]
=====================================output=====================================
[
{
"//": "Keyword \`undefined\`",
"data": [{ "undefined": undefined }, undefined, [undefined]]
},
{
"//": "back-tick quoted strings",
"data": [
\`\`,
\`foo\`,
\`
multiple-line
\`,
\`\\u{1F409}\\\`'"\\\${}\`,
{ "as-object-value": \`foo\` }
]
},
{ "//": "String escapes ", "data": ["\\0", "\\xFF", "\\u00FF", \`\\u{1F409}\`] },
{
"//": "Numbers",
"data": [0o123, 0b101010, 1e5, 123_456, 0xdeed_beef, 0123, -Infinity, -NaN]
},
{ "//": "empty members", "data": [[,], [1, , 2, , , ,], [1, , 2], [1, , 2]] }
]
================================================================================
`;
exports[`json6.json format 2`] = `
====================================options=====================================
parsers: ["json5"]
printWidth: 80
| printWidth
=====================================input======================================
[
{'//': 'Keyword \`undefined\`',
"data": [
{undefined: undefined},
undefined,
[undefined, ]
]
},
{'//': 'back-tick quoted strings',
"data": [
\`\`,
\`foo\`,
\`
multiple-line
\`,
\`\\u{1F409}\\\`'"\\\${}\`,
{'as-object-value': \`foo\`}
]
},
{'//': 'String escapes ',
"data": [
'\\0', '\\xFF', '\\u00FF', \`\\u{1F409}\`
]
},
{'//': 'Numbers',
"data": [
0o123, 0b101010, 1e5, 123_456, 0xDeeD_Beef,
0123,
-Infinity, -NaN,
]
},
{'//': 'empty members',
data: [
[,],
[1, , 2,,,,],
[1, , 2],
[1, , 2,]
]
}
]
=====================================output=====================================
[
{
"//": "Keyword \`undefined\`",
data: [{ undefined: undefined }, undefined, [undefined]],
},
{
"//": "back-tick quoted strings",
data: [
\`\`,
\`foo\`,
\`
multiple-line
\`,
\`\\u{1F409}\\\`'"\\\${}\`,
{ "as-object-value": \`foo\` },
],
},
{ "//": "String escapes ", data: ["\\0", "\\xFF", "\\u00FF", \`\\u{1F409}\`] },
{
"//": "Numbers",
data: [0o123, 0b101010, 1e5, 123_456, 0xdeed_beef, 0123, -Infinity, -NaN],
},
{ "//": "empty members", data: [[,], [1, , 2, , , ,], [1, , 2], [1, , 2]] },
]
================================================================================
`;
exports[`json6.json format 3`] = `
====================================options=====================================
parsers: ["json-stringify"]
printWidth: 80
| printWidth
=====================================input======================================
[
{'//': 'Keyword \`undefined\`',
"data": [
{undefined: undefined},
undefined,
[undefined, ]
]
},
{'//': 'back-tick quoted strings',
"data": [
\`\`,
\`foo\`,
\`
multiple-line
\`,
\`\\u{1F409}\\\`'"\\\${}\`,
{'as-object-value': \`foo\`}
]
},
{'//': 'String escapes ',
"data": [
'\\0', '\\xFF', '\\u00FF', \`\\u{1F409}\`
]
},
{'//': 'Numbers',
"data": [
0o123, 0b101010, 1e5, 123_456, 0xDeeD_Beef,
0123,
-Infinity, -NaN,
]
},
{'//': 'empty members',
data: [
[,],
[1, , 2,,,,],
[1, , 2],
[1, , 2,]
]
}
]
=====================================output=====================================
[
{
"//": "Keyword \`undefined\`",
"data": [
{
"undefined": undefined
},
undefined,
[
undefined
]
]
},
{
"//": "back-tick quoted strings",
"data": [
"",
"foo",
"\\n multiple-line\\n",
"🐉\`'\\"\${}",
{
"as-object-value": "foo"
}
]
},
{
"//": "String escapes ",
"data": [
"\\u0000",
"ÿ",
"ÿ",
"🐉"
]
},
{
"//": "Numbers",
"data": [
83,
42,
100000,
123456,
3740122863,
83,
-Infinity,
-NaN
]
},
{
"//": "empty members",
"data": [
[
null
],
[
1,
null,
2,
null,
null,
null
],
[
1,
null,
2
],
[
1,
null,
2
]
]
}
]
================================================================================
`;
exports[`key-value.json - {"trailingComma":"all"} format 1`] = `
====================================options=====================================
parsers: ["json"]
+44
View File
@@ -0,0 +1,44 @@
[
{'//': 'Keyword `undefined`',
"data": [
{undefined: undefined},
undefined,
[undefined, ]
]
},
{'//': 'back-tick quoted strings',
"data": [
``,
`foo`,
`
multiple-line
`,
`\u{1F409}\`'"\${}`,
{'as-object-value': `foo`}
]
},
{'//': 'String escapes ',
"data": [
'\0', '\xFF', '\u00FF', `\u{1F409}`
]
},
{'//': 'Numbers',
"data": [
0o123, 0b101010, 1e5, 123_456, 0xDeeD_Beef,
0123,
-Infinity, -NaN,
]
},
{'//': 'empty members',
data: [
[,],
[1, , 2,,,,],
[1, , 2],
[1, , 2,]
]
}
]
@@ -73,439 +73,421 @@ exports[`snippet: #3 [json5] format 1`] = `
`;
exports[`snippet: #4 [json] format 1`] = `
"Identifier 'undefined' is not allowed in JSON. (1:9)
> 1 | {\\"foo\\": undefined}
| ^^^^^^^^^"
"'ArrowFunctionExpression' is not allowed in JSON. (1:9)
> 1 | {\\"foo\\": () => {}}
| ^^^^^^^^"
`;
exports[`snippet: #4 [json-stringify] format 1`] = `
"Identifier 'undefined' is not allowed in JSON. (1:9)
> 1 | {\\"foo\\": undefined}
| ^^^^^^^^^"
"'ArrowFunctionExpression' is not allowed in JSON. (1:9)
> 1 | {\\"foo\\": () => {}}
| ^^^^^^^^"
`;
exports[`snippet: #4 [json5] format 1`] = `
"Identifier 'undefined' is not allowed in JSON. (1:9)
> 1 | {\\"foo\\": undefined}
| ^^^^^^^^^"
"'ArrowFunctionExpression' is not allowed in JSON. (1:9)
> 1 | {\\"foo\\": () => {}}
| ^^^^^^^^"
`;
exports[`snippet: #5 [json] format 1`] = `
"'ArrowFunctionExpression' is not allowed in JSON. (1:9)
> 1 | {\\"foo\\": () => {}}
| ^^^^^^^^"
"Expecting Unicode escape sequence \\\\uXXXX (1:10)
> 1 | packages\\\\the-hub\\\\cypress\\\\fixtures\\\\gridConfiguration.json
| ^"
`;
exports[`snippet: #5 [json-stringify] format 1`] = `
"'ArrowFunctionExpression' is not allowed in JSON. (1:9)
> 1 | {\\"foo\\": () => {}}
| ^^^^^^^^"
"Expecting Unicode escape sequence \\\\uXXXX (1:10)
> 1 | packages\\\\the-hub\\\\cypress\\\\fixtures\\\\gridConfiguration.json
| ^"
`;
exports[`snippet: #5 [json5] format 1`] = `
"'ArrowFunctionExpression' is not allowed in JSON. (1:9)
> 1 | {\\"foo\\": () => {}}
| ^^^^^^^^"
"Expecting Unicode escape sequence \\\\uXXXX (1:10)
> 1 | packages\\\\the-hub\\\\cypress\\\\fixtures\\\\gridConfiguration.json
| ^"
`;
exports[`snippet: #6 [json] format 1`] = `
"Expecting Unicode escape sequence \\\\uXXXX (1:10)
> 1 | packages\\\\the-hub\\\\cypress\\\\fixtures\\\\gridConfiguration.json
| ^"
"'BinaryExpression' is not allowed in JSON. (1:1)
> 1 | 1+2
| ^^^"
`;
exports[`snippet: #6 [json-stringify] format 1`] = `
"Expecting Unicode escape sequence \\\\uXXXX (1:10)
> 1 | packages\\\\the-hub\\\\cypress\\\\fixtures\\\\gridConfiguration.json
| ^"
"'BinaryExpression' is not allowed in JSON. (1:1)
> 1 | 1+2
| ^^^"
`;
exports[`snippet: #6 [json5] format 1`] = `
"Expecting Unicode escape sequence \\\\uXXXX (1:10)
> 1 | packages\\\\the-hub\\\\cypress\\\\fixtures\\\\gridConfiguration.json
| ^"
"'BinaryExpression' is not allowed in JSON. (1:1)
> 1 | 1+2
| ^^^"
`;
exports[`snippet: #7 [json] format 1`] = `
"'BinaryExpression' is not allowed in JSON. (1:1)
> 1 | 1+2
| ^^^"
"Shorthand property is not allowed in JSON. (1:2)
> 1 | {Infinity}
| ^^^^^^^^"
`;
exports[`snippet: #7 [json-stringify] format 1`] = `
"'BinaryExpression' is not allowed in JSON. (1:1)
> 1 | 1+2
| ^^^"
"Shorthand property is not allowed in JSON. (1:2)
> 1 | {Infinity}
| ^^^^^^^^"
`;
exports[`snippet: #7 [json5] format 1`] = `
"'BinaryExpression' is not allowed in JSON. (1:1)
> 1 | 1+2
| ^^^"
"Shorthand property is not allowed in JSON. (1:2)
> 1 | {Infinity}
| ^^^^^^^^"
`;
exports[`snippet: #8 [json] format 1`] = `
"Sparse array is not allowed in JSON. (1:1)
> 1 | [,]
| ^^^"
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key]: 1}
| ^^^"
`;
exports[`snippet: #8 [json-stringify] format 1`] = `
"Sparse array is not allowed in JSON. (1:1)
> 1 | [,]
| ^^^"
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key]: 1}
| ^^^"
`;
exports[`snippet: #8 [json5] format 1`] = `
"Sparse array is not allowed in JSON. (1:1)
> 1 | [,]
| ^^^"
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key]: 1}
| ^^^"
`;
exports[`snippet: #9 [json] format 1`] = `
"Sparse array is not allowed in JSON. (1:1)
> 1 | [1,,2]
| ^^^^^^"
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key()]: 1}
| ^^^^^"
`;
exports[`snippet: #9 [json-stringify] format 1`] = `
"Sparse array is not allowed in JSON. (1:1)
> 1 | [1,,2]
| ^^^^^^"
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key()]: 1}
| ^^^^^"
`;
exports[`snippet: #9 [json5] format 1`] = `
"Sparse array is not allowed in JSON. (1:1)
> 1 | [1,,2]
| ^^^^^^"
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key()]: 1}
| ^^^^^"
`;
exports[`snippet: #10 [json] format 1`] = `
"Shorthand property is not allowed in JSON. (1:2)
> 1 | {Infinity}
| ^^^^^^^^"
"Computed key is not allowed in JSON. (1:3)
> 1 | {['CallExpression']: 1}
| ^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #10 [json-stringify] format 1`] = `
"Shorthand property is not allowed in JSON. (1:2)
> 1 | {Infinity}
| ^^^^^^^^"
"Computed key is not allowed in JSON. (1:3)
> 1 | {['CallExpression']: 1}
| ^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #10 [json5] format 1`] = `
"Shorthand property is not allowed in JSON. (1:2)
> 1 | {Infinity}
| ^^^^^^^^"
"Computed key is not allowed in JSON. (1:3)
> 1 | {['CallExpression']: 1}
| ^^^^^^^^^^^^^^^^"
`;
exports[`snippet: #11 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key]: 1}
| ^^^"
> 1 | {['StringLiteral']: 1}
| ^^^^^^^^^^^^^^^"
`;
exports[`snippet: #11 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key]: 1}
| ^^^"
> 1 | {['StringLiteral']: 1}
| ^^^^^^^^^^^^^^^"
`;
exports[`snippet: #11 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key]: 1}
| ^^^"
> 1 | {['StringLiteral']: 1}
| ^^^^^^^^^^^^^^^"
`;
exports[`snippet: #12 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key()]: 1}
| ^^^^^"
> 1 | {['string']: 1}
| ^^^^^^^^"
`;
exports[`snippet: #12 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key()]: 1}
| ^^^^^"
> 1 | {['string']: 1}
| ^^^^^^^^"
`;
exports[`snippet: #12 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[key()]: 1}
| ^^^^^"
> 1 | {['string']: 1}
| ^^^^^^^^"
`;
exports[`snippet: #13 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {['CallExpression']: 1}
| ^^^^^^^^^^^^^^^^"
> 1 | {[1]: 1}
| ^"
`;
exports[`snippet: #13 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {['CallExpression']: 1}
| ^^^^^^^^^^^^^^^^"
> 1 | {[1]: 1}
| ^"
`;
exports[`snippet: #13 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {['CallExpression']: 1}
| ^^^^^^^^^^^^^^^^"
> 1 | {[1]: 1}
| ^"
`;
exports[`snippet: #14 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {['StringLiteral']: 1}
| ^^^^^^^^^^^^^^^"
> 1 | {[Infinity]: 1}
| ^^^^^^^^"
`;
exports[`snippet: #14 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {['StringLiteral']: 1}
| ^^^^^^^^^^^^^^^"
> 1 | {[Infinity]: 1}
| ^^^^^^^^"
`;
exports[`snippet: #14 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {['StringLiteral']: 1}
| ^^^^^^^^^^^^^^^"
> 1 | {[Infinity]: 1}
| ^^^^^^^^"
`;
exports[`snippet: #15 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {['string']: 1}
| ^^^^^^^^"
> 1 | {[-Infinity]: 1}
| ^^^^^^^^^"
`;
exports[`snippet: #15 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {['string']: 1}
| ^^^^^^^^"
> 1 | {[-Infinity]: 1}
| ^^^^^^^^^"
`;
exports[`snippet: #15 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {['string']: 1}
| ^^^^^^^^"
> 1 | {[-Infinity]: 1}
| ^^^^^^^^^"
`;
exports[`snippet: #16 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[1]: 1}
| ^"
> 1 | {[{key: 'value'}]: 1}
| ^^^^^^^^^^^^^^"
`;
exports[`snippet: #16 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[1]: 1}
| ^"
> 1 | {[{key: 'value'}]: 1}
| ^^^^^^^^^^^^^^"
`;
exports[`snippet: #16 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[1]: 1}
| ^"
> 1 | {[{key: 'value'}]: 1}
| ^^^^^^^^^^^^^^"
`;
exports[`snippet: #17 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[Infinity]: 1}
| ^^^^^^^^"
> 1 | {[[]]: 1}
| ^^"
`;
exports[`snippet: #17 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[Infinity]: 1}
| ^^^^^^^^"
> 1 | {[[]]: 1}
| ^^"
`;
exports[`snippet: #17 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[Infinity]: 1}
| ^^^^^^^^"
> 1 | {[[]]: 1}
| ^^"
`;
exports[`snippet: #18 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[-Infinity]: 1}
| ^^^^^^^^^"
> 1 | {[null]: 1}
| ^^^^"
`;
exports[`snippet: #18 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[-Infinity]: 1}
| ^^^^^^^^^"
> 1 | {[null]: 1}
| ^^^^"
`;
exports[`snippet: #18 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[-Infinity]: 1}
| ^^^^^^^^^"
> 1 | {[null]: 1}
| ^^^^"
`;
exports[`snippet: #19 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[{key: 'value'}]: 1}
| ^^^^^^^^^^^^^^"
"'CallExpression' is not allowed in JSON. (1:8)
> 1 | {key: +foo()}
| ^^^^^"
`;
exports[`snippet: #19 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[{key: 'value'}]: 1}
| ^^^^^^^^^^^^^^"
"'CallExpression' is not allowed in JSON. (1:8)
> 1 | {key: +foo()}
| ^^^^^"
`;
exports[`snippet: #19 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[{key: 'value'}]: 1}
| ^^^^^^^^^^^^^^"
"'CallExpression' is not allowed in JSON. (1:8)
> 1 | {key: +foo()}
| ^^^^^"
`;
exports[`snippet: #20 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[[]]: 1}
| ^^"
"Operator 'void' is not allowed in JSON. (1:7)
> 1 | {key: void foo()}
| ^^^^^^^^^^"
`;
exports[`snippet: #20 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[[]]: 1}
| ^^"
"Operator 'void' is not allowed in JSON. (1:7)
> 1 | {key: void foo()}
| ^^^^^^^^^^"
`;
exports[`snippet: #20 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[[]]: 1}
| ^^"
"Operator 'void' is not allowed in JSON. (1:7)
> 1 | {key: void foo()}
| ^^^^^^^^^^"
`;
exports[`snippet: #21 [json] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[null]: 1}
| ^^^^"
"Unexpected token (1:1)
> 1 | #!/usr/bin/env node
| ^
2 | {}"
`;
exports[`snippet: #21 [json-stringify] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[null]: 1}
| ^^^^"
"Unexpected token (1:1)
> 1 | #!/usr/bin/env node
| ^
2 | {}"
`;
exports[`snippet: #21 [json5] format 1`] = `
"Computed key is not allowed in JSON. (1:3)
> 1 | {[null]: 1}
| ^^^^"
"Unexpected token (1:1)
> 1 | #!/usr/bin/env node
| ^
2 | {}"
`;
exports[`snippet: #22 [json] format 1`] = `
"'CallExpression' is not allowed in JSON. (1:8)
> 1 | {key: +foo()}
| ^^^^^"
"Unexpected token (2:1)
1 | \\"use strict\\"
> 2 | {}
| ^"
`;
exports[`snippet: #22 [json-stringify] format 1`] = `
"'CallExpression' is not allowed in JSON. (1:8)
> 1 | {key: +foo()}
| ^^^^^"
"Unexpected token (2:1)
1 | \\"use strict\\"
> 2 | {}
| ^"
`;
exports[`snippet: #22 [json5] format 1`] = `
"'CallExpression' is not allowed in JSON. (1:8)
> 1 | {key: +foo()}
| ^^^^^"
"Unexpected token (2:1)
1 | \\"use strict\\"
> 2 | {}
| ^"
`;
exports[`snippet: #23 [json] format 1`] = `
"Operator 'void' is not allowed in JSON. (1:7)
> 1 | {key: void foo()}
| ^^^^^^^^^^"
"Unexpected token (1:14)
> 1 | /* comment */
| ^"
`;
exports[`snippet: #23 [json-stringify] format 1`] = `
"Operator 'void' is not allowed in JSON. (1:7)
> 1 | {key: void foo()}
| ^^^^^^^^^^"
"Unexpected token (1:14)
> 1 | /* comment */
| ^"
`;
exports[`snippet: #23 [json5] format 1`] = `
"Operator 'void' is not allowed in JSON. (1:7)
> 1 | {key: void foo()}
| ^^^^^^^^^^"
"Unexpected token (1:14)
> 1 | /* comment */
| ^"
`;
exports[`snippet: #24 [json] format 1`] = `
"Unexpected token (1:1)
> 1 | #!/usr/bin/env node
| ^
2 | {}"
"Unexpected token (1:11)
> 1 | // comment
| ^"
`;
exports[`snippet: #24 [json-stringify] format 1`] = `
"Unexpected token (1:1)
> 1 | #!/usr/bin/env node
| ^
2 | {}"
"Unexpected token (1:11)
> 1 | // comment
| ^"
`;
exports[`snippet: #24 [json5] format 1`] = `
"Unexpected token (1:1)
> 1 | #!/usr/bin/env node
| ^
2 | {}"
"Unexpected token (1:11)
> 1 | // comment
| ^"
`;
exports[`snippet: #25 [json] format 1`] = `
"Unexpected token (2:1)
1 | \\"use strict\\"
> 2 | {}
| ^"
"'TemplateLiteral' with expression is not allowed in JSON. (1:7)
> 1 | \`foo\${1}bar\`
| ^"
`;
exports[`snippet: #25 [json-stringify] format 1`] = `
"Unexpected token (2:1)
1 | \\"use strict\\"
> 2 | {}
| ^"
"'TemplateLiteral' with expression is not allowed in JSON. (1:7)
> 1 | \`foo\${1}bar\`
| ^"
`;
exports[`snippet: #25 [json5] format 1`] = `
"Unexpected token (2:1)
1 | \\"use strict\\"
> 2 | {}
| ^"
"'TemplateLiteral' with expression is not allowed in JSON. (1:7)
> 1 | \`foo\${1}bar\`
| ^"
`;
exports[`snippet: #26 [json] format 1`] = `
"Unexpected token (1:14)
> 1 | /* comment */
| ^"
"Invalid left-hand side in prefix operation (1:5)
> 1 | ----123
| ^"
`;
exports[`snippet: #26 [json-stringify] format 1`] = `
"Unexpected token (1:14)
> 1 | /* comment */
| ^"
"Invalid left-hand side in prefix operation (1:5)
> 1 | ----123
| ^"
`;
exports[`snippet: #26 [json5] format 1`] = `
"Unexpected token (1:14)
> 1 | /* comment */
| ^"
`;
exports[`snippet: #27 [json] format 1`] = `
"Unexpected token (1:11)
> 1 | // comment
| ^"
`;
exports[`snippet: #27 [json-stringify] format 1`] = `
"Unexpected token (1:11)
> 1 | // comment
| ^"
`;
exports[`snippet: #27 [json5] format 1`] = `
"Unexpected token (1:11)
> 1 | // comment
| ^"
"Invalid left-hand side in prefix operation (1:5)
> 1 | ----123
| ^"
`;
+3 -3
View File
@@ -6,12 +6,9 @@ run_spec(
'{["foo"]:"bar"}',
'{"foo": ~1}',
'{"foo": false || "bar"}',
'{"foo": undefined}',
'{"foo": () => {}}',
"packages\\the-hub\\cypress\\fixtures\\gridConfiguration.json",
"1+2",
"[,]",
"[1,,2]",
"{Infinity}",
"{[key]: 1}",
"{[key()]: 1}",
@@ -30,6 +27,9 @@ run_spec(
'"use strict"\n{}',
"/* comment */",
"// comment",
"`foo${1}bar`",
// JSON6 allow this, but babel can't parse
"----123",
],
},
["json", "json5", "json-stringify"]