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

Fix removing declarator type for unsafe-wrap mode. Fixes #175 #180

Closed jjow closed 5 years ago

jjow commented 5 years ago

This is a fix for https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types/issues/175. @lencioni and I figured out that when removing newly unused identifiers in unsafe-wrap mode, we should just use the wrapTemplate instead of the unwrapTemplate.

For example, const sharedPropType = PropTypes.number; would be transformed into:

unwrapTemplate:

if (process.env.NODE_ENV !== "production") {
  const sharedPropType = PropTypes.number; // NOTE the scope issue here! 
}

wrapTemplate:

const sharedPropType = process.env.NODE_ENV !== "production" ? PropTypes.number : {};

Closes #175