Support ES7 async/await proposal #1657

Closed
gaearon opened this Issue Jan 15, 2015 · 36 comments

Comments

Projects
None yet
@gaearon

gaearon commented Jan 15, 2015

I'm talking about https://github.com/lukehoban/ecmascript-asyncawait. It's an accepted proposal for ES7.

Because https://github.com/6to5/6to5 can already compile these, it would be nice to have support for it behind a flag.

I wouldn't file issues for other ES7 features yet but this one is a game changer. It spoiled me as a C# developer a few years ago and I can't wait to start using it again.

(Yes I understand this can be done with yield. Bear with me!)

@lo1tuma

This comment has been minimized.

Show comment
Hide comment
@lo1tuma

lo1tuma Jan 15, 2015

Member

Duplicate oft #1566

Member

lo1tuma commented Jan 15, 2015

Duplicate oft #1566

@gaearon

This comment has been minimized.

Show comment
Hide comment
@gaearon

gaearon Jan 15, 2015

Whoops, pardon. Anywhere I can read why ES7 is no go?

gaearon commented Jan 15, 2015

Whoops, pardon. Anywhere I can read why ES7 is no go?

@gaearon gaearon closed this Jan 15, 2015

@nzakas

This comment has been minimized.

Show comment
Hide comment
@nzakas

nzakas Jan 15, 2015

Member

This really comes down to what the parser supports. I do think it's a bit early to lock anything in since the spec hasn't yet been finalized (or started, really). But if Espree adds experimental support then we can also experiment with it.

I think this will be a common enough ask that we should at least investigate once all ES6 stuff is done.

Member

nzakas commented Jan 15, 2015

This really comes down to what the parser supports. I do think it's a bit early to lock anything in since the spec hasn't yet been finalized (or started, really). But if Espree adds experimental support then we can also experiment with it.

I think this will be a common enough ask that we should at least investigate once all ES6 stuff is done.

@nzakas nzakas reopened this Jan 15, 2015

@gaearon

This comment has been minimized.

Show comment
Hide comment
@gaearon

gaearon Jan 15, 2015

Thanks. Parser level support is all I'm asking for. I'm not advocating linting rules around it.

gaearon commented Jan 15, 2015

Thanks. Parser level support is all I'm asking for. I'm not advocating linting rules around it.

@dfreeman

This comment has been minimized.

Show comment
Hide comment
@dfreeman

dfreeman Feb 10, 2015

For what it's worth, we'd love to see this as well once the rest of the ES6 stuff lands.

We're currently using a utility wrapper with generators to accomplish the same thing, but most of the rest of our toolchain is picking up support for the first class async/await syntax, so it would be fantastic to see ESLint/Espree accept it too.

For what it's worth, we'd love to see this as well once the rest of the ES6 stuff lands.

We're currently using a utility wrapper with generators to accomplish the same thing, but most of the rest of our toolchain is picking up support for the first class async/await syntax, so it would be fantastic to see ESLint/Espree accept it too.

@nzakas

This comment has been minimized.

Show comment
Hide comment
@nzakas

nzakas Feb 10, 2015

Member

If you want it, consider adding support to Espree: https://github.com/eslint/espree.

We will get to it, but it's low priority for the core team based on getting the rest of ES6 done. You can make it go faster by contributing. :)

Member

nzakas commented Feb 10, 2015

If you want it, consider adding support to Espree: https://github.com/eslint/espree.

We will get to it, but it's low priority for the core team based on getting the rest of ES6 done. You can make it go faster by contributing. :)

@nzakas

This comment has been minimized.

Show comment
Hide comment
@nzakas

nzakas Mar 6, 2015

Member

Given the recent developments in the world of parsers, I think that using babel-eslint is the best way to play with cutting edge features like this. https://github.com/babel/babel-eslint

That means you don't have to wait for us, and we don't need to worry about constantly updating experimental features.

Member

nzakas commented Mar 6, 2015

Given the recent developments in the world of parsers, I think that using babel-eslint is the best way to play with cutting edge features like this. https://github.com/babel/babel-eslint

That means you don't have to wait for us, and we don't need to worry about constantly updating experimental features.

@nzakas nzakas closed this Mar 6, 2015

@gaearon

This comment has been minimized.

Show comment
Hide comment

gaearon commented Mar 6, 2015

👍

@pesho pesho referenced this issue in AtomLinter/linter-eslint Mar 6, 2015

Closed

Use of `babel-eslint` #35

@mr-wildcard mr-wildcard referenced this issue in react-webpack-generators/generator-react-webpack Dec 2, 2015

Closed

Use babel-eslint as parser ? #173

@Pike Pike referenced this issue in c9/core Dec 29, 2015

Closed

ES7 async/await support for c9? #230

@Turbo87

This comment has been minimized.

Show comment
Hide comment
@Turbo87

Turbo87 Aug 15, 2016

@nzakas since async/await has progressed to stage 4 would it make sense to reopen this issue?

Turbo87 commented Aug 15, 2016

@nzakas since async/await has progressed to stage 4 would it make sense to reopen this issue?

@btmills

This comment has been minimized.

Show comment
Hide comment
@btmills

btmills Aug 16, 2016

Member

@Turbo87 we're working on supporting async/await in the parser - you can follow eslint/espree#287 for updates!

Member

btmills commented Aug 16, 2016

@Turbo87 we're working on supporting async/await in the parser - you can follow eslint/espree#287 for updates!

@Turbo87

This comment has been minimized.

Show comment
Hide comment
@Turbo87

Turbo87 Aug 16, 2016

Awesome thanks! I guess that will only be supported in babel 3 then, correct?

Turbo87 commented Aug 16, 2016

Awesome thanks! I guess that will only be supported in babel 3 then, correct?

@btmills

This comment has been minimized.

Show comment
Hide comment
@btmills

btmills Aug 16, 2016

Member

@Turbo87 I don't fully understand the question.... Once we've had time to implement support for the new features, you should be able to use ESLint and the default Espree parser by themselves (without needing the babel-eslint parser) for async/await and any of the other stage 4 proposals. Whether you need the babel compiler will depend on the features supported by the JS engine(s) you're targeting.

Member

btmills commented Aug 16, 2016

@Turbo87 I don't fully understand the question.... Once we've had time to implement support for the new features, you should be able to use ESLint and the default Espree parser by themselves (without needing the babel-eslint parser) for async/await and any of the other stage 4 proposals. Whether you need the babel compiler will depend on the features supported by the JS engine(s) you're targeting.

@Turbo87

This comment has been minimized.

Show comment
Hide comment
@Turbo87

Turbo87 Aug 16, 2016

Sorry, I meant eslint 3 😆

Turbo87 commented Aug 16, 2016

Sorry, I meant eslint 3 😆

@btmills

This comment has been minimized.

Show comment
Hide comment
@btmills

btmills Aug 16, 2016

Member

Ah! Yes, that should be coming to ESLint v3.something once it's ready.

Member

btmills commented Aug 16, 2016

Ah! Yes, that should be coming to ESLint v3.something once it's ready.

@iroy2000

This comment has been minimized.

Show comment
Hide comment
@iroy2000

iroy2000 Oct 7, 2016

I'm on "eslint": "^3.2.2"

Is that async await rule support already in place ?

iroy2000 commented Oct 7, 2016

I'm on "eslint": "^3.2.2"

Is that async await rule support already in place ?

@platinumazure

This comment has been minimized.

Show comment
Hide comment
@platinumazure

platinumazure Oct 7, 2016

Member

@iroy2000 You need to upgrade to eslint@3.6.0 or later to use async/await rule support.

Member

platinumazure commented Oct 7, 2016

@iroy2000 You need to upgrade to eslint@3.6.0 or later to use async/await rule support.

@iroy2000

This comment has been minimized.

Show comment
Hide comment
@iroy2000

iroy2000 Oct 7, 2016

👍 Thanks

iroy2000 commented Oct 7, 2016

👍 Thanks

@MarkHerhold

This comment has been minimized.

Show comment
Hide comment
@MarkHerhold

MarkHerhold Oct 9, 2016

What's the rule to enable async/await? I'm getting unexpected token function when doing:

async function create() {
}

What's the rule to enable async/await? I'm getting unexpected token function when doing:

async function create() {
}
@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Oct 9, 2016

Contributor

@MarkHerhold set your ecmaVersion to 2017.

Contributor

ljharb commented Oct 9, 2016

@MarkHerhold set your ecmaVersion to 2017.

@platinumazure

This comment has been minimized.

Show comment
Hide comment
@platinumazure

platinumazure Oct 9, 2016

Member

@MarkHerhold You need to set ecmaVersion to 8 under parserOptions in configuration, or do the equivalent in CLI.

Configuration (JSON):

{
    "parserOptions": {
        "ecmaVersion": 8 // or 2017
    },
    "rules": {}
    }
}

Via CLI:

eslint --parser-options="ecmaVersion:8"
Member

platinumazure commented Oct 9, 2016

@MarkHerhold You need to set ecmaVersion to 8 under parserOptions in configuration, or do the equivalent in CLI.

Configuration (JSON):

{
    "parserOptions": {
        "ecmaVersion": 8 // or 2017
    },
    "rules": {}
    }
}

Via CLI:

eslint --parser-options="ecmaVersion:8"
@MarkHerhold

This comment has been minimized.

Show comment
Hide comment
@MarkHerhold

MarkHerhold Oct 9, 2016

@platinumazure That worked, thanks!

@platinumazure That worked, thanks!

@oshalygin

This comment has been minimized.

Show comment
Hide comment
@oshalygin

oshalygin Feb 14, 2017

I get that ESLint supports ecmaVersion 8 and 2017, but is that the right thing to do? Should it just be 2017?

Wildly confusing especially considering the convention is the year.

oshalygin commented Feb 14, 2017

I get that ESLint supports ecmaVersion 8 and 2017, but is that the right thing to do? Should it just be 2017?

Wildly confusing especially considering the convention is the year.

@not-an-aardvark

This comment has been minimized.

Show comment
Hide comment
@not-an-aardvark

not-an-aardvark Feb 14, 2017

Member

@oshalygin It supports both.

Member

not-an-aardvark commented Feb 14, 2017

@oshalygin It supports both.

@oshalygin

This comment has been minimized.

Show comment
Hide comment
@oshalygin

oshalygin Feb 14, 2017

@not-an-aardvark sorry I just edited, I get that it does, I'm just wondering if its proper for ESLint to support both versions, since the canonical version is 2017.

I'm sure you guys discussed this in another thread, any chance you can reference it so I can read a little more about that decision?

@not-an-aardvark sorry I just edited, I get that it does, I'm just wondering if its proper for ESLint to support both versions, since the canonical version is 2017.

I'm sure you guys discussed this in another thread, any chance you can reference it so I can read a little more about that decision?

@not-an-aardvark

This comment has been minimized.

Show comment
Hide comment
Member

not-an-aardvark commented Feb 14, 2017

See #6750

@oshalygin

This comment has been minimized.

Show comment
Hide comment

@dferber90 dferber90 referenced this issue in dferber90/eslint-plugin-meteor Mar 20, 2017

Closed

Async arrow functions #468

@dcsan

This comment has been minimized.

Show comment
Hide comment
@dcsan

dcsan Mar 29, 2017

trying to use this with node 7.7 where we use await a lot.
I still get an error with the above settings

.eslintrc.json is as below. I also tried "ecmaVersion": 2017 | 7 | 8


  "parserOptions": {
    "ecmaVersion": 2017,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },

12:23 error Parsing error: The keyword 'await' is reserved

image

➜ stt git:(master) ✗ node node_modules/eslint/bin/eslint.js -v
v3.18.0

are there some other ecmaFeatures flags needed?

dcsan commented Mar 29, 2017

trying to use this with node 7.7 where we use await a lot.
I still get an error with the above settings

.eslintrc.json is as below. I also tried "ecmaVersion": 2017 | 7 | 8


  "parserOptions": {
    "ecmaVersion": 2017,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },

12:23 error Parsing error: The keyword 'await' is reserved

image

➜ stt git:(master) ✗ node node_modules/eslint/bin/eslint.js -v
v3.18.0

are there some other ecmaFeatures flags needed?

@not-an-aardvark

This comment has been minimized.

Show comment
Hide comment
@not-an-aardvark

not-an-aardvark Mar 29, 2017

Member

Your syntax is invalid -- await can only be used in an async function.

You should replace your code with

decode: async function(opts) {
  const mp3Stream = await (msg).readyStream()
  // ...
}
Member

not-an-aardvark commented Mar 29, 2017

Your syntax is invalid -- await can only be used in an async function.

You should replace your code with

decode: async function(opts) {
  const mp3Stream = await (msg).readyStream()
  // ...
}
@dcsan

This comment has been minimized.

Show comment
Hide comment
@dcsan

dcsan Mar 29, 2017

thanks, however this also errors:

async function stt(opts) {
  debug("stt", opts)
  return("done")
}

12:7 error Parsing error: Unexpected token function

maybe because top level functions also need to be inside an async block themselves?
but at some point there has to be a top level in a file?

dcsan commented Mar 29, 2017

thanks, however this also errors:

async function stt(opts) {
  debug("stt", opts)
  return("done")
}

12:7 error Parsing error: Unexpected token function

maybe because top level functions also need to be inside an async block themselves?
but at some point there has to be a top level in a file?

@not-an-aardvark

This comment has been minimized.

Show comment
Hide comment
@not-an-aardvark

not-an-aardvark Mar 29, 2017

Member

That code parses fine for me. If you're still having trouble, please ask for help on our gitter channel.

Member

not-an-aardvark commented Mar 29, 2017

That code parses fine for me. If you're still having trouble, please ask for help on our gitter channel.

@BlueRaja

