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

Elide import = statements that are only used as a type #441

Merged
merged 1 commit into from Mar 31, 2019

Conversation

alangpierce
Copy link
Owner

Fixes #422

In both CJS and ESM, we now look at the identifier in import A = and decide
whether to elide the entire statement in a similar way to normal TS import
elision. Since there are only two forms that these statements can have, I just
special cased the two when deleting statements.

Technically to implement this totally correctly, I'd need something like a graph
traversal: in an import A = B.C; statement, B is referenced as a value if
A is ever referenced as a value, so deciding if an import should be elided
requires following an arbitrary number of import statements. In practice, I
think this syntax is only ever used to pull in types (for values, you can just
use const, and the syntax is obscure anyway), so I treat it as a type
statement that gets elided.

Fixes #422

In both CJS and ESM, we now look at the identifier in `import A =` and decide
whether to elide the entire statement in a similar way to normal TS import
elision. Since there are only two forms that these statements can have, I just
special cased the two when deleting statements.

Technically to implement this totally correctly, I'd need something like a graph
traversal: in an `import A = B.C;` statement, `B` is referenced as a value if
`A` is ever referenced as a value, so deciding if an import should be elided
requires following an arbitrary number of import statements. In practice, I
think this syntax is only ever used to pull in types (for values, you can just
use `const`, and the syntax is obscure anyway), so I treat it as a type
statement that gets elided.
@codecov-io
Copy link

Codecov Report

Merging #441 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #441      +/-   ##
==========================================
+ Coverage   81.16%   81.28%   +0.12%     
==========================================
  Files          49       50       +1     
  Lines        5367     5392      +25     
  Branches     1200     1204       +4     
==========================================
+ Hits         4356     4383      +27     
+ Misses        712      711       -1     
+ Partials      299      298       -1
Impacted Files Coverage Δ
src/index.ts 89.36% <ø> (ø) ⬆️
src/transformers/ESMImportTransformer.ts 83.33% <100%> (+0.57%) ⬆️
src/transformers/CJSImportTransformer.ts 87.98% <100%> (+0.15%) ⬆️
src/CJSImportProcessor.ts 92.23% <100%> (+0.07%) ⬆️
src/util/elideImportEquals.ts 100% <100%> (ø)
src/parser/plugins/typescript.ts 79.54% <0%> (+0.28%) ⬆️

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 fd0f689...4a65e5e. Read the comment docs.

@alangpierce alangpierce merged commit bd1ee84 into master Mar 31, 2019
@alangpierce alangpierce deleted the elide-import-equals branch March 31, 2019 21:37
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.

None yet

2 participants