mirror of
https://github.com/swc-project/swc.git
synced 2024-10-05 04:39:06 +03:00
fix(es/minifier): Check this
in function params (#9229)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/9186
This commit is contained in:
parent
2f22fee353
commit
da4866d13b
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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);
|
@ -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);
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"unsafe_arrows": true,
|
||||
"ecma": 2015,
|
||||
"evaluate": true,
|
||||
"side_effects": true
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
console.log(
|
||||
(function () {
|
||||
while (true) {
|
||||
console.log(123);
|
||||
}
|
||||
})()
|
||||
);
|
||||
console.log(
|
||||
(function (a = this.a) {
|
||||
while (true) {
|
||||
console.log(123);
|
||||
}
|
||||
})()
|
||||
);
|
@ -0,0 +1,10 @@
|
||||
console.log((()=>{
|
||||
while(true){
|
||||
console.log(123);
|
||||
}
|
||||
})());
|
||||
console.log(function(a = this.a) {
|
||||
while(true){
|
||||
console.log(123);
|
||||
}
|
||||
}());
|
Loading…
Reference in New Issue
Block a user