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
fix(es/minifier): Mark delete
as a property mutation
#6063
Conversation
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.
swc-bump:
- swc_ecma_minifier
@@ -1040,7 +1061,7 @@ where | |||
v.mark_indexed_with_dynamic_key(); | |||
} | |||
|
|||
if self.ctx.in_assign_lhs { | |||
if self.ctx.in_assign_lhs || self.ctx.is_delete_arg { |
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 only catching delete foo.bar
, but fails to capture delete foo.bar.baz
? Based on the Expr::Ident(obj) = e.obj
we're inside of. Come to think of it, there are a few others like foo().bar
that won't be caught?
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.
For delete foo.bar.baz
, foo
will be marked as property mutated because we don't unset is_delete_arg
for the obj
of MemberExpr
. (
swc/crates/swc_ecma_minifier/src/analyzer/mod.rs
Lines 1032 to 1040 in 114bc97
{ | |
let ctx = Ctx { | |
is_exact_arg: false, | |
is_exact_reassignment: false, | |
is_callee: false, | |
..self.ctx | |
}; | |
e.obj.visit_with(&mut *self.with_ctx(ctx)); | |
} |
And currently, we do not inline properties. But nice catch, we should ensure it when we add partial, per-property inlining.
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, we're tracking if a variable reference has any mutations, and this is now detecting property mutations as a mutation of the variable.
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:
Related issue:
"sourceType": "module"
#6004.