Make conditional type colorization little bit better

This commit is contained in:
Sheetal Nandi 2018-03-23 12:53:51 -07:00
Родитель 591c34fffa
Коммит 377ed3642c
5 изменённых файлов: 126 добавлений и 19 удалений

Просмотреть файл

@ -1826,10 +1826,9 @@ repository:
#conditional type
type-conditional:
match: '{{startOfIdentifier}}({{identifier}})\s+(extends)\s+'
match: '{{startOfIdentifier}}(extends)\s+'
captures:
'1': { name: entity.name.type.ts }
'2': { name: storage.modifier.ts }
'1': { name: storage.modifier.ts }
# Parenthesis can contain either types and function parameters
# (number | string) or (param: number, param2: string)

Просмотреть файл

@ -5201,15 +5201,10 @@
<key>type-conditional</key>
<dict>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))([_$[:alpha:]][_$[:alnum:]]*)\s+(extends)\s+</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(extends)\s+</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>entity.name.type.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>

Просмотреть файл

@ -5147,15 +5147,10 @@
<key>type-conditional</key>
<dict>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))([_$[:alpha:]][_$[:alnum:]]*)\s+(extends)\s+</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(extends)\s+</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>entity.name.type.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>

Просмотреть файл

@ -7,7 +7,11 @@ type TypeName<T> =
T extends boolean ? "boolean" :
T extends undefined ? "undefined" :
T extends Function ? "function" :
"object";
"object";
type Extracted<Struct> = {
[K in keyof Struct]: Struct[K] extends FooBar ? ExtractFooBar<Struct[K]> : Struct[K];
}
-----------------------------------
Grammar: TypeScript.tmLanguage
@ -239,7 +243,7 @@ Grammar: TypeScript.tmLanguage
source.ts meta.type.declaration.ts keyword.operator.ternary.ts
^^
source.ts meta.type.declaration.ts
> "object";
> "object";
^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.type.declaration.ts
^
@ -249,4 +253,114 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.type.declaration.ts string.quoted.double.ts punctuation.definition.string.end.ts
^
source.ts punctuation.terminator.statement.ts
source.ts punctuation.terminator.statement.ts
^^
source.ts
>type Extracted<Struct> = {
^^^^
source.ts meta.type.declaration.ts storage.type.type.ts
^
source.ts meta.type.declaration.ts
^^^^^^^^^
source.ts meta.type.declaration.ts entity.name.type.alias.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^^^^
source.ts meta.type.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^^
source.ts meta.type.declaration.ts
^
source.ts meta.type.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.type.declaration.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts punctuation.definition.block.ts
^^
source.ts meta.type.declaration.ts meta.object.type.ts
> [K in keyof Struct]: Struct[K] extends FooBar ? ExtractFooBar<Struct[K]> : Struct[K];
^
source.ts meta.type.declaration.ts meta.object.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.indexer.mappedtype.declaration.ts meta.brace.square.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.indexer.mappedtype.declaration.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.indexer.mappedtype.declaration.ts
^^
source.ts meta.type.declaration.ts meta.object.type.ts meta.indexer.mappedtype.declaration.ts keyword.operator.expression.in.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.indexer.mappedtype.declaration.ts
^^^^^
source.ts meta.type.declaration.ts meta.object.type.ts meta.indexer.mappedtype.declaration.ts keyword.operator.expression.keyof.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.indexer.mappedtype.declaration.ts
^^^^^^
source.ts meta.type.declaration.ts meta.object.type.ts meta.indexer.mappedtype.declaration.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.indexer.mappedtype.declaration.ts meta.brace.square.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts
^^^^^^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.tuple.ts meta.brace.square.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.tuple.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.tuple.ts meta.brace.square.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts
^^^^^^^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts storage.modifier.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts
^^^^^^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts keyword.operator.ternary.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts
^^^^^^^^^^^^^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^^^^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.parameters.ts meta.type.tuple.ts meta.brace.square.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.parameters.ts meta.type.tuple.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.parameters.ts meta.type.tuple.ts meta.brace.square.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts keyword.operator.ternary.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts
^^^^^^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.tuple.ts meta.brace.square.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.tuple.ts entity.name.type.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts meta.type.annotation.ts meta.type.tuple.ts meta.brace.square.ts
^
source.ts meta.type.declaration.ts meta.object.type.ts punctuation.terminator.statement.ts
^^
source.ts meta.type.declaration.ts meta.object.type.ts
>
^^
source.ts meta.type.declaration.ts meta.object.type.ts
>}
^
source.ts meta.type.declaration.ts meta.object.type.ts punctuation.definition.block.ts

Просмотреть файл

@ -5,4 +5,8 @@ type TypeName<T> =
T extends boolean ? "boolean" :
T extends undefined ? "undefined" :
T extends Function ? "function" :
"object";
"object";
type Extracted<Struct> = {
[K in keyof Struct]: Struct[K] extends FooBar ? ExtractFooBar<Struct[K]> : Struct[K];
}