Files
test-repo/tests/format/misc/errors/json/format.test.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

122 lines
3.0 KiB
JavaScript
Raw Normal View History

runFormatTest(
2020-04-21 19:38:30 +08:00
{
2022-01-04 17:00:25 +08:00
importMeta: import.meta,
2020-04-21 19:38:30 +08:00
snippets: [
"{foo}",
'{["foo"]:"bar"}',
'{"foo": ~1}',
'{"foo": false || "bar"}',
'{"foo": () => {}}',
String.raw`packages\the-hub\cypress\fixtures\gridConfiguration.json`,
2021-02-23 19:33:10 +08:00
"1+2",
2021-03-02 13:42:49 +08:00
"{Infinity}",
"{[key]: 1}",
"{[key()]: 1}",
"{['CallExpression']: 1}",
"{['StringLiteral']: 1}",
"{['string']: 1}",
"{[1]: 1}",
"{[Infinity]: 1}",
"{[-Infinity]: 1}",
"{[{key: 'value'}]: 1}",
"{[[]]: 1}",
"{[null]: 1}",
"{key: +foo()}",
"{key: void foo()}",
"#!/usr/bin/env node\n{}",
'"use strict"\n{}',
"/* comment */",
"// comment",
2021-03-05 01:37:42 +08:00
"`foo${1}bar`",
"-+1",
"-+Infinity",
"-undefined",
"-null",
"-false",
"+'string'",
"{key: +{}}",
2022-10-22 23:33:08 +08:00
'{"identifier": identifier}',
2021-03-05 01:37:42 +08:00
// JSON6 allow this, but babel can't parse
"----123",
2021-02-23 19:33:10 +08:00
],
},
2021-03-02 13:42:49 +08:00
["json", "json5", "json-stringify"],
2021-02-23 19:33:10 +08:00
);
2023-02-24 09:20:03 +08:00
runFormatTest(
2023-02-24 09:20:03 +08:00
{
importMeta: import.meta,
snippets: [
// Invalid JS expressions
"[class {set foo() {}}]",
"[class {foo() {this.#bar}}]",
"[function(){ await 1 }]",
// Should not mention babel plugin in error message
// plugin `doExpressions`
"[do {}]",
// plugin `exportDefaultFrom`
"[function() {export a from 'a'}]",
"export a from 'a'",
// plugin `functionBind`
"[a::b]",
// plugin `functionSent`
"[function*() {function.sent}]",
// plugin `throwExpressions`
"[throw {}]",
// plugin `partialApplication`
"[foo(?)]",
// plugin `decorators`
"[@decorator class {}]",
// plugin `importAssertions`
"[import('a', {type:'json'})]",
// plugin `decimal`
"[1m]",
// plugin `moduleBlocks`
"[module {}]",
// plugin `asyncDoExpressions`
"[async do {}]",
// plugin `regexpUnicodeSets`
"[/a/v]",
// plugin `destructuringPrivate`
"[class {#foo;bar() {const {#foo: foo} = this;}}]",
// plugin `decoratorAutoAccessors`
"[class {accessor foo = 1}]",
// plugin `importReflection`
"[import('a', {reflect: 'module'})]",
"import module a from 'a'",
// plugin `explicitResourceManagement`
"[function() { {using a = b} }]",
"{using a = b}",
// plugin `recordAndTuple`
"[#[]]",
"[#{}]",
// plugin `v8intrinsic`
"[foo%bar()]",
// plugin `pipelineOperator`
"['foo' |> bar]",
"['foo' |> bar(%)]",
// plugin `jsx`
"[<foo></foo>]",
],
},
["json"],
);
2025-03-20 23:01:10 +08:00
runFormatTest(
{
importMeta: import.meta,
snippets: [
"[",
";",
'"string";',
'"string"\n;',
"/* comment */[",
"/* comment */;",
'/* comment */"string";',
'/* comment */"string"\n;',
"#!/usr/bin/env node",
"#!/usr/bin/env node\n[]",
],
},
["json", "json5", "jsonc", "json-stringify"],
);