diff --git a/nginject.js b/nginject.js index 2685788..6cc07e9 100644 --- a/nginject.js +++ b/nginject.js @@ -227,7 +227,7 @@ function inspectAssignment(path, ctx){ function inspectDeclarator(path, ctx){ const node = path.node; - if(!isFunctionExpressionOrArrow(node.init)){ + if(!isFunctionExpressionOrArrow(node.init) && !t.isClassExpression(node.init)){ return; } @@ -270,10 +270,17 @@ function inspectClassMethod(path, ctx){ const ancestry = path.getAncestry(); for(var i=0; i < ancestry.length; i++){ let ancestor = ancestry[i]; + if(ancestor.isClassDeclaration()){ addSuspect(ancestor, ctx, !annotation); return; } + + if (ancestor.isClassExpression()) { + // Add the variable declaration of the class as suspect + addSuspect(ancestor.parentPath.parentPath, ctx, !annotation); + return; + } } }