Skip to content

Commit e8c613f

Browse files
committed
Distinguish between jsx-tag start from expression vs from jsx children,
since inspection of context is not needed to distinguish relational operation when already in jsx context Fixes #283
1 parent 67954e4 commit e8c613f

File tree

4 files changed

+931
-63
lines changed

4 files changed

+931
-63
lines changed

TypeScriptReact.YAML-tmLanguage

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ repository:
119119
patterns:
120120
- include: '#jsx-children'
121121

122-
jsx-tag:
122+
jsx-tag-in-expression:
123123
# We need to differentiate between the relational '<' operator and the beginning of a tag using the surrounding context.
124124
begin: >-
125125
(?x)
@@ -137,30 +137,54 @@ repository:
137137
'3': { name: entity.name.tag.tsx }
138138
'4': { name: punctuation.definition.tag.end.tsx }
139139
patterns:
140-
- name: meta.tag.tsx
141-
begin: >-
140+
- include: '#jsx-tag'
141+
142+
jsx-child-tag:
143+
# Because this would be included from the jsx-children, this doesnt need to inspect surrounding context
144+
begin: >-
145+
(?x)
146+
(?=(<)\s*
147+
([_$a-zA-Z][-$\w.]*(?<!\.|-))
148+
(?=\s+(?!\?)|/?>))
149+
end: (/>)|(?:(</)\s*([_$a-zA-Z][-$\w.]*(?<!\.|-))\s*(>))
150+
endCaptures:
151+
'0': { name: meta.tag.tsx }
152+
'1': { name: punctuation.definition.tag.end.tsx }
153+
'2': { name: punctuation.definition.tag.begin.tsx }
154+
'3': { name: entity.name.tag.tsx }
155+
'4': { name: punctuation.definition.tag.end.tsx }
156+
patterns:
157+
- include: '#jsx-tag'
158+
159+
jsx-tag:
160+
name: meta.tag.tsx
161+
begin: >-
162+
(?x)
163+
(?=(<)\s*
164+
([_$a-zA-Z][-$\w.]*(?<!\.|-))
165+
(?=\s+(?!\?)|/?>))
166+
end: (?=(/>)|(?:(</)\s*([_$a-zA-Z][-$\w.]*(?<!\.|-))\s*(>)))
167+
patterns:
168+
- begin: >-
142169
(?x)
143170
(<)\s*
144171
([_$a-zA-Z][-$\w.]*(?<!\.|-))
145172
(?=\s+(?!\?)|/?>)
146173
beginCaptures:
147174
'1': { name: punctuation.definition.tag.begin.tsx }
148175
'2': { name: entity.name.tag.tsx }
149-
end: (?=(/>)|(?:(</)\s*([_$a-zA-Z][-$\w.]*(?<!\.|-))\s*(>)))
176+
end: (?=[/]?>)
150177
patterns:
151-
- begin: \G(?![/]?>)
152-
end: (?=[/]?>)
153-
patterns:
154-
- include: '#comment'
155-
- include: '#jsx-tag-attributes'
156-
- include: '#jsx-tag-attributes-illegal'
157-
- begin: (>)
158-
beginCaptures:
159-
'1': { name: punctuation.definition.tag.end.tsx }
160-
end: (?=</)
161-
contentName: meta.jsx.children.tsx
162-
patterns:
163-
- include: '#jsx-children'
178+
- include: '#comment'
179+
- include: '#jsx-tag-attributes'
180+
- include: '#jsx-tag-attributes-illegal'
181+
- begin: (>)
182+
beginCaptures:
183+
'1': { name: punctuation.definition.tag.end.tsx }
184+
end: (?=</)
185+
contentName: meta.jsx.children.tsx
186+
patterns:
187+
- include: '#jsx-children'
164188

165189
jsx-tag-invalid:
166190
name: invalid.illegal.tag.incomplete.tsx
@@ -169,7 +193,7 @@ repository:
169193
jsx-children:
170194
patterns:
171195
- include: '#jsx-tag-without-attributes'
172-
- include: '#jsx-tag'
196+
- include: '#jsx-child-tag'
173197
- include: '#jsx-tag-invalid'
174198
- include: '#jsx-evaluated-code'
175199
- include: '#jsx-entities'
@@ -178,7 +202,7 @@ repository:
178202
name: meta.jsx.tsx
179203
patterns:
180204
- include: '#jsx-tag-without-attributes'
181-
- include: '#jsx-tag'
205+
- include: '#jsx-tag-in-expression'
182206
- include: '#jsx-tag-invalid'
183207

184208
...

TypeScriptReact.tmLanguage

