olov / ng-annotate

Add, remove and rebuild AngularJS dependency injection annotations
MIT License
2.03k stars 152 forks source link

Different behavior on define(function(require)) files. #228

Closed johnib closed 8 years ago

johnib commented 8 years ago

Hello,

I have two files of the form;

Jonathans-MacBook-Air:app johni$ cat test.js 
define(function (require) {
    return function AggTypeService(Private) {
    “ngInject”;
        var IndexedArray = require('utils/indexed_array/index’);
    };
});
Jonathans-MacBook-Air:app johni$ ng-annotate -a test.js 
define(function (require) {
    return ["Private", function AggTypeService(Private) {
    “ngInject”;
        var IndexedArray = require('utils/indexed_array/index’);
    }];
});
Jonathans-MacBook-Air:app johni$ 

and:

Jonathans-MacBook-Air:app johni$ cat ideasHomeController.js 
define(function () {
    function ideasHomeController($scope, ideasDataSvc) {
        “ngInject”;
        $scope.ideaName = "Todo List”;
    }

    return ideasHomeController;
});
Jonathans-MacBook-Air:app johni$ ng-annotate -a ideasHomeController.js 
define(function () {
    ideasHomeController.$inject = ["$scope", "ideasDataSvc”];
    function ideasHomeController($scope, ideasDataSvc) {
        “ngInject”;
        $scope.ideaName = "Todo List”;
    }

    return ideasHomeController;
});
Jonathans-MacBook-Air:app johni$ 

What’s the difference between the two files that makes the annotate syntax different? I would like to have the second syntax on the first file. What am I missing?

Thanks a lot .

olov commented 8 years ago

The first example use a function expression, the second a function declaration. So change the first example to

function AggTypeService(Private) { “ngInject”; ... }
return AggTypeService;

if you prefer that annotation form.