olov / ng-annotate

Add, remove and rebuild AngularJS dependency injection annotations
MIT License
2.03k stars 150 forks source link

Missing annotation for $controllerProvider nested function. #196

Closed ceoaliongroo closed 9 years ago

ceoaliongroo commented 9 years ago

Inside a state of ui-router, is missing the ng-annotation. Example (for $state) :

      ...
      controllerProvider: function($stateParams) {
        switch (condition) {
          case 'condition-1':
            return function($state) {
              $state.go('logout', {}, {reload: true});
            };
          case 'condition-2':
            return function($state) { 
             $state.go('dashboard', {param1: true});
            };
          default:
            return $stateParams.param1 + 'Controller';
        }
      },
      ...
olov commented 9 years ago

Can you provide input, expected output, actual output and ng-annotate version?

ceoaliongroo commented 9 years ago

__ng-annotate:__ version 0.10.3 using __grunt-ng-annotate:__ version 0.4.0.

input:

      ...
      controllerProvider: function(condition, $stateParams) {
        switch (condition) {
          case 'condition-1':
            return function($state) {
              $state.go('logout', {}, {reload: true});
            };
          case 'condition-2':
            return function($state) { 
             $state.go('dashboard', {param1: true});
            };
          default:
            return $stateParams.param1 + 'Controller';
        }
      },
      ...

expected output:

      ...
      controllerProvider: ['condition', '$stateParams', function(condition, $stateParams) {
        switch (condition) {
          case 'condition-1':
            return ['$state', function($state) {
              $state.go('logout', {}, {reload: true});
            }];
          case 'condition-2':
            return ['$state', function($state) { 
             $state.go('dashboard', {param1: true});
            }];
          default:
            return $stateParams.param1 + 'Controller';
        }
      }],
      ...
olov commented 9 years ago

Next time please test using the latest version of ng-annotate, 0.10.3 was released almost a year ago. Upgrade to the latest grunt-ng-annotate version and you should get up to date with ng-annotate too.

In either case, from what I understand of your proposed transformation it's much too complicated to carry its weight in ng-annotate. I recommend you to do this:

return function($state) {
    "ngInject";
    $state.go('logout', {}, {reload: true});
};