disallow line terminator after async contextual keyword - fixes #1711
This commit is contained in:
@@ -292,7 +292,7 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
//
|
||||
if (this.options.features["es7.asyncFunctions"]) {
|
||||
// async functions!
|
||||
if (id.name === "async") {
|
||||
if (id.name === "async" && !this.canInsertSemicolon()) {
|
||||
// arrow functions
|
||||
if (this.type === tt.parenL) {
|
||||
let expr = this.parseParenAndDistinguishExpression(start, true, true)
|
||||
|
||||
@@ -9,6 +9,7 @@ var STATE_KEYS = [
|
||||
"lastTokEnd",
|
||||
"lineStart",
|
||||
"startLoc",
|
||||
"curLine",
|
||||
"endLoc",
|
||||
"start",
|
||||
"pos",
|
||||
|
||||
@@ -83,10 +83,13 @@ pp.parseStatement = function(declaration, topLevel) {
|
||||
return starttype === tt._import ? this.parseImport(node) : this.parseExport(node)
|
||||
|
||||
case tt.name:
|
||||
if (this.options.features["es7.asyncFunctions"] && this.value === "async" && this.lookahead().type === tt._function) {
|
||||
this.next();
|
||||
this.expect(tt._function);
|
||||
return this.parseFunction(node, true, false, true);
|
||||
if (this.options.features["es7.asyncFunctions"] && this.value === "async") {
|
||||
var lookahead = this.lookahead();
|
||||
if (lookahead.type === tt._function && !this.canInsertSemicolon.call(lookahead)) {
|
||||
this.next();
|
||||
this.expect(tt._function);
|
||||
return this.parseFunction(node, true, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
// If the statement does not start with a statement keyword or a
|
||||
|
||||
@@ -620,6 +620,63 @@ testFail("function foo(promise) { await promise; }", "Unexpected token (1:30)",
|
||||
features: { "es7.asyncFunctions": true }
|
||||
});
|
||||
|
||||
testFail("var x = async\n(x) => x + 1;", "Unexpected token (2:4)", {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.asyncFunctions": true }
|
||||
});
|
||||
|
||||
test("async\nfunction foo() {}", {
|
||||
type: "Program",
|
||||
body: [
|
||||
{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "Identifier",
|
||||
name: "async",
|
||||
loc: {
|
||||
start: {line: 1, column: 0},
|
||||
end: {line: 1, column: 5}
|
||||
}
|
||||
},
|
||||
loc: {
|
||||
start: {line: 1, column: 0},
|
||||
end: {line: 1, column: 5}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "FunctionDeclaration",
|
||||
id: {
|
||||
type: "Identifier",
|
||||
name: "foo",
|
||||
loc: {
|
||||
start: {line: 2, column: 9},
|
||||
end: {line: 2, column: 12}
|
||||
}
|
||||
},
|
||||
params: [],
|
||||
body: {
|
||||
type: "BlockStatement",
|
||||
body: [],
|
||||
loc: {
|
||||
start: {line: 2, column: 15},
|
||||
end: {line: 2, column: 17}
|
||||
}
|
||||
},
|
||||
generator: false,
|
||||
expression: false,
|
||||
async: false,
|
||||
loc: {
|
||||
start: {line: 2, column: 0},
|
||||
end: {line: 2, column: 17}
|
||||
}
|
||||
}
|
||||
]
|
||||
}, {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.asyncFunctions": true },
|
||||
locations: true
|
||||
});
|
||||
|
||||
test('async function foo(promise) { await promise; }', {
|
||||
type: "Program",
|
||||
body: [{
|
||||
|
||||
Reference in New Issue
Block a user