Skip to main content

@babel/plugin-proposal-function-sent

Example

JavaScript
function* generator() {
console.log("Sent", function.sent);
console.log("Yield", yield);
}

const iterator = generator();
iterator.next(1); // Logs "Sent 1"
iterator.next(2); // Logs "Yield 2"

Is compiled roughly to

JavaScript
let generator = _skipFirstGeneratorNext(function*() {
const _functionSent = yield;
console.log("Sent", _functionSent);
console.log("Yield", yield);
});

const iterator = generator();
iterator.next(1); // Logs "Sent 1"
iterator.next(2); // Logs "Yield 2"

Installation

npm install --save-dev @babel/plugin-proposal-function-sent

Usage

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

Via CLI

Shell
babel --plugins @babel/plugin-proposal-function-sent script.js

Via Node API

JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-function-sent"],
});

References