A Babel plugin that enables parsing of async generator functions in JavaScript code. This plugin extends Babel's parser capabilities to recognize async function* syntax without transforming the code.
npm install babel-plugin-syntax-async-generators// ES6 module (default export)
import syntaxAsyncGenerators from "babel-plugin-syntax-async-generators";CommonJS:
const syntaxAsyncGenerators = require("babel-plugin-syntax-async-generators");{
"plugins": ["syntax-async-generators"]
}babel --plugins syntax-async-generators script.jsrequire("babel-core").transform("code", {
plugins: ["syntax-async-generators"]
});Creates a Babel plugin that adds async generator parsing capability to the Babel parser.
/**
* Default export function that returns a Babel plugin object
* @returns {Object} Babel plugin object with manipulateOptions method
*/
export default function() {
return {
manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push("asyncGenerators");
}
};
}Usage Examples:
// Once plugin is installed and configured via .babelrc,
// Babel can parse async generator syntax like:
async function* asyncGenerator() {
yield await Promise.resolve(1);
yield await Promise.resolve(2);
}
// Or async generator expressions:
const gen = async function* () {
yield await fetch('/api/data');
};When applied, this plugin enables Babel to parse the following async generator patterns:
async function* name() { ... }const gen = async function* () { ... }{ async* method() { ... } }The plugin works by adding the "asyncGenerators" parser plugin to Babel's internal parser configuration, which tells the parser to recognize this syntax without transformation.
This is a simple Babel syntax plugin that:
manipulateOptions to add "asyncGenerators" to parser pluginsThe plugin enables parsing of async generator syntax so other Babel plugins can transform it if needed.
This plugin only enables parsing - it does not handle runtime errors or provide polyfills. If the target environment doesn't support async generators natively, additional transformation plugins are required.
Common issues: