Comments (15)
FYI, the related issue of logger: false
has now been patched in nodent-transform
from fast-async.
I am using babel-preset-env... so depending on browser/output scenarios there are a few differences.
I just pushed a new breaking test to my babel-preset for your reference:
sebastian-software/babel-preset-edge@1e97ac9
from fast-async.
I shipped a change a few minutes ago which makes me suspicious, however I try your loop in the nodent online transform I don't have an issue (see the link below)
Are you trying to transform nodent (or fast-async) itself with Babel? This shouldn't be necessary as arboriculture
is the transformer, not the generated code.
Please confirm you're using the correct version of fast-async for your version of Babel, fast-async@6
for Babel 6, fast-async@7
for Babel 7-Beta.
from fast-async.
I have a custom babel preset which uses "fast-async" as part of the plugin chain.
As you can see here in the package.json all versions point to v6: https://github.com/sebastian-software/babel-preset-edge/blob/master/package.json#L81 (babel+fast-async)
from fast-async.
I have played with the new "native" support for async-to-promises from this PR.: babel/babel#7076 - that's a great milestone! Congratulations!
The error I experienced with using fast-async is also gone.
As mentioned here: https://github.com/babel/babel/pull/7076/files#r183963483 there seems to be a minor issue with logging though. Setting this to console.log
I actually see a warning:
esnext_async_loop.js: Duplicate declaration '_iterator = _isArray ? _iterator : _iterator[Symbol.iterator]()'
As mentioned before, this is the code which I tested:
async function executeTasks(tasks) {
for (const taskName of tasks) {
try {
await executeCommands()
} catch (error) {
console.error("Error")
}
}
}
The generated result looks like:
import "core-js/modules/es7.symbol.async-iterator";
import "core-js/modules/es6.symbol";
import "core-js/modules/web.dom.iterable";
function executeTasks(tasks) {
return new Promise(function ($return, $error) {
var _iterator, _isArray, _i, _ref;
_iterator = tasks, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();
var $Loop_2_trampoline;
return ($Loop_2_trampoline = function (q) {
while (q) {
if (q.then) return void q.then($Loop_2_trampoline, $error);
try {
if (q.pop) {
if (q.length) return q.pop() ? $Loop_2_exit.call(this) : q;else q = $Loop_2;
} else q = q.call(this);
} catch (_exception) {
return $error(_exception);
}
}
}.bind(this))($Loop_2);
function $Loop_2() {
if (true) {
if (_isArray) {
if (_i >= _iterator.length) return [1];
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) return [1];
_ref = _i.value;
}
var $Try_1_Post = function () {
try {
return $Loop_2;
} catch ($boundEx) {
return $error($boundEx);
}
};
var $Try_1_Catch = function (error) {
try {
console.error(\\"Error\\");
return $Try_1_Post();
} catch ($boundEx) {
return $error($boundEx);
}
};
try {
return Promise.resolve(executeCommands()).then(function ($await_4) {
try {
return $Try_1_Post();
} catch ($boundEx) {
return $Try_1_Catch($boundEx);
}
}, $Try_1_Catch);
} catch (error) {
$Try_1_Catch(error)
}
} else return [1];
}
function $Loop_2_exit() {
return $return();
}
});
}
from fast-async.
It looks like the code which is warned about by your generator is actually the result of transpiling es2015 for-of:
Input:
for (const taskName of tasks) {
try {
executeCommands()
} catch (error) {
console.error("Error")
}
}
Output:
import "core-js/modules/es7.symbol.async-iterator";
import "core-js/modules/es6.symbol";
import "core-js/modules/web.dom.iterable";
for (var _iterator = tasks, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
try {
executeCommands();
} catch (error) {
console.error("Error");
}
}
from fast-async.
Ok, that's pretty interesting - the failure seems to come from transpiling the output of Bable's translation of for...of
, is that correct?
from fast-async.
The logger not being a function is a straight bug. I'll patch that ASAP.
from fast-async.
I think that's right. I opened a bug report babel/babel#7801
from fast-async.
Babel 6, 7 or both?
from fast-async.
Just Babel v7
from fast-async.
Hmmm. If I put your sample above into babel-7's cli, I get...
$ git/babel/packages/babel-cli/bin/babel.js --no-babelrc --presets=module:./git/babel/packages/babel-preset-env a.js
"use strict";
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = tasks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var taskName = _step.value;
try {
executeCommands();
} catch (error) {
console.error("Error");
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
...and if I put that into 'nodent's CLI (which should log all the outpit to stdout) I get:
$ git/babel/packages/babel-cli/bin/babel.js --no-babelrc --presets=module:./git/babel/packages/babel-preset-env a.js | git/nodent/nodent.js --out --use=promises
"use strict";
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = tasks[Symbol.iterator](), _step;!(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var taskName = _step.value;
try {
executeCommands();
} catch (error) {
console.error("Error");
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
...which looks correct (unsurprisingly, as with any async
or await
keywords the transform won't do anything)
from fast-async.
Mhh, the whole stuff it tricky. I now see your results as well. When using a clean non babel v6 environment. It seems like Babel v7 is relatively unstable when some Babel v6 stuff is in node_modules. Not yet sure, why, though.
from fast-async.
Can I suggest change the order of your plugins - try with fast-async first and again with it last to see if it makes any difference. I'm guessing that either Babel is producing code that fast-async can't transform, or the other way around. But I'd like to know!
from fast-async.
I figure I close this one as I don't see currently any issue. But I have a new one :)
from fast-async.
Related Issues (20)
- SyntaxError: Strict mode does not allow function declarations in a lexically nested statement HOT 1
- for ... of produces `Cannot read property 'length' of undefined` error HOT 2
- [Bug] 6.3.2 - Error: Cannot find module '@babel/helper-module-imports' HOT 6
- [bug] infinite recursion (stack overflow) with $super$N helper HOT 9
- Babel v7: Env Preset + nodent breaks in Babel generator HOT 13
- ReferenceError: unknown node of type "Literal" with constructor "Object" HOT 2
- Cannot await non-Promises. HOT 5
- "await is a reserved word" HOT 2
- incorrect code when this is used in async function HOT 4
- Babel 7 version ignoring options? HOT 1
- Add support for alternative Promise implementations HOT 1
- Babel 7 code should use @babel/parser HOT 2
- Babel 7 "useRuntimeModule" HOT 4
- Babel 6/Webpack 3 Module build failed: ReferenceError: Unknown plugin "fast-async" HOT 1
- generators:false not honored - still outputs code using generators HOT 2
- How to translate async/await to built-in Promise?
- async/await with for...of cannot work
- `for await` is not supported to be transformed HOT 3
- Broken code for strict mode is generated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fast-async.