or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

@babel/plugin-syntax-function-sent

Babel syntax plugin that enables parsing of the function.sent meta property. This plugin extends Babel's parser capabilities to recognize the function.sent syntax without performing any transformations, allowing developers to use this JavaScript language feature proposal in their code.

Package Information

  • Package Name: @babel/plugin-syntax-function-sent
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install --save-dev @babel/plugin-syntax-function-sent

Core Imports

// CommonJS
const functionSentPlugin = require("@babel/plugin-syntax-function-sent");

ES Module:

import functionSentPlugin from "@babel/plugin-syntax-function-sent";

Basic Usage

Configure in your Babel configuration:

// babel.config.js
module.exports = {
  plugins: ["@babel/plugin-syntax-function-sent"]
};

Or with options:

// .babelrc.json
{
  "plugins": ["@babel/plugin-syntax-function-sent"]
}

After configuration, you can use the function.sent syntax in your JavaScript code:

function* generatorFunction() {
  const value = function.sent;
  console.log("Received:", value);
  yield "response";
}

const gen = generatorFunction();
gen.next();
gen.next("hello"); // Will log "Received: hello"

Architecture

This plugin follows Babel's standard syntax plugin architecture:

  • Plugin Factory: Returns a Babel plugin object using the declare helper
  • Parser Extension: Adds "functionSent" to Babel's parser plugins array
  • No Transformations: Pure syntax extension without AST modifications
  • Version Validation: Requires Babel 7.x through assertVersion check

Capabilities

Babel Plugin Export

The main plugin factory function that creates a Babel syntax plugin.

/**
 * Default export: Babel plugin factory function
 * Creates a plugin that enables function.sent syntax parsing
 */
export default declare((api: PluginAPI) => PluginObject);

/**
 * Plugin factory implementation (conceptual representation)
 * @param api - Babel plugin API object with version and utilities
 * @returns Babel plugin object with syntax extension capabilities
 */
function pluginFactory(api: PluginAPI): PluginObject {
  api.assertVersion("^7.0.0-0"); // REQUIRED_VERSION(7) is a build-time macro
  
  return {
    name: "syntax-function-sent",
    manipulateOptions(opts, parserOpts) {
      parserOpts.plugins.push("functionSent");
    }
  };
}

Plugin Object Structure

The plugin returns an object with the following properties:

interface PluginObject {
  /** Plugin identifier name */
  name: "syntax-function-sent";
  
  /** 
   * Parser options manipulator
   * Adds "functionSent" plugin to Babel's parser
   * @param opts - Babel plugin options object  
   * @param parserOpts - Parser-specific options with plugins array
   */
  manipulateOptions(opts: any, parserOpts: { plugins: string[] }): void;
}

Dependencies

Required Dependencies

/**
 * @babel/helper-plugin-utils - Plugin creation utilities
 * Provides the declare helper function for plugin factory creation
 */
import { declare } from "@babel/helper-plugin-utils";

/**
 * REQUIRED_VERSION build-time macro (provided by Babel build system)
 * Transforms version requirements at compile time
 * @param version - Required Babel major version number
 * @returns Version constraint string (transformed at build time)
 * @note This is a compile-time macro, not a runtime function
 */
declare function REQUIRED_VERSION(version: number): string;

/**
 * PluginAPI interface from @babel/core
 * Provides utilities for Babel plugin development
 */
interface PluginAPI {
  /** Babel version string */
  version: string;
  /** Assert that the current Babel version matches requirements */
  assertVersion(range: string | number): void;
}

Peer Dependencies

  • @babel/core: ^7.0.0-0 (required for plugin execution)

Error Handling

The plugin includes built-in version validation:

  • Throws version error if Babel version is incompatible with v7.x requirement
  • Uses standard Babel error reporting through api.assertVersion()
  • No runtime errors during parsing - syntax-only extension

Node.js Compatibility

  • Minimum Node.js version: 6.9.0
  • Babel 8 support: Node.js ^20.19.0 || >=22.12.0
  • Module type: ES Module (type: "module" in package.json)

Function.sent Syntax

This plugin enables parsing of the function.sent meta property, which is part of a JavaScript language proposal. The function.sent property provides access to the value passed to a generator function's next() method:

function* example() {
  console.log(function.sent); // undefined on first call
  const received = yield "first";
  console.log(function.sent); // value passed to next()
}

const gen = example();
gen.next();           // Logs: undefined
gen.next("hello");    // Logs: "hello"

Note: This plugin only enables parsing of the syntax. To actually use function.sent functionality, you would need a corresponding transform plugin or native browser support.