babel: Bug: 7.0.0-beta.0 - export default async function named() {} is broken
Bug report
Input Code
export default async function named(input) {
return input;
}
Failing demo project: git@gist.github.com:e33790419e48fc6c504e39aa3b35572f.git or https://gist.github.com/Ambroos/e33790419e48fc6c504e39aa3b35572f - scripts in package.json.
Babel Configuration (.babelrc, package.json, cli command)
{
"scripts": {
"babelify-ok": "babel input.js --out-file output.js",
},
"devDependencies": {
"babel-cli": "^7.0.0-beta.0",
"babel-preset-env": "^2.0.0-beta.0"
},
"babel": {
"presets": [
[
"env",
{
"targets": {
"browsers": [
"IE 11",
"last 3 Chrome versions",
"last 2 Safari versions",
"last 2 Firefox versions",
"Firefox ESR",
"last 2 Edge versions",
"last 2 iOS versions"
]
}
}
]
]
}
}
Expected Behavior
Transpiling works as it did in 6.
Current Behavior
TypeError: broken.js: Property declaration of ExportNamedDeclaration expected node to be of a type ["Declaration"] but instead got "ExpressionStatement"
at Object.validate (project-dir/node_modules/babel-types/lib/definitions/index.js:86:13)
at Object.validate (project-dir/node_modules/babel-types/lib/index.js:478:9)
at NodePath._replaceWith (project-dir/node_modules/babel-traverse/lib/path/replacement.js:176:7)
at NodePath.replaceWith (project-dir/node_modules/babel-traverse/lib/path/replacement.js:160:8)
at Object.replaceWithOrRemove (project-dir/node_modules/regenerator-transform/lib/util.js:32:10)
at PluginPass.exit (project-dir/node_modules/regenerator-transform/lib/visit.js:163:14)
at newFn (project-dir/node_modules/babel-traverse/lib/visitors.js:236:21)
at NodePath._call (project-dir/node_modules/babel-traverse/lib/path/context.js:68:19)
at NodePath.call (project-dir/node_modules/babel-traverse/lib/path/context.js:42:17)
at NodePath.visit (project-dir/node_modules/babel-traverse/lib/path/context.js:112:8)```
Context
Only seems to happen when named async functions are exported in one statement: export default async function name() {...}
. Splitting the function definition and export default name
works, as does exporting unnamed async functions.
Your Environment
babel-cli 7.0.0-beta.0, babel-env 2.0.0-beta.0
software | version(s) |
---|---|
Babel | 7.0.0-beta.0 |
node | 8.5.0 |
yarn | 1.0.2 |
Operating System | macOS 10.13 Beta (17A358a) |
(as you may have noticed, I like bleeding edge/beta stuff)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 16 (6 by maintainers)
I’ve dug in a little further, and I’m pretty confident this is an incompatibility between babylon 6/7 ASTs that affects
babel-types@6
in this tree:I assume that
regenerator
needs to update tobabel@7-beta
Not sure, although we should just remove the dependency so this won’t be an issue in the future https://github.com/facebook/regenerator/issues/328
I’m confirming this is still an issue in beta.2, here is a repo/branch reproducing with the following command:
./node_modules/.bin/babel --out-dir lib src/
I did notice that anonymous functions were fixed in this situation (export, default, async). However, named are still not.
@hzoo - I think this still is an issue. Targeting Node 8 with babel-preset-env probably just disables the relevant transform as it may not be needed.
export default async function named()… is still broken as mentioned in my issue. @bradchristensen’s comments are not completely related to this.