@@ -10,6 +10,14 @@ uuid: 805375ec-d614-41f5-8993-5843fe63ea82
1010
1111variables :
1212 possiblyMultilineArrow : ([\(]\s*$) # during lookup treat ( followed by line end as arrow
13+ jsxTagOrAtrributeIdentifier : ' [_$a-zA-Z][-$\w.]'
14+ jsxTagNamespace : (?:({{jsxTagOrAtrributeIdentifier}}*)(?<!\.|-)(:))?
15+ jsxTagName : \s*{{jsxTagNamespace}}((?:[a-z][a-z0-9]*|({{jsxTagOrAtrributeIdentifier}}*))(?<!\.|-))
16+ jsxOpeningTagWithoutAttributes : (<){{jsxTagName}}?\s*(>)
17+ jsxClosingTag : (</){{jsxTagName}}?\s*(>)
18+ jsxTagStart : (<){{jsxTagName}}(?=({{typeArguments}})?\s+(?!\?)|\/?>)
19+ jsxTagStartLookahead : (?={{jsxTagStart}})
20+ jsxLookBehindInExpression : (?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
1321
1422repository :
1523 # Additions:
@@ -34,18 +42,15 @@ repository:
3442
3543 # jsx tags
3644 jsx-tag-without-attributes-in-expression :
37- begin : |-
38- (?x)
39- (?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
40- (?=(<)\s*(?:([_$a-zA-Z][-$\w.]*)(?<!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))?\s*(>))
41- end : (?!\s*(<)\s*(?:([_$a-zA-Z][-$\w.]*)(?<!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))?\s*(>))
45+ begin : ' {{jsxLookBehindInExpression}}(?={{jsxOpeningTagWithoutAttributes}})'
46+ end : (?!{{jsxOpeningTagWithoutAttributes}})
4247 patterns :
4348 - include : ' #jsx-tag-without-attributes'
4449
4550 jsx-tag-without-attributes :
4651 name : meta.tag.without-attributes.tsx
47- begin : (<)\s*(?:([_$a-zA-Z][-$\w.]*)(?<!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))?\s*(>)
48- end : (</)\s*(?:([_$a-zA-Z][-$\w.]*)(?<!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))?\s*(>)
52+ begin : ' {{jsxOpeningTagWithoutAttributes}} '
53+ end : ' {{jsxClosingTag}} '
4954 beginCaptures :
5055 ' 1 ' : {name: punctuation.definition.tag.begin.tsx}
5156 ' 2 ' : {name: entity.name.tag.namespace.tsx}
@@ -68,36 +73,18 @@ repository:
6873 # We need to differentiate between the relational '<' operator and the beginning of a tag using the surrounding context.
6974 begin : |-
7075 (?x)
71- (?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
76+ {{jsxLookBehindInExpression}}
7277 (?!<\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow
73- (?=(<)\s*
74- ([_$a-zA-Z][-$\w.]*(?<!\.|-):)?
75- ([_$a-zA-Z][-$\w.]*(?<!\.|-))
76- (?=\s+(?!\?)|/?>))
77- end : (/>)|(?:(</)\s*(?:([_$a-zA-Z][-$\w.]*)(?<!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))\s*(>))
78- endCaptures :
79- ' 0 ' : { name: meta.tag.tsx }
80- ' 1 ' : { name: punctuation.definition.tag.end.tsx }
81- ' 2 ' : { name: punctuation.definition.tag.begin.tsx }
82- ' 3 ' : { name: entity.name.tag.namespace.tsx }
83- ' 4 ' : { name: punctuation.separator.namespace.tsx }
84- ' 5 ' : { name: entity.name.tag.tsx }
85- ' 6 ' : { name: support.class.component.tsx }
86- ' 7 ' : { name: punctuation.definition.tag.end.tsx }
78+ {{jsxTagStartLookahead}}
79+ end : (?!{{jsxTagStart}})
8780 patterns :
8881 - include : ' #jsx-tag'
8982
90- jsx-child-tag :
91- # Because this would be included from the jsx-children, this doesnt need to inspect surrounding context
92- begin : |-
93- (?x)
94- (?=(<)\s*
95- ([_$a-zA-Z][-$\w.]*(?<!\.|-):)?
96- ([_$a-zA-Z][-$\w.]*(?<!\.|-))
97- (?=\s+(?!\?)|/?>))
98- end : (/>)|(?:(</)\s*(?:([_$a-zA-Z][-$\w.]*)(?<!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))\s*(>))
83+ jsx-tag :
84+ name : meta.tag.tsx
85+ begin : ' {{jsxTagStartLookahead}}'
86+ end : (/>)|(?:{{jsxClosingTag}})
9987 endCaptures :
100- ' 0 ' : { name: meta.tag.tsx }
10188 ' 1 ' : { name: punctuation.definition.tag.end.tsx }
10289 ' 2 ' : { name: punctuation.definition.tag.begin.tsx }
10390 ' 3 ' : { name: entity.name.tag.namespace.tsx }
@@ -106,36 +93,18 @@ repository:
10693 ' 6 ' : { name: support.class.component.tsx }
10794 ' 7 ' : { name: punctuation.definition.tag.end.tsx }
10895 patterns :
109- - include : ' #jsx-tag'
110-
111- jsx-tag :
112- name : meta.tag.tsx
113- begin : |-
114- (?x)
115- (?=(<)\s*
116- (?:([_$a-zA-Z][-$\w.]*)(?<!\.|-)(:))?
117- ([_$a-zA-Z][-$\w.]*(?<!\.|-))
118- (?=\s+(?!\?)|/?>))
119- end : (?=(/>)|(?:(</)\s*(?:([_$a-zA-Z][-$\w.]*)(?<!\.|-)(:))?([_$a-zA-Z][-$\w.]*(?<!\.|-))\s*(>)))
120- patterns :
121- - begin : |-
122- (?x)
123- (<)\s*
124- (?:([_$a-zA-Z][-$\w.]*)(?<!\.|-)(:))?
125- ((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))
126- (?=\s+(?!\?)|/?>)
96+ - begin : ' {{jsxTagStart}}'
12797 beginCaptures :
12898 ' 1 ' : { name: punctuation.definition.tag.begin.tsx }
12999 ' 2 ' : { name: entity.name.tag.namespace.tsx }
130100 ' 3 ' : { name: punctuation.separator.namespace.tsx }
131101 ' 4 ' : { name: entity.name.tag.tsx }
132102 ' 5 ' : { name: support.class.component.tsx }
133103 end : (?=[/]?>)
134- contentName: meta.tag.attributes.tsx
135104 patterns :
136105 - include : ' #comment'
106+ - include : ' #type-arguments'
137107 - include : ' #jsx-tag-attributes'
138- - include: '#jsx-tag-attributes-illegal'
139108 - begin : (>)
140109 beginCaptures :
141110 ' 1 ' : { name: punctuation.definition.tag.end.tsx }
@@ -148,7 +117,8 @@ repository:
148117 jsx-children :
149118 patterns :
150119 - include : ' #jsx-tag-without-attributes'
151- - include : ' #jsx-child-tag'
120+ # Because this would be included from the jsx-children, this doesnt need to inspect surrounding context
121+ - include : ' #jsx-tag'
152122 - include : ' #jsx-evaluated-code'
153123 - include : ' #jsx-entities'
154124
@@ -176,18 +146,22 @@ repository:
176146
177147 # jsx attributes
178148 jsx-tag-attributes :
149+ name : meta.tag.attributes.tsx
150+ begin : \s+
151+ end : (?=[/]?>)
179152 patterns :
180153 - include : ' #jsx-tag-attribute-name'
181154 - include : ' #jsx-tag-attribute-assignment'
182155 - include : ' #jsx-string-double-quoted'
183156 - include : ' #jsx-string-single-quoted'
184157 - include : ' #jsx-evaluated-code'
158+ - include : ' #jsx-tag-attributes-illegal'
185159
186160 jsx-tag-attribute-name :
187161 match : |-
188162 (?x)
189163 \s*
190- (?:([_$a-zA-Z][-$\w.] *)(:))?
164+ (?:({{jsxTagOrAtrributeIdentifier}} *)(:))?
191165 ([_$a-zA-Z][-$\w]*)
192166 (?=\s|=|/?>|/\*|//)
193167 captures :
0 commit comments