Skip to content

Allow removePropTypes to work on declarator variables #215

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

Open
CruuzAzul opened this issue May 5, 2025 · 1 comment
Open

Allow removePropTypes to work on declarator variables #215

CruuzAzul opened this issue May 5, 2025 · 1 comment

Comments

@CruuzAzul
Copy link

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

@CruuzAzul
Copy link
Author

Perhaps @9aoy or @JSerFeng have an idea for this topic? 🤗

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

No branches or pull requests

1 participant