fix(ts): allow abstract methods with export default abstract class (#12748)
This commit is contained in:
parent
7fb6048e7c
commit
94ba66c89b
@ -2085,8 +2085,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
if (this.isAbstractClass()) {
|
||||
const cls = this.startNode();
|
||||
this.next(); // Skip "abstract"
|
||||
this.parseClass(cls, true, true);
|
||||
cls.abstract = true;
|
||||
this.parseClass(cls, true, true);
|
||||
return cls;
|
||||
}
|
||||
|
||||
|
||||
@ -5,3 +5,4 @@ export abstract class C3 {}
|
||||
export default abstract class { }
|
||||
export default abstract class C4 { }
|
||||
// `abstract class` is not valid as an expression.
|
||||
export default abstract class C5 { abstract foo(): void; }
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":254,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":50}},
|
||||
"start":0,"end":313,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":58}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":254,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":50}},
|
||||
"start":0,"end":313,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":58}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
@ -43,6 +43,13 @@
|
||||
{
|
||||
"type": "ExportNamedDeclaration",
|
||||
"start":50,"end":77,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":27}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " `export abstract class {}` is not valid TypeScript.",
|
||||
"start":78,"end":132,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":54}}
|
||||
}
|
||||
],
|
||||
"exportKind": "value",
|
||||
"specifiers": [],
|
||||
"source": null,
|
||||
@ -61,46 +68,47 @@
|
||||
"start":75,"end":77,"loc":{"start":{"line":3,"column":25},"end":{"line":3,"column":27}},
|
||||
"body": []
|
||||
}
|
||||
},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " `export abstract class {}` is not valid TypeScript.",
|
||||
"start":78,"end":132,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":54}}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "ExportDefaultDeclaration",
|
||||
"start":133,"end":166,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":33}},
|
||||
"exportKind": "value",
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"start":148,"end":166,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":33}},
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":163,"end":166,"loc":{"start":{"line":5,"column":30},"end":{"line":5,"column":33}},
|
||||
"body": []
|
||||
},
|
||||
"abstract": true
|
||||
},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " `export abstract class {}` is not valid TypeScript.",
|
||||
"start":78,"end":132,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":54}}
|
||||
}
|
||||
]
|
||||
],
|
||||
"exportKind": "value",
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"start":148,"end":166,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":33}},
|
||||
"abstract": true,
|
||||
"id": null,
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":163,"end":166,"loc":{"start":{"line":5,"column":30},"end":{"line":5,"column":33}},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportDefaultDeclaration",
|
||||
"start":167,"end":203,"loc":{"start":{"line":6,"column":0},"end":{"line":6,"column":36}},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " `abstract class` is not valid as an expression.",
|
||||
"start":204,"end":254,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":50}}
|
||||
}
|
||||
],
|
||||
"exportKind": "value",
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"start":182,"end":203,"loc":{"start":{"line":6,"column":15},"end":{"line":6,"column":36}},
|
||||
"abstract": true,
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":197,"end":199,"loc":{"start":{"line":6,"column":30},"end":{"line":6,"column":32},"identifierName":"C4"},
|
||||
@ -111,17 +119,63 @@
|
||||
"type": "ClassBody",
|
||||
"start":200,"end":203,"loc":{"start":{"line":6,"column":33},"end":{"line":6,"column":36}},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"abstract": true
|
||||
},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "ExportDefaultDeclaration",
|
||||
"start":255,"end":313,"loc":{"start":{"line":8,"column":0},"end":{"line":8,"column":58}},
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " `abstract class` is not valid as an expression.",
|
||||
"start":204,"end":254,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":50}}
|
||||
}
|
||||
],
|
||||
"exportKind": "value",
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"start":270,"end":313,"loc":{"start":{"line":8,"column":15},"end":{"line":8,"column":58}},
|
||||
"abstract": true,
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":285,"end":287,"loc":{"start":{"line":8,"column":30},"end":{"line":8,"column":32},"identifierName":"C5"},
|
||||
"name": "C5"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":288,"end":313,"loc":{"start":{"line":8,"column":33},"end":{"line":8,"column":58}},
|
||||
"body": [
|
||||
{
|
||||
"type": "TSDeclareMethod",
|
||||
"start":290,"end":311,"loc":{"start":{"line":8,"column":35},"end":{"line":8,"column":56}},
|
||||
"abstract": true,
|
||||
"static": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start":299,"end":302,"loc":{"start":{"line":8,"column":44},"end":{"line":8,"column":47},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"computed": false,
|
||||
"kind": "method",
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"returnType": {
|
||||
"type": "TSTypeAnnotation",
|
||||
"start":304,"end":310,"loc":{"start":{"line":8,"column":49},"end":{"line":8,"column":55}},
|
||||
"typeAnnotation": {
|
||||
"type": "TSVoidKeyword",
|
||||
"start":306,"end":310,"loc":{"start":{"line":8,"column":51},"end":{"line":8,"column":55}}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user