-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
area: errorsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser
Description
Feature Request
- I would like to work on this feature!
Is your feature request related to a problem?
Yes, Prettier needs to handle the errors provided by babel-parser in recovery mode, which can be ignored.
The current Prettier hardcodes error messages for this purpose. See https://github.com/prettier/prettier/blob/3995c2a1a1839753e08f0576c4161876bc5ad62e/src/language-js/parser-babel.js#L147-L204. This is not a good. Fixing Babel's error messages may break Prettier.
Context: prettier/prettier#10495 (comment)
Describe the solution you'd like
Introduce error code.
Describe alternatives you've considered.
Continue hardcoding...
Documentation, Adoption, Migration Strategy
I think the following interface looks good.
const { parse } = require("@babel/parser");
const ast = parse("const foo = 1; const foo = 2;", { errorRecovery: true }));
console.log(ast.errors[0].message); // Identifier 'foo' has already been declared
console.log(ast.errors[0].code); // BABEL_PARSER_SYNTAX_ERROR_001
Metadata
Metadata
Assignees
Labels
area: errorsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser