While Syntax async generators · Babel says
If you want to transform it then see transform-regenerator, transform-async-to-generator, or transform-async-to-module-method.
it seems only transform-regenerator supports async generators.
*.out.js | |
### https://raw.github.com/github/gitignore/c696ec7b8ca5443513fe4ef0844c07129f6a2c6c/Node.gitignore | |
# Logs | |
logs | |
*.log | |
npm-debug.log* | |
# Runtime data | |
pids | |
*.pid | |
*.seed | |
# Directory for instrumented libs generated by jscoverage/JSCover | |
lib-cov | |
# Coverage directory used by tools like istanbul | |
coverage | |
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | |
.grunt | |
# node-waf configuration | |
.lock-wscript | |
# Compiled binary addons (http://nodejs.org/api/addons.html) | |
build/Release | |
# Dependency directories | |
node_modules | |
jspm_packages | |
# Optional npm cache directory | |
.npm | |
# Optional REPL history | |
.node_repl_history |
While Syntax async generators · Babel says
If you want to transform it then see transform-regenerator, transform-async-to-generator, or transform-async-to-module-method.
it seems only transform-regenerator supports async generators.
var babel = require('babel-core'); | |
var fs = require('fs'); | |
var code = fs.readFileSync(process.argv[2]); | |
var plugins = { | |
'transform-async-to-generator': [ | |
'syntax-async-functions', | |
'syntax-async-generators', | |
'transform-async-to-generator' | |
], | |
'transform-async-to-module-method': [ | |
'syntax-async-functions', | |
'syntax-async-generators', | |
['transform-async-to-module-method', { | |
// Without these options transforming fails. | |
module: 'bluebird', | |
method: 'coroutine' | |
}] | |
], | |
'transform-regenerator': [ | |
'syntax-async-functions', | |
'syntax-async-generators', | |
['transform-regenerator', { | |
asyncGenerators: true, | |
generators: true, | |
async: true | |
}] | |
] | |
}; | |
for (var key of Object.keys(plugins)) { | |
console.log(key); | |
var result = babel.transform(code, { plugins: plugins[key] }); | |
var path = `out/${key}.out.js`; | |
fs.writeFileSync(path, result.code); | |
} |
{ | |
"dependencies": { | |
"babel-core": "^6.7.2", | |
"babel-plugin-syntax-async-functions": "^6.5.0", | |
"babel-plugin-syntax-async-generators": "^6.5.0", | |
"babel-plugin-transform-async-to-generator": "^6.7.0", | |
"babel-plugin-transform-async-to-module-method": "^6.7.0", | |
"babel-plugin-transform-regenerator": "^6.6.5" | |
}, | |
"license": "CC0-1.0" | |
} |
async function * asyncGenerator () { | |
await Promise.resolve(1); | |
yield Promise.resolve(1); | |
} | |
async function asyncFunction () { | |
await Promise.resolve(1); | |
} | |
function * generator () { | |
yield 1; | |
} |