restringer icon indicating copy to clipboard operation
restringer copied to clipboard

Respect order in unwrapIIFEs

Open jorants opened this issue 1 year ago • 1 comments

Fix for https://github.com/PerimeterX/restringer/issues/102

jorants avatar Jan 11 '24 15:01 jorants

Although the mentioned bug seems fixed by this, there is a larger problem, consider:

var a = 0;
var x= 1;
(x=2) + function(){
 a=3
}();
console.log(x)

In general, the IIFE might be part of a larger expression that still needs executing. The safe option would be to only consider IIFE's that are directly part of the body, or a single assignment. This would however ignore cases like

void !function(){
 ... some code with outside effects ...
}

jorants avatar Jan 12 '24 11:01 jorants