Allow TSInterfaceDeclaration to be default export (#8408)
<!-- Before making a PR, please read our contributing guidelines https://github.com/babel/babel/blob/master/CONTRIBUTING.md For issue references: Add a comma-separated list of a [closing word](https://help.github.com/articles/closing-issues-via-commit-messages/) followed by the ticket number fixed by the PR. (it should be underlined in the preview if done correctly) If you are making a change that should have a docs update: submit another PR to https://github.com/babel/website --> | Q | A <!--(Can use an emoji 👍) --> | ------------------------ | --- | Fixed Issues? | Fixes #7118 | Patch: Bug Fix? | Y | Major: Breaking Change? | N | Minor: New Feature? | N | Tests Added + Pass? | Yes | Documentation PR Link | | Any Dependency Changes? | | License | MIT
This commit is contained in:
parent
1a0fe993f5
commit
55ca90b3fc
@ -1535,6 +1535,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
cls.abstract = true;
|
||||
return cls;
|
||||
}
|
||||
|
||||
// export default interface allowed in:
|
||||
// https://github.com/Microsoft/TypeScript/pull/16040
|
||||
if (this.state.value === "interface") {
|
||||
return this.tsParseDeclaration(
|
||||
this.startNode(),
|
||||
this.state.value,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
return super.parseExportDefaultExpression();
|
||||
}
|
||||
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
export interface I {}
|
||||
// `export default` does not work with interfaces
|
||||
export default interface A {}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 71,
|
||||
"end": 51,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
@ -9,13 +9,13 @@
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 49
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 71,
|
||||
"end": 51,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
@ -23,7 +23,7 @@
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 49
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
@ -92,45 +92,72 @@
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExportDefaultDeclaration",
|
||||
"start": 22,
|
||||
"end": 51,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " `export default` does not work with interfaces",
|
||||
"start": 22,
|
||||
"end": 71,
|
||||
"declaration": {
|
||||
"type": "TSInterfaceDeclaration",
|
||||
"start": 37,
|
||||
"end": 51,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 47,
|
||||
"end": 48,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
"column": 25
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 49
|
||||
"column": 26
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"body": {
|
||||
"type": "TSInterfaceBody",
|
||||
"start": 49,
|
||||
"end": 51,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 27
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 29
|
||||
}
|
||||
}
|
||||
},
|
||||
"body": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": " `export default` does not work with interfaces",
|
||||
"start": 22,
|
||||
"end": 71,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 49
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
2
packages/babel-plugin-transform-typescript/test/fixtures/exports/interface/input.mjs
vendored
Normal file
2
packages/babel-plugin-transform-typescript/test/fixtures/exports/interface/input.mjs
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export interface I {}
|
||||
export default interface A {}
|
||||
Loading…
x
Reference in New Issue
Block a user