diff --git a/index.js b/index.js index 9988a6e..14464b0 100644 --- a/index.js +++ b/index.js @@ -142,7 +142,9 @@ function doesReturnJSX (body) { var lastBlock = block.slice(0).pop() if (lastBlock.type === 'ReturnStatement') { - return lastBlock.argument !== null && lastBlock.argument.type === 'JSXElement' + return lastBlock.argument !== null && (lastBlock.argument.type === 'JSXElement' || + (lastBlock.argument.type === 'ConditionalExpression' && + (lastBlock.argument.consequent.type === 'JSXElement' || lastBlock.argument.alternate.type === 'JSXElement'))) } } diff --git a/test/fixtures/functionExpr/expected.js b/test/fixtures/functionExpr/expected.js index b48b3bf..c7a17ce 100644 --- a/test/fixtures/functionExpr/expected.js +++ b/test/fixtures/functionExpr/expected.js @@ -57,4 +57,14 @@ export default function Component1f(value) { value ); } -Component1f.displayName = "Component1f"; \ No newline at end of file + +Component1f.displayName = "Component1f"; +// Exported named stateless component used in variable declaration returning conditional JSX +export var Component1g = function (value) { + return true ? React.createElement( + "div", + null, + value + ) : null; +}; +Component1g.displayName = "Component1g"; \ No newline at end of file diff --git a/test/fixtures/functionExpr/input.js b/test/fixtures/functionExpr/input.js index 2f85ac1..a6b2126 100644 --- a/test/fixtures/functionExpr/input.js +++ b/test/fixtures/functionExpr/input.js @@ -28,3 +28,8 @@ Component1e = function (value) { export default function Component1f (value) { return
{value}
} + +// Exported named stateless component used in variable declaration returning conditional JSX +export var Component1g = function (value) { + return true ?
{value}
: null +}