[parser] Allow optional async methods (#10582)
* Add parsePostMemberNameModifiers to aync method * Add test
This commit is contained in:
parent
cfd26fdbf2
commit
10213655bc
@ -1399,6 +1399,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
method.kind = "method";
|
||||
// The so-called parsed name would have been "async": get the real name.
|
||||
this.parseClassPropertyName(method);
|
||||
this.parsePostMemberNameModifiers(publicMember);
|
||||
|
||||
if (method.key.type === "PrivateName") {
|
||||
// private async method
|
||||
|
||||
3
packages/babel-parser/test/fixtures/typescript/class/async-optional-method/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/class/async-optional-method/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
class A extends B {
|
||||
async method?(val: string): Promise<void>;
|
||||
}
|
||||
268
packages/babel-parser/test/fixtures/typescript/class/async-optional-method/output.json
vendored
Normal file
268
packages/babel-parser/test/fixtures/typescript/class/async-optional-method/output.json
vendored
Normal file
@ -0,0 +1,268 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 66,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 66,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start": 0,
|
||||
"end": 66,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"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": {
|
||||
"type": "Identifier",
|
||||
"start": 16,
|
||||
"end": 17,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 17
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
},
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 18,
|
||||
"end": 66,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 18
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "TSDeclareMethod",
|
||||
"start": 22,
|
||||
"end": 64,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 44
|
||||
}
|
||||
},
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 28,
|
||||
"end": 34,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 14
|
||||
},
|
||||
"identifierName": "method"
|
||||
},
|
||||
"name": "method"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"optional": true,
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start": 36,
|
||||
"end": 47,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 27
|
||||
},
|
||||
"identifierName": "val"
|
||||
},
|
||||
"name": "val",
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start": 39,
|
||||
"end": 47,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 19
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 27
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSStringKeyword",
|
||||
"start": 41,
|
||||
"end": 47,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 21
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 27
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"returnType": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start": 48,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 28
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 43
|
||||
}
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TSTypeReference",
|
||||
"start": 50,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 30
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 43
|
||||
}
|
||||
},
|
||||
"typeName": {
|
||||
"type": "Identifier",
|
||||
"start": 50,
|
||||
"end": 57,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 30
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 37
|
||||
},
|
||||
"identifierName": "Promise"
|
||||
},
|
||||
"name": "Promise"
|
||||
},
|
||||
"typeParameters": {
|
||||
"type": "TSTypeParameterInstantiation",
|
||||
"start": 57,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 37
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 43
|
||||
}
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"type": "TSVoidKeyword",
|
||||
"start": 58,
|
||||
"end": 62,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 38
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 42
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user