Disable Babel's error recovery for omitted call arguments (#10065)

This commit is contained in:
Georgii Dolzhykov authored and GitHub committed 2021-01-18 09:45:37 +02:00
1 parent 2808f401ba
commit 92cf9452e9
9 files changed
+58 -77

No files matched your search

+4 -2
View File
@@ -1,4 +1,4 @@
#### Print null items in arguments (#9787 by @sosukesuzuki)
#### Disable Babel's error recovery for omitted call arguments (#9787 by @sosukesuzuki, #10065 by @thorn0)
<!-- prettier-ignore -->
```js
@@ -9,5 +9,7 @@ foo("a", , "b");
TypeError: Cannot read property 'type' of null
// Prettier master
foo("a", , "b");
[error] stdin: SyntaxError: Argument expression expected. (1:10)
[error] > 1 | foo("a", , "b");
[error] | ^
```
+3
View File
@@ -164,6 +164,9 @@ const messagesShouldThrow = new Set([
// FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction
// https://github.com/babel/babel/blob/a023b6456cac4505096028f91c5b78829955bfc2/packages/babel-parser/src/plugins/flow.js#L118
"Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`",
// Rethrow on omitted call arguments: foo("a", , "b");
// ErrorMessages.UnexpectedToken
"Unexpected token ','",
]);
function shouldRethrowRecoveredError(error) {
+8 -10
View File
@@ -834,18 +834,16 @@ function isFunctionCompositionArgs(args) {
}
let count = 0;
for (const arg of args) {
if (arg) {
if (isFunctionOrArrowExpression(arg)) {
count += 1;
if (count > 1) {
if (isFunctionOrArrowExpression(arg)) {
count += 1;
if (count > 1) {
return true;
}
} else if (isCallOrOptionalCallExpression(arg)) {
for (const childArg of arg.arguments) {
if (isFunctionOrArrowExpression(childArg)) {
return true;
}
} else if (isCallOrOptionalCallExpression(arg)) {
for (const childArg of arg.arguments) {
if (isFunctionOrArrowExpression(childArg)) {
return true;
}
}
}
}
}
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`null-arguments-item.js [babel] format 1`] = `
"Unexpected token ',' (1:12)
> 1 | foor('a', , 'b');
| ^
2 | foo('looooooooooooooooooooooooooooooooooooooooooooooong', , 'looooooooooooooooooooooooooooooooooooooooooooooong');
3 | foo(\\"a\\",
4 | //1"
`;
exports[`null-arguments-item.js [espree] format 1`] = `
"Unexpected token , (1:11)
> 1 | foor('a', , 'b');
| ^
2 | foo('looooooooooooooooooooooooooooooooooooooooooooooong', , 'looooooooooooooooooooooooooooooooooooooooooooooong');
3 | foo(\\"a\\",
4 | //1"
`;
exports[`null-arguments-item.js [meriyah] format 1`] = `
"[1:11]: Unexpected token: ',' (1:11)
> 1 | foor('a', , 'b');
| ^
2 | foo('looooooooooooooooooooooooooooooooooooooooooooooong', , 'looooooooooooooooooooooooooooooooooooooooooooooong');
3 | foo(\\"a\\",
4 | //1"
`;
@@ -1,5 +1,6 @@
run_spec(__dirname, ["babel"], {
errors: {
babel: true,
espree: true,
meriyah: true,
},
@@ -1,50 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`null-arguments-item.js [espree] format 1`] = `
"Unexpected token , (1:11)
> 1 | foor('a', , 'b');
| ^
2 | foo('looooooooooooooooooooooooooooooooooooooooooooooong', , 'looooooooooooooooooooooooooooooooooooooooooooooong');
3 | foo(\\"a\\",
4 | //1"
`;
exports[`null-arguments-item.js [meriyah] format 1`] = `
"[1:11]: Unexpected token: ',' (1:11)
> 1 | foor('a', , 'b');
| ^
2 | foo('looooooooooooooooooooooooooooooooooooooooooooooong', , 'looooooooooooooooooooooooooooooooooooooooooooooong');
3 | foo(\\"a\\",
4 | //1"
`;
exports[`null-arguments-item.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
foor('a', , 'b');
foo('looooooooooooooooooooooooooooooooooooooooooooooong', , 'looooooooooooooooooooooooooooooooooooooooooooooong');
foo("a",
//1
, "b");
foo("a", /* comment */, "b");
=====================================output=====================================
foor("a", , "b");
foo(
"looooooooooooooooooooooooooooooooooooooooooooooong",
,
"looooooooooooooooooooooooooooooooooooooooooooooong"
);
foo(
"a",
,
//1
"b"
);
foo("a" /* comment */, , "b");
================================================================================
`;
@@ -48,6 +48,13 @@ assert(rest[1] === 3);
================================================================================
`;
exports[`invalid-tuple-holes.js [babel] format 1`] = `
"Unexpected token ',' (1:4)
> 1 | #[,]
| ^
2 | "
`;
exports[`invalid-tuple-holes.js [espree] format 1`] = `
"Unexpected character '#' (1:1)
> 1 | #[,]
@@ -62,20 +69,6 @@ exports[`invalid-tuple-holes.js [meriyah] format 1`] = `
2 | "
`;
exports[`invalid-tuple-holes.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
#[,]
=====================================output=====================================
#[,];
================================================================================
`;
exports[`syntax.js [espree] format 1`] = `
"Unexpected character '#' (1:1)
> 1 | #[]
+7 -1
View File
@@ -1 +1,7 @@
run_spec(__dirname, ["babel"], { errors: { espree: true, meriyah: true } });
run_spec(__dirname, ["babel"], {
errors: {
babel: ["invalid-tuple-holes.js"],
espree: true,
meriyah: true,
},
});