@babel/plugin-proposal-function-sent

Example

  1. function* generator() {
  2. console.log("Sent", function.sent);
  3. console.log("Yield", yield);
  4. }
  5. const iterator = generator();
  6. iterator.next(1); // Logs "Sent 1"
  7. iterator.next(2); // Logs "Yield 2"

Is compiled roughly to

  1. let generator = _skipFirstGeneratorNext(function* () {
  2. const _functionSent = yield;
  3. console.log("Sent", _functionSent);
  4. console.log("Yield", yield);
  5. });
  6. const iterator = generator();
  7. iterator.next(1); // Logs "Sent 1"
  8. iterator.next(2); // Logs "Yield 2"

Installation

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

Usage

  1. {
  2. "plugins": ["@babel/plugin-proposal-function-sent"]
  3. }

Via CLI

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

Via Node API

  1. require("@babel/core").transform("code", {
  2. plugins: ["@babel/plugin-proposal-function-sent"]
  3. });

References