Skip to content

Commit

Permalink
Hide cause
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jan 15, 2024
1 parent 91c0286 commit de46f0c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 37 deletions.
4 changes: 3 additions & 1 deletion src/language-js/parse/utils/create-babel-parse-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ function createBabelParseError(error) {
reasonCode,
} = error;

let cause = error;
if (reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins") {
message = "Unexpected token.";
cause = undefined;
}

const suffix = ` (${line}:${column})`;
Expand All @@ -20,7 +22,7 @@ function createBabelParseError(error) {

return createError(message, {
loc: { start: { line, column: column + 1 } },
cause: error,
cause,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
exports[`snippet: #0 [babel] format 1`] = `
"Unexpected token. (1:8)
> 1 | export type Foo = number;
| ^
Cause: This experimental syntax requires enabling one of the following parser plugin(s): "flow", "typescript". (1:7)"
| ^"
`;
51 changes: 17 additions & 34 deletions tests/format/misc/errors/json/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ exports[`snippet: #3 [json] format 1`] = `
exports[`snippet: #3 [json] format 2`] = `
"Unexpected token. (1:2)
> 1 | [do {}]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "doExpressions". (1:1)"
| ^"
`;

exports[`snippet: #3 [json-stringify] format 1`] = `
Expand Down Expand Up @@ -187,8 +186,7 @@ exports[`snippet: #7 [json] format 1`] = `
exports[`snippet: #7 [json] format 2`] = `
"Unexpected token. (1:24)
> 1 | [function*() {function.sent}]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "functionSent". (1:23)"
| ^"
`;

exports[`snippet: #7 [json-stringify] format 1`] = `
Expand All @@ -212,8 +210,7 @@ exports[`snippet: #8 [json] format 1`] = `
exports[`snippet: #8 [json] format 2`] = `
"Unexpected token. (1:2)
> 1 | [throw {}]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "throwExpressions". (1:1)"
| ^"
`;

exports[`snippet: #8 [json-stringify] format 1`] = `
Expand All @@ -237,8 +234,7 @@ exports[`snippet: #9 [json] format 1`] = `
exports[`snippet: #9 [json] format 2`] = `
"Unexpected token. (1:6)
> 1 | [foo(?)]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "partialApplication". (1:5)"
| ^"
`;

exports[`snippet: #9 [json-stringify] format 1`] = `
Expand All @@ -262,8 +258,7 @@ exports[`snippet: #10 [json] format 1`] = `
exports[`snippet: #10 [json] format 2`] = `
"Unexpected token. (1:2)
> 1 | [@decorator class {}]
| ^
Cause: This experimental syntax requires enabling one of the following parser plugin(s): "decorators", "decorators-legacy". (1:1)"
| ^"
`;

exports[`snippet: #10 [json-stringify] format 1`] = `
Expand All @@ -287,8 +282,7 @@ exports[`snippet: #11 [json] format 1`] = `
exports[`snippet: #11 [json] format 2`] = `
"Unexpected token. (1:28)
> 1 | [import('a', {type:'json'})]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "importAttributes". (1:27)"
| ^"
`;

exports[`snippet: #11 [json-stringify] format 1`] = `
Expand All @@ -312,8 +306,7 @@ exports[`snippet: #12 [json] format 1`] = `
exports[`snippet: #12 [json] format 2`] = `
"Unexpected token. (1:3)
> 1 | [1m]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "decimal". (1:2)"
| ^"
`;

exports[`snippet: #12 [json-stringify] format 1`] = `
Expand All @@ -337,8 +330,7 @@ exports[`snippet: #13 [json] format 1`] = `
exports[`snippet: #13 [json] format 2`] = `
"Unexpected token. (1:2)
> 1 | [module {}]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "moduleBlocks". (1:1)"
| ^"
`;

exports[`snippet: #13 [json-stringify] format 1`] = `
Expand All @@ -362,8 +354,7 @@ exports[`snippet: #14 [json] format 1`] = `
exports[`snippet: #14 [json] format 2`] = `
"Unexpected token. (1:8)
> 1 | [async do {}]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "doExpressions". (1:7)"
| ^"
`;

exports[`snippet: #14 [json-stringify] format 1`] = `
Expand Down Expand Up @@ -411,8 +402,7 @@ exports[`snippet: #16 [json] format 1`] = `
exports[`snippet: #16 [json] format 2`] = `
"Unexpected token. (1:28)
> 1 | [class {#foo;bar() {const {#foo: foo} = this;}}]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "destructuringPrivate". (1:27)"
| ^"
`;

exports[`snippet: #16 [json-stringify] format 1`] = `
Expand All @@ -436,8 +426,7 @@ exports[`snippet: #17 [json] format 1`] = `
exports[`snippet: #17 [json] format 2`] = `
"Unexpected token. (1:18)
> 1 | [class {accessor foo = 1}]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "decoratorAutoAccessors". (1:17)"
| ^"
`;

exports[`snippet: #17 [json-stringify] format 1`] = `
Expand All @@ -461,8 +450,7 @@ exports[`snippet: #18 [json] format 1`] = `
exports[`snippet: #18 [json] format 2`] = `
"Unexpected token. (1:34)
> 1 | [import('a', {reflect: 'module'})]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "importAttributes". (1:33)"
| ^"
`;

exports[`snippet: #18 [json-stringify] format 1`] = `
Expand Down Expand Up @@ -511,8 +499,7 @@ exports[`snippet: #20 [json] format 1`] = `
exports[`snippet: #20 [json] format 2`] = `
"Unexpected token. (1:16)
> 1 | [function() { {using a = b} }]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "explicitResourceManagement". (1:15)"
| ^"
`;

exports[`snippet: #20 [json-stringify] format 1`] = `
Expand Down Expand Up @@ -599,8 +586,7 @@ Cause: Unexpected token (1:13)"
exports[`snippet: #23 [json] format 2`] = `
"Unexpected token. (1:2)
> 1 | [#{}]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "recordAndTuple". (1:1)"
| ^"
`;

exports[`snippet: #23 [json-stringify] format 1`] = `
Expand Down Expand Up @@ -653,8 +639,7 @@ exports[`snippet: #25 [json] format 1`] = `
exports[`snippet: #25 [json] format 2`] = `
"Unexpected token. (1:8)
> 1 | ['foo' |> bar]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "pipelineOperator". (1:7)"
| ^"
`;

exports[`snippet: #25 [json-stringify] format 1`] = `
Expand All @@ -678,8 +663,7 @@ exports[`snippet: #26 [json] format 1`] = `
exports[`snippet: #26 [json] format 2`] = `
"Unexpected token. (1:8)
> 1 | ['foo' |> bar(%)]
| ^
Cause: This experimental syntax requires enabling the parser plugin: "pipelineOperator". (1:7)"
| ^"
`;

exports[`snippet: #26 [json-stringify] format 1`] = `
Expand All @@ -703,8 +687,7 @@ exports[`snippet: #27 [json] format 1`] = `
exports[`snippet: #27 [json] format 2`] = `
"Unexpected token. (1:2)
> 1 | [<foo></foo>]
| ^
Cause: This experimental syntax requires enabling one of the following parser plugin(s): "jsx", "flow", "typescript". (1:1)"
| ^"
`;

exports[`snippet: #27 [json-stringify] format 1`] = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,53 @@ printWidth: 80
================================================================================
`;

exports[`snippet: .prettierrc in yaml (with flowMapping) format 1`] = `
====================================options=====================================
parsers: []
printWidth: 80
| printWidth
=====================================input======================================
# comment
printWidth: 100
overrides: {
"files": [".prettierrc", "prettierrc.json"],
"options": { "parser": "json"}
}
=====================================output=====================================
# comment
printWidth: 100
overrides:
{
"files": [".prettierrc", "prettierrc.json"],
"options": { "parser": "json" },
}
================================================================================
`;

exports[`snippet: .prettierrc in yaml format 1`] = `
====================================options=====================================
parsers: []
printWidth: 80
| printWidth
=====================================input======================================
# comment
printWidth: 100
overrides:
- files: '.prettierrc'
options:
parser: "json"
=====================================output=====================================
# comment
printWidth: 100
overrides:
- files: ".prettierrc"
options:
parser: "json"
================================================================================
`;

exports[`test.html format 1`] = `
====================================options=====================================
parsers: []
Expand Down

0 comments on commit de46f0c

Please sign in to comment.