-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve output of for await
#15943
base: main
Are you sure you want to change the base?
Improve output of for await
#15943
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
/*#__PURE__*/babelHelpers.asyncToGenerator(function* () { | ||
var _iteratorAbruptCompletion = false; | ||
var _didIteratorError = false; | ||
var _iteratorError; | ||
var _iterator = babelHelpers.asyncIterator(y), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If calling |
||
_step, | ||
_notDone; | ||
try { | ||
for (var _iterator = babelHelpers.asyncIterator(y), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false) { | ||
for (; _notDone = !(_step = yield _iterator.next()).done; _notDone = false) { | ||
let x = _step.value; | ||
{ | ||
f(x); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} catch (e) { | ||
_step = null; | ||
throw e; | ||
} finally { | ||
try { | ||
if (_iteratorAbruptCompletion && _iterator.return != null) { | ||
if (_notDone && _iterator.return) { | ||
yield _iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} catch (e) { | ||
if (_step) throw e; | ||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
async function foo() { | ||
var _iteratorAbruptCompletion = false; | ||
var _didIteratorError = false; | ||
var _iteratorError; | ||
var _iterator = babelHelpers.asyncIterator(y), | ||
_step, | ||
_notDone; | ||
try { | ||
for (var _iterator = babelHelpers.asyncIterator(y), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) { | ||
for (; _notDone = !(_step = await _iterator.next()).done; _notDone = false) { | ||
const x = _step.value; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} catch (e) { | ||
_step = null; | ||
throw e; | ||
} finally { | ||
try { | ||
if (_iteratorAbruptCompletion && _iterator.return != null) { | ||
if (_notDone && _iterator.return) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only undefined should skip the call. |
||
await _iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} catch (e) { | ||
if (_step) throw e; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
babelHelpers.asyncToGenerator(function* () { | ||
var _iteratorAbruptCompletion = false; | ||
var _didIteratorError = false; | ||
var _iteratorError; | ||
var _iterator = babelHelpers.asyncIterator(y), | ||
_step, | ||
_notDone; | ||
try { | ||
for (var _iterator = babelHelpers.asyncIterator(y), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false) { | ||
for (; _notDone = !(_step = yield _iterator.next()).done; _notDone = false) { | ||
obj.x = _step.value; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} catch (e) { | ||
_step = null; | ||
throw e; | ||
} finally { | ||
try { | ||
if (_iteratorAbruptCompletion && _iterator.return != null) { | ||
if (_notDone && _iterator.return) { | ||
yield _iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} catch (e) { | ||
if (_step) throw e; | ||
} | ||
} | ||
})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
/*#__PURE__*/babelHelpers.asyncToGenerator(function* () { | ||
var _iteratorAbruptCompletion = false; | ||
var _didIteratorError = false; | ||
var _iteratorError; | ||
var _iterator = babelHelpers.asyncIterator([]), | ||
_step, | ||
_notDone; | ||
try { | ||
for (var _iterator = babelHelpers.asyncIterator([]), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false) { | ||
for (; _notDone = !(_step = yield _iterator.next()).done; _notDone = false) { | ||
let x = _step.value; | ||
{ | ||
let x; | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} catch (e) { | ||
_step = null; | ||
throw e; | ||
} finally { | ||
try { | ||
if (_iteratorAbruptCompletion && _iterator.return != null) { | ||
if (_notDone && _iterator.return) { | ||
yield _iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} catch (e) { | ||
if (_step) throw e; | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.next()
might setBoolean.prototype.done
totrue
and returnfalse
:)Could you also rename
_notDone
to_iteratorAbruptCompletion
, to reduce the diff and make it easier to follow the changes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
.next()
must return an Object; otherwise agree explicit null-check looks clearer.ForIn/OfBodyEvaluation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's worth doing, it's really weird usage. :)
Since I completely changed the position of variable declarations and the logic of throwing exceptions, the changes may not be less,
_notDone
is slightly shorter and easier to read in the output.