MatAtBread / fast-async

605 stars 21 forks source link

Cannot append Element node to non-array #12

Closed dessaya closed 7 years ago

dessaya commented 7 years ago

Hi, I'm trying to switch from transform-async-to-module-method to fast-async, and I bumped into this error. I reduced the code to this minimal example:

test.js:

export const A = '';

class B {
  async f() {
    await g();
  }
}

.babelrc:

{
  "presets": [
    "es2015",
    "stage-0"
  ],
  "plugins": [
    ["fast-async", {
      "runtimePattern": "main.js"
    }],
  ]
}

And it produces the following error:

Error: test.js: Cannot append Element node to non-array
    at Object.append (/home/diego/repos/brainiac-www/node_modules/nodent/lib/parser.js:87:23)
    at /home/diego/repos/brainiac-www/node_modules/nodent/lib/arboriculture.js:2190:34
    at Array.forEach (native)
    at /home/diego/repos/brainiac-www/node_modules/nodent/lib/arboriculture.js:2189:32
    at Object.treeWalker (/home/diego/repos/brainiac-www/node_modules/nodent/lib/parser.js:156:5)
    at hoistDeclarations (/home/diego/repos/brainiac-www/node_modules/nodent/lib/arboriculture.js:2136:16)
    at asyncTransforms (/home/diego/repos/brainiac-www/node_modules/nodent/lib/arboriculture.js:359:9)
    at asynchronize (/home/diego/repos/brainiac-www/node_modules/nodent/lib/arboriculture.js:352:9)
    at NodentCompiler.asynchronize (/home/diego/repos/brainiac-www/node_modules/nodent/lib/arboriculture.js:2657:20)
    at PluginPass.Program (/home/diego/repos/brainiac-www/node_modules/fast-async/plugin.js:36:14)

Is this a bug in fast-async, or perhaps something wrong in my code?

Thanks!

matAtWork commented 7 years ago

It's probably a nodent/babel issue. It works in the nodent playground at http://nodent.mailed.me.uk/#export%20const%20A%20%3D%20''%3B%0A%0Aclass%20B%20%7B%0A%20%20async%20f()%20%7B%0A%20%20%20%20await%20g()%3B%0A%20%20%7D%0A%7D%0A

I'll try and take a look and see if there's a simple patch in the next day or two

matAtWork commented 7 years ago

Scrub this - it's not true!!


Quick workaround - applying fast-async after es2015 seems to work:

babel.js --presets es2015 --plugins fast-async < tests/test-input.js

I'll dig a bit deeper and see what the unpleasant interaction actually is