{"action":"created","issue":{"url":"https://api.github.com/repos/oliviertassinari/babel-plugin-transform-react-remove-prop-types/issues/145","repository_url":"https://api.github.com/repos/oliviertassinari/babel-plugin-transform-react-remove-prop-types","labels_url":"https://api.github.com/repos/oliviertassinari/babel-plugin-transform-react-remove-prop-types/issues/145/labels{/name}","comments_url":"https://api.github.com/repos/oliviertassinari/babel-plugin-transform-react-remove-prop-types/issues/145/comments","events_url":"https://api.github.com/repos/oliviertassinari/babel-plugin-transform-react-remove-prop-types/issues/145/events","html_url":"https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types/issues/145","id":340221301,"node_id":"MDU6SXNzdWUzNDAyMjEzMDE=","number":145,"title":"Feature request: remove unused propTypes intermediate variable","user":{"login":"lencioni","id":195534,"node_id":"MDQ6VXNlcjE5NTUzNA==","avatar_url":"https://avatars3.githubusercontent.com/u/195534?v=4","gravatar_id":"","url":"https://api.github.com/users/lencioni","html_url":"https://github.com/lencioni","followers_url":"https://api.github.com/users/lencioni/followers","following_url":"https://api.github.com/users/lencioni/following{/other_user}","gists_url":"https://api.github.com/users/lencioni/gists{/gist_id}","starred_url":"https://api.github.com/users/lencioni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lencioni/subscriptions","organizations_url":"https://api.github.com/users/lencioni/orgs","repos_url":"https://api.github.com/users/lencioni/repos","events_url":"https://api.github.com/users/lencioni/events{/privacy}","received_events_url":"https://api.github.com/users/lencioni/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-11T12:31:13Z","updated_at":"2018-07-25T19:03:45Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"This is a request for a feature similar to #75.\r\n\r\n\r\nPulling this comment out from #75 for visibility:\r\n\r\nI'm seeing the same behavior. I think one cause of the unused variable not being removed is that if it contains any function calls the minifier won't remove it in case there are side-effects to the function calls.\r\n\r\nI have noticed the additional problem that when using the `removeImport` option, the imports are also not removed since they are still referenced in the propTypes variable. So even if the minifier was removing the unused variable, it will not remove the imports.\r\n\r\nI think this plugin should be enhanced so that it transforms code that looks like this:\r\n\r\n```jsx\r\nimport React from 'react';\r\nimport PropTypes from 'prop-types';\r\n\r\nconst propTypes = {\r\n  children: PropTypes.node,\r\n};\r\n\r\nexport default class MyComponent extends React.Component {\r\n  render() {\r\n    return <div>{this.props.children}</div>;\r\n  }\r\n}\r\n\r\nMyComponent.propTypes = propTypes;\r\n```\r\n\r\ninto this:\r\n\r\n```jsx\r\nimport React from 'react';\r\n\r\nexport default class MyComponent extends React.Component {\r\n  render() {\r\n    return <div>{this.props.children}</div>;\r\n  }\r\n}\r\n```\r\n\r\nAt least for the simple case when it can be determined that the variable is no longer used.\r\n\r\nAdditionally, we often wrap our propTypes in a function when assigning it to the component, like this:\r\n\r\n```jsx\r\nimport { forbidExtraProps } from 'airbnb-prop-types';\r\n\r\nconst propTypes = {\r\n  // ...\r\n};\r\n\r\nclass MyComponent extends React.Component {\r\n  // ...\r\n}\r\n\r\nMyComponent.propTypes = forbidExtraProps(propTypes);\r\n```\r\n\r\nSo the unused variable detection would ideally be smart enough to transform the above to:\r\n\r\n```jsx\r\nclass MyComponent extends React.Component {\r\n  // ...\r\n}\r\n```\r\n\r\nWhat do you think? Is it worth taking a swing at this?"},"comment":{"url":"https://api.github.com/repos/oliviertassinari/babel-plugin-transform-react-remove-prop-types/issues/comments/407861709","html_url":"https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types/issues/145#issuecomment-407861709","issue_url":"https://api.github.com/repos/oliviertassinari/babel-plugin-transform-react-remove-prop-types/issues/145","id":407861709,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNzg2MTcwOQ==","user":{"login":"lencioni","id":195534,"node_id":"MDQ6VXNlcjE5NTUzNA==","avatar_url":"https://avatars3.githubusercontent.com/u/195534?v=4","gravatar_id":"","url":"https://api.github.com/users/lencioni","html_url":"https://github.com/lencioni","followers_url":"https://api.github.com/users/lencioni/followers","following_url":"https://api.github.com/users/lencioni/following{/other_user}","gists_url":"https://api.github.com/users/lencioni/gists{/gist_id}","starred_url":"https://api.github.com/users/lencioni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lencioni/subscriptions","organizations_url":"https://api.github.com/users/lencioni/orgs","repos_url":"https://api.github.com/users/lencioni/repos","events_url":"https://api.github.com/users/lencioni/events{/privacy}","received_events_url":"https://api.github.com/users/lencioni/received_events","type":"User","site_admin":false},"created_at":"2018-07-25T19:03:44Z","updated_at":"2018-07-25T19:03:44Z","author_association":"CONTRIBUTOR","body":"@oliviertassinari I've added some failing test cases for this here: https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types/pull/146\r\n\r\nDo you have any thoughts about this?"}}
{"actor":{"display_login":"lencioni"}}