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
241 stars 26 forks source link

$inject is not added on exported class when transforming to ES5 #35

Open sarod opened 6 years ago

sarod commented 6 years ago

When using the following code angularjs-annotate fails to annotate the class if the class is transpiled to ES5

/*@ngInject*/
export class Broken {
    constructor($q) {

    }  
}box chec

The problem can be reproduced on the demo page https://schmod.github.io/babel-plugin-angularjs-annotate/ with the transform checkbox checked

Note that this works fine if the class is not exported.

I found several alternative placement of the @ngInject that work.

export /*@ngInject*/ class Ok {
    constructor($q) {

    }  
}

export class Ok2 {
  /*@ngInject*/ 
  constructor($q) {

    }  
}

It 1 also works if I use an alias for export

/* @ngInject */
class MyControllerInternal {
  constructor($q) {}
}

export const MyController = MyControllerInternal;
superted17 commented 6 years ago

@sarod thanks for posting your findings. I've got the same issue, and your suggestion to use /@ngInject/ before the constructor sort of worked for me.

This got the plugin to actually run, but the place that it inserts the $inject statement wasn't right and caused problems at runtime.

I'll see if I can add some failing unit tests...