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

Add onlyRemoveTypeImports option to transform-typescript #11173

Conversation

kaicataldo
Copy link
Member

@kaicataldo kaicataldo commented Feb 26, 2020

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

This is based on the feat-7.9.0/ts-import-type branch, and I believed the test failures are from that branch.

With the addition of type-only imports and exports to TypeScript, we are now able to explicitly mark imports as types. This PR adds an onlyExplicitTypeImports option to plugin-transform-typescript, which allows the user to opt into only removing imports that are unambiguously types. We will probably want to make this the default behavior in the future.

Questions for reviewers:

  1. Are there any missing test cases?
  2. Would it be worth adding a second test file that explicitly sets the new option to false?

@nicolo-ribaudo nicolo-ribaudo added area: typescript PR: New Feature 🚀 A type of pull request used for our changelog categories labels Feb 26, 2020
@nicolo-ribaudo nicolo-ribaudo added this to the v7.9.0 milestone Feb 26, 2020
@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Feb 26, 2020

@kaicataldo I have rebased feat-7.9.0/... and your branch on master to make CI pass.

Don't forget to git fetch origin && git reset --hard origin/only-explit-type-imports 🙏

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

WDYT rename the option to onlyRemoveTypeImports or onlyElideTypeImports?

@kaicataldo
Copy link
Member Author

onlyRemoveTypeImports seems like the clearest option name to me.

@nicolo-ribaudo
Copy link
Member

Kai doesn't like using newly learned words! 😛

@kaicataldo
Copy link
Member Author

Maybe I did know the word at some point and it was elided from my vocabulary.

@nicolo-ribaudo
Copy link
Member

Could you also add tests for import {} from "x" and import "x", since they are explicitly pointed out in a comment in the code?

@nicolo-ribaudo
Copy link
Member

Merged into #11171

@nicolo-ribaudo nicolo-ribaudo changed the title [plugin-transform-typescript]: onlyExplicitTypeImports Add onlyRemoveTypeImports option to transform-typescript Feb 26, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit 60989bb into babel:feat-7.9.0/ts-import-type Feb 26, 2020
@kaicataldo kaicataldo deleted the only-explit-type-imports branch February 26, 2020 23:54
@JLHwung
Copy link
Contributor

JLHwung commented Feb 27, 2020

We also need

  1. add this option to preset-typescript.
  2. update docs on https://babeljs.io/docs/en/babel-preset-typescript#options and https://babeljs.io/docs/en/babel-plugin-transform-typescript#options

nicolo-ribaudo pushed a commit that referenced this pull request Mar 2, 2020
* [plugin-transform-typescript]: onlyExplicitTypeImports

* onlyExplicitTypeImports -> onlyRemoveTypeImports

* Add test for exceptions
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 28, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 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 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.

None yet

4 participants