@@ -214,6 +214,51 @@
},
/**
+ * Check if createElement is destructured from React import
+ *
+ * @returns {Boolean} True if createElement is destructured from React
+ */
+ hasDestructuredReactCreateElement: function() {
+ var variables = variableUtil.variablesInScope(context);
+ var variable = variableUtil.getVariable(variables, 'createElement');
+ if (variable) {
+ var map = variable.scope.set;
+ if (map.has('React')) {
+ return true;
+ }
+ }
+ return false;
+ },
+
+ /**
+ * Checks to see if node is called within React.createElement
+ *
+ * @param {ASTNode} node The AST node being checked.
+ * @returns {Boolean} True if React.createElement called
+ */
+ isReactCreateElement: function(node) {
+ var calledOnReact = (
+ node &&
+ node.callee &&
+ node.callee.object &&
+ node.callee.object.name === 'React' &&
+ node.callee.property &&
+ node.callee.property.name === 'createElement'
+ );
+
+ var calledDirectly = (
+ node &&
+ node.callee &&
+ node.callee.name === 'createElement'
+ );
+
+ if (this.hasDestructuredReactCreateElement()) {
+ return calledDirectly || calledOnReact;
+ }
+ return calledOnReact;
+ },
+
+ /**
* Check if the node is returning JSX
*
* @param {ASTNode} ASTnode The AST node being checked
@@ -256,26 +301,7 @@
node[property] &&
node[property].type === 'JSXElement'
;
- var destructuredReactCreateElement = function () {
- var variables = variableUtil.variablesInScope(context);
- var variable = variableUtil.getVariable(variables, 'createElement');
- if (variable) {
- var map = variable.scope.set;
- if (map.has('React')) {
- return true;
- }
- }
- return false;
- };
- var returnsReactCreateElement =
- destructuredReactCreateElement() ||
- node[property] &&
- node[property].callee &&
- node[property].callee.object &&
- node[property].callee.object.name === 'React' &&
- node[property].callee.property &&
- node[property].callee.property.name === 'createElement'
- ;
+ var returnsReactCreateElement = this.isReactCreateElement(node[property]);
return Boolean(
returnsConditionalJSX ||