Fuco1 / flow-js2-mode

[UNMAINTAINED] Support for flow for js2-mode
GNU General Public License v3.0
46 stars 3 forks source link

Return type on arrow functions not working #15

Open strayer opened 6 years ago

strayer commented 6 years ago

It seems like this code is not working properly:

function func1(n: number): boolean {
  if (n > 1) {
    return true;
  } else {
    return false;
  }
}

const func2 = (n: number): boolean => {
  if (n > 2) {
    return true;
  } else {
    return false;
  }
};

The reported error is missing ; before statement.

grafik

Fuco1 commented 6 years ago

Thanks for the report!

I think I've run into something similar when annotating function types in signatures and I wasn't able to fix it there. I'm afraid this might be similar but I'll have a look.

The way I approach this now is really hackish in that it "overrides" some of the internal js2 methods but at times there is no good extension point for that.

I would like to participate in the js2-mode project a bit more and refactor it such that modes like this have easier time extending the syntax.

strayer commented 6 years ago

Hey, thanks for looking into it! Too bad, arrow functions with return types are very common in our React Native projects :( I won't be able to help with this in code, sadly – while I know functional programming, emacs and elisp are still very new to me. If I can somehow help, please reach out to me!