From 56bc618d33b22480ec2ed4f0a186e83024602a50 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 2 Jan 2015 04:21:56 +1100 Subject: [PATCH] actually parse async functions as statements --- acorn.js | 49 +++++++++++++++++++++++++++---------------------- package.json | 2 +- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/acorn.js b/acorn.js index f1c6cf4077..df16c19886 100644 --- a/acorn.js +++ b/acorn.js @@ -2008,7 +2008,7 @@ if (tokType === _slash || tokType === _assign && tokVal == "/=") readToken(true); - var starttype = tokType, node = startNode(); + var starttype = tokType, node = startNode(), start = storeCurrentPos(); // Most types of statements are recognized by the keyword they // start with. Many are trivial to parse, some require a bit of @@ -2043,28 +2043,33 @@ // next token is a colon and the expression was a simple // Identifier node, we switch to interpreting it as a label. default: - var maybeName = tokVal, expr = parseExpression(); - if (starttype === _name) { - if (expr.type === "FunctionExpression" && expr.async) { - expr.type = "FunctionDeclaration"; - return expr; - } else if (expr.type === "Identifier") { - if (eat(_colon)) { - return parseLabeledStatement(node, maybeName, expr); - } + if (tokType === _name && tokVal === "async") { + var id = parseIdent(); + if (tokType === _function) { + next(); + return parseFunction(node, true, true); + } else { + return parseSubscripts(id, start); + } + } - if (options.ecmaVersion >= 7 && expr.name === "private" && tokType === _name) { - return parsePrivate(node); - } else if (expr.name === "declare") { - if (tokType === _class || tokType === _name || tokType === _function || tokType === _var) { - return parseDeclare(node); - } - } else if (tokType === _name) { - if (expr.name === "interface") { - return parseInterface(node); - } else if (expr.name === "type") { - return parseTypeAlias(node); - } + var maybeName = tokVal, expr = parseExpression(); + if (starttype === _name && expr.type === "Identifier") { + if (eat(_colon)) { + return parseLabeledStatement(node, maybeName, expr); + } + + if (options.ecmaVersion >= 7 && expr.name === "private" && tokType === _name) { + return parsePrivate(node); + } else if (expr.name === "declare") { + if (tokType === _class || tokType === _name || tokType === _function || tokType === _var) { + return parseDeclare(node); + } + } else if (tokType === _name) { + if (expr.name === "interface") { + return parseInterface(node); + } else if (expr.name === "type") { + return parseTypeAlias(node); } } } diff --git a/package.json b/package.json index e48fd1d010..f7e89739c3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "acorn-6to5", "description": "Acorn fork used by 6to5", "main": "acorn.js", - "version": "0.11.1-1", + "version": "0.11.1-2", "maintainers": [ { "name": "Marijn Haverbeke",