@@ -71,10 +71,10 @@ module.exports = {
7171 * @returns {Boolean } True if node is decorated name with a custom decorated, false if not.
7272 */
7373 var hasCustomDecorator = function ( node ) {
74- var allowLenght = allowDecorators . length ;
74+ var allowLength = allowDecorators . length ;
7575
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 ++ ) {
7878 for ( var j = 0 , l = node . decorators . length ; j < l ; j ++ ) {
7979 if (
8080 node . decorators [ j ] . expression &&
@@ -161,6 +161,24 @@ module.exports = {
161161 } ) ;
162162 } ;
163163
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+
164182 return {
165183 ArrowFunctionExpression : function ( node ) {
166184 // Stateless Functional Components cannot be optimized (yet)
@@ -175,11 +193,19 @@ module.exports = {
175193 } ,
176194
177195 FunctionDeclaration : function ( node ) {
196+ // Skip if the function is declared in the class
197+ if ( isFunctionInClass ( ) ) {
198+ return ;
199+ }
178200 // Stateless Functional Components cannot be optimized (yet)
179201 markSCUAsDeclared ( node ) ;
180202 } ,
181203
182204 FunctionExpression : function ( node ) {
205+ // Skip if the function is declared in the class
206+ if ( isFunctionInClass ( ) ) {
207+ return ;
208+ }
183209 // Stateless Functional Components cannot be optimized (yet)
184210 markSCUAsDeclared ( node ) ;
185211 } ,
0 commit comments