or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

babel-plugin-syntax-async-generators

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.

Package Information

  • Package Name: babel-plugin-syntax-async-generators
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install babel-plugin-syntax-async-generators

Core Imports

// ES6 module (default export)
import syntaxAsyncGenerators from "babel-plugin-syntax-async-generators";

CommonJS:

const syntaxAsyncGenerators = require("babel-plugin-syntax-async-generators");

Basic Usage

Via .babelrc (Recommended)

{
  "plugins": ["syntax-async-generators"]
}

Via CLI

babel --plugins syntax-async-generators script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["syntax-async-generators"]
});

Capabilities

Plugin Function

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');
};

Parser Integration

When applied, this plugin enables Babel to parse the following async generator patterns:

  • Async Generator Functions: async function* name() { ... }
  • Async Generator Expressions: const gen = async function* () { ... }
  • Async Generator Methods: { async* method() { ... } }
  • Async Generator Arrow Functions: Not supported (syntax limitation)

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.

Architecture

This is a simple Babel syntax plugin that:

  • Extends Parser: Adds async generator syntax recognition to Babel's parser
  • No Transformation: Only enables parsing - does not modify or transform code
  • Minimal Implementation: Single function with zero dependencies
  • Plugin Hook: Uses manipulateOptions to add "asyncGenerators" to parser plugins

The plugin enables parsing of async generator syntax so other Babel plugins can transform it if needed.

Error Handling

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:

  • Syntax errors: Occur when async generator syntax is malformed
  • Runtime errors: Occur when executing async generators in unsupported environments
  • Plugin ordering: Must be applied before any transformation plugins that process async generators