fix: implement early errors for record and tuple#11652
fix: implement early errors for record and tuple#11652nicolo-ribaudo merged 5 commits intobabel:mainfrom
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9705b1e:
|
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/23345/ |
|
What if in |
|
@nicolo-ribaudo |
436153c to
42f44ea
Compare
42f44ea to
5d91a42
Compare
You are right, we don't. However, it's an error we can easily recover from: we just need to find a good error message for it. Maybe |
| UnexpectedReservedWord: "Unexpected reserved word '%0'", | ||
| UnexpectedSuper: "super is only allowed in object methods and classes", | ||
| UnexpectedToken: "Unexpected token '%'", | ||
| UnexpectedToken: "Unexpected token '%0'", |
| if (allowEmpty && this.match(tt.comma)) { | ||
| if (this.match(tt.comma)) { | ||
| if (!allowEmpty) { | ||
| this.raise(this.state.pos, Errors.UnexpectedToken, ","); |
There was a problem hiding this comment.
I resort to the most generic error message. I still feel awkward mentioning holes when throwing f(,). Any suggestions are definitely welcome.
At least the error is now recoverable.
|
@JLHwung thank you for pinging me on this! The changes you have listed look good to me. On syntax options, there is still some discussion in tc39/proposal-record-tuple#10 on which exact sigils to use for the literal syntax. I would be fine with removing the |
|
@nicolo-ribaudo Can we consider this PR has also approval from Rick Button? |
|
Yes 👍 |
Implements early syntax errors specified in https://github.com/tc39/proposal-record-tuple#syntax-errors
ObjectPropertyandSpreadElementinRecordExpression.TupleExpressionI don't have a good idea on throwing recoverable errors other than passing throughThey are now recoverable.isTupleeverywhere.__proto__as key inRecordExpression.@rickbutton BTW do you think we can deprecate
syntaxType: bar? It seems to me{|is longer proposed because I don't see a spec text on that.