From 17e885ce8f07f1a5497099c7f5840234e4cf562e Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Sun, 30 Apr 2017 23:39:27 +1000 Subject: [PATCH] Fix: Set async on async FunctionExpressions (fixes #244) --- lib/ast-converter.js | 2 +- .../async-function-expression.result.js | 330 ++++++++++++++++++ .../basics/async-function-expression.src.ts | 2 + 3 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/typescript/basics/async-function-expression.result.js create mode 100644 tests/fixtures/typescript/basics/async-function-expression.src.ts diff --git a/lib/ast-converter.js b/lib/ast-converter.js index 76805fc..ec795f4 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -1286,7 +1286,7 @@ module.exports = function(ast, extra) { generator: !!node.asteriskToken, params: node.parameters.map(convertChild), body: convertChild(node.body), - async: hasModifier(SyntaxKind.AbstractKeyword, node), + async: hasModifier(SyntaxKind.AsyncKeyword, node), expression: false }); // Process returnType diff --git a/tests/fixtures/typescript/basics/async-function-expression.result.js b/tests/fixtures/typescript/basics/async-function-expression.result.js new file mode 100644 index 0000000..f096104 --- /dev/null +++ b/tests/fixtures/typescript/basics/async-function-expression.result.js @@ -0,0 +1,330 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "range": [ + 0, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "expression": { + "type": "CallExpression", + "range": [ + 0, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "callee": { + "type": "FunctionExpression", + "range": [ + 1, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 16, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "name": "test" + }, + "generator": false, + "params": [], + "body": { + "type": "BlockStatement", + "range": [ + 23, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "body": [] + }, + "async": true, + "expression": false + }, + "arguments": [] + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Punctuator", + "value": "(", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "async", + "range": [ + 1, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 6 + } + } + }, + { + "type": "Keyword", + "value": "function", + "range": [ + 7, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + { + "type": "Identifier", + "value": "test", + "range": [ + 16, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + } + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/async-function-expression.src.ts b/tests/fixtures/typescript/basics/async-function-expression.src.ts new file mode 100644 index 0000000..7849af4 --- /dev/null +++ b/tests/fixtures/typescript/basics/async-function-expression.src.ts @@ -0,0 +1,2 @@ +(async function test() { +})(); \ No newline at end of file