oliviertassinari / babel-plugin-transform-react-remove-prop-types

Remove unnecessary React propTypes from the production build. :balloon:
MIT License
897 stars 61 forks source link

Add handling for removing propTypes from babel output code #163

Closed gandazgul closed 5 years ago

gandazgul commented 6 years ago

So this is a third party library that ships their compiled code with propTypes, with this change it will removed.

gandazgul commented 6 years ago

In:

var ClassName = _react2.default.createClass({
  displayName: 'ClassName',

  propTypes: {
    string: _react2.default.PropTypes.string,
    func: _react2.default.PropTypes.func,
    boll: _react2.default.PropTypes.bool,
    number: _react2.default.PropTypes.number,
  },

  render: function () { ... }
});

Out:

var ClassName = _react2.default.createClass({
  displayName: 'ClassName',

  render: function () { ... }
});
oliviertassinari commented 6 years ago

Could we add a test case? I thought we were already supporting that. Maybe there is a regression.

gandazgul commented 6 years ago

It doesn't work for me, the function is called createClass in React 16, so the search for the parent returns null. This fix is to both look for the funciona name in a different place (what I saw while debugging)a and the function name being createClass instead of createReactClass (which is an import).

gandazgul commented 6 years ago

I can add a test case, I'll research how to do that.

oliviertassinari commented 6 years ago

I think that we already have a test case for it.

gandazgul commented 6 years ago

You have a test case for the usage of the npm module create-react-class but not for this case which is re-parsing babel output.

I renamed the test case for create-react-class and added one for this case

gandazgul commented 6 years ago

Test cases and build passing, can we merge this?

oliviertassinari commented 5 years ago

@gandazgul Thank you!

gandazgul commented 5 years ago

Woohoo! Thank you!