match myMod.component("foo", {controller: fn})

This commit is contained in:
Olov Lassus
2015-12-19 12:53:52 +01:00
parent 17beb453a7
commit 5bfb3b124e
4 changed files with 21 additions and 5 deletions
+1 -1
View File
@@ -121,7 +121,7 @@ myMod.controller("MyCtrl", function($scope, $timeout) {
It's not limited to `.controller` of course. It understands `.config`, `.factory`,
`.directive`, `.filter`, `.run`, `.controller`, `.provider`, `.service`, `.decorator`,
`.animation` and `.invoke`.
`.component`, `.animation` and `.invoke`.
For short forms it does not need to see the declaration of `myMod` so you can run it
on your individual source files without concatenating. If ng-annotate detects a short form
+10 -2
View File
@@ -352,7 +352,7 @@ function matchRegular(node, ctx) {
}
const matchAngularModule = (obj.$chained === chainedRegular || isReDef(obj, ctx) || isLongDef(obj)) &&
is.someof(method.name, ["provider", "value", "constant", "bootstrap", "config", "factory", "directive", "filter", "run", "controller", "service", "animation", "invoke", "store", "decorator"]);
is.someof(method.name, ["provider", "value", "constant", "bootstrap", "config", "factory", "directive", "filter", "run", "controller", "service", "animation", "invoke", "store", "decorator", "component"]);
if (!matchAngularModule) {
return false;
}
@@ -363,10 +363,18 @@ function matchRegular(node, ctx) {
}
const args = node.arguments;
const target = (is.someof(method.name, ["config", "run"]) ?
let target = (is.someof(method.name, ["config", "run"]) ?
args.length === 1 && args[0] :
args.length === 2 && args[0].type === "Literal" && is.string(args[0].value) && args[1]);
if (method.name === "component") {
const controllerProp = (target && target.type === "ObjectExpression" && matchProp("controller", target.properties));
if (!controllerProp) {
return false;
}
target = controllerProp;
}
if (target) {
target.$methodName = method.name;
}
+5 -1
View File
@@ -27,6 +27,7 @@ myMod.store("foo", function($scope, $timeout) {
});
myMod.decorator("foo", function($scope, $timeout) {
});
myMod.component("foo", {controller: function($scope, $timeout) {}});
// implicit config function
angular.module("MyMod", function($interpolateProvider) {});
@@ -57,6 +58,7 @@ myMod.store("foo", function() {
});
myMod.decorator("foo", function() {
});
myMod.component("foo", {controller: function() {}});
// run, config don't take names
myMod.run(function($scope, $timeout) {
@@ -163,7 +165,9 @@ myMod.directive("foo", function($a, $b) {
d;
}).animation("foo", function($f, $g) {
e;
}).invoke("foo", function($f, $g) {
}).component("foo", {controller: function($scope, $timeout) {
i;
}}).invoke("foo", function($f, $g) {
f;
}).decorator("foo", function($f, $g) {
g;
+5 -1
View File
@@ -41,6 +41,7 @@ myMod.store("foo", ["$scope", "$timeout", function($scope, $timeout) {
}]);
myMod.decorator("foo", ["$scope", "$timeout", function($scope, $timeout) {
}]);
myMod.component("foo", {controller: ["$scope", "$timeout", function($scope, $timeout) {}]});
// implicit config function
angular.module("MyMod", ["$interpolateProvider", function($interpolateProvider) {}]);
@@ -71,6 +72,7 @@ myMod.store("foo", function() {
});
myMod.decorator("foo", function() {
});
myMod.component("foo", {controller: function() {}});
// run, config don't take names
myMod.run(["$scope", "$timeout", function($scope, $timeout) {
@@ -178,7 +180,9 @@ myMod.directive("foo", ["$a", "$b", function($a, $b) {
d;
}]).animation("foo", ["$f", "$g", function($f, $g) {
e;
}]).invoke("foo", ["$f", "$g", function($f, $g) {
}]).component("foo", {controller: ["$scope", "$timeout", function($scope, $timeout) {
i;
}]}).invoke("foo", ["$f", "$g", function($f, $g) {
f;
}]).decorator("foo", ["$f", "$g", function($f, $g) {
g;