New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Regression in for await
transform, is not await
ing iterator values
#13811
Comments
The yielded value is not supposed to be awaited, though: https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-asynciterator-interface |
Oh, right, you are correct; the codegen here is not necessarily wrong. The code I expected is, however, part of the AsyncFromSyncIterator behavior (it awaits value before returning iterator result), and it doesn't seem to be happening either. I'll check again once I'm not on the phone. |
Yep, checking the full codegen: // reformatted with prettier for readability
function _asyncIterator(iterable) {
var method
if (typeof Symbol !== 'undefined') {
if (Symbol.asyncIterator) method = iterable[Symbol.asyncIterator]
if (method == null && Symbol.iterator) method = iterable[Symbol.iterator]
}
if (method == null) method = iterable['@@asyncIterator']
if (method == null) method = iterable['@@iterator']
if (method == null) throw new TypeError('Object is not async iterable')
return method.call(iterable)
}
function f() {
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, x;
return regeneratorRuntime.async(function f$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_iteratorAbruptCompletion = false;
_didIteratorError = false;
_context.prev = 2;
_iterator = _asyncIterator([].push());
case 4:
_context.next = 6;
return regeneratorRuntime.awrap(_iterator.next());
case 6:
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
_context.next = 11;
break;
}
x = _step.value;
// ... The The old codegen happened to guard against |
Looks like the codegen change was done in #13491 (with no helper change) |
Thanks for the detailed explanation. So I guess another way to show the bug would be: async function* bar() {
yield* [Promise.resolve("ok")] // CreateAsyncFromSyncIterator
}
bar().next().then(console.log);
// should print { value: 'ok', done: false } |
馃捇
How are you using Babel?
babel-loader (webpack)
Input code
Minimal example that shows the compilation issue:
More elaborate example that crashes at runtime if
f
is invoked:Configuration file name
babel.config.js
Configuration
https://babeljs.io/repl defaults with
not ie 11
in "targets" changed toie 11
Current and expected behavior
(This section was a red herring as the codegen change was intended, the actual issue is that the AsyncFromSyncIterator behavior was not updated to match the new codegen; see #13811 (comment))
Babel is miscompiling the sample
for await
loop in such a way that it's effectively building a regularfor of
loop on top of regenerator. While theiterator.next()
call is beingawait
ed, the yielded value is not itself gettingawait
ed as it's supposed to, so the looped over values arePromise
instances instead of their values.This is a regression from (at least) 7.13. The REPL doesn't seem to have 7.14 so I couldn't check that.
Relevant annotated output in 7.13.17:
Relevant annotated output in 7.15.7:
Environment
Possible solution
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: