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

ngInject does not work on direct export #24

Closed clemgrim closed 7 years ago

clemgrim commented 7 years ago

Hello,

ngInject does not work when exporting a class, it worked with ng-annotate.

/* @ngInject */
class A {
    constructor(test){
      this.test = test;
    }
}

This works.

/* @ngInject */
export class A {
    constructor(test){
      this.test = test;
    }
}

This doesn't.

/* @ngInject */
class A {
    constructor(test){
      this.test = test;
    }
}

export {A};

This does.

schmod commented 7 years ago

Interesting.

While I look into this, there are a few workarounds you can use:

export class A {
    /* @ngInject */
    constructor(test){
      this.test = test;
    }
}

and

export class A {
    constructor(test){
      'ngInject';
      this.test = test;
    }
}

will both work.

In general, the second syntax (prologue directives) is going to be more reliable, as other tools/transformations should leave these untouched (whereas comments are frequently moved around or mangled by other transformations).

schmod commented 7 years ago

fixed in 0.8.0