Skip to content

Commit 137e542

Browse files
committed
Add the context test for jsx tag without attributes when matching in expression
Handles #478
1 parent 3bf5728 commit 137e542

File tree

5 files changed

+317
-5
lines changed

5 files changed

+317
-5
lines changed

TypeScriptReact.YAML-tmLanguage

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ repository:
9292
name: invalid.illegal.attribute.tsx
9393
match: \S+
9494

95+
jsx-tag-without-attributes-in-expression:
96+
begin: |-
97+
(?x)
98+
(?<=[({\[,?=>:*]|&&|\|\||\?|\Wreturn|^return|\Wdefault|^)\s*
99+
(?=(<)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))\s*(>))
100+
end: (?!\s*(<)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))\s*(>))
101+
patterns:
102+
- include: '#jsx-tag-without-attributes'
103+
95104
jsx-tag-without-attributes:
96105
name: meta.tag.without-attributes.tsx
97106
begin: (<)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?<!\.|-))\s*(>)
@@ -115,7 +124,6 @@ repository:
115124
begin: |-
116125
(?x)
117126
(?<=[({\[,?=>:*]|&&|\|\||\?|\Wreturn|^return|\Wdefault|^)\s*
118-
(?!(<)\s*([_$a-zA-Z][-$\w.]*(?<!\.|-))\s*(>)) #look ahead is not start of tag without attributes
119127
(?!<\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow
120128
(?=(<)\s*
121129
([_$a-zA-Z][-$\w.]*(?<!\.|-))
@@ -194,7 +202,7 @@ repository:
194202

195203
jsx:
196204
patterns:
197-
- include: '#jsx-tag-without-attributes'
205+
- include: '#jsx-tag-without-attributes-in-expression'
198206
- include: '#jsx-tag-in-expression'
199207
- include: '#jsx-tag-invalid'
200208

TypeScriptReact.tmLanguage

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6665,6 +6665,22 @@
66656665
<key>match</key>
66666666
<string>\S+</string>
66676667
</dict>
6668+
<key>jsx-tag-without-attributes-in-expression</key>
6669+
<dict>
6670+
<key>begin</key>
6671+
<string>(?x)
6672+
(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|\Wreturn|^return|\Wdefault|^)\s*
6673+
(?=(&lt;)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))\s*(&gt;))</string>
6674+
<key>end</key>
6675+
<string>(?!\s*(&lt;)\s*((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))\s*(&gt;))</string>
6676+
<key>patterns</key>
6677+
<array>
6678+
<dict>
6679+
<key>include</key>
6680+
<string>#jsx-tag-without-attributes</string>
6681+
</dict>
6682+
</array>
6683+
</dict>
66686684
<key>jsx-tag-without-attributes</key>
66696685
<dict>
66706686
<key>name</key>
@@ -6734,7 +6750,6 @@
67346750
<key>begin</key>
67356751
<string>(?x)
67366752
(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|\Wreturn|^return|\Wdefault|^)\s*
6737-
(?!(&lt;)\s*([_$a-zA-Z][-$\w.]*(?&lt;!\.|-))\s*(&gt;)) #look ahead is not start of tag without attributes
67386753
(?!&lt;\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=&gt;])|,)) # look ahead is not type parameter of arrow
67396754
(?=(&lt;)\s*
67406755
([_$a-zA-Z][-$\w.]*(?&lt;!\.|-))
@@ -6951,7 +6966,7 @@
69516966
<array>
69526967
<dict>
69536968
<key>include</key>
6954-
<string>#jsx-tag-without-attributes</string>
6969+
<string>#jsx-tag-without-attributes-in-expression</string>
69556970
</dict>
69566971
<dict>
69576972
<key>include</key>

tests/baselines/Issue478.baseline.txt

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
original file
2+
-----------------------------------
3+
// Before
4+
a = (b: string, c: number) => {
5+
console.log(b, c);
6+
}
7+
8+
d = (e: string) => (
9+
f: G<H>
10+
) => {
11+
console.log(e, f);
12+
};
13+
14+
// After
15+
a = (b: string, c: number) => {
16+
console.log(b, c);
17+
}
18+
-----------------------------------
19+
20+
Grammar: TypeScriptReact.tmLanguage
21+
-----------------------------------
22+
>// Before
23+
^^
24+
source.tsx comment.line.double-slash.tsx punctuation.definition.comment.tsx
25+
^^^^^^^^^
26+
source.tsx comment.line.double-slash.tsx
27+
>a = (b: string, c: number) => {
28+
^
29+
source.tsx entity.name.function.tsx
30+
^
31+
source.tsx
32+
^
33+
source.tsx keyword.operator.assignment.tsx
34+
^
35+
source.tsx meta.arrow.tsx
36+
^
37+
source.tsx meta.arrow.tsx meta.parameters.tsx punctuation.definition.parameters.begin.tsx
38+
^
39+
source.tsx meta.arrow.tsx meta.parameters.tsx variable.parameter.tsx
40+
^
41+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx keyword.operator.type.annotation.tsx
42+
^
43+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx
44+
^^^^^^
45+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx support.type.primitive.tsx
46+
^
47+
source.tsx meta.arrow.tsx meta.parameters.tsx punctuation.separator.parameter.tsx
48+
^
49+
source.tsx meta.arrow.tsx meta.parameters.tsx
50+
^
51+
source.tsx meta.arrow.tsx meta.parameters.tsx variable.parameter.tsx
52+
^
53+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx keyword.operator.type.annotation.tsx
54+
^
55+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx
56+
^^^^^^
57+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx support.type.primitive.tsx
58+
^
59+
source.tsx meta.arrow.tsx meta.parameters.tsx punctuation.definition.parameters.end.tsx
60+
^
61+
source.tsx meta.arrow.tsx
62+
^^
63+
source.tsx meta.arrow.tsx storage.type.function.arrow.tsx
64+
^
65+
source.tsx meta.arrow.tsx
66+
^
67+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.definition.block.tsx
68+
^^
69+
source.tsx meta.arrow.tsx meta.block.tsx
70+
> console.log(b, c);
71+
^^
72+
source.tsx meta.arrow.tsx meta.block.tsx
73+
^^^^^^^
74+
source.tsx meta.arrow.tsx meta.block.tsx meta.function-call.tsx support.class.console.tsx
75+
^
76+
source.tsx meta.arrow.tsx meta.block.tsx meta.function-call.tsx punctuation.accessor.tsx
77+
^^^
78+
source.tsx meta.arrow.tsx meta.block.tsx meta.function-call.tsx support.function.console.tsx
79+
^
80+
source.tsx meta.arrow.tsx meta.block.tsx meta.brace.round.tsx
81+
^
82+
source.tsx meta.arrow.tsx meta.block.tsx variable.other.readwrite.tsx
83+
^
84+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.separator.comma.tsx
85+
^
86+
source.tsx meta.arrow.tsx meta.block.tsx
87+
^
88+
source.tsx meta.arrow.tsx meta.block.tsx variable.other.readwrite.tsx
89+
^
90+
source.tsx meta.arrow.tsx meta.block.tsx meta.brace.round.tsx
91+
^
92+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.terminator.statement.tsx
93+
^^
94+
source.tsx meta.arrow.tsx meta.block.tsx
95+
>}
96+
^
97+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.definition.block.tsx
98+
^^
99+
source.tsx
100+
>
101+
^^
102+
source.tsx
103+
>d = (e: string) => (
104+
^
105+
source.tsx entity.name.function.tsx
106+
^
107+
source.tsx
108+
^
109+
source.tsx keyword.operator.assignment.tsx
110+
^
111+
source.tsx meta.arrow.tsx
112+
^
113+
source.tsx meta.arrow.tsx meta.parameters.tsx punctuation.definition.parameters.begin.tsx
114+
^
115+
source.tsx meta.arrow.tsx meta.parameters.tsx variable.parameter.tsx
116+
^
117+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx keyword.operator.type.annotation.tsx
118+
^
119+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx
120+
^^^^^^
121+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx support.type.primitive.tsx
122+
^
123+
source.tsx meta.arrow.tsx meta.parameters.tsx punctuation.definition.parameters.end.tsx
124+
^
125+
source.tsx meta.arrow.tsx
126+
^^
127+
source.tsx meta.arrow.tsx storage.type.function.arrow.tsx
128+
^
129+
source.tsx meta.arrow.tsx
130+
^
131+
source.tsx meta.brace.round.tsx
132+
^^
133+
source.tsx
134+
> f: G<H>
135+
^^
136+
source.tsx
137+
^
138+
source.tsx variable.other.readwrite.tsx
139+
^^
140+
source.tsx
141+
^
142+
source.tsx variable.other.constant.tsx
143+
^
144+
source.tsx keyword.operator.relational.tsx
145+
^
146+
source.tsx variable.other.constant.tsx
147+
^
148+
source.tsx keyword.operator.relational.tsx
149+
^^
150+
source.tsx
151+
>) => {
152+
^
153+
source.tsx meta.brace.round.tsx
154+
^
155+
source.tsx
156+
^^
157+
source.tsx meta.arrow.tsx storage.type.function.arrow.tsx
158+
^
159+
source.tsx meta.arrow.tsx
160+
^
161+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.definition.block.tsx
162+
^^
163+
source.tsx meta.arrow.tsx meta.block.tsx
164+
> console.log(e, f);
165+
^^
166+
source.tsx meta.arrow.tsx meta.block.tsx
167+
^^^^^^^
168+
source.tsx meta.arrow.tsx meta.block.tsx meta.function-call.tsx support.class.console.tsx
169+
^
170+
source.tsx meta.arrow.tsx meta.block.tsx meta.function-call.tsx punctuation.accessor.tsx
171+
^^^
172+
source.tsx meta.arrow.tsx meta.block.tsx meta.function-call.tsx support.function.console.tsx
173+
^
174+
source.tsx meta.arrow.tsx meta.block.tsx meta.brace.round.tsx
175+
^
176+
source.tsx meta.arrow.tsx meta.block.tsx variable.other.readwrite.tsx
177+
^
178+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.separator.comma.tsx
179+
^
180+
source.tsx meta.arrow.tsx meta.block.tsx
181+
^
182+
source.tsx meta.arrow.tsx meta.block.tsx variable.other.readwrite.tsx
183+
^
184+
source.tsx meta.arrow.tsx meta.block.tsx meta.brace.round.tsx
185+
^
186+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.terminator.statement.tsx
187+
^^
188+
source.tsx meta.arrow.tsx meta.block.tsx
189+
>};
190+
^
191+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.definition.block.tsx
192+
^
193+
source.tsx punctuation.terminator.statement.tsx
194+
^^
195+
source.tsx
196+
>
197+
^^
198+
source.tsx
199+
>// After
200+
^^
201+
source.tsx comment.line.double-slash.tsx punctuation.definition.comment.tsx
202+
^^^^^^^^
203+
source.tsx comment.line.double-slash.tsx
204+
>a = (b: string, c: number) => {
205+
^
206+
source.tsx entity.name.function.tsx
207+
^
208+
source.tsx
209+
^
210+
source.tsx keyword.operator.assignment.tsx
211+
^
212+
source.tsx meta.arrow.tsx
213+
^
214+
source.tsx meta.arrow.tsx meta.parameters.tsx punctuation.definition.parameters.begin.tsx
215+
^
216+
source.tsx meta.arrow.tsx meta.parameters.tsx variable.parameter.tsx
217+
^
218+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx keyword.operator.type.annotation.tsx
219+
^
220+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx
221+
^^^^^^
222+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx support.type.primitive.tsx
223+
^
224+
source.tsx meta.arrow.tsx meta.parameters.tsx punctuation.separator.parameter.tsx
225+
^
226+
source.tsx meta.arrow.tsx meta.parameters.tsx
227+
^
228+
source.tsx meta.arrow.tsx meta.parameters.tsx variable.parameter.tsx
229+
^
230+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx keyword.operator.type.annotation.tsx
231+
^
232+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx
233+
^^^^^^
234+
source.tsx meta.arrow.tsx meta.parameters.tsx meta.type.annotation.tsx support.type.primitive.tsx
235+
^
236+
source.tsx meta.arrow.tsx meta.parameters.tsx punctuation.definition.parameters.end.tsx
237+
^
238+
source.tsx meta.arrow.tsx
239+
^^
240+
source.tsx meta.arrow.tsx storage.type.function.arrow.tsx
241+
^
242+
source.tsx meta.arrow.tsx
243+
^
244+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.definition.block.tsx
245+
^^
246+
source.tsx meta.arrow.tsx meta.block.tsx
247+
> console.log(b, c);
248+
^^
249+
source.tsx meta.arrow.tsx meta.block.tsx
250+
^^^^^^^
251+
source.tsx meta.arrow.tsx meta.block.tsx meta.function-call.tsx support.class.console.tsx
252+
^
253+
source.tsx meta.arrow.tsx meta.block.tsx meta.function-call.tsx punctuation.accessor.tsx
254+
^^^
255+
source.tsx meta.arrow.tsx meta.block.tsx meta.function-call.tsx support.function.console.tsx
256+
^
257+
source.tsx meta.arrow.tsx meta.block.tsx meta.brace.round.tsx
258+
^
259+
source.tsx meta.arrow.tsx meta.block.tsx variable.other.readwrite.tsx
260+
^
261+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.separator.comma.tsx
262+
^
263+
source.tsx meta.arrow.tsx meta.block.tsx
264+
^
265+
source.tsx meta.arrow.tsx meta.block.tsx variable.other.readwrite.tsx
266+
^
267+
source.tsx meta.arrow.tsx meta.block.tsx meta.brace.round.tsx
268+
^
269+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.terminator.statement.tsx
270+
^^
271+
source.tsx meta.arrow.tsx meta.block.tsx
272+
>}
273+
^
274+
source.tsx meta.arrow.tsx meta.block.tsx punctuation.definition.block.tsx

tests/cases/Issue478.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Before
2+
a = (b: string, c: number) => {
3+
console.log(b, c);
4+
}
5+
6+
d = (e: string) => (
7+
f: G<H>
8+
) => {
9+
console.log(e, f);
10+
};
11+
12+
// After
13+
a = (b: string, c: number) => {
14+
console.log(b, c);
15+
}

tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "test.ts",
77
"scripts": {
88
"pretest": "node ../build/build.js && tsc",
9-
"test": "mocha test.js"
9+
"test": "mocha --full-trace test.js"
1010
},
1111
"dependencies": {
1212
"@types/chai": "latest",

0 commit comments

Comments
 (0)