sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.59k stars 211 forks source link

breaks code that uses async or await #647

Open gkovacs opened 7 years ago

gkovacs commented 7 years ago

I'm running the master branch, at commit https://github.com/sweet-js/sweet.js/commit/62a63cd09762f9ab9b3a89147d882344dad8d1f5 With the following code:

async function a() {
  var x = await foo();
}

I get the following error

geza@gezamac ~> sjs --no-babel ~/test3.js
/usr/local/lib/node_modules/sweet.js/node_modules/babel-core/lib/transformation/file/index.js:590
      throw err;
      ^

SyntaxError: unknown: await is a reserved word (3:12)
  1 | async;
  2 | function a() {
> 3 |   var x_0 = await;
    |             ^
  4 |   foo();
  5 | }
  6 |
    at Parser.pp$5.raise (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:4373:13)
    at Parser.pp$3.checkReservedWord (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:4266:10)
    at Parser.pp$3.parseIdentifier (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:4243:10)
    at Parser.pp$3.parseExprAtom (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:3581:21)
    at Parser.pp$3.parseExprSubscripts (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:3427:19)
    at Parser.pp$3.parseMaybeUnary (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:3407:19)
    at Parser.pp$3.parseExprOps (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:3337:19)
    at Parser.pp$3.parseMaybeConditional (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:3314:19)
    at Parser.pp$3.parseMaybeAssign (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:3277:19)
    at Parser.pp$1.parseVar (/usr/local/lib/node_modules/sweet.js/node_modules/babylon/lib/index.js:2295:24)

Result is same if I don't use the --no-babel option

gabejohnson commented 7 years ago

The reader and enforester don't currently handle async and await.

@disnet we'll have to update sweet-spec, and tokens, enforester, etc. and the version of shift-codegen I think.

disnet commented 7 years ago

shift doesn't have es2017 (async/await) support just yet so we're blocked on that. I hear it's being prioritized soon though.