MatAtBread / fast-async

603 stars 21 forks source link

I think fast-async and rest-spread is not incompatible #6

Closed coudly closed 8 years ago

coudly commented 8 years ago

I think fast-async and rest spread is not incompatible the error sample :

origin es file

(props) => {
  let { ...others } = props
}

babel options

module.exports = {
  "presets": [ "es2015", "stage-2" ],
  "plugins": [
     [require("fast-async"), { runtimePattern: 'directive' }]
  ]
}

exception stack info

"TypeError: Cannot read property 'name' of undefined
    at fast-async\node_modules\nodent\lib\arboriculture.js:2004:63
    at Array.map (native)
    at getDeclNames (fast-async\node_modules\nodent\lib\arboriculture.js:2004:34)
    at fast-async\node_modules\nodent\lib\arboriculture.js:2050:29
    at treeWalker (fast-async\node_modules\nodent\lib\parser.js:156:5)
    at goDown (fast-async\node_modules\nodent\lib\parser.js:122:9)
    at down (fast-async\node_modules\nodent\lib\parser.js:146:25)
    at Object.__dirname.1.base.Function (fast-async\node_modules\nodent\node_modules\acorn\dist\walk.js:269:4)
    at down (fast-async\node_modules\nodent\lib\parser.js:133:60)
    at Object.__dirname.1.base.FunctionDeclaration (fast-async\node_modules\nodent\node_modules\acorn\dist\walk.js:253:10)"
coudly commented 8 years ago

1

debug screenshot

matAtWork commented 8 years ago

Thanks - I'll take a look

matAtWork commented 8 years ago

It appears that this is not valid ES6 - see https://github.com/ternjs/acorn/issues/388 - Object rest is a babel extension. I'll see if I can patch it up, however support for non-ES6 constructs is not guaranteed as they may change in the future.

matAtWork commented 8 years ago

This should be fixed in https://github.com/MatAtBread/fast-async/releases/tag/6.0.30

Please re-open if you this doesn't fix your issues. Thanks for reporting it.

mikekasprzak commented 6 years ago

Best I can tell this only implements Rest. i.e.

let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };

not Spread

let n = { x, y, ...z };

I haven't done the most thorough testing, but our toolchain is choking on nodents ability to parse spread.

matAtWork commented 6 years ago

[IGNORE THIS - SEE BELOW] This appears to be a bug in Acorn (the parser used by fast-async/nodent). Acorn adheres strictly to the ECMA spec, and I believe this is an extension - it fails in Babel as well unless you enable the objectRestSpread option (see astexplorer.net), as well as in Esprima, Shift, recast and Traceur.

The current ECMA standard permits the Spread operator in array literals, not object literals.

If you think this is part of the ECMA standard, please post an issue with Acorn I will look into a fix when it has been updated: https://github.com/ternjs/acorn/issues

matAtWork commented 6 years ago

...actually, this should work with fast-async (rather than nodent), as it uses Babylon (from Babel) as the parser, not acorn. I'll see if I can work out what it's doing in the next few days