UNPKG

1.24 kBMarkdownView Raw
1# babel-plugin-transform-regenerator
2
3> Transform async/generator functions with [regenerator](https://github.com/facebook/regenerator)
4
5## Example
6
7**In**
8
9```javascript
10function* a() {
11 yield 1;
12}
13```
14
15**Out**
16
17```javascript
18var _marked = [a].map(regeneratorRuntime.mark);
19
20function a() {
21 return regeneratorRuntime.wrap(function a$(_context) {
22 while (1) {
23 switch (_context.prev = _context.next) {
24 case 0:
25 _context.next = 2;
26 return 1;
27
28 case 2:
29 case "end":
30 return _context.stop();
31 }
32 }
33 }, _marked[0], this);
34}
35```
36
37## Installation
38
39```sh
40npm install --save-dev babel-plugin-transform-regenerator
41```
42
43## Usage
44
45### Via `.babelrc` (Recommended)
46
47Without options:
48
49```json
50{
51 "plugins": ["transform-regenerator"]
52}
53```
54
55With options:
56
57|name|default value|
58|---|---|
59|asyncGenerators|true|
60|generators|true|
61|async|true|
62
63```json
64{
65 "plugins": [
66 ["transform-regenerator", {
67 "asyncGenerators": false,
68 "generators": false,
69 "async": false
70 }]
71 ]
72}
73```
74
75### Via CLI
76
77```sh
78babel --plugins transform-regenerator script.js
79```
80
81### Via Node API
82
83```javascript
84require("babel-core").transform("code", {
85 plugins: ["transform-regenerator"]
86});
87```