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 1 commit
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)[0];
liuxingbaoyu marked this conversation as resolved.
Show resolved Hide resolved

// 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,13 @@
{
"presets": [
[
"env",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to use the minimal number of plugins necessary to reproduce the bug:

transform-parameters
proposal-async-generator-functions

{
"targets": "node 4"
}
]
],
"parserOpts": {
"allowReturnOutsideFunction": true
}
liuxingbaoyu marked this conversation as resolved.
Show resolved Hide resolved
}
@@ -0,0 +1,71 @@
function v() {
return _v.apply(this, arguments);
}
function _v() {
_v = babelHelpers.asyncToGenerator( /*#__PURE__*/babelHelpers.regeneratorRuntime().mark(function _callee() {
var source,
_iteratorAbruptCompletion,
_didIteratorError,
_iteratorError,
_iterator,
_step,
_args = arguments;
return babelHelpers.regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
source = _args.length > 0 && _args[0] !== undefined ? _args[0] : 2;
_iteratorAbruptCompletion = false;
_didIteratorError = false;
_context.prev = 3;
_iterator = babelHelpers.asyncIterator([1]);
case 5:
_context.next = 7;
return _iterator.next();
case 7:
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
_context.next = 12;
break;
}
source = _step.value;
case 9:
_iteratorAbruptCompletion = false;
_context.next = 5;
break;
case 12:
_context.next = 18;
break;
case 14:
_context.prev = 14;
_context.t0 = _context["catch"](3);
_didIteratorError = true;
_iteratorError = _context.t0;
case 18:
_context.prev = 18;
_context.prev = 19;
if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
_context.next = 23;
break;
}
_context.next = 23;
return _iterator.return();
case 23:
_context.prev = 23;
if (!_didIteratorError) {
_context.next = 26;
break;
}
throw _iteratorError;
case 26:
return _context.finish(23);
case 27:
return _context.finish(18);
case 28:
case "end":
return _context.stop();
}
}
}, _callee, null, [[3, 14, 18, 28], [19,, 23, 27]]);
}));
return _v.apply(this, arguments);
}