What is @babel/plugin-proposal-function-sent?
@babel/plugin-proposal-function-sent is a Babel plugin that allows you to use the `function.sent` meta-property within generator functions. This meta-property provides a way to access the value passed to the generator's `next` method, which can be useful for more advanced control flow within generator functions.
Accessing the value passed to the generator's next method
This feature allows you to access the value passed to the generator's `next` method using `function.sent`. In the example, the generator function logs the value received each time `next` is called.
function* generator() {
let value = function.sent;
while (true) {
value = yield value;
console.log('Received:', value);
}
}
const gen = generator();
console.log(gen.next('First').value); // Logs: 'First'
console.log(gen.next('Second').value); // Logs: 'Second'