Skip to content

Conversation

@ChaitanyaGadodia
Copy link

@ChaitanyaGadodia ChaitanyaGadodia commented Sep 9, 2021

Q                       A
Fixed Issues? Fixes #13702
Patch: Bug Fix? 👍
Major: Breaking Change? -
Minor: New Feature? -
Tests Added + Pass? 👍
Documentation PR Link -
Any Dependency Changes? -
License MIT

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).

@babel-bot
Copy link
Collaborator

babel-bot commented Sep 9, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/48788/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 9, 2021

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:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@nicolo-ribaudo nicolo-ribaudo added pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Sep 9, 2021
const rest = this.eat(tt.ellipsis);
let type = this.tsParseType();
let type;
const ALLOWED_KEYWORDS = ["function"];
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Member

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.",
Copy link
Member

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."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 93be0ff

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 14, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Typescript plugin fails on named tuple positions where the name is a reserved word in JS

4 participants