Skip to content

Commit 95bce1d

Browse files
committed
Handle jsx expression after yield
Fixes #636
1 parent d7df3e3 commit 95bce1d

File tree

4 files changed

+153
-3
lines changed

4 files changed

+153
-3
lines changed

TypeScriptReact.YAML-tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ variables:
1717
jsxClosingTag: (</){{jsxTagName}}?\s*(>)
1818
jsxTagStart: (<){{jsxTagName}}(?=((<\s*)|(\s+))(?!\?)|\/?>)
1919
jsxTagStartLookahead: (?={{jsxTagStart}})
20-
jsxLookBehindInExpression: (?<!\+\+|--)(?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindReturn}}|{{lookBehindDefault}}|^)\s*
20+
jsxLookBehindInExpression: (?<!\+\+|--)(?<=[({\[,?=>:*]|&&|\|\||\?|{{lookBehindAwait}}|{{lookBehindReturn}}|{{lookBehindDefault}}|{{lookBehindYield}}|^)\s*
2121

2222
repository:
2323
# Additions:

TypeScriptReact.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7768,7 +7768,7 @@
77687768
<key>jsx-tag-without-attributes-in-expression</key>
77697769
<dict>
77707770
<key>begin</key>
7771-
<string>(?&lt;!\+\+|--)(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^)\s*(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
7771+
<string>(?&lt;!\+\+|--)(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^yield|[^\._$[:alnum:]]yield|^)\s*(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
77727772
<key>end</key>
77737773
<string>(?!(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))?\s*(&gt;))</string>
77747774
<key>patterns</key>
@@ -7867,7 +7867,7 @@
78677867
<dict>
78687868
<key>begin</key>
78697869
<string>(?x)
7870-
(?&lt;!\+\+|--)(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^)\s*
7870+
(?&lt;!\+\+|--)(?&lt;=[({\[,?=&gt;:*]|&amp;&amp;|\|\||\?|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^yield|[^\._$[:alnum:]]yield|^)\s*
78717871
(?!&lt;\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=&gt;])|,)) # look ahead is not type parameter of arrow
78727872
(?=(&lt;)\s*(?:([_$a-zA-Z][-$\w.]*)(?&lt;!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$a-zA-Z][-$\w.]*))(?&lt;!\.|-))(?=((&lt;\s*)|(\s+))(?!\?)|\/?&gt;))</string>
78737873
<key>end</key>

tests/baselines/Issue636.baseline.txt

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
original file
2+
-----------------------------------
3+
// @onlyOwnGrammar - As this has jsx
4+
class Baz { }
5+
6+
class F {
7+
public *foo() {
8+
yield <Baz />;
9+
}
10+
11+
public fuu() {
12+
return <Baz />;
13+
}
14+
}
15+
-----------------------------------
16+
17+
Grammar: TypeScriptReact.tmLanguage
18+
-----------------------------------
19+
>// @onlyOwnGrammar - As this has jsx
20+
^^
21+
source.tsx comment.line.double-slash.tsx punctuation.definition.comment.tsx
22+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
source.tsx comment.line.double-slash.tsx
24+
>class Baz { }
25+
^^^^^
26+
source.tsx meta.class.tsx storage.type.class.tsx
27+
^
28+
source.tsx meta.class.tsx
29+
^^^
30+
source.tsx meta.class.tsx entity.name.type.class.tsx
31+
^
32+
source.tsx meta.class.tsx
33+
^
34+
source.tsx meta.class.tsx punctuation.definition.block.tsx
35+
^
36+
source.tsx meta.class.tsx
37+
^
38+
source.tsx meta.class.tsx punctuation.definition.block.tsx
39+
>
40+
^
41+
source.tsx
42+
>class F {
43+
^^^^^
44+
source.tsx meta.class.tsx storage.type.class.tsx
45+
^
46+
source.tsx meta.class.tsx
47+
^
48+
source.tsx meta.class.tsx entity.name.type.class.tsx
49+
^
50+
source.tsx meta.class.tsx
51+
^
52+
source.tsx meta.class.tsx punctuation.definition.block.tsx
53+
> public *foo() {
54+
^
55+
source.tsx meta.class.tsx
56+
^^^^^^
57+
source.tsx meta.class.tsx meta.method.declaration.tsx storage.modifier.tsx
58+
^
59+
source.tsx meta.class.tsx meta.method.declaration.tsx
60+
^
61+
source.tsx meta.class.tsx meta.method.declaration.tsx keyword.generator.asterisk.tsx
62+
^^^
63+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.definition.method.tsx entity.name.function.tsx
64+
^
65+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.parameters.tsx punctuation.definition.parameters.begin.tsx
66+
^
67+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.parameters.tsx punctuation.definition.parameters.end.tsx
68+
^
69+
source.tsx meta.class.tsx meta.method.declaration.tsx
70+
^
71+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx punctuation.definition.block.tsx
72+
> yield <Baz />;
73+
^^
74+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx
75+
^^^^^
76+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx keyword.control.flow.tsx
77+
^
78+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx
79+
^
80+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx meta.tag.tsx punctuation.definition.tag.begin.tsx
81+
^^^
82+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx meta.tag.tsx entity.name.tag.tsx support.class.component.tsx
83+
^
84+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx meta.tag.tsx meta.tag.attributes.tsx
85+
^^
86+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx meta.tag.tsx punctuation.definition.tag.end.tsx
87+
^
88+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx punctuation.terminator.statement.tsx
89+
> }
90+
^
91+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx
92+
^
93+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx punctuation.definition.block.tsx
94+
>
95+
^^
96+
source.tsx meta.class.tsx
97+
> public fuu() {
98+
^
99+
source.tsx meta.class.tsx
100+
^^^^^^
101+
source.tsx meta.class.tsx meta.method.declaration.tsx storage.modifier.tsx
102+
^
103+
source.tsx meta.class.tsx meta.method.declaration.tsx
104+
^^^
105+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.definition.method.tsx entity.name.function.tsx
106+
^
107+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.parameters.tsx punctuation.definition.parameters.begin.tsx
108+
^
109+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.parameters.tsx punctuation.definition.parameters.end.tsx
110+
^
111+
source.tsx meta.class.tsx meta.method.declaration.tsx
112+
^
113+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx punctuation.definition.block.tsx
114+
> return <Baz />;
115+
^^
116+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx
117+
^^^^^^
118+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx keyword.control.flow.tsx
119+
^
120+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx
121+
^
122+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx meta.tag.tsx punctuation.definition.tag.begin.tsx
123+
^^^
124+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx meta.tag.tsx entity.name.tag.tsx support.class.component.tsx
125+
^
126+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx meta.tag.tsx meta.tag.attributes.tsx
127+
^^
128+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx meta.tag.tsx punctuation.definition.tag.end.tsx
129+
^
130+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx punctuation.terminator.statement.tsx
131+
> }
132+
^
133+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx
134+
^
135+
source.tsx meta.class.tsx meta.method.declaration.tsx meta.block.tsx punctuation.definition.block.tsx
136+
>}
137+
^
138+
source.tsx meta.class.tsx punctuation.definition.block.tsx

tests/cases/Issue636.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @onlyOwnGrammar - As this has jsx
2+
class Baz { }
3+
4+
class F {
5+
public *foo() {
6+
yield <Baz />;
7+
}
8+
9+
public fuu() {
10+
return <Baz />;
11+
}
12+
}

0 commit comments

Comments
 (0)