aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@babel/plugin-proposal-function-sent/README.md
blob: 9c4984919db46013e71943b7f9d7d6913080e41f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# @babel/plugin-proposal-function-sent

> Compile the `function.sent` meta property, used inside generator functions, to valid ES2015 code.

## Example

```js
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

```js
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 1"
```

## Installation

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

## Usage

### Via `.babelrc` (Recommended)

**.babelrc**

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

### Via CLI

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

### Via Node API

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

## References

* [Proposal](https://github.com/allenwb/ESideas/blob/master/Generator%20metaproperty.md)