- Notifications
You must be signed in to change notification settings - Fork1.2k
Source transformer enabling ECMAScript 6 generator functions in JavaScript-of-today.
License
facebook/regenerator
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This package implements a fully-functional source transformation thattakes the syntax for generators/yield
fromECMAScript 2015 or ES2015 andAsynchronous Iteration proposal andspits out efficient JS-of-today (ES5) that behaves the same way.
A small runtime library (less than 1KB compressed) is required to provide thewrapGenerator
function. You can install it either as a CommonJS moduleor as a standalone .js file, whichever you prefer.
From npm:
npm install -g regenerator
From GitHub:
cd path/to/node_modulesgit clone git://github.com/facebook/regenerator.gitcd regeneratornpm install.npmtest
You have several options for using this module.
Simplest usage:
regenerator es6.js> es5.js# Just the transform.regenerator --include-runtime es6.js> es5.js# Add the runtime too.regenerator src lib# Transform every .js file in src and output to lib.
Programmatic usage:
vares5Source=require("regenerator").compile(es6Source).code;vares5SourceWithRuntime=require("regenerator").compile(es6Source,{includeRuntime:true}).code;
AST transformation:
varrecast=require("recast");varast=recast.parse(es6Source);ast=require("regenerator").transform(ast);vares5Source=recast.print(ast);
The easiest way to get involved is to look for buggy examples usingthesandbox, and when you findsomething strange just click the "report a bug" link (the new issue formwill be populated automatically with the problematic code).
Alternatively, you canfork the repository,create some failing tests cases intest/tests.es6.js,and send pull requests for me to fix.
If you're feeling especially brave, you are more than welcome to dive intothe transformer code and fix the bug(s) yourself, but I must warn you thatthe code could really benefit frombetter implementationcomments.
About
Source transformer enabling ECMAScript 6 generator functions in JavaScript-of-today.