facebook / facebook/jscodeshift

Problems with `renameTo` and block scope

オープン
#263 コメント 2 件 リアクション 3 件 担当者 0 名 GitHub で見る
bug
主要言語
JavaScript
スター
10k
フォーク
498
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。