Flow: Support for ES6 features

Created on 19 Nov 2014  Â·  55Comments  Â·  Source: facebook/flow

I didn't see an existing issue for this, nor do I see anything on the website about it, but I'm sure you all have plans for this. Looks like there are several ES6 features this doesn't support yet, particularly let:

let x = 5;
/Users/james/projects/mozilla/gecko-dev/toolkit/devtools/server/actors/foo.js:3:1,10: 
Unsupported variable declaration: let

/Users/james/projects/mozilla/gecko-dev/toolkit/devtools/server/actors/foo.js:3:5,5: var x
Unknown global name

I'm interested in using this as a "light" type checker in Firefox. I don't know if we'll ever start adding a lot of type declarations, but this looks like it could be a nice "linter" using the weak mode. (still not sure how far that goes yet, but if it can even catch a few things that would be cool).

Since we can code against SpiderMonkey, we use ES6 a lot, like:

  • let/const
  • for-of
  • short-hand object syntax ({ foo } turns into { foo: foo })
  • generators

That's just off the top of my head. On the file I tried, the main things I hit were let/const and for-of.

feature request

Most helpful comment

@webhipster @meagar and anyone else here, please check out #560.

All 55 comments

short-hand object syntax ({ foo } turns into { foo: foo })

This one is supported :)

/* @flow */
var a = 'a';
var b = {a};
$> flow check
No errors!

Not only that but when I tried to run it on my ES6 repos flow seemed to go into an infinite loop.
I killed it after 15 mins or so but it provided no feedback, I tried shorter runs with --profile and that wasn't so helpful. I guess flow has an npm package resolver that allows it to follow CJS requires, correct?

Add modules to the ES6 list.

/home/brian/dev/global-compiler/src/cjs-require-remover.js: 
Failure("Unimplemented: ExportDeclaration")

ES6 compatibility is an explicit goal. We'll fix let and for-of right away, generators may be a bit longer (but soon).

@briandipalma Hmm, if Flow goes into an infinite loop that's a bug, so providing more information would be helpful (like if you could narrow down to one file that's causing it). We'll put more logging information in the binary to make it useful to do this kind of debugging.

On the other hand, it may be that there's a particularly large file or a file with a lot of reflection in your repo and that's causing Flow's type inference to be ridiculously confused. Again, would be good to know which file.

@avikchaudhuri is support for const also planned?

Sure, we can add that too.

@avikchaudhuri I should have been more clear, but I was also wondering if flow will enforce the const so that this will be an error:

const x = 5;
x = 6; // Error cannot reassign const

Sure, otherwise what's the point? :)

Fantastic :)

On Thu Nov 20 2014 at 10:51:35 AM Avik Chaudhuri [email protected]
wrote:

Sure, otherwise what's the point? :)

—
Reply to this email directly or view it on GitHub
https://github.com/facebook/flow/issues/62#issuecomment-63784426.

fwiw, my vote priority-wise is generators and then let/const. Generators are the biggest thing holding me back from using it. I know it'll get there though!

async\await would be nice also :)

It would be nice to have destructive assignment support too.

function test({prop = 'defaultValue'}) { }

will error

Unexpected token =

I'm using a lot of ES6 features via Traceur. I mainly need flow to support modules (import/export) and arrow functions.

+1 for modules

:+1:
Please do it :)

+1 for import

+1 for modules

+1 for let and const

+1 for async/await. Would love to use flow with 6to5.

+1 for only supporting things that are directly relevant to type checking. Many of the new ES6 keywords have no effect on checking / inference.

Modules please... :-)

+1 for arrow functions

Are +1's helpful? The things that I'm really hoping for are import/export, const/let, and generators.


Edit: It looks like generators are happy now I think. Thanks!

Something that would be helpful here would be a checklist like in https://github.com/eslint/espree/issues/10 so that we can see how close we are.

Also, :sadtrombone:, I had just tested:

var foo = function *() {
  foooooooo()
}

And I didn't get any errors. I hand't tried actually putting in a yield statement yet. Sorry. Generators are still unsupported.

Is there any update on this? The support for es6 modules would be really something to look forward to. Currently a show stopper for me as the whole project here is purely written in es6 using babel

+1 Yes, let, const and modules. Babel+flow is a real alternative of typescript.

+1 for using es6 with flow.

Modules would be very nice. +1

+1 modules

+1 modules

Could we add getter/setter methods to the list?

class MyList<T> {
  list: T[];
  constructor(list: T[]) { this.list = list; }
  get length() { return this.list.length; }
}
new MyList([1,2,3]).length

+1 modules!

:+1: for the modules, is it in the roadmap for the near future?

What @ivanoats said. Can a collaborator please edit the issue description at the top to add a GFM checklist like this, and check things off as they are done?

I keep coming back to this thread to find out if Flow is compatible with my project yet, and a checklist would really help me out!

+1 for a checklist

Checklist would be awesome. +1

Is there a status page on what ES6 features are currently supported? Would be nice to have a quick overview. I keep running into blockers when implementing flow in my ES6 projects.

Edit: Should of read the previous comments. A checklist would be great. :+1:

+1 for generators. Thank you so much for implementing modules!

+1 for stop using this issue thread as a poll of specific unimplemented es6-features, however +1 for a checklist!

+1. looking forward to let/const support

Note that you can get most ES6 feature in Flow right now by running your code through Babel with the flow blacklist. http://www.keendevelopment.ch/flow-babel-gulp-es6/ has a recipe for doing this.

@ccapndave The problem with that, at least in my case, is that Flow can have problems with the generated code from Babel. Eg, for me even using class with a method, eg:

class MyClass {
  func() {}
}

will cause babel to generate code that Flow believes is incorrect. Specifically the _createClass generated line. Have you found a workaround for that? _(and possible other generated code issues)_

@leeola in that case blacklisting es6.classes will solve that issue since Flow understands ES6 classes.

@ccapndave wouldn't that make all your flow errors report incorrect line numbers?

I don't use classes in ES6 so I couldn't say for sure, but I think the sourcemaps will figure it all out. Have a go and let us know!

Thanks for your input, everyone! I'm organizing the existing issues around this and taking @callumlocke's advice to create a checklist. To that end, I'm merging this with #560.

I'm not normally one to complain, but as of flow 0.13.1 I'm still waiting for const/let. I would really love to use flow, but I have a lot of let and const in my project.

Thanks.

@Hector409-hmg Work is being done (or at least was until recently). They're implementing it the "proper" way. If you just want to be able to use let/const, but have flow validate them as var there are instructions in the "Let/const" pr comments: https://github.com/facebook/flow/pull/431#issuecomment-118206002

+1 for let const

+1

+1

+1 for let

@webhipster @meagar and anyone else here, please check out #560.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bradennapier picture bradennapier  Â·  38Comments

MarcoPolo picture MarcoPolo  Â·  67Comments

TylerEich picture TylerEich  Â·  49Comments

xtinec picture xtinec  Â·  65Comments

STRML picture STRML  Â·  48Comments