flow icon indicating copy to clipboard operation
flow copied to clipboard

ES2015 & 2016 Features meta-issue

Open samwgoldman opened this issue 11 years ago • 56 comments

Feel free to open an issue for any unchecked feature that doesn't already have one, but please try to keep discussion in a single issue if possible. Use cases (and test cases) are very welcome!

To report a bug with a completed feature, please open a new issue for the bug.

ES2015+

  • [x] let/const declarations (#784)
  • [x] Regular expression u flag (#2510)
  • [x] Regular expression y flag
  • [x] Binary literals (#566)
  • [x] New octal literals (#566)
  • [x] Arrow functions
  • [x] Default parameters (mostly supported, except using this: #1234)
  • [x] Rest parameters
  • [x] Spread operator
  • [x] super references
  • [x] Classes
  • [x] for-of loops
  • [x] Generators (#534)
  • [x] Object literal property shorthand
  • [x] Object literal method shorthand
  • [ ] Object literal computed properties (#252)
  • [x] Template strings
  • [x] Tagged templates
  • [ ] Tagged template fn strings param has a raw prop
  • [ ] Tagged template fn strings and raw arrays are frozen
  • [x] Destructuring
  • [x] Default values in destructuring (#183)
  • [ ] Unicode code point escapes
  • [x] Allow duplicate object literal properties (except proto)
  • [x] Modules
  • [x] new.target (#1152)
  • [ ] Symbols (#810, #1015)
  • [x] export Foo from 'foo' (#2403)
  • [x] object spread
  • [x] async/await
  • [x] async iterators (#1824)
  • [ ] Shared memory and atomics (#7811)
  • [ ] String.prototype.matchAll (#7812)
  • [ ] Promise.allSettled
  • [ ] Lifting template literal restriction

Proposals

Stage 4

Stage 3

Stage 2

Stage 1

Stage 0

samwgoldman avatar Jun 24 '15 02:06 samwgoldman

this is super useful!

there are probably a bunch of new APIs that we need to add, too. for example, I just noticed that we don't have String.prototype.codePointAt (part of new unicode stuff)

mroch avatar Jun 25 '15 23:06 mroch

Perhaps, add an ES7 section and mark async-await as done.

(BTW, I find it surprising that async-await is done before generators!)

nmn avatar Jun 29 '15 11:06 nmn

It seems there is an issue with ES6 Class support. I am using atom/nuclide IDE and having the following code:

export default class Resource {
  constructor(req:string) {
    this.req = req * 2;
  }
}

assignment of property req Property req not found in Resource even though I am defining it here in the constructor.

Globegitter avatar Jul 18 '15 13:07 Globegitter

@Globegitter, Flow wants you to declare class properties like so:

export default class Resource {
  req: number;
  constructor(req: number) {
    this.req = req * 2;
  }
}

Why do we require this? Well, if we don't make people declare properties then we can't detect things like

function getReq(resource: Resource): number {
  return resource.rep;
}

We do realize this is a little bit more work for the developer, but we're hoping the benefits outweigh the pain.

gabelevi avatar Jul 19 '15 21:07 gabelevi

Aahh, I see, thanks @gabelevi For know I mostly want to use flow for its type inference with /* @flow weak */. The issue here is that I can not just put req; res; at the top, it does throw an 'Unexpected token;` issue.

Generally I do think this is an acceptable extra-effort, but why can flow not just get the information from the constructor itself? Is it that much more complex to see what this.req is assigned to and then look up the type in the constructor's parameter list?

As a side note kind of fitting to this, it would be great to see property initialiser support as mentioned here: http://babeljs.io/blog/2015/06/07/react-on-es6-plus/

Globegitter avatar Jul 20 '15 14:07 Globegitter

I think at the moment that Flow requires type annotations for the class member properties you declare. So

req: any; res: any;

should work. I did recently change the parsing of that (https://github.com/facebook/flow/commit/7e5b2a9a4bed89d97b5961b27d92a405f98f7b65) in preparation for class property initializers. We absolutely are planning support for class property initializers. They solve so many problems! The one I hate the most is how you have to do

class Foo {
  constructor() {
    this.myCallBack = this.myCallBack.bind(this);
  }
  myCallBack() { ... }
}

but with class property initializers you can do

class Foo {
  myCallBack = () => { ... }
}

gabelevi avatar Jul 20 '15 14:07 gabelevi

Thanks for the quick response that all sounds good :) And yep it really does solve a lot of issues.

Globegitter avatar Jul 20 '15 14:07 Globegitter

Generally I do think this is an acceptable extra-effort, but why can flow not just get the information from the constructor itself? Is it that much more complex to see what this.req is assigned to and then look up the type in the constructor's parameter list?

@Globegitter, good insight! Actually, flow used to do this, but the functionality was removed. I'm not sure about the details surrounding this, but there is some explanation in a comment in the source code.

Unfortunately, this change was from the days of "sync to upstream" so the diff is big and it's hard to see the implications in terms of the code changes themselves.

samwgoldman avatar Jul 20 '15 17:07 samwgoldman

image

^ What happened with let support?

I think it'd help if this was taken care of if only because at a glance it makes the whole project seem to be behind. For example it's being used as a con on this list, which happens to be a top result for googling "flow vs TypeScript"

image http://www.reddit.com/r/javascript/comments/39cere/typescript_vs_flow_results_from_our_investigation/

Also in this comment: image http://www.reddit.com/r/javascript/comments/39cere/typescript_vs_flow_results_from_our_investigation/ct6xagb

Flow looks really promising, keep up the great work!

oztune avatar Jul 28 '15 17:07 oztune

What happened with let support?

We're actively working on it. Please be patient.

samwgoldman avatar Jul 28 '15 17:07 samwgoldman

@oztune by all means use my fork in the mean time: github.com/nmn/flow

  • Up to date with flow itself
  • Let/const support added by making flow treat them like var. (if you use Babel, the block scoping and const checking is already done for you)

nmn avatar Jul 28 '15 21:07 nmn

classes are checked, but class property initializers are not supported: can we have a check box for that? Making it hard for me to swallow ES6 classes right now.

An alternative approach to much of this work is to leverage babel more

gregwebs avatar Aug 29 '15 23:08 gregwebs

@gregwebs class property initializers are not ES6/ES2015, but it's definitely on our radar. I think, instead of creating a separate meta issue for ES2016 features, we should just track that here. I'll make the necessary changes.

samwgoldman avatar Aug 29 '15 23:08 samwgoldman

Ah, in that case I will take any hack I can get. Seems to work to put this in the constructor:

      // fix broken es6 classes
      _.each(Object.getOwnPropertyNames( Object.getPrototypeOf(this) ), prop => {
        this[prop] = this[prop].bind(this)
      })

gregwebs avatar Aug 30 '15 01:08 gregwebs

@samwgoldman I think it would make sense to update #431 to #784 given that's where the ongoing work is now.

Gozala avatar Sep 11 '15 22:09 Gozala

@Gozala You're right! Thanks & done.

samwgoldman avatar Sep 11 '15 22:09 samwgoldman

I'd vote for adding export extensions to the ES2016 list. (Not sure if they're supported?)

cesarandreu avatar Sep 11 '15 23:09 cesarandreu

Is there an maintained list of the various proposals, along with the stage? Official would be ideal, but anything would help.

samwgoldman avatar Sep 11 '15 23:09 samwgoldman

@samwgoldman there's a list of the ones that are available in babel.

cesarandreu avatar Sep 11 '15 23:09 cesarandreu

@samwgoldman Here is the official list: https://github.com/tc39/ecma262

BenoitZugmeyer avatar Sep 12 '15 00:09 BenoitZugmeyer