Fix code generation for async generator methods (#6998)
Fixes generator to write `async *foo() {}` instead of `*async foo() {}`.
This commit is contained in:
@@ -31,12 +31,6 @@ export function _methodHead(node: Object) {
|
||||
const kind = node.kind;
|
||||
const key = node.key;
|
||||
|
||||
if (kind === "method" || kind === "init") {
|
||||
if (node.generator) {
|
||||
this.token("*");
|
||||
}
|
||||
}
|
||||
|
||||
if (kind === "get" || kind === "set") {
|
||||
this.word(kind);
|
||||
this.space();
|
||||
@@ -47,6 +41,12 @@ export function _methodHead(node: Object) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (kind === "method" || kind === "init") {
|
||||
if (node.generator) {
|
||||
this.token("*");
|
||||
}
|
||||
}
|
||||
|
||||
if (node.computed) {
|
||||
this.token("[");
|
||||
this.print(key, node);
|
||||
|
||||
19
packages/babel-generator/test/fixtures/edgecase/async-generator/actual.js
vendored
Normal file
19
packages/babel-generator/test/fixtures/edgecase/async-generator/actual.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
function a() {}
|
||||
function *b() {}
|
||||
async function c() {}
|
||||
async function *d() {}
|
||||
var e = function () {};
|
||||
var f = function *() {};
|
||||
var g = async function () {};
|
||||
var h = async function *() {};
|
||||
|
||||
class A {
|
||||
a() {}
|
||||
*b() {}
|
||||
async c() {}
|
||||
async *d() {}
|
||||
e = () => {};
|
||||
// f = () =>* {};
|
||||
g = async () => {};
|
||||
// h = async () =>* {};
|
||||
}
|
||||
30
packages/babel-generator/test/fixtures/edgecase/async-generator/expected.js
vendored
Normal file
30
packages/babel-generator/test/fixtures/edgecase/async-generator/expected.js
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
function a() {}
|
||||
|
||||
function* b() {}
|
||||
|
||||
async function c() {}
|
||||
|
||||
async function* d() {}
|
||||
|
||||
var e = function () {};
|
||||
|
||||
var f = function* () {};
|
||||
|
||||
var g = async function () {};
|
||||
|
||||
var h = async function* () {};
|
||||
|
||||
class A {
|
||||
a() {}
|
||||
|
||||
*b() {}
|
||||
|
||||
async c() {}
|
||||
|
||||
async *d() {}
|
||||
|
||||
e = () => {}; // f = () =>* {};
|
||||
|
||||
g = async () => {}; // h = async () =>* {};
|
||||
|
||||
}
|
||||
1
packages/babel-generator/test/fixtures/edgecase/async-generator/options.json
vendored
Normal file
1
packages/babel-generator/test/fixtures/edgecase/async-generator/options.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{ "plugins": ["asyncGenerators", "classProperties"] }
|
||||
Reference in New Issue
Block a user