Skip to content
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

[TypeScript] Implement labeled tuple members #3837

Merged
merged 4 commits into from
Sep 24, 2023

Conversation

Thom1729
Copy link
Collaborator

@Thom1729 Thom1729 commented Sep 3, 2023

E.g. type Rational = [numerator: bigint, denominator: bigint];

Introduced in TypeScript 4.0 more than three years ago, but documented nowhere outside those release notes (plus the recent 5.2 release notes).

I used the scope meta.mapping.key for the labels, which doesn't seem quite right but I don't know what would be more right.

The implementation uses branching because a lookahead would have to span multiple lines. I initially intended to use a cover grammar approach, but that would be a mess if the label were the name of a type operator (which you would think wouldn't be allowed, but here we are).

@keith-hall
Copy link
Collaborator

C# and Python support named tuples, it may make sense to check what scopes they use

This commit ...

1. optimizes implementation to speed it up by about 15%
2. rescopes labels to `variable.other.member` as variable scope is what C# uses
   and this is what labels are for. Create named access to tuple members as if
   they were normal struct members.

Note:
1. `meta.mapping.key` should be used in mappings only.
2. We shouldn't mix up sequence and mapping scopes, although a mapping is just
   a sequence of key-value pairs.
@deathaxe
Copy link
Collaborator

Sorry, for directly pushing. I wanted to create a PR to this PR, but Sublime Merge decided to not give me an option to push it to my local repo, but decided to directly push it here.

@Thom1729
Copy link
Collaborator Author

LGTM.

@Thom1729 Thom1729 merged commit 01cce12 into sublimehq:master Sep 24, 2023
2 checks passed
@Thom1729 Thom1729 deleted the typescript-labeled-tuple-members branch September 24, 2023 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants