Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`async` syntax causes `Parsing error: Unexpected token` #602

Closed
zeke opened this issue Aug 20, 2016 · 8 comments

Comments

@zeke
Copy link
Contributor

commented Aug 20, 2016

This test passes, and babel doesn't seem to have a problem with it:

const {test} = require('ava')

test('bar', async t => {
  const bar = Promise.resolve('bar')
  t.is(await bar, 'bar')
})

but standard doesn't like it:

standard: Use JavaScript Standard Style (http://standardjs.com) Try `standard --fix` to automatically fix problems.
  /Users/zeke/zeke/repos-using-electron/test/index.js:3:19: Parsing error: Unexpected token t
❯ ./node_modules/.bin/standard --version
8.0.0-beta.5
@feross

This comment has been minimized.

Copy link
Member

commented Aug 20, 2016

@zeke I think you may have accidentally run a global version of standard. Can you check if standard --version is an older version?

@feross feross added the question label Aug 20, 2016

@sotojuan

This comment has been minimized.

Copy link

commented Aug 20, 2016

Try doing this.

npm install --save-dev babel-eslint

Then in package.json:

 "standard": {
  "parser": "babel-eslint"
}

I'm on the AVA team and this has happened to me many times 😅

@zeke

This comment has been minimized.

Copy link
Contributor Author

commented Aug 20, 2016

I'm running the local version, 8.0.0-beta.5

❯ ./node_modules/.bin/standard          
standard: Use JavaScript Standard Style (http://standardjs.com)
  /Users/zeke/zeke/repos-using-electron/test/index.js:3:19: Parsing error: Unexpected token t

❯ ./node_modules/.bin/standard --version
8.0.0-beta.5

❯ cat test/index.js                     
const {test} = require('ava')

test('bar', async t => {
  const bar = Promise.resolve('bar')
  t.is(await bar, 'bar')
})
@feross

This comment has been minimized.

Copy link
Member

commented Aug 21, 2016

@zeke Try following @sotojuan's advice in an earlier comment.

You need to specify babel-eslint as your eslint parser if you want to use the async syntax. Once you do that, it'll work!

$ ./node_modules/.bin/standard --version
8.0.0-beta.5

$./node_modules/.bin/standard t.js
standard: Use JavaScript Standard Style (http://standardjs.com)
  /Users/feross/code/test/t.js:3:19: Parsing error: Unexpected token t

$ npm install babel-eslint
...

$ ./node_modules/.bin/standard --parser babel-eslint t.js

Though it's easier to use the package.json method to specifying the parser, IMO.

@feross feross closed this Aug 21, 2016

@zeke

This comment has been minimized.

Copy link
Contributor Author

commented Aug 21, 2016

Thank you @sotojuan and @feross

@timdp

This comment has been minimized.

Copy link

commented Sep 28, 2016

@feross Per your recent tweet, isn't async supported out of the box with standard@8.2.0? I'm still getting errors.

@feross

This comment has been minimized.

Copy link
Member

commented Sep 29, 2016

@timdp See this issue (#645)

The last release (8.2.0) added ES7 support, but async actually is part of the ES8 spec. Fortunately, we just enabled ES8 support in 8.3.0 -- released just a couple minutes ago.

Give standard 8.3.0 a shot -- should work really nicely, without the need for babel-eslint!

@timdp

This comment has been minimized.

Copy link

commented Sep 30, 2016

@feross That's awesome, thanks!

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants
You can’t perform that action at this time.