1.0 KiB
1.0 KiB
Make Babel’s error recovery more selective (#10495 by @fisker, #9787 by @sosukesuzuki, #10065, #10322 by @thorn0)
Previously, because of the error recovery, the Babel parser was too permissive, which lead to all kinds of AST shapes that Prettier couldn’t print. Prettier main lets Babel recover only from a few harmless types of errors – for example, multiple const declarations with the same name. Anything else is reported as syntax errors.
// Input
foo("a", , "b");
// Prettier stable
TypeError: Cannot read property 'type' of null
// Prettier main
[error] stdin: SyntaxError: Argument expression expected. (1:10)
[error] > 1 | foo("a", , "b");
[error] | ^
// Input
const \u{20} = 1
// Prettier stable
const = 1;
// Prettier main
[error] stdin: SyntaxError: Invalid Unicode escape (1:7)
[error] > 1 | const \u{20} = 1
[error] | ^ ^