55'use strict' ;
66
77const estraverse = require ( 'estraverse' ) ;
8+ // const pragmaUtil = require('./pragma');
89
910/**
1011 * Wrapper for estraverse.traverse
@@ -65,10 +66,11 @@ function findReturnStatement(node) {
6566 * returned expression in the case of an arrow function) of a function
6667 *
6768 * @param {ASTNode } ASTNode The AST node being checked
69+ * @param {Context } context The context of `ASTNode`.
6870 * @param {function } enterFunc Function to execute for each returnStatement found
6971 * @returns {undefined }
7072 */
71- function traverseReturns ( ASTNode , enterFunc ) {
73+ function traverseReturns ( ASTNode , context , enterFunc ) {
7274 const nodeType = ASTNode . type ;
7375
7476 if ( nodeType === 'ReturnStatement' ) {
@@ -79,12 +81,31 @@ function traverseReturns(ASTNode, enterFunc) {
7981 return enterFunc ( ASTNode . body ) ;
8082 }
8183
82- if ( nodeType !== 'FunctionExpression'
83- && nodeType !== 'FunctionDeclaration'
84- && nodeType !== 'ArrowFunctionExpression'
85- && nodeType !== 'MethodDefinition'
84+ /* TODO: properly warn on React.forwardRefs having typo properties
85+ if (nodeType === 'CallExpression') {
86+ const callee = ASTNode.callee;
87+ const pragma = pragmaUtil.getFromContext(context);
88+ if (
89+ callee.type === 'MemberExpression'
90+ && callee.object.type === 'Identifier'
91+ && callee.object.name === pragma
92+ && callee.property.type === 'Identifier'
93+ && callee.property.name === 'forwardRef'
94+ && ASTNode.arguments.length > 0
95+ ) {
96+ return enterFunc(ASTNode.arguments[0]);
97+ }
98+ return;
99+ }
100+ */
101+
102+ if (
103+ nodeType !== 'FunctionExpression'
104+ && nodeType !== 'FunctionDeclaration'
105+ && nodeType !== 'ArrowFunctionExpression'
106+ && nodeType !== 'MethodDefinition'
86107 ) {
87- throw new TypeError ( 'only function nodes are expected' ) ;
108+ return ;
88109 }
89110
90111 traverse ( ASTNode . body , {
0 commit comments