p42ai / js-assistant

120+ refactorings and code-assists for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=p42ai.refactor
MIT License
125 stars 8 forks source link

`You can remove the IIFE` is unsafe #52

Closed AlexXanderGrib closed 2 years ago

AlexXanderGrib commented 2 years ago

Code:

function tick() { /* works with canvas */ }

(function loop() {
  tick();
  requestAnimationFrame(loop);
})();

p42 suggests to remove IIFE and deems it safe. Result:

{
  tick();
  requestAnimationFrame(loop); // So loop is undefined
}
lgrammel commented 2 years ago

Thanks for the bug report!

Starting in v1.147.2, remove IIFE is not available any more when there are self-references to the function. Please re-open if the bug still occurs.