-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Named Tuple label : reserved keywords #13743
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
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/48788/ |
|
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 93be0ff:
|
| const rest = this.eat(tt.ellipsis); | ||
| let type = this.tsParseType(); | ||
| let type; | ||
| const ALLOWED_KEYWORDS = ["function"]; |
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.
IMO TS should have allowed all keywords as the label in the named tuple members, I have file an issue to TS: microsoft/TypeScript#45819
After that issue is resolved, we can remove the ALLOWED_KEYWORDS here.
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 TS issue has been marked as [suggestion]/[awaiting more feedback]. Maybe we can start by matching TS's behavior, and then relax the restriction when they relax it.
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 we want to match the TS behaviour, which I think is an overlook when implementing named tuple elements, the complete "allowed" keyword set can be found in https://github.com/microsoft/TypeScript/blob/0af2497fecef9e41d7d0260fd37932dd33912c66/src/compiler/parser.ts#L3726
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 100% agree that this is an overlook, but the TS team doesn't seem to much interested in relaxing this restriction 😅
As an alternative, we can just allow every keyword: valid TS programs will still be accepted.
| InvalidModifierOnTypeMember: | ||
| "'%0' modifier cannot appear on a type member.", | ||
| InvalidModifiersOrder: "'%0' modifier must precede '%1' modifier.", | ||
| InvalidTuple: "Invalid Tuple.", |
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.
We can have a better error, like InvalidTupleElementKeyword: "The '%0' keyword cannot be used as a tuple element."
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.
done in 93be0ff
Named tuples can have labels which are reserved keywords. At the same time keywords are not valid types (i.e. type X = [function] is invalid).