From 766e42d1404fde83d6b44b2bca0200c00cc67cdc Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 25 Jan 2015 23:44:17 +1100 Subject: [PATCH] clean up async function declaration parsing --- acorn.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/acorn.js b/acorn.js index 168732d657..6f49749bc8 100644 --- a/acorn.js +++ b/acorn.js @@ -2622,20 +2622,6 @@ raise(tokStart, "'import' and 'export' may only appear at the top level"); return starttype === _import ? parseImport(node) : parseExport(node); - case _name: - /*if (options.ecmaVersion >= 7 && tokVal === "async") { - var start = storeCurrentPos(); - var expr = startNode(); - var id = parseIdent(); - - if (tokType === _function) { - next(); - return parseFunction(expr, true, true); - } else { - // ??? - } - }*/ - // If the statement does not start with a statement keyword or a // brace, it's an ExpressionStatement or LabeledStatement. We // simply start parsing an expression, and afterwards, if the @@ -2644,6 +2630,13 @@ default: var maybeName = tokVal, expr = parseExpression(false, true); + if (options.ecmaVersion >= 7 && starttype === _name && maybeName === "async" && tokType === _function) { + next(); + var func = parseFunctionStatement(node); + func.async = true; + return func; + } + if (starttype === _name && expr.type === "Identifier") { if (eat(_colon)) { return parseLabeledStatement(node, maybeName, expr); @@ -3233,9 +3226,6 @@ // normal functions if (tokType === _function) { - // no line terminator after `async` contextual keyword - if (canInsertSemicolon()) return id; - next(); return parseFunction(node, false, true); }