Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 2ad791b

Browse files
soda0289JamesHenry
authored andcommitted
Fix: Add name to JSXIdentifier when converting ThisKeyword (fixes #307) (#310)
1 parent 519907e commit 2ad791b

5 files changed

+729
-2
lines changed

lib/convert.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@ module.exports = function convert(config) {
290290
// Assign the appropriate types
291291
tagNameToken.object.type = (isNestedMemberExpression) ? AST_NODE_TYPES.JSXMemberExpression : AST_NODE_TYPES.JSXIdentifier;
292292
tagNameToken.property.type = AST_NODE_TYPES.JSXIdentifier;
293-
294293
} else {
295-
296294
tagNameToken.name = tagNameToken.value;
297295
}
298296

@@ -1447,6 +1445,9 @@ module.exports = function convert(config) {
14471445
property: convertChild(node.name)
14481446
};
14491447
const isNestedMemberExpression = (node.expression.kind === SyntaxKind.PropertyAccessExpression);
1448+
if (node.expression.kind === SyntaxKind.ThisKeyword) {
1449+
jsxMemberExpression.object.name = "this";
1450+
}
14501451

14511452
jsxMemberExpression.object.type = (isNestedMemberExpression) ? AST_NODE_TYPES.MemberExpression : AST_NODE_TYPES.JSXIdentifier;
14521453
jsxMemberExpression.property.type = AST_NODE_TYPES.JSXIdentifier;
Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
25
6+
],
7+
"loc": {
8+
"start": {
9+
"line": 1,
10+
"column": 0
11+
},
12+
"end": {
13+
"line": 1,
14+
"column": 25
15+
}
16+
},
17+
"body": [
18+
{
19+
"type": "ExpressionStatement",
20+
"range": [
21+
0,
22+
25
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 1,
27+
"column": 0
28+
},
29+
"end": {
30+
"line": 1,
31+
"column": 25
32+
}
33+
},
34+
"expression": {
35+
"type": "JSXElement",
36+
"range": [
37+
0,
38+
24
39+
],
40+
"loc": {
41+
"start": {
42+
"line": 1,
43+
"column": 0
44+
},
45+
"end": {
46+
"line": 1,
47+
"column": 24
48+
}
49+
},
50+
"openingElement": {
51+
"type": "JSXOpeningElement",
52+
"range": [
53+
0,
54+
24
55+
],
56+
"loc": {
57+
"start": {
58+
"line": 1,
59+
"column": 0
60+
},
61+
"end": {
62+
"line": 1,
63+
"column": 24
64+
}
65+
},
66+
"selfClosing": true,
67+
"name": {
68+
"type": "JSXMemberExpression",
69+
"range": [
70+
1,
71+
21
72+
],
73+
"loc": {
74+
"start": {
75+
"line": 1,
76+
"column": 1
77+
},
78+
"end": {
79+
"line": 1,
80+
"column": 21
81+
}
82+
},
83+
"object": {
84+
"type": "JSXMemberExpression",
85+
"range": [
86+
1,
87+
11
88+
],
89+
"loc": {
90+
"start": {
91+
"line": 1,
92+
"column": 1
93+
},
94+
"end": {
95+
"line": 1,
96+
"column": 11
97+
}
98+
},
99+
"object": {
100+
"type": "JSXIdentifier",
101+
"range": [
102+
1,
103+
5
104+
],
105+
"loc": {
106+
"start": {
107+
"line": 1,
108+
"column": 1
109+
},
110+
"end": {
111+
"line": 1,
112+
"column": 5
113+
}
114+
},
115+
"name": "this"
116+
},
117+
"property": {
118+
"type": "JSXIdentifier",
119+
"range": [
120+
6,
121+
11
122+
],
123+
"loc": {
124+
"start": {
125+
"line": 1,
126+
"column": 6
127+
},
128+
"end": {
129+
"line": 1,
130+
"column": 11
131+
}
132+
},
133+
"name": "state"
134+
}
135+
},
136+
"property": {
137+
"type": "JSXIdentifier",
138+
"range": [
139+
12,
140+
21
141+
],
142+
"loc": {
143+
"start": {
144+
"line": 1,
145+
"column": 12
146+
},
147+
"end": {
148+
"line": 1,
149+
"column": 21
150+
}
151+
},
152+
"name": "Component"
153+
}
154+
},
155+
"attributes": []
156+
},
157+
"closingElement": null,
158+
"children": []
159+
}
160+
}
161+
],
162+
"sourceType": "script",
163+
"tokens": [
164+
{
165+
"type": "Punctuator",
166+
"value": "<",
167+
"range": [
168+
0,
169+
1
170+
],
171+
"loc": {
172+
"start": {
173+
"line": 1,
174+
"column": 0
175+
},
176+
"end": {
177+
"line": 1,
178+
"column": 1
179+
}
180+
}
181+
},
182+
{
183+
"type": "Keyword",
184+
"value": "this",
185+
"range": [
186+
1,
187+
5
188+
],
189+
"loc": {
190+
"start": {
191+
"line": 1,
192+
"column": 1
193+
},
194+
"end": {
195+
"line": 1,
196+
"column": 5
197+
}
198+
}
199+
},
200+
{
201+
"type": "Punctuator",
202+
"value": ".",
203+
"range": [
204+
5,
205+
6
206+
],
207+
"loc": {
208+
"start": {
209+
"line": 1,
210+
"column": 5
211+
},
212+
"end": {
213+
"line": 1,
214+
"column": 6
215+
}
216+
}
217+
},
218+
{
219+
"type": "JSXIdentifier",
220+
"value": "state",
221+
"range": [
222+
6,
223+
11
224+
],
225+
"loc": {
226+
"start": {
227+
"line": 1,
228+
"column": 6
229+
},
230+
"end": {
231+
"line": 1,
232+
"column": 11
233+
}
234+
}
235+
},
236+
{
237+
"type": "Punctuator",
238+
"value": ".",
239+
"range": [
240+
11,
241+
12
242+
],
243+
"loc": {
244+
"start": {
245+
"line": 1,
246+
"column": 11
247+
},
248+
"end": {
249+
"line": 1,
250+
"column": 12
251+
}
252+
}
253+
},
254+
{
255+
"type": "JSXIdentifier",
256+
"value": "Component",
257+
"range": [
258+
12,
259+
21
260+
],
261+
"loc": {
262+
"start": {
263+
"line": 1,
264+
"column": 12
265+
},
266+
"end": {
267+
"line": 1,
268+
"column": 21
269+
}
270+
}
271+
},
272+
{
273+
"type": "Punctuator",
274+
"value": "/",
275+
"range": [
276+
22,
277+
23
278+
],
279+
"loc": {
280+
"start": {
281+
"line": 1,
282+
"column": 22
283+
},
284+
"end": {
285+
"line": 1,
286+
"column": 23
287+
}
288+
}
289+
},
290+
{
291+
"type": "Punctuator",
292+
"value": ">",
293+
"range": [
294+
23,
295+
24
296+
],
297+
"loc": {
298+
"start": {
299+
"line": 1,
300+
"column": 23
301+
},
302+
"end": {
303+
"line": 1,
304+
"column": 24
305+
}
306+
}
307+
},
308+
{
309+
"type": "Punctuator",
310+
"value": ";",
311+
"range": [
312+
24,
313+
25
314+
],
315+
"loc": {
316+
"start": {
317+
"line": 1,
318+
"column": 24
319+
},
320+
"end": {
321+
"line": 1,
322+
"column": 25
323+
}
324+
}
325+
}
326+
]
327+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<this.state.Component />;

0 commit comments

Comments
 (0)