From 59c9f473ae71b68d24bb1d959c69c3795d83ae72 Mon Sep 17 00:00:00 2001 From: Felix Kling Date: Mon, 15 Dec 2014 22:33:47 -0800 Subject: [PATCH] Support async functions in export declarations 6to5 is able to transpile `export async function foo(){}` but acorn-6to5 is unable to parse it. --- acorn.js | 2 +- bin/acorn | 1 + test/tests-6to5.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/acorn.js b/acorn.js index 3aa7f661c7..570ec31b9b 100644 --- a/acorn.js +++ b/acorn.js @@ -3139,7 +3139,7 @@ function parseExport(node) { next(); // export var|const|let|function|class ...; - if (tokType === _var || tokType === _const || tokType === _let || tokType === _function || tokType === _class) { + if (tokType === _var || tokType === _const || tokType === _let || tokType === _function || tokType === _class || tokType === _name && tokVal === 'async') { node.declaration = parseStatement(); node['default'] = false; node.specifiers = null; diff --git a/bin/acorn b/bin/acorn index 2a226da063..dd5baea012 100755 --- a/bin/acorn +++ b/bin/acorn @@ -20,6 +20,7 @@ for (var i = 2; i < process.argv.length; ++i) { else if (arg == "--ecma3") options.ecmaVersion = 3; else if (arg == "--ecma5") options.ecmaVersion = 5; else if (arg == "--ecma6") options.ecmaVersion = 6; + else if (arg == "--ecma7") options.ecmaVersion = 7; else if (arg == "--strictSemicolons") options.strictSemicolons = true; else if (arg == "--locations") options.locations = true; else if (arg == "--silent") silent = true; diff --git a/test/tests-6to5.js b/test/tests-6to5.js index a0a24fe647..708937b9cd 100644 --- a/test/tests-6to5.js +++ b/test/tests-6to5.js @@ -1901,6 +1901,45 @@ test('var obj = { async() {} };', { ecmaVersion: 7 }); +test('export async function foo(){}', { + "type": "Program", + "start": 0, + "end": 29, + "body": [{ + "type": "ExportDeclaration", + "start": 0, + "end": 29, + "declaration": { + "type": "FunctionDeclaration", + "start": 7, + "end": 29, + "id": { + "type": "Identifier", + "start": 22, + "end": 25, + "name": "foo" + }, + "params": [], + "defaults": [], + "rest": null, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 27, + "end": 29, + "body": [] + }, + "expression": false + }, + "default": false, + "specifiers": null, + "source": null + }] +}, { + ecmaVersion: 7 +}); + // ES7: Abstract references test('foo::bar;', {