Skip to content

Commit 3c3c537

Browse files
ArtemGovorovRReverser
authored andcommitted
Fix node types for fragments
`openingFragment` and `closingFragment` should be JSXOpeningFragment and JSXClosingFragment for JSX fragments
1 parent 1dc3245 commit 3c3c537

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

inject.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,23 @@ module.exports = function(acorn) {
289289
pp.jsx_parseOpeningElementAt = function(startPos, startLoc) {
290290
var node = this.startNodeAt(startPos, startLoc);
291291
node.attributes = [];
292-
node.name = this.jsx_parseElementName();
292+
var nodeName = this.jsx_parseElementName();
293+
if (nodeName) node.name = nodeName;
293294
while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
294295
node.attributes.push(this.jsx_parseAttribute());
295296
node.selfClosing = this.eat(tt.slash);
296297
this.expect(tt.jsxTagEnd);
297-
return this.finishNode(node, 'JSXOpeningElement');
298+
return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
298299
};
299300

300301
// Parses JSX closing tag starting after '</'.
301302

302303
pp.jsx_parseClosingElementAt = function(startPos, startLoc) {
303304
var node = this.startNodeAt(startPos, startLoc);
304-
node.name = this.jsx_parseElementName();
305+
var nodeName = this.jsx_parseElementName();
306+
if (nodeName) node.name = nodeName;
305307
this.expect(tt.jsxTagEnd);
306-
return this.finishNode(node, 'JSXClosingElement');
308+
return this.finishNode(node, nodeName ? 'JSXClosingElement' : 'JSXClosingFragment');
307309
};
308310

309311
// Parses entire JSX element, including it's opening tag

test/tests-jsx.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,7 +3216,7 @@ var fbTestFixture = {
32163216
},
32173217
range: [0, 16],
32183218
openingElement: {
3219-
type: 'JSXOpeningElement',
3219+
type: 'JSXOpeningFragment',
32203220
start: 0,
32213221
end: 2,
32223222
loc: {
@@ -3231,11 +3231,10 @@ var fbTestFixture = {
32313231
},
32323232
range: [0, 2],
32333233
attributes: [],
3234-
name: '',
32353234
selfClosing: false
32363235
},
32373236
closingElement: {
3238-
type: 'JSXClosingElement',
3237+
type: 'JSXClosingFragment',
32393238
start: 13,
32403239
end: 16,
32413240
loc: {
@@ -3248,8 +3247,7 @@ var fbTestFixture = {
32483247
column: 16
32493248
}
32503249
},
3251-
range: [13, 16],
3252-
name: ''
3250+
range: [13, 16]
32533251
},
32543252
children: [{
32553253
type: 'JSXElement',

0 commit comments

Comments
 (0)