Lines changed: 97 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,7 +5262,7 @@
52625262
</dict>
52635263
</array>
52645264
</dict>
5265-
<key>jsx-tag</key>
5265+
<key>jsx-tag-in-expression</key>
52665266
<dict>
52675267
<key>begin</key>
52685268
<string>(?x)
@@ -5304,9 +5304,71 @@
53045304
</dict>
53055305
<key>patterns</key>
53065306
<array>
5307+
<dict>
5308+
<key>include</key>
5309+
<string>#jsx-tag</string>
5310+
</dict>
5311+
</array>
5312+
</dict>
5313+
<key>jsx-child-tag</key>
5314+
<dict>
5315+
<key>begin</key>
5316+
<string>(?x)
5317+
(?=(&lt;)\s*
5318+
([_$a-zA-Z][-$\w.]*(?&lt;!\.|-))
5319+
(?=\s+(?!\?)|/?&gt;))</string>
5320+
<key>end</key>
5321+
<string>(/&gt;)|(?:(&lt;/)\s*([_$a-zA-Z][-$\w.]*(?&lt;!\.|-))\s*(&gt;))</string>
5322+
<key>endCaptures</key>
5323+
<dict>
5324+
<key>0</key>
53075325
<dict>
53085326
<key>name</key>
53095327
<string>meta.tag.tsx</string>
5328+
</dict>
5329+
<key>1</key>
5330+
<dict>
5331+
<key>name</key>
5332+
<string>punctuation.definition.tag.end.tsx</string>
5333+
</dict>
5334+
<key>2</key>
5335+
<dict>
5336+
<key>name</key>
5337+
<string>punctuation.definition.tag.begin.tsx</string>
5338+
</dict>
5339+
<key>3</key>
5340+
<dict>
5341+
<key>name</key>
5342+
<string>entity.name.tag.tsx</string>
5343+
</dict>
5344+
<key>4</key>
5345+
<dict>
5346+
<key>name</key>
5347+
<string>punctuation.definition.tag.end.tsx</string>
5348+
</dict>
5349+
</dict>
5350+
<key>patterns</key>
5351+
<array>
5352+
<dict>
5353+
<key>include</key>
5354+
<string>#jsx-tag</string>
5355+
</dict>
5356+
</array>
5357+
</dict>
5358+
<key>jsx-tag</key>
5359+
<dict>
5360+
<key>name</key>
5361+
<string>meta.tag.tsx</string>
5362+
<key>begin</key>
5363+
<string>(?x)
5364+
(?=(&lt;)\s*
5365+
([_$a-zA-Z][-$\w.]*(?&lt;!\.|-))
5366+
(?=\s+(?!\?)|/?&gt;))</string>
5367+
<key>end</key>
5368+
<string>(?=(/&gt;)|(?:(&lt;/)\s*([_$a-zA-Z][-$\w.]*(?&lt;!\.|-))\s*(&gt;)))</string>
5369+
<key>patterns</key>
5370+
<array>
5371+
<dict>
53105372
<key>begin</key>
53115373
<string>(?x)
53125374
(&lt;)\s*
@@ -5326,52 +5388,43 @@
53265388
</dict>
53275389
</dict>
53285390
<key>end</key>
5329-
<string>(?=(/&gt;)|(?:(&lt;/)\s*([_$a-zA-Z][-$\w.]*(?&lt;!\.|-))\s*(&gt;)))</string>
5391+
<string>(?=[/]?&gt;)</string>
53305392
<key>patterns</key>
53315393
<array>
53325394
<dict>
5333-
<key>begin</key>
5334-
<string>\G(?![/]?&gt;)</string>
5335-
<key>end</key>
5336-
<string>(?=[/]?&gt;)</string>
5337-
<key>patterns</key>
5338-
<array>
5339-
<dict>
5340-
<key>include</key>
5341-
<string>#comment</string>
5342-
</dict>
5343-
<dict>
5344-
<key>include</key>
5345-
<string>#jsx-tag-attributes</string>
5346-
</dict>
5347-
<dict>
5348-
<key>include</key>
5349-
<string>#jsx-tag-attributes-illegal</string>
5350-
</dict>
5351-
</array>
5395+
<key>include</key>
5396+
<string>#comment</string>
53525397
</dict>
53535398
<dict>
5354-
<key>begin</key>
5355-
<string>(&gt;)</string>
5356-
<key>beginCaptures</key>
5357-
<dict>
5358-
<key>1</key>
5359-
<dict>
5360-
<key>name</key>
5361-
<string>punctuation.definition.tag.end.tsx</string>
5362-
</dict>
5363-
</dict>
5364-
<key>end</key>
5365-
<string>(?=&lt;/)</string>
5366-
<key>contentName</key>
5367-
<string>meta.jsx.children.tsx</string>
5368-
<key>patterns</key>
5369-
<array>
5370-
<dict>
5371-
<key>include</key>
5372-
<string>#jsx-children</string>
5373-
</dict>
5374-
</array>
5399+
<key>include</key>
5400+
<string>#jsx-tag-attributes</string>
5401+
</dict>
5402+
<dict>
5403+
<key>include</key>
5404+
<string>#jsx-tag-attributes-illegal</string>
5405+
</dict>
5406+
</array>
5407+
</dict>
5408+
<dict>
5409+
<key>begin</key>
5410+
<string>(&gt;)</string>
5411+
<key>beginCaptures</key>
5412+
<dict>
5413+
<key>1</key>
5414+
<dict>
5415+
<key>name</key>
5416+
<string>punctuation.definition.tag.end.tsx</string>
5417+
</dict>
5418+
</dict>
5419+
<key>end</key>
5420+
<string>(?=&lt;/)</string>
5421+
<key>contentName</key>
5422+
<string>meta.jsx.children.tsx</string>
5423+
<key>patterns</key>
5424+
<array>
5425+
<dict>
5426+
<key>include</key>
5427+
<string>#jsx-children</string>
53755428
</dict>
53765429
</array>
53775430
</dict>
@@ -5394,7 +5447,7 @@
53945447
</dict>
53955448
<dict>
53965449
<key>include</key>
5397-
<string>#jsx-tag</string>
5450+
<string>#jsx-child-tag</string>
53985451
</dict>
53995452
<dict>
54005453
<key>include</key>
@@ -5422,7 +5475,7 @@
54225475
</dict>
54235476
<dict>
54245477
<key>include</key>
5425-
<string>#jsx-tag</string>
5478+
<string>#jsx-tag-in-expression</string>
54265479
</dict>
54275480
<dict>
54285481
<key>include</key>

0 commit comments

Comments
 (0)