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

Support TypeScript 4.5 type-only import/export specifiers #13802

Merged
merged 27 commits into from Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9b91e84
Implement parser
sosukesuzuki Sep 30, 2021
1b20596
Add parser tests
sosukesuzuki Sep 30, 2021
8daf3bc
Implement generator
sosukesuzuki Sep 30, 2021
16b4bc1
Add generator tests
sosukesuzuki Sep 30, 2021
a2edbe3
Implement types
sosukesuzuki Sep 30, 2021
6421008
Implement plugin-transform-typescript
sosukesuzuki Sep 30, 2021
6a596b9
Add plugin-transform-typescript tests
sosukesuzuki Sep 30, 2021
4929209
Remove imported-type from exports
sosukesuzuki Oct 2, 2021
d337f69
Use string literal instead of variable
sosukesuzuki Oct 11, 2021
8cb6dc0
Use set instead of array
sosukesuzuki Oct 11, 2021
4d1cde6
Keep import statement if all of specifiers are type-only one
sosukesuzuki Oct 11, 2021
05d5183
Rename isTypeOnly to hasTypeSpecifier
sosukesuzuki Oct 13, 2021
31b273c
Use isContextual instead of string comparison
sosukesuzuki Oct 15, 2021
ec6398e
Use tokenIsKeywordOrIdentifier instead of match
sosukesuzuki Oct 15, 2021
6b79fd1
Remove import statement if all of specifiers are type-only one
sosukesuzuki Oct 16, 2021
72b3c3b
Merge branch 'main' into type-only-import-specifier
sosukesuzuki Oct 22, 2021
ebf0a58
Fix type errors
sosukesuzuki Oct 22, 2021
d5c69eb
Merge branch 'main' into type-only-import-specifier
sosukesuzuki Oct 25, 2021
d459c8b
Extract parseExportSpecifier
sosukesuzuki Oct 26, 2021
519f977
Extract parameters
sosukesuzuki Oct 28, 2021
cb0f943
Move the logic for error
sosukesuzuki Oct 28, 2021
91918b7
Refactor exports
sosukesuzuki Oct 28, 2021
d074010
Refactor imports
sosukesuzuki Oct 28, 2021
ab1f5c2
Fix lint comments
sosukesuzuki Oct 28, 2021
c44171a
Fix babel-parser/types.js
sosukesuzuki Oct 28, 2021
bfd0f9d
Throw error for string local for import
sosukesuzuki Oct 28, 2021
1f933af
check lval
sosukesuzuki Oct 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-typescript/src/index.ts
Expand Up @@ -288,7 +288,7 @@ export default declare((api, opts) => {
}
}

if (isAllSpecifiersElided()) {
if (!onlyRemoveTypeImports && isAllSpecifiersElided()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why should we keep import statements when onlyRemoveTypeImports is true?

TS removes them anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

@nicolo-ribaudo You said #13802 (review). What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Whoops, I assumed that import { type X } from "x" would have been equivalent to import {} from "x" and thus not removed. I'm sorry!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, interesting. TS removes import {} from "x", too. It preserves only import "x".

Copy link
Member Author

Choose a reason for hiding this comment

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

According to behavior of TypeScript, it is better to remove the Import Statement in such cases. 6b79fd1

stmt.remove();
} else {
for (const importPath of importsToRemove) {
Expand Down
Expand Up @@ -5,5 +5,6 @@ import d, { d2 } from "d";
import e, { e3 as e4 } from "e";
import "f";
import "g";
import "k";
import { L2 } from "l";
;
@@ -0,0 +1 @@
import { type A } from "x";
@@ -0,0 +1,10 @@
{
"plugins": [
[
"transform-typescript",
{
"onlyRemoveTypeImports": true
}
]
]
}
@@ -0,0 +1 @@
import "x";