Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/generators/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,30 +509,34 @@ export default class Generator {
});

const addArrowFunctionExpression = (name: string, node: Node) => {
const { body, params } = node;
const { body, params, async } = node;
const fnKeyword = async ? 'async function' : 'function';

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

if (body.type === 'BlockStatement') {
componentDefinition.addBlock(deindent`
function ${name}(${paramString}) [✂${body.start}-${body.end}✂]
${fnKeyword} ${name}(${paramString}) [✂${body.start}-${body.end}✂]
`);
} else {
componentDefinition.addBlock(deindent`
function ${name}(${paramString}) {
${fnKeyword} ${name}(${paramString}) {
return [✂${body.start}-${body.end}✂];
}
`);
}
};

const addFunctionExpression = (name: string, node: Node) => {
const { async } = node;
const fnKeyword = async ? 'async function' : 'function';

let c = node.start;
while (this.source[c] !== '(') c += 1;
componentDefinition.addBlock(deindent`
function ${name}[✂${c}-${node.end}✂];
${fnKeyword} ${name}[✂${c}-${node.end}✂];
`);
};

Expand Down
1 change: 1 addition & 0 deletions test/runtime/samples/oncreate-async-arrow-block/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
7 changes: 7 additions & 0 deletions test/runtime/samples/oncreate-async-arrow-block/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
export default {
oncreate: async () => {
await 123
}
};
</script>
1 change: 1 addition & 0 deletions test/runtime/samples/oncreate-async-arrow/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
5 changes: 5 additions & 0 deletions test/runtime/samples/oncreate-async-arrow/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export default {
oncreate: async () => await 123
};
</script>
1 change: 1 addition & 0 deletions test/runtime/samples/oncreate-async/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
7 changes: 7 additions & 0 deletions test/runtime/samples/oncreate-async/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
export default {
async oncreate() {
await 123
}
};
</script>