Skip to content

Commit

Permalink
Fix parsing async get/set in a class
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Jun 15, 2018
1 parent aefb57a commit c0dfa42
Show file tree
Hide file tree
Showing 13 changed files with 1,452 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3241,12 +3241,8 @@ export class Parser {
isAsync = true;
token = this.lookahead;
key = this.parseObjectPropertyKey();
if (token.type === Token.Identifier) {
if (token.value === 'get' || token.value === 'set') {
this.tolerateUnexpectedToken(token);
} else if (token.value === 'constructor') {
this.tolerateUnexpectedToken(token, Messages.ConstructorIsAsync);
}
if (token.type === Token.Identifier && token.value === 'constructor') {
this.tolerateUnexpectedToken(token, Messages.ConstructorIsAsync);
}
}
}
Expand Down
335 changes: 335 additions & 0 deletions test/fixtures/es2017/async/methods/class-async-get.tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
{
"type": "Program",
"body": [
{
"type": "ClassDeclaration",
"id": {
"type": "Identifier",
"name": "X",
"range": [
6,
7
],
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
}
}
},
"superClass": null,
"body": {
"type": "ClassBody",
"body": [
{
"type": "MethodDefinition",
"key": {
"type": "Identifier",
"name": "get",
"range": [
16,
19
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 19
}
}
},
"computed": false,
"value": {
"type": "FunctionExpression",
"id": null,
"params": [],
"body": {
"type": "BlockStatement",
"body": [],
"range": [
21,
23
],
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 23
}
}
},
"generator": false,
"expression": false,
"async": true,
"range": [
19,
23
],
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 23
}
}
},
"kind": "method",
"static": false,
"range": [
10,
23
],
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 23
}
}
}
],
"range": [
8,
25
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 25
}
}
},
"range": [
0,
25
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
}
}
],
"sourceType": "script",
"range": [
0,
25
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"tokens": [
{
"type": "Keyword",
"value": "class",
"range": [
0,
5
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
}
},
{
"type": "Identifier",
"value": "X",
"range": [
6,
7
],
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
}
}
},
{
"type": "Punctuator",
"value": "{",
"range": [
8,
9
],
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
}
}
},
{
"type": "Identifier",
"value": "async",
"range": [
10,
15
],
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 15
}
}
},
{
"type": "Identifier",
"value": "get",
"range": [
16,
19
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 19
}
}
},
{
"type": "Punctuator",
"value": "(",
"range": [
19,
20
],
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 20
}
}
},
{
"type": "Punctuator",
"value": ")",
"range": [
20,
21
],
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 21
}
}
},
{
"type": "Punctuator",
"value": "{",
"range": [
21,
22
],
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 22
}
}
},
{
"type": "Punctuator",
"value": "}",
"range": [
22,
23
],
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 23
}
}
},
{
"type": "Punctuator",
"value": "}",
"range": [
24,
25
],
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 25
}
}
}
]
}
Loading

0 comments on commit c0dfa42

Please sign in to comment.