Skip to content

Commit

Permalink
[TypeScript] Optimize labeled tuple members
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deathaxe committed Sep 22, 2023
1 parent 4281dbe commit 4f61672
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
23 changes: 12 additions & 11 deletions JavaScript/TypeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -935,26 +935,27 @@ contexts:
- ts-type-tuple-possible-member-label

ts-type-tuple-possible-member-label:
- match: (?={{identifier_name}})
- match: ''
branch_point: ts-type-tuple-member-label
branch:
- ts-type-tuple-member-label
- immediately-pop
pop: 1
- include: else-pop

ts-type-tuple-member-label:
- match: ''
- match: '{{identifier_name}}'
scope: variable.other.member.js
set:
- - match: ':'
scope: punctuation.separator.type.js
pop: 1
- match: (?=\S)
fail: ts-type-tuple-member-label
- ts-type-tuple-member-label-separator
- ts-type-annotation-optional
- - match: '{{identifier_name}}'
scope: meta.mapping.key.js
pop: 1
- include: else-pop

ts-type-tuple-member-label-separator:
- match: ':'
scope: punctuation.separator.type.js
pop: 1
- match: (?=\S)
fail: ts-type-tuple-member-label

ts-type-tuple-spread:
- match: \.\.\.
Expand Down
6 changes: 3 additions & 3 deletions JavaScript/tests/syntax_test_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,11 +860,11 @@ let x: [ first: any, rest: ...any ];
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.type
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.sequence
// ^ punctuation.section.sequence.begin
// ^^^^^ meta.mapping.key
// ^^^^^ variable.other.member
// ^ punctuation.separator.type
// ^^^ support.type.any
// ^ punctuation.separator.comma
// ^^^^ meta.mapping.key
// ^^^^ variable.other.member
// ^ punctuation.separator.type
// ^^^ keyword.operator.spread
// ^^^ support.type.any
Expand All @@ -873,7 +873,7 @@ let x: [ first: any, rest: ...any ];

let x: [
typeof
// ^^^^^ meta.mapping.key
// ^^^^^ variable.other.member
?
// ^ storage.modifier.optional
:
Expand Down

0 comments on commit 4f61672

Please sign in to comment.