From 0997107e1d3baecfd92ec1f1494dbcb5cd7607c5 Mon Sep 17 00:00:00 2001 From: Johnny Hauser Date: Wed, 25 Oct 2017 10:12:51 -0500 Subject: [PATCH 1/3] oncreate async tests (function, arrow, arrow block) --- test/runtime/samples/oncreate-async-arrow-block/_config.js | 1 + test/runtime/samples/oncreate-async-arrow-block/main.html | 7 +++++++ test/runtime/samples/oncreate-async-arrow/_config.js | 1 + test/runtime/samples/oncreate-async-arrow/main.html | 5 +++++ test/runtime/samples/oncreate-async/_config.js | 1 + test/runtime/samples/oncreate-async/main.html | 7 +++++++ 6 files changed, 22 insertions(+) create mode 100644 test/runtime/samples/oncreate-async-arrow-block/_config.js create mode 100644 test/runtime/samples/oncreate-async-arrow-block/main.html create mode 100644 test/runtime/samples/oncreate-async-arrow/_config.js create mode 100644 test/runtime/samples/oncreate-async-arrow/main.html create mode 100644 test/runtime/samples/oncreate-async/_config.js create mode 100644 test/runtime/samples/oncreate-async/main.html diff --git a/test/runtime/samples/oncreate-async-arrow-block/_config.js b/test/runtime/samples/oncreate-async-arrow-block/_config.js new file mode 100644 index 0000000000..ff8b4c5632 --- /dev/null +++ b/test/runtime/samples/oncreate-async-arrow-block/_config.js @@ -0,0 +1 @@ +export default {}; diff --git a/test/runtime/samples/oncreate-async-arrow-block/main.html b/test/runtime/samples/oncreate-async-arrow-block/main.html new file mode 100644 index 0000000000..6a3f4c48f1 --- /dev/null +++ b/test/runtime/samples/oncreate-async-arrow-block/main.html @@ -0,0 +1,7 @@ + diff --git a/test/runtime/samples/oncreate-async-arrow/_config.js b/test/runtime/samples/oncreate-async-arrow/_config.js new file mode 100644 index 0000000000..ff8b4c5632 --- /dev/null +++ b/test/runtime/samples/oncreate-async-arrow/_config.js @@ -0,0 +1 @@ +export default {}; diff --git a/test/runtime/samples/oncreate-async-arrow/main.html b/test/runtime/samples/oncreate-async-arrow/main.html new file mode 100644 index 0000000000..b37145dd17 --- /dev/null +++ b/test/runtime/samples/oncreate-async-arrow/main.html @@ -0,0 +1,5 @@ + diff --git a/test/runtime/samples/oncreate-async/_config.js b/test/runtime/samples/oncreate-async/_config.js new file mode 100644 index 0000000000..ff8b4c5632 --- /dev/null +++ b/test/runtime/samples/oncreate-async/_config.js @@ -0,0 +1 @@ +export default {}; diff --git a/test/runtime/samples/oncreate-async/main.html b/test/runtime/samples/oncreate-async/main.html new file mode 100644 index 0000000000..b8b74050b2 --- /dev/null +++ b/test/runtime/samples/oncreate-async/main.html @@ -0,0 +1,7 @@ + From 5275892152ee589f559ffec8890c5cda742ab04f Mon Sep 17 00:00:00 2001 From: Johnny Hauser Date: Wed, 25 Oct 2017 10:20:35 -0500 Subject: [PATCH 2/3] keep "async" keyword for async oncreate functions --- src/generators/Generator.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 5b7ec8f071..6e78d0fc74 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -509,7 +509,8 @@ 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}✂]` : @@ -517,11 +518,11 @@ export default class Generator { 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}✂]; } `); @@ -529,10 +530,13 @@ export default class Generator { }; 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}✂]; `); }; From c5943d7b6dfae66060486a93e6c8372a453441b6 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 28 Oct 2017 11:27:10 -0400 Subject: [PATCH 3/3] skip async-await tests below node 8 --- test/runtime/samples/oncreate-async-arrow-block/_config.js | 4 +++- test/runtime/samples/oncreate-async-arrow/_config.js | 4 +++- test/runtime/samples/oncreate-async/_config.js | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/test/runtime/samples/oncreate-async-arrow-block/_config.js b/test/runtime/samples/oncreate-async-arrow-block/_config.js index ff8b4c5632..ce28992e0a 100644 --- a/test/runtime/samples/oncreate-async-arrow-block/_config.js +++ b/test/runtime/samples/oncreate-async-arrow-block/_config.js @@ -1 +1,3 @@ -export default {}; +export default { + skip: +(/^v(\d)/.exec(process.version)[0]) < 8 +}; diff --git a/test/runtime/samples/oncreate-async-arrow/_config.js b/test/runtime/samples/oncreate-async-arrow/_config.js index ff8b4c5632..ce28992e0a 100644 --- a/test/runtime/samples/oncreate-async-arrow/_config.js +++ b/test/runtime/samples/oncreate-async-arrow/_config.js @@ -1 +1,3 @@ -export default {}; +export default { + skip: +(/^v(\d)/.exec(process.version)[0]) < 8 +}; diff --git a/test/runtime/samples/oncreate-async/_config.js b/test/runtime/samples/oncreate-async/_config.js index ff8b4c5632..ce28992e0a 100644 --- a/test/runtime/samples/oncreate-async/_config.js +++ b/test/runtime/samples/oncreate-async/_config.js @@ -1 +1,3 @@ -export default {}; +export default { + skip: +(/^v(\d)/.exec(process.version)[0]) < 8 +};