swc-plugins
swc-plugins copied to clipboard
Allow `removePropTypes` to work on declarator variables
👋🏼 When migrating to swc, you want to be able to remove proptypes. Previously we used babel-plugin-transform-react-remove-prop-types and swc-plugins seems to be the only alternative.
The problem is that removePropTypes does not take into account and does not work with proptypes declared in constants. For example :
const extraReference = {
bar: PropTypes.string
};
const propTypesWithExtraReference = Object.assign({}, extraReference, {
foo: PropTypes.string
});
const FooExtraReference = () => (
<div />
);
FooExtraReference.propTypes = propTypesWithExtraReference;
will not work and the variable extraReference and propTypesWithExtraReference will be interpreted as <invalid>. Is there a workaround for this? Could the feature be added?
For the babel-plugin-transform-react-remove-prop-types part, you can find the test cases here: https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types/tree/master/test/fixtures/variable-assignment
Thanksss ! 🙏🏼
Perhaps @9aoy or @JSerFeng have an idea for this topic? 🤗