New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: add parser message template #11192
Refactor: add parser message template #11192
Conversation
// $FlowIgnore | ||
const err: SyntaxError & { pos: number, loc: Position } = new SyntaxError( | ||
const message = | ||
errorTemplate.replace(/%(\d+)/g, (_, i: number) => params[i]) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message now supports naive %0
-style templates.
I am not sure if I should do this for TypeScript plugin because the way ts compiler indexes diagnostics is quite brutal: https://github.com/microsoft/TypeScript/blob/9c71eaf59040ae75343da8cdff01344020f5bba2/lib/diagnosticMessages.generated.json |
We should probably diverge from their error codes, and be consistent with the other parts of our parser. |
3321481
to
5ededb5
Compare
Time for a lint rule that prevents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the super minor question about consistency, nice work LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
truly superb! goes a long way for maintenance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
63bd85c
to
1af4064
Compare
This PR collects the scattered babel parser error messages into a centralized message store. By doing so we can implement expression scops which records different types of errors when parsing ambiguous patterns.
The naming conventions of error messages strictly follows v8's message template if they exists, otherwise I coin some phrase so PTAL on the message template. 🙏
Todo