Skip to content

Commit

Permalink
fix: Compile re-declare var in init and body of for await (#15103)
Browse files Browse the repository at this point in the history
* fix

* exec test
  • Loading branch information
liuxingbaoyu committed Oct 31, 2022
1 parent e4bc031 commit 9836e24
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 10 deletions.
Expand Up @@ -54,11 +54,13 @@ export default declare(api => {
// add the value declaration to the new loop body
if (declar) {
block.body.push(declar);
if (path.node.body.body.length) {
block.body.push(t.blockStatement(path.node.body.body));
}
} else {
block.body.push(...path.node.body.body);
}

// push the rest of the original loop body onto our new body
block.body.push(...path.node.body.body);

t.inherits(loop, node);
t.inherits(loop.body, node.body);

Expand Down
Expand Up @@ -5,7 +5,9 @@
try {
for (var _iterator = babelHelpers.asyncIterator(y), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false) {
let x = _step.value;
f(x);
{
f(x);
}
}
} catch (err) {
_didIteratorError = true;
Expand Down
Expand Up @@ -9,7 +9,9 @@ function _f() {
try {
for (var _iterator = babelHelpers.asyncIterator(y), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false) {
let x = _step.value;
g(x);
{
g(x);
}
}
} catch (err) {
_didIteratorError = true;
Expand Down
Expand Up @@ -9,7 +9,9 @@ function _g() {
try {
for (var _iterator = babelHelpers.asyncIterator(y), _step; _iteratorAbruptCompletion = !(_step = yield babelHelpers.awaitAsyncGenerator(_iterator.next())).done; _iteratorAbruptCompletion = false) {
let x = _step.value;
f(x);
{
f(x);
}
}
} catch (err) {
_didIteratorError = true;
Expand Down
Expand Up @@ -9,9 +9,11 @@ function _fn() {
try {
for (var _iterator = babelHelpers.asyncIterator([Promise.resolve("ok")]), _step; _iteratorAbruptCompletion = !(_step = yield babelHelpers.awaitAsyncGenerator(_iterator.next())).done; _iteratorAbruptCompletion = false) {
const result = _step.value;
return {
result
};
{
return {
result
};
}
}
} catch (err) {
_didIteratorError = true;
Expand Down
Expand Up @@ -12,7 +12,9 @@ function _f() {
x,
y: [z]
} = _step.value;
g(x, z);
{
g(x, z);
}
}
} catch (err) {
_didIteratorError = true;
Expand Down
@@ -0,0 +1,3 @@
( async () => {
for await ( let x of [ ] ) { let x; }
} ) ;
@@ -0,0 +1,3 @@
( async () => {
for await ( let x of [ ] ) { let x; }
} ) ;
@@ -0,0 +1,26 @@
/*#__PURE__*/babelHelpers.asyncToGenerator(function* () {
var _iteratorAbruptCompletion = false;
var _didIteratorError = false;
var _iteratorError;
try {
for (var _iterator = babelHelpers.asyncIterator([]), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false) {
let x = _step.value;
{
let x;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (_iteratorAbruptCompletion && _iterator.return != null) {
yield _iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
});

0 comments on commit 9836e24

Please sign in to comment.