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:
Brian Ng 2018-07-31 12:57:57 -05:00 committed by GitHub
parent 1a0fe993f5
commit 55ca90b3fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 34 deletions

View File

@ -1535,6 +1535,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
cls.abstract = true; cls.abstract = true;
return cls; 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(); return super.parseExportDefaultExpression();
} }

View File

@ -1,2 +1,2 @@
export interface I {} export interface I {}
// `export default` does not work with interfaces export default interface A {}

View File

@ -1,7 +1,7 @@
{ {
"type": "File", "type": "File",
"start": 0, "start": 0,
"end": 71, "end": 51,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
@ -9,13 +9,13 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 49 "column": 29
} }
}, },
"program": { "program": {
"type": "Program", "type": "Program",
"start": 0, "start": 0,
"end": 71, "end": 51,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
@ -23,7 +23,7 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 49 "column": 29
} }
}, },
"sourceType": "module", "sourceType": "module",
@ -92,13 +92,12 @@
}, },
"body": [] "body": []
} }
}
}, },
"trailingComments": [
{ {
"type": "CommentLine", "type": "ExportDefaultDeclaration",
"value": " `export default` does not work with interfaces",
"start": 22, "start": 22,
"end": 71, "end": 51,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
@ -106,31 +105,59 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 49 "column": 29
}
},
"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": 25
},
"end": {
"line": 2,
"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": [] "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
} }
}
}
]
} }

View File

@ -0,0 +1,2 @@
export interface I {}
export default interface A {}