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

fix(ts): allow abstract methods with export default abstract class #12748

Merged
merged 1 commit into from Feb 3, 2021
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
2 changes: 1 addition & 1 deletion packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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": [
Expand Down Expand Up @@ -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,
Expand All @@ -61,46 +68,47 @@
"start":75,"end":77,"loc":{"start":{"line":3,"column":25},"end":{"line":3,"column":27}},
"body": []
}
},
"trailingComments": [
}
},
{
"type": "ExportDefaultDeclaration",
"start":133,"end":166,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":33}},
"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}}
}
]
},
{
"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}},
"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": []
},
"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}}
}
]
}
},
{
"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"},
Expand All @@ -111,16 +119,62 @@
"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": []
Expand Down