Skip to content

Commit 5bfb3b1

Browse files
committed
match myMod.component("foo", {controller: fn})
1 parent 17beb45 commit 5bfb3b1

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ myMod.controller("MyCtrl", function($scope, $timeout) {
121121

122122
It's not limited to `.controller` of course. It understands `.config`, `.factory`,
123123
`.directive`, `.filter`, `.run`, `.controller`, `.provider`, `.service`, `.decorator`,
124-
`.animation` and `.invoke`.
124+
`.component`, `.animation` and `.invoke`.
125125

126126
For short forms it does not need to see the declaration of `myMod` so you can run it
127127
on your individual source files without concatenating. If ng-annotate detects a short form

ng-annotate-main.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ function matchRegular(node, ctx) {
352352
}
353353

354354
const matchAngularModule = (obj.$chained === chainedRegular || isReDef(obj, ctx) || isLongDef(obj)) &&
355-
is.someof(method.name, ["provider", "value", "constant", "bootstrap", "config", "factory", "directive", "filter", "run", "controller", "service", "animation", "invoke", "store", "decorator"]);
355+
is.someof(method.name, ["provider", "value", "constant", "bootstrap", "config", "factory", "directive", "filter", "run", "controller", "service", "animation", "invoke", "store", "decorator", "component"]);
356356
if (!matchAngularModule) {
357357
return false;
358358
}
@@ -363,10 +363,18 @@ function matchRegular(node, ctx) {
363363
}
364364

365365
const args = node.arguments;
366-
const target = (is.someof(method.name, ["config", "run"]) ?
366+
let target = (is.someof(method.name, ["config", "run"]) ?
367367
args.length === 1 && args[0] :
368368
args.length === 2 && args[0].type === "Literal" && is.string(args[0].value) && args[1]);
369369

370+
if (method.name === "component") {
371+
const controllerProp = (target && target.type === "ObjectExpression" && matchProp("controller", target.properties));
372+
if (!controllerProp) {
373+
return false;
374+
}
375+
target = controllerProp;
376+
}
377+
370378
if (target) {
371379
target.$methodName = method.name;
372380
}

tests/original.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ myMod.store("foo", function($scope, $timeout) {
2727
});
2828
myMod.decorator("foo", function($scope, $timeout) {
2929
});
30+
myMod.component("foo", {controller: function($scope, $timeout) {}});
3031

3132
// implicit config function
3233
angular.module("MyMod", function($interpolateProvider) {});
@@ -57,6 +58,7 @@ myMod.store("foo", function() {
5758
});
5859
myMod.decorator("foo", function() {
5960
});
61+
myMod.component("foo", {controller: function() {}});
6062

6163
// run, config don't take names
6264
myMod.run(function($scope, $timeout) {
@@ -163,7 +165,9 @@ myMod.directive("foo", function($a, $b) {
163165
d;
164166
}).animation("foo", function($f, $g) {
165167
e;
166-
}).invoke("foo", function($f, $g) {
168+
}).component("foo", {controller: function($scope, $timeout) {
169+
i;
170+
}}).invoke("foo", function($f, $g) {
167171
f;
168172
}).decorator("foo", function($f, $g) {
169173
g;

tests/with_annotations.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ myMod.store("foo", ["$scope", "$timeout", function($scope, $timeout) {
4141
}]);
4242
myMod.decorator("foo", ["$scope", "$timeout", function($scope, $timeout) {
4343
}]);
44+
myMod.component("foo", {controller: ["$scope", "$timeout", function($scope, $timeout) {}]});
4445

4546
// implicit config function
4647
angular.module("MyMod", ["$interpolateProvider", function($interpolateProvider) {}]);
@@ -71,6 +72,7 @@ myMod.store("foo", function() {
7172
});
7273
myMod.decorator("foo", function() {
7374
});
75+
myMod.component("foo", {controller: function() {}});
7476

7577
// run, config don't take names
7678
myMod.run(["$scope", "$timeout", function($scope, $timeout) {
@@ -178,7 +180,9 @@ myMod.directive("foo", ["$a", "$b", function($a, $b) {
178180
d;
179181
}]).animation("foo", ["$f", "$g", function($f, $g) {
180182
e;
181-
}]).invoke("foo", ["$f", "$g", function($f, $g) {
183+
}]).component("foo", {controller: ["$scope", "$timeout", function($scope, $timeout) {
184+
i;
185+
}]}).invoke("foo", ["$f", "$g", function($f, $g) {
182186
f;
183187
}]).decorator("foo", ["$f", "$g", function($f, $g) {
184188
g;

0 commit comments

Comments
 (0)