@@ -38,6 +38,22 @@ module.exports = Components.detect(function(context, components, utils) {
38
38
}
39
39
}
40
40
41
+ /**
42
+ * Get properties name
43
+ * @param {Object } node - Property.
44
+ * @returns {String } Property name.
45
+ */
46
+ function getPropertyName ( node ) {
47
+ // Special case for class properties
48
+ // (babel-eslint does not expose property name so we have to rely on tokens)
49
+ if ( node . type === 'ClassProperty' ) {
50
+ var tokens = context . getFirstTokens ( node , 2 ) ;
51
+ return tokens [ 1 ] && tokens [ 1 ] . type === 'Identifier' ? tokens [ 1 ] . value : tokens [ 0 ] . value ;
52
+ }
53
+
54
+ return node . key . name ;
55
+ }
56
+
41
57
/**
42
58
* Check if a given AST node has a render method
43
59
* @param {ASTNode } node The AST node being checked.
@@ -46,10 +62,10 @@ module.exports = Components.detect(function(context, components, utils) {
46
62
function hasRenderMethod ( node ) {
47
63
var properties = getComponentProperties ( node ) ;
48
64
for ( var i = 0 , j = properties . length ; i < j ; i ++ ) {
49
- if ( properties [ i ] . key . name !== 'render' ) {
65
+ if ( getPropertyName ( properties [ i ] ) !== 'render' ) {
50
66
continue ;
51
67
}
52
- return properties [ i ] . value . type === 'FunctionExpression' ;
68
+ return / F u n c t i o n E x p r e s s i o n $ / . test ( properties [ i ] . value . type ) ;
53
69
}
54
70
return false ;
55
71
}
@@ -63,8 +79,8 @@ module.exports = Components.detect(function(context, components, utils) {
63
79
depth ++ ;
64
80
}
65
81
if (
66
- ( ancestors [ i ] . type !== ' Property' && ancestors [ i ] . type !== 'MethodDefinition' ) ||
67
- ancestors [ i ] . key . name !== 'render' ||
82
+ ! / ( M e t h o d D e f i n i t i o n | ( C l a s s ) ? P r o p e r t y ) $ / . test ( ancestors [ i ] . type ) ||
83
+ getPropertyName ( ancestors [ i ] ) !== 'render' ||
68
84
depth > 1
69
85
) {
70
86
continue ;
@@ -73,6 +89,13 @@ module.exports = Components.detect(function(context, components, utils) {
73
89
}
74
90
} ,
75
91
92
+ ArrowFunctionExpression : function ( node ) {
93
+ if ( node . expression === false || getPropertyName ( node . parent ) !== 'render' ) {
94
+ return ;
95
+ }
96
+ markReturnStatementPresent ( node ) ;
97
+ } ,
98
+
76
99
'Program:exit' : function ( ) {
77
100
var list = components . list ( ) ;
78
101
for ( var component in list ) {
0 commit comments