@@ -10,6 +10,14 @@ uuid: 805375ec-d614-41f5-8993-5843fe63ea82
10
10
11
11
variables :
12
12
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*
13
21
14
22
repository :
15
23
# Additions:
@@ -34,18 +42,15 @@ repository:
34
42
35
43
# jsx tags
36
44
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}})
42
47
patterns :
43
48
- include : ' #jsx-tag-without-attributes'
44
49
45
50
jsx-tag-without-attributes :
46
51
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}} '
49
54
beginCaptures :
50
55
' 1 ' : {name: punctuation.definition.tag.begin.tsx}
51
56
' 2 ' : {name: entity.name.tag.namespace.tsx}
@@ -68,36 +73,18 @@ repository:
68
73
# We need to differentiate between the relational '<' operator and the beginning of a tag using the surrounding context.
69
74
begin : |-
70
75
(?x)
71
- (?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
76
+ {{jsxLookBehindInExpression}}
72
77
(?!<\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}})
87
80
patterns :
88
81
- include : ' #jsx-tag'
89
82
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}})
99
87
endCaptures :
100
- ' 0 ' : { name: meta.tag.tsx }
101
88
' 1 ' : { name: punctuation.definition.tag.end.tsx }
102
89
' 2 ' : { name: punctuation.definition.tag.begin.tsx }
103
90
' 3 ' : { name: entity.name.tag.namespace.tsx }
@@ -106,36 +93,18 @@ repository:
106
93
' 6 ' : { name: support.class.component.tsx }
107
94
' 7 ' : { name: punctuation.definition.tag.end.tsx }
108
95
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}}'
127
97
beginCaptures :
128
98
' 1 ' : { name: punctuation.definition.tag.begin.tsx }
129
99
' 2 ' : { name: entity.name.tag.namespace.tsx }
130
100
' 3 ' : { name: punctuation.separator.namespace.tsx }
131
101
' 4 ' : { name: entity.name.tag.tsx }
132
102
' 5 ' : { name: support.class.component.tsx }
133
103
end : (?=[/]?>)
134
- contentName: meta.tag.attributes.tsx
135
104
patterns :
136
105
- include : ' #comment'
106
+ - include : ' #type-arguments'
137
107
- include : ' #jsx-tag-attributes'
138
- - include: '#jsx-tag-attributes-illegal'
139
108
- begin : (>)
140
109
beginCaptures :
141
110
' 1 ' : { name: punctuation.definition.tag.end.tsx }
@@ -148,7 +117,8 @@ repository:
148
117
jsx-children :
149
118
patterns :
150
119
- 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'
152
122
- include : ' #jsx-evaluated-code'
153
123
- include : ' #jsx-entities'
154
124
@@ -176,18 +146,22 @@ repository:
176
146
177
147
# jsx attributes
178
148
jsx-tag-attributes :
149
+ name : meta.tag.attributes.tsx
150
+ begin : \s+
151
+ end : (?=[/]?>)
179
152
patterns :
180
153
- include : ' #jsx-tag-attribute-name'
181
154
- include : ' #jsx-tag-attribute-assignment'
182
155
- include : ' #jsx-string-double-quoted'
183
156
- include : ' #jsx-string-single-quoted'
184
157
- include : ' #jsx-evaluated-code'
158
+ - include : ' #jsx-tag-attributes-illegal'
185
159
186
160
jsx-tag-attribute-name :
187
161
match : |-
188
162
(?x)
189
163
\s*
190
- (?:([_$a-zA-Z][-$\w.] *)(:))?
164
+ (?:({{jsxTagOrAtrributeIdentifier}} *)(:))?
191
165
([_$a-zA-Z][-$\w]*)
192
166
(?=\s|=|/?>|/\*|//)
193
167
captures :
0 commit comments