Skip to content

Commit 00dd70e

Browse files
soda0289RReverser
authored andcommitted
Change Literal to JSXText
Fixes #73
1 parent 9a20597 commit 00dd70e

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

inject.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,15 @@ module.exports = function(acorn) {
351351
return this.finishNode(node, 'JSXElement');
352352
};
353353

354+
// Parse JSX text
355+
356+
pp.jsx_parseText = function(value) {
357+
var node = this.parseLiteral(value);
358+
node.type = "JSXText";
359+
360+
return node;
361+
};
362+
354363
// Parses entire JSX element from current position.
355364

356365
pp.jsx_parseElement = function() {
@@ -376,7 +385,7 @@ module.exports = function(acorn) {
376385
instance.extend('parseExprAtom', function(inner) {
377386
return function(refShortHandDefaultPos) {
378387
if (this.type === tt.jsxText)
379-
return this.parseLiteral(this.value);
388+
return this.jsx_parseText(this.value);
380389
else if (this.type === tt.jsxTagStart)
381390
return this.jsx_parseElement();
382391
else

test/tests-jsx.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ var fbTestFixture = {
214214
}
215215
},
216216
children: [{
217-
type: 'Literal',
217+
type: 'JSXText',
218218
value: ' ',
219219
raw: ' ',
220220
range: [15, 16],
@@ -239,7 +239,7 @@ var fbTestFixture = {
239239
end: { line: 1, column: 23 }
240240
}
241241
}, {
242-
type: 'Literal',
242+
type: 'JSXText',
243243
value: ' ',
244244
raw: ' ',
245245
range: [23, 24],
@@ -735,7 +735,7 @@ var fbTestFixture = {
735735
},
736736
children: [
737737
{
738-
type: "Literal",
738+
type: "JSXText",
739739
value: "\nbar\nbaz\n",
740740
raw: "\nbar\nbaz\n",
741741
range: [
@@ -1238,7 +1238,7 @@ var fbTestFixture = {
12381238
}
12391239
},
12401240
children: [{
1241-
type: 'Literal',
1241+
type: 'JSXText',
12421242
value: '@test content',
12431243
raw: '@test content',
12441244
range: [5, 18],
@@ -1392,7 +1392,7 @@ var fbTestFixture = {
13921392
}
13931393
}
13941394
}, {
1395-
type: 'Literal',
1395+
type: 'JSXText',
13961396
value: '7x invalid-js-identifier',
13971397
raw: '7x invalid-js-identifier',
13981398
range: [
@@ -1654,7 +1654,7 @@ var fbTestFixture = {
16541654
},
16551655
"children": [
16561656
{
1657-
"type": "Literal",
1657+
"type": "JSXText",
16581658
"value": "monkeys /> gorillas",
16591659
"raw": "monkeys /> gorillas",
16601660
"range": [
@@ -3200,7 +3200,7 @@ var fbTestFixture = {
32003200
},
32013201
children: [
32023202
{
3203-
type: "Literal",
3203+
type: "JSXText",
32043204
start: 3,
32053205
end: 7,
32063206
value: "foo ",
@@ -3252,15 +3252,15 @@ var fbTestFixture = {
32523252
}
32533253
},
32543254
children: [{
3255-
type: "Literal",
3255+
type: "JSXText",
32563256
start: 22,
32573257
end: 26,
32583258
value: " bar",
32593259
raw: " bar"
32603260
}]
32613261
},
32623262
{
3263-
type: "Literal",
3263+
type: "JSXText",
32643264
start: 30,
32653265
end: 34,
32663266
value: " baz",
@@ -3441,7 +3441,7 @@ var fbTestFixture = {
34413441
}
34423442
},
34433443
children: [{
3444-
type: "Literal",
3444+
type: "JSXText",
34453445
start: 5,
34463446
end: 10,
34473447
value: "/text",

0 commit comments

Comments
 (0)