UNPKG

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