olov / ng-annotate

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

angular.extend() support #242

Closed aramk closed 8 years ago

aramk commented 8 years ago

angular.extend() usage doesn't seem to be supported by ng-annotate:

export default ngModule => {
  ngModule.directive('fooBar', (fooBar) => {
    return angular.extend({}, fooBar[0], {
      restrict: 'A',
      template: require('./template.html'),
      controllerAs: 'vm',
      controller: function($state, $window) {
        // ...
      }
    });
  })
}

Adding /*@ngInject*/ did it for me:

export default ngModule => {
  ngModule.directive('fooBar', (fooBar) => {
    return angular.extend({}, fooBar[0], {
      restrict: 'A',
      template: require('./template.html'),
      controllerAs: 'vm',
      controller: /*@ngInject*/ function($state, $window) {
        // ...
      }
    });
  })
}
olov commented 8 years ago

https://github.com/olov/ng-annotate/issues/245

schmod commented 8 years ago

Is angular.extend() your problem, or is it the fact that you're doing this in an ES6 export statement?

Either way, I don't think that there's a good path for implicitly detecting annotatable functions inside of something like angular.extend(), _.extend(), or Object.assign() without hard-coding lots of special cases, or potentially picking up tons of false-positives.

Adding /*@ngInject*/ is definitely the way to go here.