Skip to content

Allow removePropTypes to work on declarator variables #215

@mickaelalvs

Description

@mickaelalvs

👋🏼 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 ! 🙏🏼

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions