From 373e292d3c6165d1132c0f2085a3779ef5bae36f Mon Sep 17 00:00:00 2001 From: Martijn Welker Date: Tue, 19 Nov 2019 12:27:03 +0100 Subject: [PATCH] Check for class expressions in inspectDeclarator and inspectClassMethod --- nginject.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; + } } }