Skip to content

Implement "export type {}"#11122

Merged
nicolo-ribaudo merged 2 commits intobabel:feat-7.9.0/ts-import-typefrom
nicolo-ribaudo:ts-export-type
Feb 18, 2020
Merged

Implement "export type {}"#11122
nicolo-ribaudo merged 2 commits intobabel:feat-7.9.0/ts-import-typefrom
nicolo-ribaudo:ts-export-type

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

Q                       A
Fixed Issues? Partially fixes #10981
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Implement export type { A } and export type { A } from "mod" new TypeScript syntax in parser, transform and generator.
When this syntax is used, the AST nodes have an exportKind: "type" property, otherwise it is set to exportKind: "value".

TODO (different PR):

  • Add exportKind: "type" for type-only export decarations like export type A = 2 or export interface B {}, etc.

@nicolo-ribaudo nicolo-ribaudo added PR: New Feature 🚀 A type of pull request used for our changelog categories pkg: generator pkg: parser area: typescript labels Feb 10, 2020
@nicolo-ribaudo nicolo-ribaudo added this to the v7.9.0 milestone Feb 10, 2020
@@ -0,0 +1 @@
export type { T } from './mod';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a new test

export type from "./mod"

where both exportDefaultFrom and typescript are enabled? So we can cover the situation when this.isContextual("type") is true but the lookahead char is not left bracket.

{
"plugins": ["exportDefaultFrom", "typescript"],
"sourceType": "module",
"throws": "Unexpected token, expected \"=\" (1:17)"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this work before this PR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It throws before this PR because isExportDefaultSpecifier returns false

isExportDefaultSpecifier(): boolean {

It may be copied and revised from flow plugin. I think we should consider relax the constraint unless banned by the export-default-from proposal.

@nicolo-ribaudo nicolo-ribaudo changed the title [typescript] Implement "export type {}" Implement "export type {}" Feb 18, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit 1227e10 into babel:feat-7.9.0/ts-import-type Feb 18, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the ts-export-type branch February 18, 2020 00:11
nicolo-ribaudo added a commit that referenced this pull request Feb 26, 2020
* [typescript] Implement "export type {}"

* test: add test on default-type-with-typescript

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
nicolo-ribaudo added a commit that referenced this pull request Mar 2, 2020
* [typescript] Implement "export type {}"

* test: add test on default-type-with-typescript

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
nicolo-ribaudo added a commit that referenced this pull request Mar 16, 2020
* Add support for type only imports in TS (#11053)
* Implement "export type {}" (#11122)
* Add "exportKind: type" when needed with TS (#11157)
* Add `onlyRemoveTypeImports` option to `transform-typescript` (#11173)
* Add onlyRemoveTypeImports to preset-typescript (#11179)

Co-authored-by: Brian Ng <bng412@gmail.com>
Co-authored-by: Raja Sekar <rajasekarm.dev@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Kai Cataldo <kai@kaicataldo.com>
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
Co-authored-by: Henry Zhu <smiley.we@gmail.com>
Co-authored-by: Siddhant N Trivedi <sidntrivedi012@gmail.com>
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 19, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator pkg: parser PR: New Feature 🚀 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants