-
-
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
feat: add preserve_imports_with_side_effects option for simplify optimization #6962
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
238baf9
feat: add drop_unused_imports option for simplify optimization
nissy-dev 6d0ae8e
Merge branch 'main' into fix-6771
nissy-dev ddba656
fix: refactor option
nissy-dev 5ee9469
fix: rename option
nissy-dev 6114dce
fix: update option name
nissy-dev ea95e08
fix: update tests
nissy-dev cb6f660
fix: update node test
nissy-dev d52f486
fix: revert test config
nissy-dev 7c24306
Revert "fix: update node test"
nissy-dev d296f8b
feat: refactor simplify option
nissy-dev 65861d8
feat: refactor default function
nissy-dev eaeea1a
fix: ci error
nissy-dev c89bd09
fix: move option to Config
nissy-dev 35c138f
Merge branch 'main' into fix-6771
swc-bot File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
crates/swc_ecma_transforms_optimization/tests/drop_unused_imports.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use swc_common::{chain, pass::Repeat, Mark}; | ||
use swc_ecma_parser::{EsConfig, Syntax}; | ||
use swc_ecma_transforms_base::resolver; | ||
use swc_ecma_transforms_optimization::simplify::dce::{dce, Config}; | ||
use swc_ecma_transforms_testing::test; | ||
use swc_ecma_visit::Fold; | ||
|
||
fn tr() -> impl Fold { | ||
Repeat::new(dce( | ||
Config { | ||
top_level: true, | ||
..Default::default() | ||
}, | ||
Mark::new(), | ||
true, | ||
)) | ||
} | ||
|
||
macro_rules! to { | ||
($name:ident, $src:expr, $expected:expr) => { | ||
test!( | ||
Syntax::Es(EsConfig { | ||
decorators: true, | ||
..Default::default() | ||
}), | ||
|_| chain!(resolver(Mark::new(), Mark::new(), false), tr()), | ||
$name, | ||
$src, | ||
$expected | ||
); | ||
}; | ||
} | ||
|
||
macro_rules! optimized_out { | ||
($name:ident, $src:expr) => { | ||
to!($name, $src, ""); | ||
}; | ||
} | ||
|
||
macro_rules! noop { | ||
($name:ident, $src:expr) => { | ||
to!($name, $src, $src); | ||
}; | ||
} | ||
|
||
to!( | ||
single_pass, | ||
" | ||
const a = 1; | ||
|
||
if (a) { | ||
const b = 2; | ||
} | ||
", | ||
" | ||
const a = 1; | ||
if (a) {} | ||
" | ||
); | ||
|
||
optimized_out!(import_default_unused, "import foo from 'foo'"); | ||
|
||
optimized_out!(import_specific_unused, "import {foo} from 'foo'"); | ||
|
||
optimized_out!(import_mixed_unused, "import foo, { bar } from 'foo'"); | ||
|
||
noop!( | ||
import_export_named, | ||
"import foo from 'src'; export { foo };" | ||
); | ||
|
||
to!( | ||
import_unused_export_named, | ||
"import foo, { bar } from 'src'; export { foo }; ", | ||
"import foo from 'src'; export { foo }; " | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ fn tr() -> impl Fold { | |
..Default::default() | ||
}, | ||
Mark::new(), | ||
false, | ||
)) | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?