Skip to content

Commit

Permalink
Fix visitor to not remove catch clause param when binding being assig…
Browse files Browse the repository at this point in the history
…ned a new value
  • Loading branch information
MarckK committed Aug 8, 2017
1 parent 3dde13b commit f0de374
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 57 deletions.
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-remove-unused-catch-binding",
"version": "7.0.0-alpha.18",
"version": "7.0.0-alpha.19",
"description": "Remove unused catch bindings",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-remove-unused-catch-binding",
"license": "MIT",
Expand All @@ -9,9 +9,9 @@
"babel-plugin"
],
"dependencies": {
"babel-plugin-syntax-optional-catch-binding": "7.0.0-alpha.18"
"babel-plugin-syntax-optional-catch-binding": "7.0.0-alpha.19"
},
"devDependencies": {
"babel-helper-plugin-test-runner": "7.0.0-alpha.18"
"babel-helper-plugin-test-runner": "7.0.0-alpha.19"
}
}
Expand Up @@ -6,10 +6,17 @@ export default function() {

visitor: {
CatchClause(path) {
const binding = path.scope.getOwnBinding(path.node.param.name);
if (
binding.constantViolations.filter(el => {
return el.node.left.name === path.node.param.name;
}).length > 0
) {
return;
}
if (
path.node.param &&
!path.scope.getOwnBinding(path.node.param.name).referenced &&
!path.scope.getOwnBinding(path.node.param.name).constantViolation &&
!binding.referenced &&
path.scope.hasBinding(path.node.param.name)
) {
const paramPath = path.get("param");
Expand Down
58 changes: 6 additions & 52 deletions yarn.lock
Expand Up @@ -1013,10 +1013,6 @@ babylon@7.0.0-beta.18:
version "7.0.0-beta.18"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.18.tgz#5c23ee3fdb66358aabf3789779319c5b78a233c7"

babylon@7.0.0-beta.19, babylon@^7.0.0-beta.19:
version "7.0.0-beta.19"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.19.tgz#e928c7e807e970e0536b078ab3e0c48f9e052503"

babylon@^6.17.2, babylon@^6.17.4:
version "6.17.4"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.4.tgz#3e8b7402b88d22c3423e137a1577883b15ff869a"
Expand Down Expand Up @@ -1280,10 +1276,6 @@ caller-path@^0.1.0:
dependencies:
callsites "^0.2.0"

callsite@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20"

callsites@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-0.2.0.tgz#afab96262910a7f33c19a5775825c69f34e350ca"
Expand Down Expand Up @@ -1529,15 +1521,7 @@ concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

concat-stream@^1.4.10, concat-stream@^1.4.6, concat-stream@^1.5.0, concat-stream@^1.5.2:
version "1.6.0"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.0.tgz#0aac662fd52be78964d5532f694784e70110acf7"
dependencies:
inherits "^2.0.3"
readable-stream "^2.2.2"
typedarray "^0.0.6"

concat-stream@~1.5.0, concat-stream@~1.5.1:
concat-stream@^1.4.10, concat-stream@^1.4.6, concat-stream@^1.5.0, concat-stream@^1.5.2, concat-stream@~1.5.0, concat-stream@~1.5.1:
version "1.5.2"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.5.2.tgz#708978624d856af41a5a741defdd261da752c266"
dependencies:
Expand Down Expand Up @@ -1863,12 +1847,6 @@ debug@2.6.8, debug@^2.1.1, debug@^2.2.0, debug@^2.6.3:
dependencies:
ms "2.0.0"

decache@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/decache/-/decache-4.1.0.tgz#2037d5edf756dda230c85023659e7c3d1d6e0105"
dependencies:
callsite "^1.0.0"

decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
Expand Down Expand Up @@ -1897,12 +1875,6 @@ default-require-extensions@^1.0.0:
dependencies:
strip-bom "^2.0.0"

default-require-extensions@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-2.0.0.tgz#f5f8fbb18a7d6d50b21f641f649ebb522cfe24f7"
dependencies:
strip-bom "^3.0.0"

defaults@^1.0.0, defaults@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
Expand Down Expand Up @@ -2250,7 +2222,7 @@ estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"

esutils@^2.0.0, esutils@^2.0.2:
esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"

Expand Down Expand Up @@ -4050,7 +4022,7 @@ minimatch@~0.2.11:
lru-cache "2"
sigmund "~1.0.0"

minimist@0.0.8:
minimist@0.0.8, minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

Expand All @@ -4062,10 +4034,6 @@ minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

mkdirp@0.5.1, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
Expand Down Expand Up @@ -5323,7 +5291,7 @@ subarg@^1.0.0:
dependencies:
minimist "^1.1.0"

supports-color@3.1.2:
supports-color@3.1.2, supports-color@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5"
dependencies:
Expand All @@ -5333,12 +5301,6 @@ supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"

supports-color@^3.1.2:
version "3.2.3"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.2.3.tgz#65ac0504b3954171d8a64946b2ae3cbb8a5f54f6"
dependencies:
has-flag "^1.0.0"

supports-color@^4.0.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.2.1.tgz#65a4bb2631e90e02420dba5554c375a4754bb836"
Expand Down Expand Up @@ -5504,10 +5466,6 @@ trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"

try-resolve@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/try-resolve/-/try-resolve-1.0.1.tgz#cfde6fabd72d63e5797cfaab873abbe8e700e912"

tryit@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"
Expand Down Expand Up @@ -5540,7 +5498,7 @@ type-detect@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.3.tgz#0e3f2670b44099b0b46c284d136a7ef49c74c2ea"

typedarray@^0.0.6, typedarray@~0.0.5:
typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

Expand Down Expand Up @@ -5747,14 +5705,10 @@ window-size@0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d"

wordwrap@0.0.2:
wordwrap@0.0.2, wordwrap@~0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f"

wordwrap@~0.0.2:
version "0.0.3"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"

wordwrap@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
Expand Down

0 comments on commit f0de374

Please sign in to comment.