Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support static class getter propTypes #137

Open
freaktechnik opened this issue Feb 20, 2018 · 6 comments
Open

Support static class getter propTypes #137

freaktechnik opened this issue Feb 20, 2018 · 6 comments

Comments

@freaktechnik
Copy link

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;
    }
}
@omichelsen
Copy link

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,
  }

@jeremyong
Copy link

+1. We actually write things in the latter style for stylistic reasons

@koxen
Copy link

koxen commented Apr 6, 2018

is there any progress on this?

@sonaye
Copy link

sonaye commented Jun 8, 2018

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();
  }
}

@oliviertassinari
Copy link
Owner

@sonaye In this case, we miss a test to assert it :)

@Lazzaro83
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants