schmod / babel-plugin-angularjs-annotate

Add Angular 1.x dependency injection annotations to ES6 code
http://schmod.github.io/babel-plugin-angularjs-annotate
MIT License
240 stars 29 forks source link

Annotation doesn't work for a controller with name as a variable #19

Open EladBezalel opened 7 years ago

EladBezalel commented 7 years ago

And probably with any other .module api

I use webpack and angular

import angular from 'angular';

const MY_CONTROLLER = 'myController';

angular.module('myApp').controller(MY_CONTROLLER, $scope => {});

export default MY_CONTROLLER;
schmod commented 7 years ago

There's some history here about why this is difficult: https://github.com/olov/ng-annotate/issues/22

In general, in this use-case (and all use-cases, really), I strongly recommend using the explicit 'ngInject'; prologue directives (and explicitOnly configuration option) to annotate your functions.

Also, in your specific example, I'd advise against using a lambda function for a controller declaration, as you'll have no way of accessing your controller's of this.

I'll leave this open, as it's something that we could hypothetically support some day. However, I want to lean on the side of caution when making any changes that could introduce false-positives.