{"action":"created","issue":{"url":"https://api.github.com/repos/babel/babel/issues/4586","repository_url":"https://api.github.com/repos/babel/babel","labels_url":"https://api.github.com/repos/babel/babel/issues/4586/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel/issues/4586/comments","events_url":"https://api.github.com/repos/babel/babel/issues/4586/events","html_url":"https://github.com/babel/babel/issues/4586","id":179678894,"number":4586,"title":"babel-traverse cache not initialized with TryStatement path?","user":{"login":"kentcdodds","id":1500684,"avatar_url":"https://avatars.githubusercontent.com/u/1500684?v=3","gravatar_id":"","url":"https://api.github.com/users/kentcdodds","html_url":"https://github.com/kentcdodds","followers_url":"https://api.github.com/users/kentcdodds/followers","following_url":"https://api.github.com/users/kentcdodds/following{/other_user}","gists_url":"https://api.github.com/users/kentcdodds/gists{/gist_id}","starred_url":"https://api.github.com/users/kentcdodds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kentcdodds/subscriptions","organizations_url":"https://api.github.com/users/kentcdodds/orgs","repos_url":"https://api.github.com/users/kentcdodds/repos","events_url":"https://api.github.com/users/kentcdodds/events{/privacy}","received_events_url":"https://api.github.com/users/kentcdodds/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-28T04:43:57Z","updated_at":"2016-09-28T09:54:42Z","closed_at":null,"body":"### Input Code\r\n\r\n```js\r\nexport {tryCatch}\r\n\r\nfunction tryCatch(shouldThrow) {\r\n  const ret = {}\r\n  try {\r\n    if (shouldThrow) {\r\n      throw new Error('throw error')\r\n    }\r\n    ret.noThrow = true\r\n  } catch (error) {\r\n    ret.error = error\r\n    return error\r\n  } finally {\r\n    return ret\r\n  }\r\n}\r\n```\r\n\r\n### astexplorer.net\r\n\r\n[Here](https://astexplorer.net/#/SPHNWQu0EQ/1) is the astexplorer.net example\r\n\r\nThe plugin:\r\n\r\n```js\r\nexport default function () {\r\n  return {\r\n    visitor: {\r\n      TryStatement(path) {\r\n        // this plugin is intended to replace the try/catch with simply the code in the try and finally blocks\r\n        path.parentPath.insertAfter([...path.node.block.body, ...path.node.finalizer.body])\r\n        path.remove()\r\n      } \r\n    }\r\n  }\r\n}\r\n```\r\n\r\n### Current Behavior\r\n\r\nGetting error: `Cannot read property 'length' of undefined`\r\nFrom [this line](https://github.com/babel/babel/blob/590ad4d24fef8268696149b3ae67aec54ee12fcc/packages/babel-traverse/src/path/modification.js#L139). It appears that the `pathCache` isn't primed with the paths it needs. I'm not sure I understand what's going on or how to fix it though...\r\n\r\n### Context\r\n\r\nI'm writing a plugin to create a program slice based on code coverage data. So I need to remove the `TryStatement` when the `catch` is uncovered."},"comment":{"url":"https://api.github.com/repos/babel/babel/issues/comments/250123410","html_url":"https://github.com/babel/babel/issues/4586#issuecomment-250123410","issue_url":"https://api.github.com/repos/babel/babel/issues/4586","id":250123410,"user":{"login":"boopathi","id":294474,"avatar_url":"https://avatars.githubusercontent.com/u/294474?v=3","gravatar_id":"","url":"https://api.github.com/users/boopathi","html_url":"https://github.com/boopathi","followers_url":"https://api.github.com/users/boopathi/followers","following_url":"https://api.github.com/users/boopathi/following{/other_user}","gists_url":"https://api.github.com/users/boopathi/gists{/gist_id}","starred_url":"https://api.github.com/users/boopathi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boopathi/subscriptions","organizations_url":"https://api.github.com/users/boopathi/orgs","repos_url":"https://api.github.com/users/boopathi/repos","events_url":"https://api.github.com/users/boopathi/events{/privacy}","received_events_url":"https://api.github.com/users/boopathi/received_events","type":"User","site_admin":false},"created_at":"2016-09-28T09:54:42Z","updated_at":"2016-09-28T09:54:42Z","body":"Maybe you can use this now - \r\n\r\n```js\r\npath.replaceWithMultiple([ path.node.block, path.node.finalizer ])\r\n```\r\n\r\nNote: block scoped variables inside `block` and `finalizer` might give problems if the BlockStatement is removed without checking for those."}}
{"actor":{"display_login":"boopathi"}}