-
Notifications
You must be signed in to change notification settings - Fork 290
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
Migrate ReactNative View.propTypes to ViewPropTypes #99
Conversation
…g codemod on Facebook internal codebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
🎉 |
We probably don't have this pattern internally so it's fine, but if |
That's interesting. Good thing to be aware of, @keyanzhang. When scanning the diff I ran internally I didn't see any such substitutions FWIW. |
In open source usage people aren't allowed to reference ViewPropTypes directly because CommonJS instead of Haste. Except in the internals of react-native. How is open source going to require this? require('react-native').ViewPropTypes |
@sebmarkbage Yeah, I added a getter for |
ReactNative
will soon be deprecatingView.propTypes
in favor ofViewPropTypes
. This codemod helps with that deprecation by doing the following:View.propTypes
and replaces them withViewPropTypes
.import
orrequire
statement (depending on the convention followed in the parent file) for the newViewPropTypes
.import
/require
statement forView
if it is no longer in use.import ViewPropTypes from 'ViewPropTypes';
) if it detects their use in the file else uses Node modules (egimport { ViewPropTypes } from 'react-native';
).Testing
In addition to the newly added Jest tests this codemod was also run internally against Facebook's
ReactNative
code.Caveats
This codemod may introduce an unnecessary newline before certain types of imports. This is not a problem with the codemod but with recast. See facebook/jscodeshift/issues/185 and benjamn/recast/issues/371
This codemod doesn't handle the case demonstrated below:
This pattern isn't common within Facebook and I didn't think it would be worth the extra complexity it would add to the codemod. If others feel strongly about this I could add support for it.