From a46f87f7261483912bd8ecfa8e5d68ad8b2b7554 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Wed, 19 Jul 2017 13:03:49 -0500 Subject: [PATCH] Check for function when parsing export async (#639) --- src/parser/statement.js | 9 +++++++++ .../es2017/async-functions/export-async/actual.js | 1 + .../es2017/async-functions/export-async/options.json | 4 ++++ 3 files changed, 14 insertions(+) create mode 100644 test/fixtures/es2017/async-functions/export-async/actual.js create mode 100644 test/fixtures/es2017/async-functions/export-async/options.json diff --git a/src/parser/statement.js b/src/parser/statement.js index 566942c7a8..5d99d9c4d6 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -1255,6 +1255,15 @@ export default class StatementParser extends ExpressionParser { this.checkExport(node, true, true); return this.finishNode(node, "ExportDefaultDeclaration"); } else if (this.shouldParseExportDeclaration()) { + if (this.isContextual("async")) { + const next = this.lookahead(); + + // export async; + if (next.type !== tt._function) { + this.unexpected(next.start, "Unexpected token, expected function"); + } + } + node.specifiers = []; node.source = null; node.declaration = this.parseExportDeclaration(node); diff --git a/test/fixtures/es2017/async-functions/export-async/actual.js b/test/fixtures/es2017/async-functions/export-async/actual.js new file mode 100644 index 0000000000..110e84d257 --- /dev/null +++ b/test/fixtures/es2017/async-functions/export-async/actual.js @@ -0,0 +1 @@ +export async; diff --git a/test/fixtures/es2017/async-functions/export-async/options.json b/test/fixtures/es2017/async-functions/export-async/options.json new file mode 100644 index 0000000000..c1f7fc9e8b --- /dev/null +++ b/test/fixtures/es2017/async-functions/export-async/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token, expected function (1:12)" +}