5
5
'use strict' ;
6
6
7
7
const estraverse = require ( 'estraverse' ) ;
8
+ // const pragmaUtil = require('./pragma');
8
9
9
10
/**
10
11
* Wrapper for estraverse.traverse
@@ -65,10 +66,11 @@ function findReturnStatement(node) {
65
66
* returned expression in the case of an arrow function) of a function
66
67
*
67
68
* @param {ASTNode } ASTNode The AST node being checked
69
+ * @param {Context } context The context of `ASTNode`.
68
70
* @param {function } enterFunc Function to execute for each returnStatement found
69
71
* @returns {undefined }
70
72
*/
71
- function traverseReturns ( ASTNode , enterFunc ) {
73
+ function traverseReturns ( ASTNode , context , enterFunc ) {
72
74
const nodeType = ASTNode . type ;
73
75
74
76
if ( nodeType === 'ReturnStatement' ) {
@@ -79,12 +81,31 @@ function traverseReturns(ASTNode, enterFunc) {
79
81
return enterFunc ( ASTNode . body ) ;
80
82
}
81
83
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'
86
107
) {
87
- throw new TypeError ( 'only function nodes are expected' ) ;
108
+ return ;
88
109
}
89
110
90
111
traverse ( ASTNode . body , {
0 commit comments