Browse Source

Proper support for for-await-of

master
Lee Byron 8 years ago
parent
commit
daf7811c69
  1. 5
      index.js
  2. 2
      package.json
  3. 6
      test/expected.js
  4. 3
      test/source.js

5
index.js

@ -18,7 +18,7 @@ module.exports = function(options) {
includeHelper: false includeHelper: false
}); });
if (result.isEdited) { if (result.isEdited) {
result.prepend('import { __async, __asyncGen } from "' + getAsyncHelperFile() + '"\n'); result.prepend('import { __async, __asyncGen, __asyncIterator } from "' + getAsyncHelperFile() + '"\n');
} }
return { return {
code: result.toString(), code: result.toString(),
@ -37,7 +37,8 @@ function getAsyncHelperFile() {
fs.writeFileSync( fs.writeFileSync(
_asyncHelperFile, _asyncHelperFile,
'export ' + asyncToGen.asyncHelper + '\n' + 'export ' + asyncToGen.asyncHelper + '\n' +
'export ' + asyncToGen.asyncGenHelper 'export ' + asyncToGen.asyncGenHelper + '\n' +
'export ' + asyncToGen.asyncIteratorHelper
); );
process.on('exit', function () { process.on('exit', function () {
fs.unlinkSync(_asyncHelperFile) fs.unlinkSync(_asyncHelperFile)

2
package.json

@ -24,7 +24,7 @@
"async-to-gen" "async-to-gen"
], ],
"dependencies": { "dependencies": {
"async-to-gen": "^1.1.0", "async-to-gen": "^1.2.0",
"rollup-pluginutils": "^1.5.1" "rollup-pluginutils": "^1.5.1"
}, },
"devDependencies": { "devDependencies": {

6
test/expected.js

@ -1,6 +1,7 @@
'use strict'; 'use strict';
function __async(g){return new Promise(function(s,j){function c(a,x){try{var r=g[x?"throw":"next"](a)}catch(e){return j(e)}return r.done?s(r.value):Promise.resolve(r.value).then(c,d)}function d(e){return c(e,1)}c()})} function __async(g){return new Promise(function(s,j){function c(a,x){try{var r=g[x?"throw":"next"](a)}catch(e){j(e);return}r.done?s(r.value):Promise.resolve(r.value).then(c,d)}function d(e){c(e,1)}c()})}
function __asyncIterator(o){var i=o[Symbol&&Symbol.asyncIterator||"@@asyncIterator"]||o[Symbol&&Symbol.iterator||"@@iterator"];if(!i)throw new TypeError("Object is not AsyncIterable.");return i.call(o)}
function mystery() {return __async(function*(){ function mystery() {return __async(function*(){
return yield 'oOOoooOOOooo' return yield 'oOOoooOOOooo'
@ -8,6 +9,9 @@ function mystery() {return __async(function*(){
// async function statement // async function statement
function foo() {return __async(function*(){ function foo() {return __async(function*(){
var $i1,$s1,$e1;try{for ($s1=null,$i1=__asyncIterator( asyncIterable);$s1=yield $i1.next(),!$s1.done;) {let x=$s1.value;
// Empty
}}catch(e){$e1=e}finally{try{!$s1.done&&$i1.return&&(yield $i1.return())}finally{if($e1)throw $e1}}
return yield mystery() return yield mystery()
}())} }())}

3
test/source.js

@ -2,6 +2,9 @@ import { mystery } from './source2'
// async function statement // async function statement
async function foo() { async function foo() {
for await (let x of asyncIterable) {
// Empty
}
return await mystery() return await mystery()
} }

Loading…
Cancel
Save