@@ -73,9 +73,30 @@ function matchDirectiveReturnObject(path) {
73
73
// only matches inside directives
74
74
// return { .. controller: function($scope, $timeout), ...}
75
75
76
- return limit ( "directive" ,
77
- ( t . isReturnStatement ( node ) && node . argument && t . isObjectExpression ( node . argument ) && matchProp ( "controller" , ( path . get && path . get ( "argument.properties" ) || node . argument . properties ) ) ) ||
78
- ( t . isArrowFunctionExpression ( node ) && node . body && t . isObjectExpression ( node . body ) && matchProp ( "controller" , ( path . get && path . get ( "body.properties" ) || node . body . properties ) ) ) ) ;
76
+ var returnPath ;
77
+ if ( t . isReturnStatement ( node ) && node . argument ) {
78
+ if ( t . isObjectExpression ( node . argument ) ) {
79
+ returnPath = matchProp ( "controller" , ( path . get && path . get ( "argument.properties" ) || node . argument . properties ) ) ;
80
+ } else if ( path . get && t . isIdentifier ( path . get ( "argument" ) ) ) {
81
+ var binding = path . scope . getBinding ( node . argument . name ) ;
82
+ var bound = binding && binding . path ;
83
+ if ( bound && t . isVariableDeclarator ( bound ) ) {
84
+ var init = bound . get ( "init" ) ;
85
+ if ( init && t . isObjectExpression ( init ) ) {
86
+ returnPath = matchProp ( "controller" , init . get ( "properties" ) ) ;
87
+ }
88
+ }
89
+ }
90
+ }
91
+ if ( ! returnPath ) {
92
+ returnPath =
93
+ t . isArrowFunctionExpression ( node )
94
+ && node . body
95
+ && t . isObjectExpression ( node . body )
96
+ && matchProp ( "controller" , ( path . get && path . get ( "body.properties" ) || node . body . properties ) ) ;
97
+ }
98
+
99
+ return limit ( "directive" , returnPath ) ;
79
100
}
80
101
81
102
function limit ( name , path ) {
0 commit comments