Skip to content

Commit 5275892

Browse files
committed
keep "async" keyword for async oncreate functions
1 parent 0997107 commit 5275892

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/generators/Generator.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,30 +509,34 @@ export default class Generator {
509509
});
510510

511511
const addArrowFunctionExpression = (name: string, node: Node) => {
512-
const { body, params } = node;
512+
const { body, params, async } = node;
513+
const fnKeyword = async ? 'async function' : 'function';
513514

514515
const paramString = params.length ?
515516
`[✂${params[0].start}-${params[params.length - 1].end}✂]` :
516517
``;
517518

518519
if (body.type === 'BlockStatement') {
519520
componentDefinition.addBlock(deindent`
520-
function ${name}(${paramString}) [✂${body.start}-${body.end}✂]
521+
${fnKeyword} ${name}(${paramString}) [✂${body.start}-${body.end}✂]
521522
`);
522523
} else {
523524
componentDefinition.addBlock(deindent`
524-
function ${name}(${paramString}) {
525+
${fnKeyword} ${name}(${paramString}) {
525526
return [✂${body.start}-${body.end}✂];
526527
}
527528
`);
528529
}
529530
};
530531

531532
const addFunctionExpression = (name: string, node: Node) => {
533+
const { async } = node;
534+
const fnKeyword = async ? 'async function' : 'function';
535+
532536
let c = node.start;
533537
while (this.source[c] !== '(') c += 1;
534538
componentDefinition.addBlock(deindent`
535-
function ${name}[✂${c}-${node.end}✂];
539+
${fnKeyword} ${name}[✂${c}-${node.end}✂];
536540
`);
537541
};
538542

0 commit comments

Comments
 (0)