babel: [TypeScript]: Syntax error on "export default interface" syntax
Choose one: is this a bug report or feature request? Bug report.
Input Code
export default interface A {}
Parse error in Babel repl Works in TypeScript repl
Babel/Babylon Configuration (.babelrc, package.json, cli command)
7.0.0-beta.35 repl with TypeScript transform enabled.
Expected Behavior
The syntax was added in https://github.com/Microsoft/TypeScript/pull/16040, so Babel should accept it (and no code should be emitted since it’s a type export).
Current Behavior
Babylon gives a parse error saying it’s an unexpected token.
Possible Solution
Probably something similar to #7075 😄
Context
I have a TypeScript project that I’m trying to run through a custom fork of Babylon, and it’s hitting an error on that syntax.
Your Environment
software | version(s) |
---|---|
Babel | master |
Babylon | master (from the last week or so) |
node | 9.2.0 |
npm | yarn 1.3.2 |
Operating System | macOS 10.13.2 |
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 21 (11 by maintainers)
Commits related to this issue
- [transform-typescript] Add caveat regarding default export of an interface. See https://github.com/babel/babel/issues/7118 and https://github.com/babel/babel/issues/7640 for details. [skip ci] — committed to apepper/babel by apepper 6 years ago
- [transform-typescript] Add caveat regarding default export of an interface. See https://github.com/babel/babel/issues/7118 and https://github.com/babel/babel/issues/7640 for details. [skip ci] — committed to apepper/babel by apepper 6 years ago
- 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 re... — committed to babel/babel by existentialism 6 years ago
- 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 re... — committed to UniSharp/babel by existentialism 6 years ago
I’m looking into adding TypeScript support to babel-codemod and I ran into this issue because babel-codemod itself uses the
export default interface ...
pattern in exactly the way @simonbuchan says (see Resolver.ts).For what it’s worth, I agree that babel should just delete the
export default interface
statement altogether when transforming TypeScript. I might have some time to work on this if nobody else is already going to do so.That would be weird. The TS transform otherwise is tracking new typescript features, the only transform exceptions are ones that require whole-program transformation (
const enum
,namespace
[though I’m not convinced by that one (but thats a different story!)]). Like all pure-type decls, the transform is just to delete it.Why would @Kovensky get to veto typescript language features just because he doesn’t like them?