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 support for TS type-only imports and exports #532

Merged
merged 1 commit into from May 11, 2020

Conversation

alangpierce
Copy link
Owner

Fixes #520

The PR #523 already added parsing support for type-only import and export
syntax, and there was already support for removing import type from Flow, so
the only new logic was to fully support export type. The implementation here
is a little ugly; Flow's version sets the tokens as type tokens, whereas the TS
version sets the types as regular tokens and removes them at transform type.
This seems to be necessary to follow the behavior that export type statements
do not result in the imported value being elided.

Ideally, Sucrase would support the importsNotUsedAsValues TS preference in
some way, but for now, it keeps the old behavior of eliding type-only imports.
The setting importsNotUsedAsValues=error should make the distinction
irrelevant anyway, so it seems low priority to support.

Fixes #520

The PR #523 already added parsing support for type-only import and export
syntax, and there was already support for removing `import type` from Flow, so
the only new logic was to fully support `export type`. The implementation here
is a little ugly; Flow's version sets the tokens as type tokens, whereas the TS
version sets the types as regular tokens and removes them at transform type.
This seems to be necessary to follow the behavior that `export type` statements
do not result in the imported value being elided.

Ideally, Sucrase would support the `importsNotUsedAsValues` TS preference in
some way, but for now, it keeps the old behavior of eliding type-only imports.
The setting `importsNotUsedAsValues=error` should make the distinction
irrelevant anyway, so it seems low priority to support.
@codecov-io
Copy link

Codecov Report

Merging #532 into master will increase coverage by 0.08%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #532      +/-   ##
==========================================
+ Coverage   81.34%   81.43%   +0.08%     
==========================================
  Files          55       55              
  Lines        5479     5493      +14     
  Branches     1289     1293       +4     
==========================================
+ Hits         4457     4473      +16     
+ Misses        735      734       -1     
+ Partials      287      286       -1     
Impacted Files Coverage Δ
src/transformers/CJSImportTransformer.ts 88.20% <85.71%> (+0.21%) ⬆️
src/transformers/ESMImportTransformer.ts 84.07% <100.00%> (+0.74%) ⬆️
src/parser/plugins/typescript.ts 80.87% <0.00%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a8413a...8d322de. Read the comment docs.

@alangpierce alangpierce merged commit aae7da0 into master May 11, 2020
@alangpierce alangpierce deleted the implement-type-type-only-imports-exports branch May 11, 2020 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for type only imports & exports
2 participants