It seems to me that this means that the dependency inferrer is by its
nature incompatible with obfuscation. Will it be possible to disable
inferred dependency injection (or have it disabled by default, or have
it disabled if explicit dependency declaration is present)?
Here is an example from my code:
Given this service:
(function() {
angular.service('Card', function($resource) {
return $resource('/payment/card', {}, {
get: {
method: 'GET',
isArray: false
}
});
});
}).call(this);
And this controller:
(function() {
this.SubscriptionCtrl = function(Card, $xhr) {
var scope;
scope = this;
...
};
};
this.SubscriptionCtrl.$inject = ['Card', '$xhr'];
}).call(this);
Which is obfuscated (in part), to this:
function(){this.SubscriptionCtrl=function(a,b)...
// Note that the "Card" parameter is now "a"
From AngularJS:
function injector(value){
if (!(value in instanceCache)) {
var factory = factories[value];
if (!factory) throw Error("Unknown provider for '"+value+"'.");
inferInjectionArgs(factory);
instanceCache[value] = invoke(factoryScope, factory);
}
return instanceCache[value];
}
function inferInjectionArgs(fn) {
assertArgFn(fn);
if (!fn.$inject) {
var args = fn.$inject = [];
var fnText = fn.toString().replace(STRIP_COMMENTS, '');
///////////////Matching the args, which have been obfuscated//////////
var argDecl = fnText.match(FN_ARGS);
forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg){
arg.replace(FN_ARG, function(all, name){
args.push(name);
});
});
}
return fn.$inject;
}