Navigation Menu

Skip to content
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

fix: Transform for await with shadowed variables #15235

Merged
merged 5 commits into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -64,11 +64,11 @@ export default declare(api => {
t.inherits(loop, node);
t.inherits(loop.body, node.body);

if (build.replaceParent) {
path.parentPath.replaceWithMultiple(build.node);
} else {
path.replaceWithMultiple(build.node);
}
const p = build.replaceParent ? path.parentPath : path;
p.replaceWithMultiple(build.node);

// TODO: Avoid crawl
p.scope.parent.crawl();
},
},
environmentVisitor,
Expand Down
@@ -0,0 +1,11 @@
const arr = [];
async function v(source = 2) {
for await (source of [1]) {
arr.push(source);
}
expect(source).toEqual(1);
}
return v().then(() => {
expect(arr).toEqual([1]);
});

@@ -0,0 +1,4 @@
async function v(source = 2) {
for await (source of [1]) {
}
}
@@ -0,0 +1,7 @@
{
"plugins": ["transform-parameters", "proposal-async-generator-functions"],
"parserOpts": {
"allowReturnOutsideFunction": true
},
"minNodeVersion": "8.0.0"
}
@@ -0,0 +1,24 @@
async function v() {
let source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
var _iteratorAbruptCompletion = false;
var _didIteratorError = false;
var _iteratorError;
try {
for (var _iterator = babelHelpers.asyncIterator([1]), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
source = _step.value;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (_iteratorAbruptCompletion && _iterator.return != null) {
await _iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}