fix(es/compat): Handle async in class method parameters (#5560)

This commit is contained in:
magic-akari 2022-08-19 14:49:34 +08:00 committed by GitHub
parent ef4fdd84e4
commit f2c1164026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,12 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"target": "es2016"
},
"module": {
"type": "es6"
},
"isModule": true
}

View File

@ -0,0 +1,4 @@
class Foo {
bar(x = async () => await 1) {
}
}

View File

@ -0,0 +1,6 @@
import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs";
class Foo {
bar(x = /*#__PURE__*/ _async_to_generator(function*() {
return yield 1;
})) {}
}

View File

@ -0,0 +1,22 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es5",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6",
"strict": false,
"strictMode": false,
"lazy": false,
"noInterop": false
},
"minify": false
}

View File

@ -0,0 +1,4 @@
class Foo {
bar(x = async () => await 1) {
}
}

View File

@ -0,0 +1,32 @@
import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs";
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
import _create_class from "@swc/helpers/src/_create_class.mjs";
import regeneratorRuntime from "regenerator-runtime";
var Foo = function() {
"use strict";
function Foo() {
_class_call_check(this, Foo);
}
_create_class(Foo, [
{
key: "bar",
value: function bar() {
var x = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _async_to_generator(regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_ctx) {
while(1)switch(_ctx.prev = _ctx.next){
case 0:
_ctx.next = 2;
return 1;
case 2:
return _ctx.abrupt("return", _ctx.sent);
case 3:
case "end":
return _ctx.stop();
}
}, _callee);
}));
}
}
]);
return Foo;
}();

View File

@ -125,6 +125,9 @@ impl<C: Comments> VisitMut for Actual<C> {
if m.function.body.is_none() {
return;
}
m.visit_mut_children_with(self);
if m.kind != MethodKind::Method || !m.function.is_async {
return;
}