Skip to content
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): Check this in function params #9229

Merged
merged 4 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/swc_ecma_minifier/src/compress/pure/arrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ impl Pure<'_> {
function,
}) = e
{
if contains_this_expr(&function.body) || function.is_generator {
if function.params.iter().any(contains_this_expr)
|| contains_this_expr(&function.body)
|| function.is_generator
{
return;
}

Expand Down Expand Up @@ -65,6 +68,7 @@ impl Pure<'_> {
if m.function.is_generator
|| contains_arguments(&m.function.body)
|| contains_super(&m.function.body)
|| m.function.params.iter().any(contains_this_expr)
{
return;
}
Expand Down
15 changes: 15 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/9186/1/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
o = {
foo() {
return val;
},
s: "test",
};
console.log(o.foo().length);

o = {
foo(val = this.s) {
return val;
},
s: "test",
};
console.log(o.foo().length);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
console.log((o = {
foo: ()=>val,
s: "test"
}).foo().length), console.log((o = {
foo (val1 = this.s) {
return val1;
},
s: "test"
}).foo().length);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"unsafe_arrows": true,
"ecma": 2015,
"evaluate": true,
"side_effects": true
}
14 changes: 14 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/9186/2/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
console.log(
(function () {
while (true) {
console.log(123);
}
})()
);
console.log(
(function (a = this.a) {
while (true) {
console.log(123);
}
})()
);
10 changes: 10 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/9186/2/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
console.log((()=>{
while(true){
console.log(123);
}
})());
console.log(function(a = this.a) {
while(true){
console.log(123);
}
}());
Loading