facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.27k stars 478 forks source link

Scope issues with Rename #521

Open analtevs opened 2 years ago

analtevs commented 2 years ago

this example comes from some obfuscated code

function Os(n){
...
}
...
const i = function t() {
  var e = Os;
  new MutationObserver((t=>{
    var r = e; 
    for (const e of t) {
      if (e[r(1849)] !== r(1336)) continue;
      for (const t of e['addedNodes']) if (t['tagName'] === r(416) && 'modulepreload' === t['rel']) i(t)
    }
  })) [e(2593)](document, {childList: !![], subtree: !![]});
}

when renaming e = Os i expected r to be renamed. the const e is getting in the way of this with regards to scope.

posted an example on astexplorer here

if cosnt e is manually renamed then i do get the expected results (r = Os)