Babel syntax plugin that enables parsing of the function.sent meta property
npx @tessl/cli install tessl/npm-babel-plugin-syntax-function-sent@6.13.0babel-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.
npm install babel-plugin-syntax-function-sentSince 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");The plugin is configured in your Babel setup to enable function.sent syntax parsing:
{
"plugins": ["syntax-function-sent"]
}$ babel --plugins syntax-function-sent script.jsrequire("babel-core").transform("code", {
plugins: ["syntax-function-sent"]
});Once configured, you can use function.sent syntax in your JavaScript generators:
function* example() {
const value = function.sent;
// ... generator code
}This plugin follows the standard Babel plugin architecture:
manipulateOptions hook to add parser capabilityThe 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:
manipulateOptions methodmanipulateOptions method adds "functionSent" to the parser's plugin arrayUsage 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 functionsThe 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:
parserOpts.plugins arrayfunction.sent syntax/**
* Babel plugin object interface
*/
interface BabelPlugin {
manipulateOptions(opts: any, parserOpts: ParserOptions): void;
}
/**
* Parser options interface
*/
interface ParserOptions {
plugins: string[];
}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.
function.sent meta property in JavaScript generators