Skip to content

Commit

Permalink
Treat await as a reserved word when parsing as a module.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Jul 14, 2015
1 parent 5917ae4 commit 3b17c76
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 0 deletions.
5 changes: 5 additions & 0 deletions esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,9 @@
node = new Node();

if (type === Token.Identifier) {
if (sourceType === 'module' && lookahead.value === 'await') {
tolerateUnexpectedToken(lookahead);
}
expr = node.finishIdentifier(lex().value);
} else if (type === Token.StringLiteral || type === Token.NumericLiteral) {
isAssignmentTarget = isBindingElement = false;
Expand Down Expand Up @@ -3933,6 +3936,8 @@
} else {
throwUnexpectedToken(token);
}
} else if (sourceType === 'module' && token.type === Token.Identifier && token.value === 'await') {
tolerateUnexpectedToken(token);
}

return node.finishIdentifier(token.value);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/ES6/identifier/invalid_expression_await.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var answer = await + 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":20,"lineNumber":1,"column":21,"message":"Error: Line 1: Unexpected identifier","description":"Unexpected identifier"}
1 change: 1 addition & 0 deletions test/fixtures/ES6/identifier/invalid_function_wait.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function await() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":9,"lineNumber":1,"column":10,"message":"Error: Line 1: Unexpected identifier","description":"Unexpected identifier"}
1 change: 1 addition & 0 deletions test/fixtures/ES6/identifier/invalid_var_await.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var await;
1 change: 1 addition & 0 deletions test/fixtures/ES6/identifier/invalid_var_await.module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":11,"lineNumber":1,"column":12,"message":"Error: Line 1: Unexpected identifier","description":"Unexpected identifier"}
1 change: 1 addition & 0 deletions test/fixtures/ES6/identifier/module_await.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await = 0;
100 changes: 100 additions & 0 deletions test/fixtures/ES6/identifier/module_await.tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"range": [
0,
10
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"type": "Program",
"body": [
{
"range": [
0,
10
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"type": "ExpressionStatement",
"expression": {
"range": [
0,
9
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
},
"type": "AssignmentExpression",
"operator": "=",
"left": {
"range": [
0,
5
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"type": "Identifier",
"name": "await"
},
"right": {
"range": [
8,
9
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
}
},
"type": "Literal",
"value": 0,
"raw": "0"
}
}
}
],
"sourceType": "module",
"errors": [
{
"index": 0,
"lineNumber": 1,
"column": 1,
"message": "Error: Line 1: Unexpected identifier"
}
]
}
1 change: 1 addition & 0 deletions test/fixtures/ES6/identifier/valid_await.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var await; (await);
110 changes: 110 additions & 0 deletions test/fixtures/ES6/identifier/valid_await.tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"range": [
0,
19
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"type": "Program",
"body": [
{
"range": [
0,
10
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"type": "VariableDeclaration",
"declarations": [
{
"range": [
4,
9
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 9
}
},
"type": "VariableDeclarator",
"id": {
"range": [
4,
9
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 9
}
},
"type": "Identifier",
"name": "await"
},
"init": null
}
],
"kind": "var"
},
{
"range": [
11,
19
],
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 19
}
},
"type": "ExpressionStatement",
"expression": {
"range": [
12,
17
],
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 17
}
},
"type": "Identifier",
"name": "await"
}
}
]
}

0 comments on commit 3b17c76

Please sign in to comment.