facebook / facebook/jscodeshift

Problems with `renameTo` and block scope

Offen
#263 2 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
JavaScript
Sterne
10k
Forks
498
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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)
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.