facebook / facebook/jscodeshift

Problems with `renameTo` and block scope

Aperta
#263 2 commenti 3 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
JavaScript
Stelle
10k
Fork
498
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

ES6 Block scoping seems to be broken in `renameTo`.

Repro:
```
jscodeshift: 0.5.0
- babel: 6.26.3
- babylon: 7.0.0-beta.47
- flow: 0.73.0
- recast: 0.14.7
```

Transform:
```js
module.exports = function transform(file, api, options) {
const j = api.jscodeshift
const root = j(file.source)

let first = true
root.find(j.VariableDeclarator)
.filter((path) => {let res = first; first = false; return res}) // select only first declarator
.forEach((path) => {
console.log('have path') // check we have exactly one
})
.renameTo('baz')

return root.toSource()
}
```

Input:
```js
const x = 42
{
const x = 47
console.log(x)
}
console.log(x)
```

Output:
```js
const baz = 42
{
const baz = 47
console.log(baz)
}
console.log(baz)
```

Expected output:
```js
const baz = 42
{
const x = 47
console.log(x)
}
console.log(baz)
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.