-
-
Notifications
You must be signed in to change notification settings - Fork 747
feat(minifier): remove unused import source/defer statements #17085
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
base: main
Are you sure you want to change the base?
feat(minifier): remove unused import source/defer statements #17085
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
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.
Pull request overview
This PR extends the minifier's unused declaration removal functionality to handle import source and import defer statements, which are newer import phase proposals. When these imports are determined to be unused, they are completely removed (converted to empty statements) rather than converted to side-effect imports, since phase imports have specific semantics.
Key Changes
- Added logic to detect and remove unused import source/defer statements when the imported binding is not referenced
- Added comprehensive test coverage for both import source and import defer scenarios
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging #17085 will not alter performanceComparing Summary
Footnotes
|
5ef1052 to
743488a
Compare
|
|
||
| let Statement::ImportDeclaration(import_decl) = stmt else { return }; | ||
|
|
||
| if import_decl.phase.is_some() { |
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.
| if import_decl.phase.is_some() { | |
| if let Some(phase) = import_decl.phase { | |
| let (ImportPhase::Defer | ImportPhase::Source) = phase; |
I'm not sure if this is idiomatic, but I think it'd be nice to have this check so that we notice we have to verify the condition here when a new phase is added.
| "", | ||
| &options, | ||
| ); | ||
| test_same_options("import defer * as a from 'a'; foo(a.bar);", &options); |
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.
| test_same_options("import defer * as a from 'a'; foo(a.bar);", &options); | |
| test_same_options("import defer * as a from 'a'; foo(a);", &options); | |
| test_same_options("import defer * as a from 'a'; foo(a.bar);", &options); |

fixes #16893
fixes #16894