-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: add preserve_imports_with_side_effects option for simplify optimization #6962
Conversation
crates/swc/src/config/mod.rs
Outdated
|
||
#[serde(default)] | ||
pub drop_unused_imports: BoolConfig<false>, |
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.
There was a way to modify the simplify option directly, but I added it in this way to avoid breaking change. What do you think?
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.
Can you move this to the simplify
option?
crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs
Outdated
Show resolved
Hide resolved
I'll merge PRs with breaking changes at once |
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.
Thank you!
As it's a breaking change anyway, we can use correct way.
crates/swc/src/config/mod.rs
Outdated
|
||
#[serde(default)] | ||
pub drop_unused_imports: BoolConfig<false>, |
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.
Can you move this to the simplify
option?
I am thinking that it would be soo good, to have a callback to resolve if a indentifier has side effects or not: So instead of being a |
Nope, it should never be |
Rust-side api is fine, but js api is not fine |
@manucorporat Which API do you use, JS API or Rust API? |
@@ -2,7 +2,6 @@ | |||
"jsc": { | |||
"transform": { | |||
"optimizer": { | |||
"simplify": false, |
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.
Why did you touch this? Please revert
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 Thank you for your reviews. You mean I need to modify simplify
option which receive boolean value and json? Like this.
pub struct OptimizerConfig {
#[serde(default)]
pub simplify: SimplifyOption,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SimplifyOption {
Bool(bool),
Json(SimplifyJsonOption),
}
impl Default for SimplifyOption {
fn default() -> Self {
SimplifyOption::Bool(true)
}
}
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct SimplifyJsonOption {
pub preserve_imports_with_side_effects: bool,
}
If you think so, I will refactor in this way
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.
Yes, thank you!
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 updated!
@@ -30,6 +30,7 @@ use crate::debug_assert_valid; | |||
pub fn dce( | |||
config: Config, | |||
unresolved_mark: Mark, | |||
preserve_imports_with_side_effects: bool, |
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 think this should go into Config type
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 moved this option to dce config.
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.
Thank you!
swc-bump:
- swc_ecma_transforms_optimization --breaking
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.
Automated review comment generated by auto-rebase script
Description: Fix #6771
This implementation is still rough, and there are still some implementation decisions that need to be decided on that I mentioned in my comments.
BREAKING CHANGE: Yes
Related issue (if exists):