Skip to content

Commit

Permalink
fix: check await when parsing AsyncArrowBindingIdentifier (#10953)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung authored and nicolo-ribaudo committed Jan 3, 2020
1 parent 467667a commit a283537
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -960,8 +960,18 @@ export default class ExpressionParser extends LValParser {
this.match(tt.name) &&
!this.canInsertSemicolon()
) {
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
const oldYieldPos = this.state.yieldPos;
const oldAwaitPos = this.state.awaitPos;
this.state.maybeInArrowParameters = true;
this.state.yieldPos = -1;
this.state.awaitPos = -1;
const params = [this.parseIdentifier()];
this.expect(tt.arrow);
this.checkYieldAwaitInDefaultParams();
this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
this.state.yieldPos = oldYieldPos;
this.state.awaitPos = oldAwaitPos;
// let foo = async bar => {};
this.parseArrowExpression(node, params, true);
return node;
Expand Down
@@ -0,0 +1 @@
async await => {}
@@ -0,0 +1,107 @@
{
"type": "File",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"errors": [
"SyntaxError: Await cannot be used as name inside an async function (1:6)"
],
"program": {
"type": "Program",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"id": null,
"generator": false,
"async": true,
"params": [
{
"type": "Identifier",
"start": 6,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "await"
},
"name": "await"
}
],
"body": {
"type": "BlockStatement",
"start": 15,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 17
}
},
"body": [],
"directives": []
}
}
}
],
"directives": []
}
}

0 comments on commit a283537

Please sign in to comment.