1 | regenerator [![Build Status](https://travis-ci.org/facebook/regenerator.svg?branch=master)](https://travis-ci.org/facebook/regenerator)
|
2 | ===
|
3 |
|
4 | This package implements a fully-functional source transformation that
|
5 | takes the syntax for generators/`yield` from [ECMAScript 2015 or ES2015](http://www.ecma-international.org/ecma-262/6.0/) and [Asynchronous Iteration](https://github.com/tc39/proposal-async-iteration) proposal and
|
6 | spits out efficient JS-of-today (ES5) that behaves the same way.
|
7 |
|
8 | A small runtime library (less than 1KB compressed) is required to provide the
|
9 | `wrapGenerator` function. You can install it either as a CommonJS module
|
10 | or as a standalone .js file, whichever you prefer.
|
11 |
|
12 | Installation
|
13 | ---
|
14 |
|
15 | From npm:
|
16 | ```sh
|
17 | npm install -g regenerator
|
18 | ```
|
19 |
|
20 | From GitHub:
|
21 | ```sh
|
22 | cd path/to/node_modules
|
23 | git clone git://github.com/facebook/regenerator.git
|
24 | cd regenerator
|
25 | npm install .
|
26 | npm test
|
27 | ```
|
28 |
|
29 | Usage
|
30 | ---
|
31 |
|
32 | You have several options for using this module.
|
33 |
|
34 | Simplest usage:
|
35 | ```sh
|
36 | regenerator es6.js > es5.js # Just the transform.
|
37 | regenerator --include-runtime es6.js > es5.js # Add the runtime too.
|
38 | regenerator src lib # Transform every .js file in src and output to lib.
|
39 | ```
|
40 |
|
41 | Programmatic usage:
|
42 | ```js
|
43 | var es5Source = require("regenerator").compile(es6Source).code;
|
44 | var es5SourceWithRuntime = require("regenerator").compile(es6Source, {
|
45 | includeRuntime: true
|
46 | }).code;
|
47 | ```
|
48 |
|
49 | AST transformation:
|
50 | ```js
|
51 | var recast = require("recast");
|
52 | var ast = recast.parse(es6Source);
|
53 | ast = require("regenerator").transform(ast);
|
54 | var es5Source = recast.print(ast);
|
55 | ```
|
56 |
|
57 | How can you get involved?
|
58 | ---
|
59 |
|
60 | The easiest way to get involved is to look for buggy examples using [the
|
61 | sandbox](http://facebook.github.io/regenerator/), and when you find
|
62 | something strange just click the "report a bug" link (the new issue form
|
63 | will be populated automatically with the problematic code).
|
64 |
|
65 | Alternatively, you can
|
66 | [fork](https://github.com/facebook/regenerator/fork) the repository,
|
67 | create some failing tests cases in [test/tests.es6.js](test/tests.es6.js),
|
68 | and send pull requests for me to fix.
|
69 |
|
70 | If you're feeling especially brave, you are more than welcome to dive into
|
71 | the transformer code and fix the bug(s) yourself, but I must warn you that
|
72 | the code could really benefit from [better implementation
|
73 | comments](https://github.com/facebook/regenerator/issues/7).
|