babel-plugin-angularjs-annotate
babel-plugin-angularjs-annotate copied to clipboard
reference-following does not handle re-assigned variables
We currently do not handle cases like this:
var ctrl = function(d){};
ctrl = function(e){}
var c1 = {
controller: ctrl
}
ctrl = function(f){};
var c2 = {
controller: ctrl,
}
angular
.module("myMod", [])
.component("c1", c1)
.component("c2", c2);
Output:
var ctrl = function(d){};
ctrl.$inject = ["d"];
ctrl = function(e){}
var c1 = {
controller: ctrl
}
ctrl = function(f){};
var c2 = {
controller: ctrl,
}
angular
.module("myMod", [])
.component("c1", c1)
.component("c2", c2);
Realistically, this will be difficult/impossible to infer statically, so it may not even be worth bothering to correct the test case above (which can be inferred statically).
Babel tells us that ctrl can not be treated like a constant, and it may be sufficient to simply print a warning whenever we try to follow a mutable reference.