Are you using the latest verion of NUglify, especially if used through BunderMinifier? Update before raising a bug as your issue is probably already fixed
Yes - V1.21.9
Describe the bug
Typescript compiles null chaining in a similar manner to the below:
Typescript input:
for (let myOption of collection) {
if (myOption.purpose === purpose) {
return myOption;
}
if (myOption.subItems?.length > 0 ?? false) {
myNextCollection.push(...myOption.subItems);
}
}
const findByCriteriaRecursive=function(n,t){for(var r,f,i=[],u=0,e=n;u<e.length;u++){if(r=e[u],r.criteria===t)return r;(!0&&f!==void 0?f:!1)&&i.push.apply(i,r.subItems)}return i.length>0?findByCriteriaRecursive(i,t):null},myTestItem=[{id:1,criteria:"Not this one",subItems:[]},{id:2,criteria:"Not this one either",subItems:[{id:3,criteria:"Nor this one",subItems:[]}]},{id:4,criteria:"It's in here",subItems:[{id:5,criteria:"HelloWorld",subItems:[]}]},];console.log(findByCriteriaRecursive(myTestItem,"HelloWorld"))
Excepted output code
const findByCriteriaRecursive=function(n,t){for(var r,f,i=[],u=0,e=n;u<e.length;u++){if(r=e[u],f=r.subItems,r.criteria===t)return r;(!0&&f!==void 0?f:!1)&&i.push.apply(i,r.subItems)}return i.length>0?findByCriteriaRecursive(i,t):null},myTestItem=[{id:1,criteria:"Not this one",subItems:[]},{id:2,criteria:"Not this one either",subItems:[{id:3,criteria:"Nor this one",subItems:[]}]},{id:4,criteria:"It's in here",subItems:[{id:5,criteria:"HelloWorld",subItems:[]}]},];console.log(findByCriteriaRecursive(myTestItem,"HelloWorld"))
Are you using the latest verion of NUglify, especially if used through BunderMinifier? Update before raising a bug as your issue is probably already fixed Yes - V1.21.9
Describe the bug Typescript compiles null chaining in a similar manner to the below: Typescript input:
Typescript output:
When minified with NUglify, we end up with this:
f is never assigned, so the condition to recurse through the subItems object is never executed.
To Reproduce I have produced a small sample based on the real example above (typescript compilation removed from the picture):
Minified output or stack trace
Excepted output code