-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
fix: implement early errors for record and tuple #11652
fix: implement early errors for record and tuple #11652
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 |
@@ -163,7 +166,7 @@ export const ErrorMessages = Object.freeze({ | |||
"Private names can only be used as the name of a class element (i.e. class C { #p = 42; #m() {} } )\n or a property of member expression (i.e. this.#p).", | |||
UnexpectedReservedWord: "Unexpected reserved word '%0'", | |||
UnexpectedSuper: "super is only allowed in object methods and classes", | |||
UnexpectedToken: "Unexpected token '%'", | |||
UnexpectedToken: "Unexpected token '%0'", |
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.
🤦♂️
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ObjectProperty
andSpreadElement
inRecordExpression
.TupleExpression
I don't have a good idea on throwing recoverable errors other than passing throughThey are now recoverable.isTuple
everywhere.__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.