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

Prettier issues #25

Closed maraisr closed 7 years ago

maraisr commented 7 years ago

Hi, so prettier adds a wrapping bracket to the string ('ngInject') . Which isn't compiling correctly.

class Foo {

  constructor(private $http) {
    ('ngInject');

    this.$http; // undefined
  }
}

TypeScript -> es2017 -> Babel -> es5.

Can you please direct me to the line / file I'll need to edit to make this mod. Could be a root ng-annotate issue?

schmod commented 7 years ago

Hi @maraisr:

I've tried out this code snippet on Prettier's REPL, and (apart from the lack of support for the private keyword), I'm not seeing Prettier adding any parentheses. TypeScript also doesn't seem to have a problem with it.

The 'ngInject'; string used in your example is called a Prologue Directive, and is a part of the ECMAScript language specification. Wrapping parentheses around the string fundamentally changes its meaning to the parser, which is why we're not picking it up.

I'm going to close this issue because whatever variant of Prettier that you're using is going to need to be fixed to properly support prologue directives.