-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix(es/minifier): take ident for ObjectPatProp::Assign with value: Some(_)
#9465
Conversation
|
@@ -0,0 +1,3 @@ | |||
const a = 1; | |||
const { b = "b", c, d } = {}; |
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.
Even with pure_getters
, the computation of the default value for assignment may still have side effects.
For example:
const { b = console.log("b"), c, d } = {};
@Austaras 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.
ignore_return_value
will check if the expr is side-effect-free.
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.
ignore_return_value
will check if the expr is side-effect-free.
It seems that take_ident_of_pat_if_unused
will return before calling ignore_return_value
, so that the expression will always be removed if unused.
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.
ignore_return_value
will check if the expr is side-effect-free.
No. There're multiple places that would call take_pat_if_unused
like drop_unused_arrow_params
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.
Maybe just check that assign value is side effect free using may_have_side_effects
?
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.
may_have_side_effects
I tried it. But expressions with pure annotation cannot be recognized so that there're still side-effect-free expressions in output code.
Input code
const { a = /*#__PURE__*/ sideEffectFree(), b = "b" } = {};
Output code
const { a = /*#__PURE__*/ sideEffectFree() } = {};
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.
See the latest commit, expected output is
const { a = sideEffect(), d } = {};
console.log(d);
but got
const { a = /*#__PURE__*/ sideEffectFree(sideEffect()), d } = {};
console.log(d);
is_pure_callee
doesn't consume the pure annotation.
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.
It's intentional, and if we want to drop it we can invoke ignore_return_value
from the method.
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.
…estructuring with default value
c1c126c
to
9711739
Compare
CodSpeed Performance ReportMerging #9465 will not alter performanceComparing Summary
|
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 we extract all side effects to somewhere, and drop useless bindings instead of checking for side-effect-free from here?
It's how other passes work.
I made #9478 |
Assign of object pattern only run when the binding's value is |
Maybe we could invoke |
Yeap it would be fine. |
Should we apply the optimize of export function Component(props) {
const { a, b } = props;
}
|
@@ -164,6 +164,53 @@ impl Optimizer<'_> { | |||
params.retain(|p| !p.is_invalid()); | |||
} | |||
|
|||
#[cfg_attr(feature = "debug", tracing::instrument(skip_all))] | |||
fn take_ident_of_obj_pat_if_unused_and_side_effect_free( |
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 is unnecessarily complex.
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.
OK.
This pr could be closed and then follow #9478.
Description:
In order to remove unused variables declared by object destructuring with default value, call
take_ident_of_pat_if_unused
forObjectPatProp::Assign
whosevalue
matchSome(_)
Related issue: