@@ -71,10 +71,10 @@ module.exports = {
71
71
* @returns {Boolean } True if node is decorated name with a custom decorated, false if not.
72
72
*/
73
73
var hasCustomDecorator = function ( node ) {
74
- var allowLenght = allowDecorators . length ;
74
+ var allowLength = allowDecorators . length ;
75
75
76
- if ( allowLenght && node . decorators && node . decorators . length ) {
77
- for ( var i = 0 ; i < allowLenght ; i ++ ) {
76
+ if ( allowLength && node . decorators && node . decorators . length ) {
77
+ for ( var i = 0 ; i < allowLength ; i ++ ) {
78
78
for ( var j = 0 , l = node . decorators . length ; j < l ; j ++ ) {
79
79
if (
80
80
node . decorators [ j ] . expression &&
@@ -161,6 +161,24 @@ module.exports = {
161
161
} ) ;
162
162
} ;
163
163
164
+ /**
165
+ * Checks if we are declaring function in class
166
+ * @returns {Boolean } True if we are declaring function in class, false if not.
167
+ */
168
+ var isFunctionInClass = function ( ) {
169
+ var blockNode ;
170
+ var scope = context . getScope ( ) ;
171
+ while ( scope ) {
172
+ blockNode = scope . block ;
173
+ if ( blockNode && blockNode . type === 'ClassDeclaration' ) {
174
+ return true ;
175
+ }
176
+ scope = scope . upper ;
177
+ }
178
+
179
+ return false ;
180
+ } ;
181
+
164
182
return {
165
183
ArrowFunctionExpression : function ( node ) {
166
184
// Stateless Functional Components cannot be optimized (yet)
@@ -175,11 +193,19 @@ module.exports = {
175
193
} ,
176
194
177
195
FunctionDeclaration : function ( node ) {
196
+ // Skip if the function is declared in the class
197
+ if ( isFunctionInClass ( ) ) {
198
+ return ;
199
+ }
178
200
// Stateless Functional Components cannot be optimized (yet)
179
201
markSCUAsDeclared ( node ) ;
180
202
} ,
181
203
182
204
FunctionExpression : function ( node ) {
205
+ // Skip if the function is declared in the class
206
+ if ( isFunctionInClass ( ) ) {
207
+ return ;
208
+ }
183
209
// Stateless Functional Components cannot be optimized (yet)
184
210
markSCUAsDeclared ( node ) ;
185
211
} ,
0 commit comments