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
|
10 | function* a() {
|
11 | yield 1;
|
12 | }
|
13 | ```
|
14 |
|
15 | **Out**
|
16 |
|
17 | ```javascript
|
18 | var _marked = [a].map(regeneratorRuntime.mark);
|
19 |
|
20 | function 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
|
40 | npm install --save-dev babel-plugin-transform-regenerator
|
41 | ```
|
42 |
|
43 | ## Usage
|
44 |
|
45 | ### Via `.babelrc` (Recommended)
|
46 |
|
47 | Without options:
|
48 |
|
49 | ```json
|
50 | {
|
51 | "plugins": ["transform-regenerator"]
|
52 | }
|
53 | ```
|
54 |
|
55 | With 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
|
78 | babel --plugins transform-regenerator script.js
|
79 | ```
|
80 |
|
81 | ### Via Node API
|
82 |
|
83 | ```javascript
|
84 | require("babel-core").transform("code", {
|
85 | plugins: ["transform-regenerator"]
|
86 | });
|
87 | ```
|