This comment has been minimized.

Show comment
Hide comment
@BlueRaja

BlueRaja Mar 30, 2017

return async () => ...
return async function () { ... }

Both of these cause eslint errors in the latest version

return async () => ...
return async function () { ... }

Both of these cause eslint errors in the latest version

@not-an-aardvark

This comment has been minimized.

Show comment
Hide comment
@not-an-aardvark

not-an-aardvark Mar 30, 2017

Member

You need to specify ecmaVersion: 8 in a config file to enable async function parsing. For more details, please read our configuration docs.

Member

not-an-aardvark commented Mar 30, 2017

You need to specify ecmaVersion: 8 in a config file to enable async function parsing. For more details, please read our configuration docs.

@platinumazure

This comment has been minimized.

Show comment
Hide comment
@platinumazure

platinumazure Mar 30, 2017

Member
Member

platinumazure commented Mar 30, 2017

@not-an-aardvark

This comment has been minimized.

Show comment
Hide comment
@not-an-aardvark

not-an-aardvark Mar 30, 2017

Member

I was unable to reproduce the issues. All of the following parse without errors:

require('espree').parse(`async function stt(opts) {
  debug("stt", opts)
  return("done")
}`, { ecmaVersion: 8 });

require('espree').parse('return async () => foo', { ecmaVersion: 8, ecmaFeatures: { globalReturn: true } });

require('espree').parse('return async function() { foo }', { ecmaVersion: 8, ecmaFeatures: { globalReturn: true } })
Member

not-an-aardvark commented Mar 30, 2017

I was unable to reproduce the issues. All of the following parse without errors:

require('espree').parse(`async function stt(opts) {
  debug("stt", opts)
  return("done")
}`, { ecmaVersion: 8 });

require('espree').parse('return async () => foo', { ecmaVersion: 8, ecmaFeatures: { globalReturn: true } });

require('espree').parse('return async function() { foo }', { ecmaVersion: 8, ecmaFeatures: { globalReturn: true } })
@BlueRaja

This comment has been minimized.

Show comment
Hide comment
@BlueRaja

BlueRaja Mar 30, 2017

@not-an-aardvark Yes I have ecmaVersion: 2017 specified (which is the same as 8), and code like this works fine:

async function blah() { 
  await whatever();
  ...
}

However the following fails with the error error Parsing error: Unexpected token function:

describe('Some Mocha Test', () => {
  let target, context, exampleGame;
  ...
  const checkAttributes = function (callback) {
    return async function () { // Error here
      return callback(await target.getAttributesAsync(exampleGame, context));
    };
  };
}

and the following fails with the error error Parsing error: Unexpected token =>

describe('Another Mocha Test', () => {
  let target, exampleSku;
  ...
  it('does something', async () => // Error here
    assert.equal(await target.getAttributesAsync(exampleSku), exampleSku));
});

I'm running node v7.7.3 and eslint v3.18.0

BlueRaja commented Mar 30, 2017

@not-an-aardvark Yes I have ecmaVersion: 2017 specified (which is the same as 8), and code like this works fine:

async function blah() { 
  await whatever();
  ...
}

However the following fails with the error error Parsing error: Unexpected token function:

describe('Some Mocha Test', () => {
  let target, context, exampleGame;
  ...
  const checkAttributes = function (callback) {
    return async function () { // Error here
      return callback(await target.getAttributesAsync(exampleGame, context));
    };
  };
}

and the following fails with the error error Parsing error: Unexpected token =>

describe('Another Mocha Test', () => {
  let target, exampleSku;
  ...
  it('does something', async () => // Error here
    assert.equal(await target.getAttributesAsync(exampleSku), exampleSku));
});

I'm running node v7.7.3 and eslint v3.18.0

@not-an-aardvark

This comment has been minimized.

Show comment
Hide comment
@not-an-aardvark

not-an-aardvark Mar 30, 2017

Member

I can't reproduce this issue, it seems to work fine for me.

If you're still having trouble, can you please fill out our bug report template and create a new issue, or ask on our gitter channel? Filling out the bug report template would make it much easier to help debug your problem.

Member

not-an-aardvark commented Mar 30, 2017

I can't reproduce this issue, it seems to work fine for me.

If you're still having trouble, can you please fill out our bug report template and create a new issue, or ask on our gitter channel? Filling out the bug report template would make it much easier to help debug your problem.

mikermcneil added a commit to balderdashy/sails-generate that referenced this issue May 26, 2017

mikermcneil added a commit to balderdashy/sails-generate that referenced this issue May 26, 2017

@eslint eslint locked and limited conversation to collaborators Feb 7, 2018

@eslint eslint bot added the archived due to age label Feb 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.