Skip to content

Commit

Permalink
Merge branch 'm59peacemaker-oncreate-async-#904'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Oct 28, 2017
2 parents fee5754 + c5943d7 commit 3e9d974
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 4 deletions.
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
3 changes: 3 additions & 0 deletions test/runtime/samples/oncreate-async-arrow-block/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
skip: +(/^v(\d)/.exec(process.version)[0]) < 8
};
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>
3 changes: 3 additions & 0 deletions test/runtime/samples/oncreate-async-arrow/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
skip: +(/^v(\d)/.exec(process.version)[0]) < 8
};
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>
3 changes: 3 additions & 0 deletions test/runtime/samples/oncreate-async/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
skip: +(/^v(\d)/.exec(process.version)[0]) < 8
};
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>

0 comments on commit 3e9d974

Please sign in to comment.