feat: split out JSON5 (#4367)
* feat: split out JSON5 * test: update snapshots * test: update debug-check tests * feat(playground): use JSON's code sample for JSON5 * fix: add missing trailing newlinemaster
parent
6b2be99b53
commit
317f3a3c56
|
@ -104,6 +104,7 @@ const supportOptions = {
|
|||
{ value: "less", since: "1.7.1", description: "Less" },
|
||||
{ value: "scss", since: "1.7.1", description: "SCSS" },
|
||||
{ value: "json", since: "1.5.0", description: "JSON" },
|
||||
{ value: "json5", since: "1.13.0", description: "JSON5" },
|
||||
{ value: "graphql", since: "1.5.0", description: "GraphQL" },
|
||||
{ value: "markdown", since: "1.8.0", description: "Markdown" },
|
||||
{ value: "vue", since: "1.10.0", description: "Vue" }
|
||||
|
|
|
@ -61,13 +61,16 @@ function clean(ast, newObj, parent) {
|
|||
// We change {'key': value} into {key: value}
|
||||
if (
|
||||
(ast.type === "Property" ||
|
||||
ast.type === "ObjectProperty" ||
|
||||
ast.type === "MethodDefinition" ||
|
||||
ast.type === "ClassProperty" ||
|
||||
ast.type === "TSPropertySignature" ||
|
||||
ast.type === "ObjectTypeProperty") &&
|
||||
typeof ast.key === "object" &&
|
||||
ast.key &&
|
||||
(ast.key.type === "Literal" || ast.key.type === "Identifier")
|
||||
(ast.key.type === "Literal" ||
|
||||
ast.key.type === "StringLiteral" ||
|
||||
ast.key.type === "Identifier")
|
||||
) {
|
||||
delete newObj.key;
|
||||
}
|
||||
|
|
|
@ -136,24 +136,31 @@ const languages = [
|
|||
aceMode: "json",
|
||||
codemirrorMode: "javascript",
|
||||
codemirrorMimeType: "application/json",
|
||||
extensions: [
|
||||
".json",
|
||||
".json5",
|
||||
".geojson",
|
||||
".JSON-tmLanguage",
|
||||
".topojson"
|
||||
],
|
||||
extensions: [".json", ".geojson", ".JSON-tmLanguage", ".topojson"],
|
||||
filenames: [
|
||||
".arcconfig",
|
||||
".jshintrc",
|
||||
".babelrc",
|
||||
".eslintrc",
|
||||
".prettierrc",
|
||||
"composer.lock",
|
||||
"mcmod.info"
|
||||
],
|
||||
linguistLanguageId: 174,
|
||||
vscodeLanguageIds: ["json", "jsonc"]
|
||||
vscodeLanguageIds: ["json"]
|
||||
},
|
||||
{
|
||||
name: "JSON5",
|
||||
since: "1.13.0",
|
||||
parsers: ["json5"],
|
||||
group: "JavaScript",
|
||||
tmScope: "source.json",
|
||||
aceMode: "json",
|
||||
codemirrorMode: "javascript",
|
||||
codemirrorMimeType: "application/json",
|
||||
extensions: [".json5"],
|
||||
filenames: [".babelrc"],
|
||||
linguistLanguageId: 175,
|
||||
vscodeLanguageIds: ["jsonc"]
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -184,6 +191,7 @@ const parsers = {
|
|||
return true;
|
||||
}
|
||||
}),
|
||||
json5: babylon,
|
||||
flow: {
|
||||
get parse() {
|
||||
return eval("require")("./parser-flow");
|
||||
|
|
|
@ -34,7 +34,9 @@ function parse(text, parsers, opts) {
|
|||
};
|
||||
|
||||
const parseMethod =
|
||||
opts && opts.parser === "json" ? "parseExpression" : "parse";
|
||||
opts && (opts.parser === "json" || opts.parser === "json5")
|
||||
? "parseExpression"
|
||||
: "parse";
|
||||
|
||||
let ast;
|
||||
try {
|
||||
|
|
|
@ -59,7 +59,7 @@ function printAstToDoc(ast, options, addAlignmentSize) {
|
|||
}
|
||||
docUtils.propagateBreaks(doc);
|
||||
|
||||
if (options.parser === "json") {
|
||||
if (options.parser === "json" || options.parser === "json5") {
|
||||
doc = concat([doc, hardline]);
|
||||
}
|
||||
|
||||
|
|
|
@ -178,7 +178,10 @@ function attach(comments, ast, text, options) {
|
|||
const locEnd = options.locEnd;
|
||||
|
||||
comments.forEach((comment, i) => {
|
||||
if (options.parser === "json" && locStart(comment) - locStart(ast) <= 0) {
|
||||
if (
|
||||
(options.parser === "json" || options.parser === "json5") &&
|
||||
locStart(comment) - locStart(ast) <= 0
|
||||
) {
|
||||
addLeadingComment(ast, comment);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`with-pragma.json5 1`] = `
|
||||
/** @format */
|
||||
|
||||
{hello: "world"}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/** @format */
|
||||
|
||||
{ hello: "world" }
|
||||
|
||||
`;
|
||||
|
||||
exports[`without-pragma.json5 1`] = `
|
||||
{hello: "world"}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/** @format */
|
||||
|
||||
{ hello: "world" }
|
||||
|
||||
`;
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname, ["json5"], { insertPragma: true });
|
|
@ -0,0 +1,3 @@
|
|||
/** @format */
|
||||
|
||||
{hello: "world"}
|
|
@ -0,0 +1 @@
|
|||
{hello: "world"}
|
|
@ -14,6 +14,20 @@ exports[`block-comment.json 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`block-comment.json 3`] = `
|
||||
{/*comment*/"K":"V"}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{ /*comment*/ K: "V" }
|
||||
|
||||
`;
|
||||
|
||||
exports[`block-comment.json 4`] = `
|
||||
{/*comment*/"K":"V"}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{ /*comment*/ K: "V" }
|
||||
|
||||
`;
|
||||
|
||||
exports[`boolean.json 1`] = `
|
||||
true
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -28,6 +42,20 @@ true
|
|||
|
||||
`;
|
||||
|
||||
exports[`boolean.json 3`] = `
|
||||
true
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
true
|
||||
|
||||
`;
|
||||
|
||||
exports[`boolean.json 4`] = `
|
||||
true
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
true
|
||||
|
||||
`;
|
||||
|
||||
exports[`line-comment.json 1`] = `
|
||||
{
|
||||
//comment
|
||||
|
@ -54,6 +82,32 @@ exports[`line-comment.json 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`line-comment.json 3`] = `
|
||||
{
|
||||
//comment
|
||||
"K":"V"
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{
|
||||
//comment
|
||||
K: "V"
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`line-comment.json 4`] = `
|
||||
{
|
||||
//comment
|
||||
"K":"V"
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{
|
||||
//comment
|
||||
K: "V",
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`multi-line.json 1`] = `
|
||||
{"key1":[true,false,null],"key2":{"key3":[1,2,"3",
|
||||
1e10,1e-3]}}
|
||||
|
@ -80,6 +134,32 @@ exports[`multi-line.json 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`multi-line.json 3`] = `
|
||||
{"key1":[true,false,null],"key2":{"key3":[1,2,"3",
|
||||
1e10,1e-3]}}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{
|
||||
key1: [true, false, null],
|
||||
key2: {
|
||||
key3: [1, 2, "3", 1e10, 1e-3]
|
||||
}
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`multi-line.json 4`] = `
|
||||
{"key1":[true,false,null],"key2":{"key3":[1,2,"3",
|
||||
1e10,1e-3]}}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{
|
||||
key1: [true, false, null],
|
||||
key2: {
|
||||
key3: [1, 2, "3", 1e10, 1e-3],
|
||||
},
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`null.json 1`] = `
|
||||
null
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -94,6 +174,20 @@ null
|
|||
|
||||
`;
|
||||
|
||||
exports[`null.json 3`] = `
|
||||
null
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
null
|
||||
|
||||
`;
|
||||
|
||||
exports[`null.json 4`] = `
|
||||
null
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
null
|
||||
|
||||
`;
|
||||
|
||||
exports[`number.json 1`] = `
|
||||
0
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -108,6 +202,20 @@ exports[`number.json 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`number.json 3`] = `
|
||||
0
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
0
|
||||
|
||||
`;
|
||||
|
||||
exports[`number.json 4`] = `
|
||||
0
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
0
|
||||
|
||||
`;
|
||||
|
||||
exports[`pass1.json 1`] = `
|
||||
[
|
||||
"JSON Test Pattern pass1",
|
||||
|
@ -166,7 +274,8 @@ exports[`pass1.json 1`] = `
|
|||
0.1e1,
|
||||
1e-1,
|
||||
1e00,2e+00,2e-00
|
||||
,"rosebud"]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
,"rosebud"]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
[
|
||||
"JSON Test Pattern pass1",
|
||||
{ "object with 1 member": ["array with 1 element"] },
|
||||
|
@ -284,7 +393,8 @@ exports[`pass1.json 2`] = `
|
|||
0.1e1,
|
||||
1e-1,
|
||||
1e00,2e+00,2e-00
|
||||
,"rosebud"]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
,"rosebud"]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
[
|
||||
"JSON Test Pattern pass1",
|
||||
{ "object with 1 member": ["array with 1 element"] },
|
||||
|
@ -344,6 +454,244 @@ exports[`pass1.json 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`pass1.json 3`] = `
|
||||
[
|
||||
"JSON Test Pattern pass1",
|
||||
{"object with 1 member":["array with 1 element"]},
|
||||
{},
|
||||
[],
|
||||
-42,
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
{
|
||||
"integer": 1234567890,
|
||||
"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": "/ & \\/",
|
||||
"alpha": "abcdefghijklmnopqrstuvwyz",
|
||||
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
|
||||
"digit": "0123456789",
|
||||
"0123456789": "digit",
|
||||
"special": "\`1~!@#$%^&*()_+-={':[,]}|;.</>?",
|
||||
"hex": "\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A",
|
||||
"true": true,
|
||||
"false": false,
|
||||
"null": null,
|
||||
"array":[ ],
|
||||
"object":{ },
|
||||
"address": "50 St. James Street",
|
||||
"url": "http://www.JSON.org/",
|
||||
"comment": "// /* <!-- --",
|
||||
"# -- --> */": " ",
|
||||
" s p a c e d " :[1,2 , 3
|
||||
|
||||
,
|
||||
|
||||
4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
|
||||
"jsontext": "{\\"object with 1 member\\":[\\"array with 1 element\\"]}",
|
||||
"quotes": "" \\u0022 %22 0x22 034 "",
|
||||
"\\/\\\\\\"\\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,
|
||||
1e1,
|
||||
0.1e1,
|
||||
1e-1,
|
||||
1e00,2e+00,2e-00
|
||||
,"rosebud"]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
[
|
||||
"JSON Test Pattern pass1",
|
||||
{ "object with 1 member": ["array with 1 element"] },
|
||||
{},
|
||||
[],
|
||||
-42,
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
{
|
||||
integer: 1234567890,
|
||||
real: -9876.54321,
|
||||
e: 0.123456789e-12,
|
||||
E: 1.23456789e34,
|
||||
"": 23456789012e66,
|
||||
zero: 0,
|
||||
one: 1,
|
||||
space: " ",
|
||||
quote: '"',
|
||||
backslash: "\\\\",
|
||||
controls: "\\b\\f\\n\\r\\t",
|
||||
slash: "/ & /",
|
||||
alpha: "abcdefghijklmnopqrstuvwyz",
|
||||
ALPHA: "ABCDEFGHIJKLMNOPQRSTUVWYZ",
|
||||
digit: "0123456789",
|
||||
"0123456789": "digit",
|
||||
special: "\`1~!@#$%^&*()_+-={':[,]}|;.</>?",
|
||||
hex: "\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A",
|
||||
true: true,
|
||||
false: false,
|
||||
null: null,
|
||||
array: [],
|
||||
object: {},
|
||||
address: "50 St. James Street",
|
||||
url: "http://www.JSON.org/",
|
||||
comment: "// /* <!-- --",
|
||||
"# -- --> */": " ",
|
||||
" s p a c e d ": [1, 2, 3, 4, 5, 6, 7],
|
||||
compact: [1, 2, 3, 4, 5, 6, 7],
|
||||
jsontext: '{"object with 1 member":["array with 1 element"]}',
|
||||
quotes: "" \\u0022 %22 0x22 034 "",
|
||||
"/\\\\\\"\\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,
|
||||
1e1,
|
||||
0.1e1,
|
||||
1e-1,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
"rosebud"
|
||||
]
|
||||
|
||||
`;
|
||||
|
||||
exports[`pass1.json 4`] = `
|
||||
[
|
||||
"JSON Test Pattern pass1",
|
||||
{"object with 1 member":["array with 1 element"]},
|
||||
{},
|
||||
[],
|
||||
-42,
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
{
|
||||
"integer": 1234567890,
|
||||
"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": "/ & \\/",
|
||||
"alpha": "abcdefghijklmnopqrstuvwyz",
|
||||
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
|
||||
"digit": "0123456789",
|
||||
"0123456789": "digit",
|
||||
"special": "\`1~!@#$%^&*()_+-={':[,]}|;.</>?",
|
||||
"hex": "\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A",
|
||||
"true": true,
|
||||
"false": false,
|
||||
"null": null,
|
||||
"array":[ ],
|
||||
"object":{ },
|
||||
"address": "50 St. James Street",
|
||||
"url": "http://www.JSON.org/",
|
||||
"comment": "// /* <!-- --",
|
||||
"# -- --> */": " ",
|
||||
" s p a c e d " :[1,2 , 3
|
||||
|
||||
,
|
||||
|
||||
4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
|
||||
"jsontext": "{\\"object with 1 member\\":[\\"array with 1 element\\"]}",
|
||||
"quotes": "" \\u0022 %22 0x22 034 "",
|
||||
"\\/\\\\\\"\\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,
|
||||
1e1,
|
||||
0.1e1,
|
||||
1e-1,
|
||||
1e00,2e+00,2e-00
|
||||
,"rosebud"]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
[
|
||||
"JSON Test Pattern pass1",
|
||||
{ "object with 1 member": ["array with 1 element"] },
|
||||
{},
|
||||
[],
|
||||
-42,
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
{
|
||||
integer: 1234567890,
|
||||
real: -9876.54321,
|
||||
e: 0.123456789e-12,
|
||||
E: 1.23456789e34,
|
||||
"": 23456789012e66,
|
||||
zero: 0,
|
||||
one: 1,
|
||||
space: " ",
|
||||
quote: '"',
|
||||
backslash: "\\\\",
|
||||
controls: "\\b\\f\\n\\r\\t",
|
||||
slash: "/ & /",
|
||||
alpha: "abcdefghijklmnopqrstuvwyz",
|
||||
ALPHA: "ABCDEFGHIJKLMNOPQRSTUVWYZ",
|
||||
digit: "0123456789",
|
||||
"0123456789": "digit",
|
||||
special: "\`1~!@#$%^&*()_+-={':[,]}|;.</>?",
|
||||
hex: "\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A",
|
||||
true: true,
|
||||
false: false,
|
||||
null: null,
|
||||
array: [],
|
||||
object: {},
|
||||
address: "50 St. James Street",
|
||||
url: "http://www.JSON.org/",
|
||||
comment: "// /* <!-- --",
|
||||
"# -- --> */": " ",
|
||||
" s p a c e d ": [1, 2, 3, 4, 5, 6, 7],
|
||||
compact: [1, 2, 3, 4, 5, 6, 7],
|
||||
jsontext: '{"object with 1 member":["array with 1 element"]}',
|
||||
quotes: "" \\u0022 %22 0x22 034 "",
|
||||
"/\\\\\\"\\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,
|
||||
1e1,
|
||||
0.1e1,
|
||||
1e-1,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
"rosebud",
|
||||
]
|
||||
|
||||
`;
|
||||
|
||||
exports[`single-line.json 1`] = `
|
||||
{"key1":[true,false,null],"key2":{"key3":[1,2,"3",1e10,1e-3]}}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -358,6 +706,20 @@ exports[`single-line.json 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`single-line.json 3`] = `
|
||||
{"key1":[true,false,null],"key2":{"key3":[1,2,"3",1e10,1e-3]}}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{ key1: [true, false, null], key2: { key3: [1, 2, "3", 1e10, 1e-3] } }
|
||||
|
||||
`;
|
||||
|
||||
exports[`single-line.json 4`] = `
|
||||
{"key1":[true,false,null],"key2":{"key3":[1,2,"3",1e10,1e-3]}}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{ key1: [true, false, null], key2: { key3: [1, 2, "3", 1e10, 1e-3] } }
|
||||
|
||||
`;
|
||||
|
||||
exports[`string.json 1`] = `
|
||||
"string"
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -372,6 +734,20 @@ exports[`string.json 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`string.json 3`] = `
|
||||
"string"
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
"string"
|
||||
|
||||
`;
|
||||
|
||||
exports[`string.json 4`] = `
|
||||
"string"
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
"string"
|
||||
|
||||
`;
|
||||
|
||||
exports[`top-block-comment.json 1`] = `
|
||||
/* comment */{
|
||||
"foo": "bar"
|
||||
|
@ -394,6 +770,28 @@ exports[`top-block-comment.json 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`top-block-comment.json 3`] = `
|
||||
/* comment */{
|
||||
"foo": "bar"
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/* comment */ {
|
||||
foo: "bar"
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`top-block-comment.json 4`] = `
|
||||
/* comment */{
|
||||
"foo": "bar"
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/* comment */ {
|
||||
foo: "bar",
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`top-line-comment.json 1`] = `
|
||||
// comment 1
|
||||
// comment 2
|
||||
|
@ -424,6 +822,36 @@ exports[`top-line-comment.json 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`top-line-comment.json 3`] = `
|
||||
// comment 1
|
||||
// comment 2
|
||||
{
|
||||
"foo": "bar"
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// comment 1
|
||||
// comment 2
|
||||
{
|
||||
foo: "bar"
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`top-line-comment.json 4`] = `
|
||||
// comment 1
|
||||
// comment 2
|
||||
{
|
||||
"foo": "bar"
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// comment 1
|
||||
// comment 2
|
||||
{
|
||||
foo: "bar",
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`trailingComma.notjson 1`] = `
|
||||
{
|
||||
"k1": "v1",
|
||||
|
@ -453,3 +881,33 @@ exports[`trailingComma.notjson 2`] = `
|
|||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`trailingComma.notjson 3`] = `
|
||||
{
|
||||
"k1": "v1",
|
||||
"k2": "v2",
|
||||
"k3": "v3"
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{
|
||||
k1: "v1",
|
||||
k2: "v2",
|
||||
k3: "v3"
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`trailingComma.notjson 4`] = `
|
||||
{
|
||||
"k1": "v1",
|
||||
"k2": "v2",
|
||||
"k3": "v3"
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{
|
||||
k1: "v1",
|
||||
k2: "v2",
|
||||
k3: "v3",
|
||||
}
|
||||
|
||||
`;
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
run_spec(__dirname, ["json"]);
|
||||
run_spec(__dirname, ["json"], { trailingComma: "all" });
|
||||
run_spec(__dirname, ["json5"]);
|
||||
run_spec(__dirname, ["json5"], { trailingComma: "all" });
|
||||
|
|
|
@ -55,4 +55,4 @@
|
|||
0.1e1,
|
||||
1e-1,
|
||||
1e00,2e+00,2e-00
|
||||
,"rosebud"]
|
||||
,"rosebud"]
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`with-pragma.json5 1`] = `
|
||||
/** @format */
|
||||
|
||||
{hello: "world"}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/** @format */
|
||||
|
||||
{ hello: "world" }
|
||||
|
||||
`;
|
||||
|
||||
exports[`without-pragma.json5 1`] = `
|
||||
{hello: "world"}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{hello: "world"}
|
||||
|
||||
`;
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname, ["json5"], { requirePragma: true });
|
|
@ -0,0 +1,3 @@
|
|||
/** @format */
|
||||
|
||||
{hello: "world"}
|
|
@ -0,0 +1 @@
|
|||
{hello: "world"}
|
|
@ -5,55 +5,27 @@ exports[`checks stdin with --debug-check (write) 1`] = `Array []`;
|
|||
exports[`doesn't crash when --debug-check is passed (write) 1`] = `Array []`;
|
||||
|
||||
exports[`show diff for 2+ error files with --debug-check (stderr) 1`] = `
|
||||
"[error] a.js: ast(input) !== ast(prettier(input))
|
||||
"[error] a.debug-check: prettier(input) !== prettier(prettier(input))
|
||||
[error] Index:
|
||||
[error] ===================================================================
|
||||
[error] ---
|
||||
[error] +++
|
||||
[error] @@ -17,6 +17,6 @@
|
||||
[error] \\"method\\": false,
|
||||
[error] \\"key\\": {
|
||||
[error] - \\"type\\": \\"StringLiteral\\",
|
||||
[error] - \\"value\\": \\"a\\"
|
||||
[error] + \\"type\\": \\"Identifier\\",
|
||||
[error] + \\"name\\": \\"a\\"
|
||||
[error] },
|
||||
[error] \\"computed\\": false,
|
||||
[error] @@ -1,2 +1,4 @@
|
||||
[error] hello
|
||||
[error] hello
|
||||
[error] +hello
|
||||
[error] +hello
|
||||
[error]
|
||||
[error] b.debug-check: prettier(input) !== prettier(prettier(input))
|
||||
[error] Index:
|
||||
[error] ===================================================================
|
||||
[error] ---
|
||||
[error] +++
|
||||
[error] @@ -1,3 +1,3 @@
|
||||
[error] const a = {
|
||||
[error] - 'a': 1
|
||||
[error] + a: 1
|
||||
[error] };
|
||||
[error]
|
||||
[error] b.js: ast(input) !== ast(prettier(input))
|
||||
[error] Index:
|
||||
[error] ===================================================================
|
||||
[error] ---
|
||||
[error] +++
|
||||
[error] @@ -17,6 +17,6 @@
|
||||
[error] \\"method\\": false,
|
||||
[error] \\"key\\": {
|
||||
[error] - \\"type\\": \\"StringLiteral\\",
|
||||
[error] - \\"value\\": \\"b\\"
|
||||
[error] + \\"type\\": \\"Identifier\\",
|
||||
[error] + \\"name\\": \\"b\\"
|
||||
[error] },
|
||||
[error] \\"computed\\": false,
|
||||
[error]
|
||||
[error] Index:
|
||||
[error] ===================================================================
|
||||
[error] ---
|
||||
[error] +++
|
||||
[error] @@ -1,3 +1,3 @@
|
||||
[error] const b = {
|
||||
[error] - 'b': 2
|
||||
[error] + b: 2
|
||||
[error] };
|
||||
[error] @@ -1,2 +1,4 @@
|
||||
[error] world
|
||||
[error] world
|
||||
[error] +world
|
||||
[error] +world
|
||||
[error]
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -265,7 +265,7 @@ exports[`show detailed usage with --help no-semi (write) 1`] = `Array []`;
|
|||
exports[`show detailed usage with --help parser (stderr) 1`] = `""`;
|
||||
|
||||
exports[`show detailed usage with --help parser (stdout) 1`] = `
|
||||
"--parser <flow|babylon|typescript|css|less|scss|json|graphql|markdown|vue>
|
||||
"--parser <flow|babylon|typescript|css|less|scss|json|json5|graphql|markdown|vue>
|
||||
|
||||
Which parser to use.
|
||||
|
||||
|
@ -278,6 +278,7 @@ Valid options:
|
|||
less Less
|
||||
scss SCSS
|
||||
json JSON
|
||||
json5 JSON5
|
||||
graphql GraphQL
|
||||
markdown Markdown
|
||||
vue Vue
|
||||
|
@ -565,7 +566,7 @@ Format options:
|
|||
--no-bracket-spacing Do not print spaces between brackets.
|
||||
--jsx-bracket-same-line Put > on the last line instead of at a new line.
|
||||
Defaults to false.
|
||||
--parser <flow|babylon|typescript|css|less|scss|json|graphql|markdown|vue>
|
||||
--parser <flow|babylon|typescript|css|less|scss|json|json5|graphql|markdown|vue>
|
||||
Which parser to use.
|
||||
Defaults to babylon.
|
||||
--print-width <int> The line length where Prettier will try wrap.
|
||||
|
@ -661,7 +662,7 @@ exports[`show warning with --help not-found (typo) (stderr) 1`] = `
|
|||
`;
|
||||
|
||||
exports[`show warning with --help not-found (typo) (stdout) 1`] = `
|
||||
"--parser <flow|babylon|typescript|css|less|scss|json|graphql|markdown|vue>
|
||||
"--parser <flow|babylon|typescript|css|less|scss|json|json5|graphql|markdown|vue>
|
||||
|
||||
Which parser to use.
|
||||
|
||||
|
@ -674,6 +675,7 @@ Valid options:
|
|||
less Less
|
||||
scss SCSS
|
||||
json JSON
|
||||
json5 JSON5
|
||||
graphql GraphQL
|
||||
markdown Markdown
|
||||
vue Vue
|
||||
|
@ -707,7 +709,7 @@ Format options:
|
|||
--no-bracket-spacing Do not print spaces between brackets.
|
||||
--jsx-bracket-same-line Put > on the last line instead of at a new line.
|
||||
Defaults to false.
|
||||
--parser <flow|babylon|typescript|css|less|scss|json|graphql|markdown|vue>
|
||||
--parser <flow|babylon|typescript|css|less|scss|json|json5|graphql|markdown|vue>
|
||||
Which parser to use.
|
||||
Defaults to babylon.
|
||||
--print-width <int> The line length where Prettier will try wrap.
|
||||
|
|
|
@ -15,7 +15,7 @@ exports[` 1`] = `
|
|||
+ Defaults to bar.
|
||||
--jsx-bracket-same-line Put > on the last line instead of at a new line.
|
||||
Defaults to false.
|
||||
--parser <flow|babylon|typescript|css|less|scss|json|graphql|markdown|vue>
|
||||
--parser <flow|babylon|typescript|css|less|scss|json|json5|graphql|markdown|vue>
|
||||
Which parser to use.
|
||||
Defaults to babylon."
|
||||
`;
|
||||
|
|
|
@ -532,17 +532,10 @@ exports[`CLI --support-info (stdout) 1`] = `
|
|||
\\"aceMode\\": \\"json\\",
|
||||
\\"codemirrorMimeType\\": \\"application/json\\",
|
||||
\\"codemirrorMode\\": \\"javascript\\",
|
||||
\\"extensions\\": [
|
||||
\\".json\\",
|
||||
\\".json5\\",
|
||||
\\".geojson\\",
|
||||
\\".JSON-tmLanguage\\",
|
||||
\\".topojson\\"
|
||||
],
|
||||
\\"extensions\\": [\\".json\\", \\".geojson\\", \\".JSON-tmLanguage\\", \\".topojson\\"],
|
||||
\\"filenames\\": [
|
||||
\\".arcconfig\\",
|
||||
\\".jshintrc\\",
|
||||
\\".babelrc\\",
|
||||
\\".eslintrc\\",
|
||||
\\".prettierrc\\",
|
||||
\\"composer.lock\\",
|
||||
|
@ -554,7 +547,7 @@ exports[`CLI --support-info (stdout) 1`] = `
|
|||
\\"parsers\\": [\\"json\\"],
|
||||
\\"since\\": \\"1.5.0\\",
|
||||
\\"tmScope\\": \\"source.json\\",
|
||||
\\"vscodeLanguageIds\\": [\\"json\\", \\"jsonc\\"]
|
||||
\\"vscodeLanguageIds\\": [\\"json\\"]
|
||||
},
|
||||
{
|
||||
\\"aceMode\\": \\"css\\",
|
||||
|
|
|
@ -21,7 +21,12 @@ describe("checks stdin with --debug-check", () => {
|
|||
});
|
||||
|
||||
describe("show diff for 2+ error files with --debug-check", () => {
|
||||
runPrettier("cli/debug-check", ["*.js", "--debug-check"]).test({
|
||||
runPrettier("cli/debug-check", [
|
||||
"*.debug-check",
|
||||
"--debug-check",
|
||||
"--plugin",
|
||||
"./plugin-for-testing-debug-check"
|
||||
]).test({
|
||||
status: "non-zero"
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
hello
|
|
@ -1,3 +0,0 @@
|
|||
const a = {
|
||||
'a': 1
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
world
|
|
@ -1,3 +0,0 @@
|
|||
const b = {
|
||||
'b': 2
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
languages: [
|
||||
{
|
||||
name: "debug-check",
|
||||
parsers: ["debug-check-parser"],
|
||||
extensions: [".debug-check"]
|
||||
}
|
||||
],
|
||||
parsers: {
|
||||
"debug-check-parser": {
|
||||
parse: text => ({ text }),
|
||||
astFormat: "debug-check-ast"
|
||||
}
|
||||
},
|
||||
printers: {
|
||||
"debug-check-ast": {
|
||||
print: path => path.getValue().text + path.getValue().text
|
||||
}
|
||||
}
|
||||
};
|
|
@ -110,6 +110,7 @@ export default function(parser) {
|
|||
"}"
|
||||
].join("\n");
|
||||
case "json":
|
||||
case "json5":
|
||||
// Excerpted & adapted from Wikipedia, under the Creative Commons Attribution-ShareAlike License
|
||||
// https://en.wikipedia.org/wiki/JSON#Example
|
||||
return [
|
||||
|
|
Loading…
Reference in New Issue