Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

Nested arrow async functions #230

Closed
zhanzhenzhen opened this issue Jan 16, 2016 · 9 comments
Closed

Nested arrow async functions #230

zhanzhenzhen opened this issue Jan 16, 2016 · 9 comments

Comments

@zhanzhenzhen
Copy link

var a = async () => {
  return await (async () => {
    return await b();
  })();
};

It can't parse this. It seems the syntax is OK.

@benjamn
Copy link
Contributor

benjamn commented Jan 16, 2016

What's the stack trace? Sorry not at my computer at the moment.

@zhanzhenzhen
Copy link
Author

Error while reading module a:
Error: unknown Expression of type "ArrowFunctionExpression"
    at Emitter.Ep.explodeExpression (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1209:11)
    at Emitter.Ep.explodeExpression (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1043:24)
    at explodeViaTempVar (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:954:23)
    at NodePath.<anonymous> (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1062:20)
    at NodePath.each (/home/zzz/async-test/node_modules/ast-types/lib/path.js:99:22)
    at Emitter.Ep.explodeExpression (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1061:14)
    at Emitter.Ep.explodeExpression (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1184:37)
    at Emitter.Ep.explodeStatement (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:672:19)
    at NodePath.each (/home/zzz/async-test/node_modules/ast-types/lib/path.js:99:22)
    at Emitter.Ep.explodeStatement (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:399:29)
From previous event:
    at buildP (/home/zzz/async-test/node_modules/commoner/lib/reader.js:167:16)
    at Object.ModuleReader.processOutputP (/home/zzz/async-test/node_modules/commoner/lib/reader.js:221:16)
    at Object.ModuleReader.buildModuleP (/home/zzz/async-test/node_modules/commoner/lib/reader.js:132:23)
    at Object.wrapper [as buildModuleP] (/home/zzz/async-test/node_modules/commoner/lib/util.js:53:31)
    at /home/zzz/async-test/node_modules/commoner/lib/reader.js:126:27
Error: unknown Expression of type "ArrowFunctionExpression"
    at Emitter.Ep.explodeExpression (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1209:11)
    at Emitter.Ep.explodeExpression (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1043:24)
    at explodeViaTempVar (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:954:23)
    at NodePath.<anonymous> (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1062:20)
    at NodePath.each (/home/zzz/async-test/node_modules/ast-types/lib/path.js:99:22)
    at Emitter.Ep.explodeExpression (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1061:14)
    at Emitter.Ep.explodeExpression (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:1184:37)
    at Emitter.Ep.explodeStatement (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:672:19)
    at NodePath.each (/home/zzz/async-test/node_modules/ast-types/lib/path.js:99:22)
    at Emitter.Ep.explodeStatement (/home/zzz/async-test/node_modules/regenerator/lib/emit.js:399:29)
From previous event:
    at buildP (/home/zzz/async-test/node_modules/commoner/lib/reader.js:167:16)
    at Object.ModuleReader.processOutputP (/home/zzz/async-test/node_modules/commoner/lib/reader.js:221:16)
    at Object.ModuleReader.buildModuleP (/home/zzz/async-test/node_modules/commoner/lib/reader.js:132:23)
    at Object.wrapper [as buildModuleP] (/home/zzz/async-test/node_modules/commoner/lib/util.js:53:31)
    at /home/zzz/async-test/node_modules/commoner/lib/reader.js:126:27

@insidewhy
Copy link

I've seen the same thing via babel, the error message you get back in this case is mega deceptive.

@insidewhy
Copy link

I get the same unknown expression of type... error even when not using nested async functions, sometimes just having an arrow function in an async function is enough to give that same error from babel. It also doesn't give you a line number, just the file. Pretty serious bug.

@insidewhy
Copy link

async function registerApps(app, r) {
  console.log('server listening, registering apps')

  let appModulePaths = await glob('./api/*/app.js', { cwd: 'server' })

  // regenerator forces me to use non-arrow function... stupid bug
  return Promise.map(appModulePaths, function(appModulePath) {
    let appName = path.dirname(path.relative('api', appModulePath))
    let ApiApp = require(appModulePath)
    console.info('loading app', appName)
    return buildApp(ApiApp, r, app).then(router => {
      app.use(`/${NAMESPACE}/${appName}`, router)
    })
  })

This here it won't accept in arrow function in the Promise.map callback.

@benjamn benjamn closed this as completed in 535eb67 Dec 1, 2016
@kangax
Copy link
Contributor

kangax commented Dec 1, 2016

I ran into this at FB as well when trying an experiment couple weeks ago. Was just about to report and here it is, fixed. @benjamn thank you!

@kangax
Copy link
Contributor

kangax commented Dec 15, 2016

@benjamn it seems that regenerator always transpiles to arrow functions now (due to transform-es2015-arrow-functions)? Is it possible to have it working with nested arrows while still outputting them? Should I open a new issue?

@benjamn
Copy link
Contributor

benjamn commented Dec 20, 2016

@kangax I agree that forcing all arrow functions to be transpiled is overkill. Can you open a new issue to handle arrows in the transform (rather than assuming they've all been transpiled already)?

@rjdestigter
Copy link

rjdestigter commented Apr 7, 2017

I'm having this issue at the moment using:
node: 6.9.3
npm: 4.1.1
webpack: 2 + babel-preset-env + stage-0

presets: [
      ['env', {
        targets: {
          browsers: [
            '>1%',
            'last 2 versions',
            'not ie <= 11',
          ],
        },
        modules: false,
        useBuiltIns: false,
        debug: true,
      }],
      'react',
      'stage-0',
    ],

But only on a windows machine. On a linux machine no problems compiling.

Edit: I had everything installed using npm install however yarn was also available and after running yarn the issue was resolved. I'm assuming an older version of one of the dependencies was still present.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants