btford / ngmin

**deprecated** AngularJS Pre-minifier –> use ng-annotate –>
https://github.com/olov/ng-annotate
860 stars 42 forks source link

Annotate `this.$get` function in providers #33

Closed BinaryMuse closed 11 years ago

BinaryMuse commented 11 years ago

Hi, Brian,

This pull request annotates this.$get = function(dep) in providers (#31). From the test, it transforms:

angular.module('myMod', []).
  provider('myService', function (dep) {
    this.$get = function(otherDep) {};
  });

into this:

angular.module('myMod', []).provider('myService', [
  'dep',
  function (dep) {
    this.$get = ['otherDep', function(otherDep) {}];
  }
]);

It's based of the DDO annotation code in lib/annotate-ast.js. I've also included some refactoring in that file that extracts repeated code from inside the final deepApplys into a function annotateInjectables (I'll let you decide on a decent name :) that takes the argument usually named originalFn and returns the ArrayExpression it should be replaced with (or else returns originalFn if nothing is to be annotated).

BinaryMuse commented 11 years ago

angular/angularjs-batarang#66 made me realize that there was a hole in the support for $get in providers when the provider definition was provided as an object literal; this commit adds that support.

btford commented 11 years ago

Looks good! Thanks @BinaryMuse.

btford commented 11 years ago

Landed as a91b8fdf1eefb159311badb0861715ba999be9e5, 13bf914830216aa1a3da2937f9a9617cecf21404, and a2b79a5b4331c4d72674341fc1c5d1b3a93868dc. Published in v0.3.7, which is now available on npm. Thanks again, @BinaryMuse!