@@ -42,8 +42,6 @@ function inspectCallExpression(path, ctx) {
4242 } ) ;
4343}
4444
45- const ngAnnotatePrologueDirectives = [ "ngInject" , "ngNoInject" ] ;
46-
4745function inspectFunction ( path , ctx ) {
4846 const node = path . node ;
4947
@@ -62,17 +60,16 @@ function inspectFunction(path, ctx) {
6260 return ;
6361 }
6462
65- const str = matchPrologueDirectives ( ngAnnotatePrologueDirectives , path ) ;
66- if ( ! str ) {
63+ const annotate = matchPrologueDirectives ( path ) ;
64+ if ( annotate === null ) {
6765 return ;
6866 }
69- const block = ( str === "ngNoInject" ) ;
7067
7168 // now add the correct suspect
7269
7370 // for function declarations, it is always the function declaration node itself
7471 if ( t . isFunctionDeclaration ( node ) ) {
75- addSuspect ( path , ctx , block ) ;
72+ addSuspect ( path , ctx , ! annotate ) ;
7673 return ;
7774 }
7875
@@ -86,7 +83,7 @@ function inspectFunction(path, ctx) {
8683 // or /*@ngInject */ var f1 = function(a) ..
8784 // f1.$inject = ["a"]; will be added (or rebuilt/removed)
8885 if ( t . isVariableDeclarator ( path . parent ) ) {
89- addSuspect ( path . parentPath , ctx , block ) ;
86+ addSuspect ( path . parentPath , ctx , ! annotate ) ;
9087 return ;
9188 }
9289
@@ -104,9 +101,9 @@ function inspectFunction(path, ctx) {
104101 // }]);
105102 const maybeArrayExpression = path . parent ;
106103 if ( isAnnotatedArray ( maybeArrayExpression ) ) {
107- addSuspect ( path . parentPath , ctx , block ) ;
104+ addSuspect ( path . parentPath , ctx , ! annotate ) ;
108105 } else {
109- addSuspect ( path , ctx , block ) ;
106+ addSuspect ( path , ctx , ! annotate ) ;
110107 }
111108}
112109
@@ -189,13 +186,16 @@ function inspectObjectExpression(path, ctx) {
189186 // });
190187}
191188
192- function matchPrologueDirectives ( prologueDirectives , path ) {
189+ function matchPrologueDirectives ( path ) {
190+ const prologueDirectives = [ "ngInject" , "ngNoInject" ] ;
193191 const directives = path . node . body . directives || [ ] ;
194192 let matches = directives . map ( dir => dir . value . value )
195193 . filter ( val => prologueDirectives . indexOf ( val ) !== - 1 ) ;
196194
197195 if ( matches . length ) {
198- return matches [ 0 ] ;
196+ let match = matches [ 0 ] . trim ( ) ;
197+ if ( match === "ngInject" ) return true ;
198+ if ( match === "ngNoInject" ) return false ;
199199 }
200200
201201 return null ;
@@ -255,7 +255,10 @@ function inspectClassMethod(path, ctx){
255255
256256 let annotation = getAnnotation ( path . node ) ;
257257 if ( annotation === null ) {
258- return ;
258+ annotation = matchPrologueDirectives ( path ) ;
259+ if ( annotation === null ) {
260+ return ;
261+ }
259262 }
260263
261264 const ancestry = path . getAncestry ( ) ;
0 commit comments