Skip to content

Commit

Permalink
Support the JSX Opening or self closing tag's type arguments
Browse files Browse the repository at this point in the history
This handles support for microsoft/TypeScript#22415
  • Loading branch information
sheetalkamat committed Mar 13, 2018
1 parent 30a2e6b commit aef7be5
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 83 deletions.
28 changes: 16 additions & 12 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ variables:
# Identifier start | matching braces | matching parenthesis | matching square brackets | matching strings
typeArgumentsStart: ({{typeParamersStart}}|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))
typeArgumentsInnerExpressionPart: '[^<>\(]|{{matchingParenthesis}}|(?<==)\>'
typeArguments: (<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}}|\<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}})*(?!=)\>)*(?!=)>\s*)
functionCallLookup: \s*(\?\.\s*)?{{typeArguments}}?\(
typeArguments: '<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}}|\<\s*{{typeArgumentsStart}}({{typeArgumentsInnerExpressionPart}})*(?!=)\>)*(?!=)>'
functionCallLookup: \s*(\?\.\s*)?({{typeArguments}}\s*)?\(
arrowLookup: |-
# sure shot arrow functions even if => is on new line
(
Expand Down Expand Up @@ -1111,16 +1111,7 @@ repository:
- include: '#comment'
- name: meta.function-call.ts punctuation.accessor.optional.ts
match: \?\.
- name: meta.type.parameters.ts
begin: \<
beginCaptures:
'0': { name: punctuation.definition.typeparameters.begin.ts }
end: \>
endCaptures:
'0': { name: punctuation.definition.typeparameters.end.ts }
patterns:
- include: '#type'
- include: '#punctuation-comma'
- include: '#type-arguments'
- include: '#paren-expression'

new-expr:
Expand Down Expand Up @@ -1755,6 +1746,19 @@ repository:
- include: '#type'
- include: '#punctuation-comma'

#type arguments
type-arguments:
name: meta.type.parameters.ts
begin: \<
beginCaptures:
'0': { name: punctuation.definition.typeparameters.begin.ts }
end: \>
endCaptures:
'0': { name: punctuation.definition.typeparameters.end.ts }
patterns:
- include: '#type'
- include: '#punctuation-comma'

#different types
type:
patterns:
Expand Down
71 changes: 38 additions & 33 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -3481,39 +3481,8 @@
<string>\?\.</string>
</dict>
<dict>
<key>name</key>
<string>meta.type.parameters.ts</string>
<key>begin</key>
<string>\&lt;</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.typeparameters.begin.ts</string>
</dict>
</dict>
<key>end</key>
<string>\&gt;</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.typeparameters.end.ts</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type</string>
</dict>
<dict>
<key>include</key>
<string>#punctuation-comma</string>
</dict>
</array>
<key>include</key>
<string>#type-arguments</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -4985,6 +4954,42 @@
</dict>
</array>
</dict>
<key>type-arguments</key>
<dict>
<key>name</key>
<string>meta.type.parameters.ts</string>
<key>begin</key>
<string>\&lt;</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.typeparameters.begin.ts</string>
</dict>
</dict>
<key>end</key>
<string>\&gt;</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.typeparameters.end.ts</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type</string>
</dict>
<dict>
<key>include</key>
<string>#punctuation-comma</string>
</dict>
</array>
</dict>
<key>type</key>
<dict>
<key>patterns</key>
Expand Down
3 changes: 2 additions & 1 deletion TypeScriptReact.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ variables:
jsxTagName: \s*{{jsxTagNamespace}}((?:[a-z][a-z0-9]*|({{jsxTagOrAtrributeIdentifier}}*))(?<!\.|-))
jsxOpeningTagWithoutAttributes: (<){{jsxTagName}}?\s*(>)
jsxClosingTag: (</){{jsxTagName}}?\s*(>)
jsxTagStart: (<){{jsxTagName}}(?=\s+(?!\?)|\/?>)
jsxTagStart: (<){{jsxTagName}}(?=(?:\s*{{typeArguments}})?\s+(?!\?)|\/?>)
jsxTagStartLookahead: (?={{jsxTagStart}})

repository:
Expand Down Expand Up @@ -122,6 +122,7 @@ repository:
contentName: meta.tag.attributes.tsx
patterns:
- include: '#comment'
- include: '#type-arguments'
- include: '#jsx-tag-attributes'
- include: '#jsx-tag-attributes-illegal'
- begin: (>)
Expand Down
83 changes: 46 additions & 37 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -3485,39 +3485,8 @@
<string>\?\.</string>
</dict>
<dict>
<key>name</key>
<string>meta.type.parameters.tsx</string>
<key>begin</key>
<string>\&lt;</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.typeparameters.begin.tsx</string>
</dict>
</dict>
<key>end</key>
<string>\&gt;</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.typeparameters.end.tsx</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type</string>
</dict>
<dict>
<key>include</key>
<string>#punctuation-comma</string>
</dict>
</array>
<key>include</key>
<string>#type-arguments</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -4931,6 +4900,42 @@
</dict>
</array>
</dict>
<key>type-arguments</key>
<dict>
<key>name</key>
<string>meta.type.parameters.tsx</string>
<key>begin</key>
<string>\&lt;</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.typeparameters.begin.tsx</string>
</dict>
</dict>
<key>end</key>
<string>\&gt;</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.typeparameters.end.tsx</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#type</string>
</dict>
<dict>
<key>include</key>
<string>#punctuation-comma</string>
</dict>
</array>
</dict>
<key>type</key>
<dict>
<key>patterns</key>
Expand Down Expand Up @@ -7024,7 +7029,7 @@
<string>(?x)
(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^)\s*
(?!&lt;\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=&gt;])|,)) # look ahead is not type parameter of arrow
(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=\s+(?!\?)|\/?&gt;))</string>
(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=(?:\s*&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;|\&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;)*(?!=)\&gt;)*(?!=)&gt;)?\s+(?!\?)|\/?&gt;))</string>
<key>end</key>
<string>(/&gt;)|(?:(&lt;/)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>endCaptures</key>
Expand Down Expand Up @@ -7081,7 +7086,7 @@
<key>jsx-child-tag</key>
<dict>
<key>begin</key>
<string>(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=\s+(?!\?)|\/?&gt;))</string>
<string>(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=(?:\s*&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;|\&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;)*(?!=)\&gt;)*(?!=)&gt;)?\s+(?!\?)|\/?&gt;))</string>
<key>end</key>
<string>(/&gt;)|(?:(&lt;/)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
<key>endCaptures</key>
Expand Down Expand Up @@ -7140,14 +7145,14 @@
<key>name</key>
<string>meta.tag.tsx</string>
<key>begin</key>
<string>(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=\s+(?!\?)|\/?&gt;))</string>
<string>(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=(?:\s*&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;|\&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;)*(?!=)\&gt;)*(?!=)&gt;)?\s+(?!\?)|\/?&gt;))</string>
<key>end</key>
<string>(?=(/&gt;)|(?:(&lt;/)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;)))</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=\s+(?!\?)|\/?&gt;)</string>
<string>(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=(?:\s*&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;|\&lt;\s*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))|(\'[^\']*\')|(\"[^\"]*\")|(\`[^\`]*\`))([^&lt;&gt;\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?&lt;==)\&gt;)*(?!=)\&gt;)*(?!=)&gt;)?\s+(?!\?)|\/?&gt;)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -7186,6 +7191,10 @@
<key>include</key>
<string>#comment</string>
</dict>
<dict>
<key>include</key>
<string>#type-arguments</string>
</dict>
<dict>
<key>include</key>
<string>#jsx-tag-attributes</string>
Expand Down
40 changes: 40 additions & 0 deletions tests/baselines/jsxTagWithTypeArguments.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
original file
-----------------------------------
// @onlyOwnGrammar - As this has jsx
<MyComponent<number> data={12} />
-----------------------------------

Grammar: TypeScriptReact.tmLanguage
-----------------------------------
>// @onlyOwnGrammar - As this has jsx
^^
source.tsx comment.line.double-slash.tsx punctuation.definition.comment.tsx
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.tsx comment.line.double-slash.tsx
><MyComponent<number> data={12} />
^
source.tsx meta.tag.tsx punctuation.definition.tag.begin.tsx
^^^^^^^^^^^
source.tsx meta.tag.tsx entity.name.tag.tsx support.class.component.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx meta.type.parameters.tsx punctuation.definition.typeparameters.begin.tsx
^^^^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx meta.type.parameters.tsx support.type.primitive.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx meta.type.parameters.tsx punctuation.definition.typeparameters.end.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx
^^^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx entity.other.attribute-name.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx keyword.operator.assignment.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx meta.embedded.expression.tsx punctuation.section.embedded.begin.tsx
^^
source.tsx meta.tag.tsx meta.tag.attributes.tsx meta.embedded.expression.tsx constant.numeric.decimal.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx meta.embedded.expression.tsx punctuation.section.embedded.end.tsx
^
source.tsx meta.tag.tsx meta.tag.attributes.tsx
^^
source.tsx meta.tag.tsx punctuation.definition.tag.end.tsx
2 changes: 2 additions & 0 deletions tests/cases/jsxTagWithTypeArguments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @onlyOwnGrammar - As this has jsx
<MyComponent<number> data={12} />

0 comments on commit aef7be5

Please sign in to comment.