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

Set correct async/generator in IIFE for params #11346

Merged
merged 3 commits into from Mar 29, 2020
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
6 changes: 6 additions & 0 deletions packages/babel-plugin-transform-parameters/src/params.js
Expand Up @@ -181,6 +181,12 @@ export default function convertFunctionParams(path, loose) {
const bodyPath = path.get("body.body");
const arrowPath = bodyPath[bodyPath.length - 1].get("argument.callee");
arrowPath.arrowFunctionToExpression();

arrowPath.node.generator = path.node.generator;
arrowPath.node.async = path.node.async;

path.node.generator = false;
path.node.async = false;
} else {
path.get("body").unshiftContainer("body", body);
}
Expand Down
@@ -0,0 +1,14 @@
function* f(a = 1) {
var a = yield a;
return a;
}

async function g(a = 1) {
var a = await a;
return a;
}

async function* h(a = 1) {
var a = await (yield a);
return a;
}
@@ -0,0 +1,5 @@
{
"plugins": [
"transform-parameters"
]
}
@@ -0,0 +1,23 @@
function f() {
let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
return function* (a) {
var a = yield a;
return a;
}(a);
}

function g() {
let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
Copy link
Member

Choose a reason for hiding this comment

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

The default expression could actually throw a sync error, which needs to be caught sand turned into a rejected promise.

return async function (a) {
var a = await a;
return a;
}(a);
}

function h() {
let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
return async function* (a) {
var a = await (yield a);
return a;
}(a);
}