'use strict';
(async () => {
for await (const item of [Promise.resolve('a'), Promise.resolve('b')]) {
console.log(item);
}
})();
4:3 error iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations no-restricted-syntax
Should the ForOfStatement entry in no-restricted-syntax be alleviated in such cases? Maybe it is worth to remove the second part of the message ("loops should be avoided in favor of array iterations"), since there seems to be no easy different way for array asynchronous iteration?
Is there a way for AST parser to distinguish an async ForOfStatement from a sync one?
In this case, you're iterating an array of promises you already have, so using async iteration provides precisely zero benefit.
[Promise.resolve('a'), Promise.resolve('b')].forEach((promise) => {
promise.then((item) => { console.log(item); });
});
Regardless, no, it should be alleviated in no cases, because the transpilation of it still currently requires regenerator-runtime.
Sorry, it was just a simplified example. What about something like this?
@vsemozhetbyt if you're in a node-only environment, you can certainly override rules that are concerned with transpilation overhead.
Most helpful comment
@vsemozhetbyt if you're in a node-only environment, you can certainly override rules that are concerned with transpilation overhead.