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

Commit a9ca775

Browse files
authored
Fix: Use name 'this' in JSXMemberExpression (fixes #337) (#338)
1 parent ef2687b commit a9ca775

File tree

3 files changed

+241
-3
lines changed

3 files changed

+241
-3
lines changed

lib/convert.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ module.exports = function convert(config) {
297297
// Assign the appropriate types
298298
tagNameToken.object.type = (isNestedMemberExpression) ? AST_NODE_TYPES.JSXMemberExpression : AST_NODE_TYPES.JSXIdentifier;
299299
tagNameToken.property.type = AST_NODE_TYPES.JSXIdentifier;
300+
if (tagName.expression.kind === SyntaxKind.ThisKeyword) {
301+
tagNameToken.object.name = "this";
302+
}
300303
} else {
301304
tagNameToken.type = AST_NODE_TYPES.JSXIdentifier;
302305
tagNameToken.name = tagNameToken.value;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
<this.state.Component />;
2+
<this.Component />;

tests/lib/__snapshots__/jsx.js.snap

Lines changed: 237 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5504,11 +5504,119 @@ Object {
55045504
],
55055505
"type": "ExpressionStatement",
55065506
},
5507+
Object {
5508+
"expression": Object {
5509+
"children": Array [],
5510+
"closingElement": null,
5511+
"loc": Object {
5512+
"end": Object {
5513+
"column": 18,
5514+
"line": 2,
5515+
},
5516+
"start": Object {
5517+
"column": 0,
5518+
"line": 2,
5519+
},
5520+
},
5521+
"openingElement": Object {
5522+
"attributes": Array [],
5523+
"loc": Object {
5524+
"end": Object {
5525+
"column": 18,
5526+
"line": 2,
5527+
},
5528+
"start": Object {
5529+
"column": 0,
5530+
"line": 2,
5531+
},
5532+
},
5533+
"name": Object {
5534+
"loc": Object {
5535+
"end": Object {
5536+
"column": 15,
5537+
"line": 2,
5538+
},
5539+
"start": Object {
5540+
"column": 1,
5541+
"line": 2,
5542+
},
5543+
},
5544+
"object": Object {
5545+
"loc": Object {
5546+
"end": Object {
5547+
"column": 5,
5548+
"line": 2,
5549+
},
5550+
"start": Object {
5551+
"column": 1,
5552+
"line": 2,
5553+
},
5554+
},
5555+
"name": "this",
5556+
"range": Array [
5557+
27,
5558+
31,
5559+
],
5560+
"type": "JSXIdentifier",
5561+
},
5562+
"property": Object {
5563+
"loc": Object {
5564+
"end": Object {
5565+
"column": 15,
5566+
"line": 2,
5567+
},
5568+
"start": Object {
5569+
"column": 6,
5570+
"line": 2,
5571+
},
5572+
},
5573+
"name": "Component",
5574+
"range": Array [
5575+
32,
5576+
41,
5577+
],
5578+
"type": "JSXIdentifier",
5579+
},
5580+
"range": Array [
5581+
27,
5582+
41,
5583+
],
5584+
"type": "JSXMemberExpression",
5585+
},
5586+
"range": Array [
5587+
26,
5588+
44,
5589+
],
5590+
"selfClosing": true,
5591+
"type": "JSXOpeningElement",
5592+
},
5593+
"range": Array [
5594+
26,
5595+
44,
5596+
],
5597+
"type": "JSXElement",
5598+
},
5599+
"loc": Object {
5600+
"end": Object {
5601+
"column": 19,
5602+
"line": 2,
5603+
},
5604+
"start": Object {
5605+
"column": 0,
5606+
"line": 2,
5607+
},
5608+
},
5609+
"range": Array [
5610+
26,
5611+
45,
5612+
],
5613+
"type": "ExpressionStatement",
5614+
},
55075615
],
55085616
"loc": Object {
55095617
"end": Object {
5510-
"column": 25,
5511-
"line": 1,
5618+
"column": 19,
5619+
"line": 2,
55125620
},
55135621
"start": Object {
55145622
"column": 0,
@@ -5517,7 +5625,7 @@ Object {
55175625
},
55185626
"range": Array [
55195627
0,
5520-
25,
5628+
45,
55215629
],
55225630
"sourceType": "script",
55235631
"tokens": Array [
@@ -5683,6 +5791,132 @@ Object {
56835791
"type": "Punctuator",
56845792
"value": ";",
56855793
},
5794+
Object {
5795+
"loc": Object {
5796+
"end": Object {
5797+
"column": 1,
5798+
"line": 2,
5799+
},
5800+
"start": Object {
5801+
"column": 0,
5802+
"line": 2,
5803+
},
5804+
},
5805+
"range": Array [
5806+
26,
5807+
27,
5808+
],
5809+
"type": "Punctuator",
5810+
"value": "<",
5811+
},
5812+
Object {
5813+
"loc": Object {
5814+
"end": Object {
5815+
"column": 5,
5816+
"line": 2,
5817+
},
5818+
"start": Object {
5819+
"column": 1,
5820+
"line": 2,
5821+
},
5822+
},
5823+
"range": Array [
5824+
27,
5825+
31,
5826+
],
5827+
"type": "Keyword",
5828+
"value": "this",
5829+
},
5830+
Object {
5831+
"loc": Object {
5832+
"end": Object {
5833+
"column": 6,
5834+
"line": 2,
5835+
},
5836+
"start": Object {
5837+
"column": 5,
5838+
"line": 2,
5839+
},
5840+
},
5841+
"range": Array [
5842+
31,
5843+
32,
5844+
],
5845+
"type": "Punctuator",
5846+
"value": ".",
5847+
},
5848+
Object {
5849+
"loc": Object {
5850+
"end": Object {
5851+
"column": 15,
5852+
"line": 2,
5853+
},
5854+
"start": Object {
5855+
"column": 6,
5856+
"line": 2,
5857+
},
5858+
},
5859+
"range": Array [
5860+
32,
5861+
41,
5862+
],
5863+
"type": "JSXIdentifier",
5864+
"value": "Component",
5865+
},
5866+
Object {
5867+
"loc": Object {
5868+
"end": Object {
5869+
"column": 17,
5870+
"line": 2,
5871+
},
5872+
"start": Object {
5873+
"column": 16,
5874+
"line": 2,
5875+
},
5876+
},
5877+
"range": Array [
5878+
42,
5879+
43,
5880+
],
5881+
"type": "Punctuator",
5882+
"value": "/",
5883+
},
5884+
Object {
5885+
"loc": Object {
5886+
"end": Object {
5887+
"column": 18,
5888+
"line": 2,
5889+
},
5890+
"start": Object {
5891+
"column": 17,
5892+
"line": 2,
5893+
},
5894+
},
5895+
"range": Array [
5896+
43,
5897+
44,
5898+
],
5899+
"type": "Punctuator",
5900+
"value": ">",
5901+
},
5902+
Object {
5903+
"loc": Object {
5904+
"end": Object {
5905+
"column": 19,
5906+
"line": 2,
5907+
},
5908+
"start": Object {
5909+
"column": 18,
5910+
"line": 2,
5911+
},
5912+
},
5913+
"range": Array [
5914+
44,
5915+
45,
5916+
],
5917+
"type": "Punctuator",
5918+
"value": ";",
5919+
},
56865920
],
56875921
"type": "Program",
56885922
}

0 commit comments

Comments
 (0)