Skip to content

Commit

Permalink
Merge remote-tracking branch 'kmccullough/Issue232'
Browse files Browse the repository at this point in the history
* kmccullough/Issue232:
  HttpInterceptor Not Annotated (Fixes olov#232)
  • Loading branch information
pioug committed May 4, 2016
2 parents a5cee1b + 3acb8d9 commit 9ab58e7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion IMPLICIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ ng-annotate understands `$routeProvider.when("path", { .. })`.
ng-annotate understands `$controllerProvider.register("foo", function($scope) ..)`.

ng-annotate understands `$httpProvider.interceptors.push(function($scope) ..)` and
`$httpProvider.responseInterceptors.push(function($scope) ..)`.
`$httpProvider.responseInterceptors.push(function($scope) ..)` and
`$httpProvider.interceptors.unshift(function($scope) ..)` and
`$httpProvider.responseInterceptors.unshift(function($scope) ..)`.

ng-annotate understands `$injector.invoke(function ..)`.

Expand Down
4 changes: 3 additions & 1 deletion ng-annotate-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,15 @@ function matchInjectorInvoke(node) {
function matchHttpProvider(node) {
// $httpProvider.interceptors.push(function($scope) {});
// $httpProvider.responseInterceptors.push(function($scope) {});
// $httpProvider.interceptors.unshift(function($scope) {});
// $httpProvider.responseInterceptors.unshift(function($scope) {});

// we already know that node is a (non-computed) method call
const callee = node.callee;
const obj = callee.object; // identifier or expression
const method = callee.property; // identifier

return (method.name === "push" &&
return ((method.name === "push" || method.name === "unshift") &&
obj.type === "MemberExpression" && !obj.computed &&
obj.object.name === "$httpProvider" && is.someof(obj.property.name, ["interceptors", "responseInterceptors"]) &&
node.arguments.length >= 1 && node.arguments);
Expand Down
4 changes: 4 additions & 0 deletions tests/original.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ angular.module("MyMod").directive("pleasematchthis", function() {
// $httpProvider
$httpProvider.interceptors.push(function($scope) { a });
$httpProvider.responseInterceptors.push(function($scope) { a }, function(a, b) { b }, function() { c });
$httpProvider.interceptors.unshift(function($scope) { a });
$httpProvider.responseInterceptors.unshift(function($scope) { a }, function(a, b) { b }, function() { c });

// $routeProvider
$routeProvider.when("path", {
Expand Down Expand Up @@ -454,6 +456,8 @@ foobar.irrespective("dontmatchthis", function() {
// $httpProvider
$httpProvider.interceptors.push(function($scope) { a });
$httpProvider.responseInterceptors.push(function($scope) { a }, function(a, b) { b }, function() { c });
$httpProvider.interceptors.unshift(function($scope) { a });
$httpProvider.responseInterceptors.unshift(function($scope) { a }, function(a, b) { b }, function() { c });

// $routeProvider
$routeProvider.when("path", {
Expand Down
4 changes: 4 additions & 0 deletions tests/with_annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ angular.module("MyMod").directive("pleasematchthis", function() {
// $httpProvider
$httpProvider.interceptors.push(["$scope", function($scope) { a }]);
$httpProvider.responseInterceptors.push(["$scope", function($scope) { a }], ["a", "b", function(a, b) { b }], function() { c });
$httpProvider.interceptors.unshift(["$scope", function($scope) { a }]);
$httpProvider.responseInterceptors.unshift(["$scope", function($scope) { a }], ["a", "b", function(a, b) { b }], function() { c });

// $routeProvider
$routeProvider.when("path", {
Expand Down Expand Up @@ -471,6 +473,8 @@ foobar.irrespective("dontmatchthis", function() {
// $httpProvider
$httpProvider.interceptors.push(function($scope) { a });
$httpProvider.responseInterceptors.push(function($scope) { a }, function(a, b) { b }, function() { c });
$httpProvider.interceptors.unshift(function($scope) { a });
$httpProvider.responseInterceptors.unshift(function($scope) { a }, function(a, b) { b }, function() { c });

// $routeProvider
$routeProvider.when("path", {
Expand Down

0 comments on commit 9ab58e7

Please sign in to comment.