-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
typescript_strip: option to remove completely unused imports #1060
Conversation
I feel this behavior is The import statement For example: // types.ts
windows.a = 1 And in other file:
|
I'm not sure about this.
I agree with you. That's why I implemented it to preserve side effects. But I'm now confused because typescript compiler removes it. |
I think because |
@kdy1 The behaviour you implemented aligns with |
The typescript default is |
Yeah I guess it makes less sense for swc to be opinionated about that. Can it be a configuration option? |
@nayeemrmn I'll add a option to switch behavior, while preserving current semantic as default. |
#[derive(Debug, Serialize, Deserialize)] | ||
#[non_exhaustive] | ||
pub enum ImportNotUsedAsValues { | ||
#[serde(rename = "rename")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename = "remove"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks!
ImportNotUsedAsValues::Preserve => match entry { | ||
Some(&DeclInfo { | ||
has_type: true, | ||
has_concrete: false, | ||
.. | ||
}) => false, | ||
_ => true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kdy1 This is not the behaviour of tsc
under "importsNotUsedAsValues": "preserve"
. The correct behaviour is to never preserve completely unused import identifiers. The above branch should always be used.
I think ImportNotUsedAsValues
should be removed since it's a misunderstanding of the equivalent tsc
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make a breaking change to fix it.
Current behavior is intended for multiple reason.
import type
are only stripped out if it's used as type.ts 3.8 introduced type-only imports, because the problem I wrote above.
(Note that typescript had a breaking change after it)
swc
works on file-by-file basis, so it cannot know if it's a type-only.I'm considering two options.
Implement emit-only tsc which also handles some special stuffs like const enum within swc_bundler, as it already works by loading multiple file.
Add config to allow user select which behavior should be used.
See: denoland/deno#7413 (comment)