babel-plugin-transform-react-remove-prop-types
babel-plugin-transform-react-remove-prop-types copied to clipboard
Support static class getter propTypes
With classes you can also define your propTypes
on a static getter property, which this plugin doesn't seem to be able to remove currently.
Example:
class MyComponent extends React.Component {
static get propTypes() {
return {
children: PropTypes.node.isRequired
};
}
render() {
return this.props.children;
}
}
Would like this too, just adding another syntax that is almost similar for completeness:
export default class MyComponent extends React.Component {
static propTypes = {
children: PropTypes.node.isRequired,
}
+1. We actually write things in the latter style for stylistic reasons
is there any progress on this?
Static propTypes when defined as a class prop are supported I believe, not sure why the comments state otherwise.
This visitor should take care of both cases.
visitor: {
ClassProperty(path) {
if (path.node.static && path.node.key.name === 'propTypes')
path.remove();
},
ClassMethod(path) {
if (path.node.static && path.node.key.name === 'propTypes')
path.remove();
}
}
@sonaye In this case, we miss a test to assert it :)
Is there any progress on this? I am using this babel plugin but, I still have propTypes that are static fields in my components being transpiled into webpack bundle.