Permalink
Browse files

Fix parsing async get/set in a class

Fixes #1861
Fixes #1875
Closes gh-1939
  • Loading branch information...
ariya committed Jun 10, 2018
1 parent aefb57a commit c0dfa42da4da9fa242dac623278a082cb38edc20
@@ -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);
}
}
}
@@ -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
}
}
}
]
}
Oops, something went wrong.

0 comments on commit c0dfa42

Please sign in to comment.