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

Avoid removeNewlyUnusedIdentifiers when encountering destructuring #161

Closed lencioni closed 5 years ago

lencioni commented 5 years ago

In 0.14.6, I ran into the following error when updating in a project:

Cannot read property 'referencePaths' of undefined at VariableDeclarator, lib/index.js:292:56

I have so far been unable to reproduce this in our test suite, but I can reproduce it in a local repo by using npm link. I wonder if this could be a weird interaction of multiple babel plugins.

It seems that in the case I am encountering, the VariableDeclarator has an id of type ObjectPattern, which means that there is some object destructuring happening.

We should ideally take care to clean up the destructuring in the same way that we clean up other variable usage, but I think that will be a little more complicated than what I have time for right now, so as a quick fix, I am escaping from this function in this case.

In my local testing, this prevents the plugin from crashing and produces the same result as before.

Fixes #160