Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[parser] Parse only modifiers of actual methods #10594

Merged
merged 2 commits into from Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -1348,6 +1348,7 @@ export default class StatementParser extends ExpressionParser {
const isPrivate = key.type === "PrivateName";
// Check the key is not a computed expression or string literal.
const isSimple = key.type === "Identifier";
const maybeQuestionTokenStart = this.state.start;

this.parsePostMemberNameModifiers(publicMember);

Expand Down Expand Up @@ -1403,6 +1404,10 @@ export default class StatementParser extends ExpressionParser {
// an async method
const isGenerator = this.eat(tt.star);

if (publicMember.optional) {
this.unexpected(maybeQuestionTokenStart);
}

method.kind = "method";
// The so-called parsed name would have been "async": get the real name.
this.parseClassPropertyName(method);
Expand Down
@@ -0,0 +1,4 @@
class A {
async?(): void
async?: boolean
}
@@ -0,0 +1,221 @@
{
"type": "File",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "A"
},
"name": "A"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "TSDeclareMethod",
"start": 12,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 16
}
},
"static": false,
"key": {
"type": "Identifier",
"start": 12,
"end": 17,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 7
},
"identifierName": "async"
},
"name": "async"
},
"computed": false,
"optional": true,
"kind": "method",
"id": null,
"generator": false,
"async": false,
"params": [],
"returnType": {
"type": "TSTypeAnnotation",
"start": 20,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 16
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 22,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 16
}
}
}
}
},
{
"type": "ClassProperty",
"start": 29,
"end": 44,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 17
}
},
"static": false,
"key": {
"type": "Identifier",
"start": 29,
"end": 34,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 7
},
"identifierName": "async"
},
"name": "async"
},
"computed": false,
"optional": true,
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start": 35,
"end": 44,
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 3,
"column": 17
}
},
"typeAnnotation": {
"type": "TSBooleanKeyword",
"start": 37,
"end": 44,
"loc": {
"start": {
"line": 3,
"column": 10
},
"end": {
"line": 3,
"column": 17
}
}
}
},
"value": null
}
]
}
}
],
"directives": []
}
}
@@ -0,0 +1,4 @@
class B { }
class A extends B {
async? method(val: string): Promise<void>;
}
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (3:9)"
}