CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-syntax-function-sent

Babel syntax plugin that enables parsing of the function.sent meta property

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

babel-plugin-syntax-function-sent

babel-plugin-syntax-function-sent is a Babel syntax plugin that enables parsing of the function.sent meta property in JavaScript code. This is a pure syntax plugin that only extends Babel's parser capabilities without transforming code - it allows JavaScript generators to use function.sent syntax during the compilation process.

Package Information

  • Package Name: babel-plugin-syntax-function-sent
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install babel-plugin-syntax-function-sent

Core Imports

Since this is a Babel plugin, it's not imported directly in your code. Instead, it's configured as part of your Babel setup:

// Via require (if needed programmatically)
const syntaxFunctionSent = require("babel-plugin-syntax-function-sent");

Basic Usage

The plugin is configured in your Babel setup to enable function.sent syntax parsing:

Via .babelrc (Recommended)

{
  "plugins": ["syntax-function-sent"]
}

Via CLI

$ babel --plugins syntax-function-sent script.js

Via Node API

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

What it enables

Once configured, you can use function.sent syntax in your JavaScript generators:

function* example() {
  const value = function.sent;
  // ... generator code
}

Architecture

This plugin follows the standard Babel plugin architecture:

  • Plugin Factory: The main default export returns a Babel plugin object
  • Parser Extension: Uses the manipulateOptions hook to add parser capability
  • Syntax Only: No code transformation - purely enables parsing
  • Zero Dependencies: Lightweight with no runtime dependencies

Capabilities

Plugin Factory Function

The main entry point that creates a Babel plugin instance.

/**
 * Main plugin factory function that returns a Babel plugin object
 * @returns {BabelPlugin} Plugin object with manipulateOptions method
 */
export default function(): BabelPlugin;

interface BabelPlugin {
  manipulateOptions(opts: any, parserOpts: ParserOptions): void;
}

interface ParserOptions {
  plugins: string[];
}

The plugin factory function:

  • Takes no parameters
  • Returns a Babel plugin object
  • The returned object contains a manipulateOptions method
  • The manipulateOptions method adds "functionSent" to the parser's plugin array

Usage Example:

// Direct usage (typically not needed)
const plugin = require("babel-plugin-syntax-function-sent");
const pluginInstance = plugin();

// The plugin is normally used through Babel configuration
// It enables parsing of function.sent in generator functions

manipulateOptions Method

The Babel plugin hook that modifies parser options to enable function.sent syntax.

/**
 * Babel plugin hook that modifies parser options to enable function.sent syntax
 * @param {any} opts - Babel options object (unused by this plugin)
 * @param {ParserOptions} parserOpts - Parser options object that gets modified
 * @returns {void}
 */
manipulateOptions(opts: any, parserOpts: ParserOptions): void;

This method:

  • Receives Babel's options and parser options
  • Adds "functionSent" to the parserOpts.plugins array
  • Enables the parser to recognize function.sent syntax
  • Does not transform or modify the code itself

Types

/**
 * Babel plugin object interface
 */
interface BabelPlugin {
  manipulateOptions(opts: any, parserOpts: ParserOptions): void;
}

/**
 * Parser options interface
 */
interface ParserOptions {
  plugins: string[];
}

Error Handling

This plugin operates at the parser level and does not throw runtime errors. Parse errors would be handled by Babel's parser if invalid function.sent syntax is encountered.

Notes

  • This is a syntax-only plugin - it does not transform code
  • Enables parsing of the function.sent meta property in JavaScript generators
  • Must be configured in Babel setup, not imported in application code
  • Zero runtime dependencies and minimal performance impact
  • Compatible with all Babel configurations and build tools
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/babel-plugin-syntax-function-sent@6.13.x
Publish Source
CLI
Badge
tessl/npm-babel-plugin-syntax-function-sent badge