Update async READMEs from babel.github.io [skip ci] (#4919)
This commit is contained in:
parent
66dfd8f0c1
commit
c2b3ea793f
@ -1,6 +1,6 @@
|
||||
# babel-plugin-transform-async-generator-functions
|
||||
|
||||
Turn async generator functions and for-await statements to ES2015 generators
|
||||
> Turn async generator functions and for-await statements to ES2015 generators
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
@ -1,6 +1,27 @@
|
||||
# babel-plugin-transform-async-to-generator
|
||||
|
||||
Turn async functions into ES2015 generators
|
||||
> Turn async functions into ES2015 generators
|
||||
|
||||
## Example
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
async function foo() {
|
||||
await bar();
|
||||
}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
var _asyncToGenerator = function (fn) {
|
||||
...
|
||||
};
|
||||
var foo = _asyncToGenerator(function* () {
|
||||
yield bar();
|
||||
});
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
@ -33,3 +54,7 @@ require("babel-core").transform("code", {
|
||||
plugins: ["transform-async-to-generator"]
|
||||
});
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* [Proposal: Async Functions for ECMAScript](https://github.com/tc39/ecmascript-asyncawait)
|
||||
|
||||
@ -1,6 +1,26 @@
|
||||
# babel-plugin-transform-async-to-module-method
|
||||
|
||||
Turn async functions into a Bluebird coroutine
|
||||
> Turn async functions into a Bluebird coroutine
|
||||
|
||||
## Example
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
async function foo() {
|
||||
await bar();
|
||||
}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
var Bluebird = require("bluebird");
|
||||
|
||||
var foo = Bluebird.coroutine(function* () {
|
||||
yield bar();
|
||||
});
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
@ -1,6 +1,40 @@
|
||||
# babel-plugin-transform-regenerator
|
||||
|
||||
Transform async/generator functions with [regenerator](https://github.com/facebook/regenerator)
|
||||
> Transform async/generator functions with [regenerator](https://github.com/facebook/regenerator)
|
||||
|
||||
## Example
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
function* a() {
|
||||
yield 1;
|
||||
}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
var _marked = [a].map(regeneratorRuntime.mark);
|
||||
|
||||
function a() {
|
||||
return regeneratorRuntime.wrap(function a$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
_context.next = 2;
|
||||
return 1;
|
||||
|
||||
case 2:
|
||||
case "end":
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _marked[0], this);
|
||||
}
|
||||
```
|
||||
|
||||
[Try in REPL](http://babeljs.io/repl/#?evaluate=true&lineWrap=true&presets=es2015%2Ces2015-loose%2Creact&experimental=false&loose=false&spec=false&code=function%20*range(max%2C%20step)%20%7B%0A%20%20var%20count%20%3D%200%3B%0A%20%20step%20%3D%20step%20%7C%7C%201%3B%0A%20%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20max%3B%20i%20%2B%3D%20step)%20%7B%0A%20%20%20%20count%2B%2B%3B%0A%20%20%20%20yield%20i%3B%0A%20%20%7D%0A%20%0A%20%20return%20count%3B%0A%7D%0A%20%0Avar%20gen%20%3D%20range(20%2C%203)%2C%20info%3B%0A%20%0Awhile%20(!(info%20%3D%20gen.next()).done)%20%7B%0A%20%20console.log(info.value)%3B%0A%7D%0A%20%0Aconsole.log(%22steps%20taken%3A%20%22%20%2B%20info.value)%3B&playground=true)
|
||||
|
||||
## Installation
|
||||
|
||||
@ -23,9 +57,9 @@ npm install --save-dev babel-plugin-transform-regenerator
|
||||
{
|
||||
"plugins": [
|
||||
["transform-regenerator", {
|
||||
asyncGenerators: false, // true by default
|
||||
generators: false, // true by default
|
||||
async: false // true by default
|
||||
asyncGenerators: false, // true by default
|
||||
generators: false, // true by default
|
||||
async: false // true by default
|
||||
}]
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user