@babel/plugin-proposal-function-sent
Traducción Beta No Oficial
Esta página fue traducida por PageTurner AI (beta). No está respaldada oficialmente por el proyecto. ¿Encontraste un error? Reportar problema →
Ejemplo
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"
Se compila aproximadamente a
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"
Instalación
- npm
- Yarn
- pnpm
- Bun
npm install --save-dev @babel/plugin-proposal-function-sent
yarn add --dev @babel/plugin-proposal-function-sent
pnpm add --save-dev @babel/plugin-proposal-function-sent
bun add --dev @babel/plugin-proposal-function-sent
Uso
Mediante un archivo de configuración (Recomendado)
babel.config.json
{
"plugins": ["@babel/plugin-proposal-function-sent"]
}
Mediante la CLI
Shell
babel --plugins @babel/plugin-proposal-function-sent script.js
Mediante la API de Node
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-function-sent"],
});