Skip to content

Commit

Permalink
Updated to support 'infer..extends'
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Mar 18, 2022
1 parent 08fbf95 commit df2caa8
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 19 deletions.
26 changes: 23 additions & 3 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2332,8 +2332,8 @@ repository:
- include: '#type-parameters'
- include: '#type-tuple'
- include: '#type-object'
- include: '#type-conditional'
- include: '#type-operators'
- include: '#type-conditional'
- include: '#type-fn-type-parameters'
- include: '#type-paren-or-function-parameters'
- include: '#type-function-return-type'
Expand Down Expand Up @@ -2519,6 +2519,7 @@ repository:
type-operators:
patterns:
- include: '#typeof-operator'
- include: '#type-infer'
# Handle the object types followed by | or & operator as { can be used as end of Type in many places and this avoids tripping that
- begin: ([&|])(?=\s*\{)
beginCaptures:
Expand All @@ -2536,11 +2537,30 @@ repository:
match: '{{startOfIdentifier}}keyof{{endOfIdentifier}}'
- name: keyword.operator.ternary.ts
match: (\?|\:)
- name: keyword.operator.expression.infer.ts
match: '{{startOfIdentifier}}infer(?=\s+[_$[:alpha:]])'
- name: keyword.operator.expression.import.ts
match: '{{startOfIdentifier}}import(?=\s*\()'

type-infer:
patterns:
# try to match infer..extends on a single line
- match: '{{startOfIdentifier}}(infer)\s+({{identifier}})\s+(extends){{endOfIdentifier}}'
name: meta.type.infer.ts
captures:
'1': { name: keyword.operator.expression.infer.ts }
'2': { name: entity.name.type.ts }
'3': { name: keyword.operator.expression.extends.ts }
# alternatively, match across multiple lines
- begin: '{{startOfIdentifier}}infer(?=\s+[_$[:alpha:]])'
beginCaptures:
'0': { name: keyword.operator.expression.infer.ts }
end: '(?={{lookAheadEndOfType}}|[''"`|&])'
name: meta.type.infer.ts
patterns:
- name: keyword.operator.expression.extends.ts
match: '{{startOfIdentifier}}extends{{endOfIdentifier}}'
- name: entity.name.type.ts
match: '{{startOfIdentifier}}{{identifier}}{{endOfIdentifier}}'

type-predicate-operator:
patterns:
- match: '{{startOfIdentifier}}(?:(asserts)\s+)?(?!asserts)(?:(this)|({{identifier}}))\s(is){{endOfIdentifier}}'
Expand Down
73 changes: 66 additions & 7 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -7076,11 +7076,11 @@
</dict>
<dict>
<key>include</key>
<string>#type-conditional</string>
<string>#type-operators</string>
</dict>
<dict>
<key>include</key>
<string>#type-operators</string>
<string>#type-conditional</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -7630,6 +7630,10 @@
<key>include</key>
<string>#typeof-operator</string>
</dict>
<dict>
<key>include</key>
<string>#type-infer</string>
</dict>
<dict>
<key>begin</key>
<string>([&amp;|])(?=\s*\{)</string>
Expand Down Expand Up @@ -7679,15 +7683,70 @@
</dict>
<dict>
<key>name</key>
<string>keyword.operator.expression.infer.ts</string>
<string>keyword.operator.expression.import.ts</string>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))infer(?=\s+[_$[:alpha:]])</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))import(?=\s*\()</string>
</dict>
</array>
</dict>
<key>type-infer</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>keyword.operator.expression.import.ts</string>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))import(?=\s*\()</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(infer)\s+([_$[:alpha:]][_$[:alnum:]]*)\s+(extends)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>name</key>
<string>meta.type.infer.ts</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.expression.infer.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>entity.name.type.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>keyword.operator.expression.extends.ts</string>
</dict>
</dict>
</dict>
<dict>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))infer(?=\s+[_$[:alpha:]])</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.operator.expression.infer.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?=[;),}\]:?\-\+\&gt;]|\|\||\&amp;\&amp;|\!\=\=|$|['"`|&amp;])</string>
<key>name</key>
<string>meta.type.infer.ts</string>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>keyword.operator.expression.extends.ts</string>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))extends(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
</dict>
<dict>
<key>name</key>
<string>entity.name.type.ts</string>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))[_$[:alpha:]][_$[:alnum:]]*(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
</dict>
</array>
</dict>
</array>
</dict>
Expand Down
73 changes: 66 additions & 7 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -7024,11 +7024,11 @@
</dict>
<dict>
<key>include</key>
<string>#type-conditional</string>
<string>#type-operators</string>
</dict>
<dict>
<key>include</key>
<string>#type-operators</string>
<string>#type-conditional</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -7578,6 +7578,10 @@
<key>include</key>
<string>#typeof-operator</string>
</dict>
<dict>
<key>include</key>
<string>#type-infer</string>
</dict>
<dict>
<key>begin</key>
<string>([&amp;|])(?=\s*\{)</string>
Expand Down Expand Up @@ -7627,15 +7631,70 @@
</dict>
<dict>
<key>name</key>
<string>keyword.operator.expression.infer.tsx</string>
<string>keyword.operator.expression.import.tsx</string>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))infer(?=\s+[_$[:alpha:]])</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))import(?=\s*\()</string>
</dict>
</array>
</dict>
<key>type-infer</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>keyword.operator.expression.import.tsx</string>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))import(?=\s*\()</string>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(infer)\s+([_$[:alpha:]][_$[:alnum:]]*)\s+(extends)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>name</key>
<string>meta.type.infer.tsx</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.expression.infer.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>entity.name.type.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>keyword.operator.expression.extends.tsx</string>
</dict>
</dict>
</dict>
<dict>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))infer(?=\s+[_$[:alpha:]])</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.operator.expression.infer.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?=[;),}\]:?\-\+\&gt;]|\|\||\&amp;\&amp;|\!\=\=|$|['"`|&amp;])</string>
<key>name</key>
<string>meta.type.infer.tsx</string>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>keyword.operator.expression.extends.tsx</string>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))extends(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
</dict>
<dict>
<key>name</key>
<string>entity.name.type.tsx</string>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))[_$[:alpha:]][_$[:alnum:]]*(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
</dict>
</array>
</dict>
</array>
</dict>
Expand Down
66 changes: 66 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"mocha": "latest",
"plist": "latest",
"typescript": "latest",
"vscode-grammar-updater": "^1.0.4",
"vscode-textmate": "^4.1.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit df2caa8

Please sign in to comment.