Skip to content

Commit e248365

Browse files
committed
Support shorthand fragments in Components
1 parent 72a71b3 commit e248365

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/util/Components.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const variableUtil = require('./variable');
1111
const pragmaUtil = require('./pragma');
1212
const astUtil = require('./ast');
1313
const propTypes = require('./propTypes');
14+
const jsxUtil = require('./jsx');
1415

1516
function getId(node) {
1617
return node && node.range.join(':');
@@ -349,12 +350,12 @@ function componentRule(rule, context) {
349350
const returnsConditionalJSXConsequent =
350351
node[property] &&
351352
node[property].type === 'ConditionalExpression' &&
352-
node[property].consequent.type === 'JSXElement'
353+
jsxUtil.isJSX(node[property].consequent)
353354
;
354355
const returnsConditionalJSXAlternate =
355356
node[property] &&
356357
node[property].type === 'ConditionalExpression' &&
357-
node[property].alternate.type === 'JSXElement'
358+
jsxUtil.isJSX(node[property].alternate)
358359
;
359360
const returnsConditionalJSX =
360361
strict ?
@@ -363,7 +364,7 @@ function componentRule(rule, context) {
363364

364365
const returnsJSX =
365366
node[property] &&
366-
node[property].type === 'JSXElement'
367+
jsxUtil.isJSX(node[property])
367368
;
368369
const returnsReactCreateElement = this.isReactCreateElement(node[property]);
369370

lib/util/jsx.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const COMPAT_TAG_REGEX = /^[a-z]|\-/;
99

1010
/**
1111
* Checks if a node represents a DOM element.
12-
* @param {String} node - JSXOpeningElement to check.
12+
* @param {object} node - JSXOpeningElement to check.
1313
* @returns {boolean} Whether or not the node corresponds to a DOM element.
1414
*/
1515
function isDOMComponent(node) {
@@ -25,6 +25,16 @@ function isDOMComponent(node) {
2525
return COMPAT_TAG_REGEX.test(name);
2626
}
2727

28+
/**
29+
* Checks if a node represents a JSX element or fragment.
30+
* @param {object} node - node to check.
31+
* @returns {boolean} Whether or not the node if a JSX element or fragment.
32+
*/
33+
function isJSX(node) {
34+
return ['JSXElement', 'JSXFragment'].indexOf(node.type) >= 0;
35+
}
36+
2837
module.exports = {
29-
isDOMComponent: isDOMComponent
38+
isDOMComponent: isDOMComponent,
39+
isJSX: isJSX
3040
};

0 commit comments

Comments
 (0)