schmod / babel-plugin-angularjs-annotate

Add Angular 1.x dependency injection annotations to ES6 code
http://schmod.github.io/babel-plugin-angularjs-annotate
MIT License
240 stars 29 forks source link

Directive definition in a variable #36

Closed noppa closed 6 years ago

noppa commented 6 years ago

Adds implicit annotation support for directive definitions that are returned from a variable.

angular.module('MyMod').directive('foo', function() {
  var directive = {
    // Ctrl wasn't annotated before, but will be now.
    controller: function Ctrl(FooService) {},
  };
  return directive;
});

Currently, implicit annotations only work for a directive if the directive definition is returned as an object literal.

angular.module('MyMod').directive('foo', function() {
  return {
    // Ctrl is correctly annotated.
    controller: function Ctrl(FooService) {},
  };
});

We have used the former quite a lot in our codebase, so we needed to add support for it. I understand that the general recommendation for more complex use cases like this is to add explicit annotations, but here's a PR for the feature anyway if you are interested. All the tests pass and I added one more to test this specific case.

schmod commented 6 years ago

Looks good to me! Thanks for the contribution!

noppa commented 6 years ago

No problem, thanks for the awesome plugin!