Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions transforms/React-PropTypes-to-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,17 @@ function replacePropTypesReferences(j, root) {
.forEach(path => {
hasModifications = true;

j(path.parent).replaceWith(
j.identifier('PropTypes')
);
// VariableDeclarator should be removed entirely
// eg 'PropTypes = React.PropTypes'
if (path.parent.parent.node.type === 'VariableDeclarator') {
j(path.parent.parent).remove();
} else {
// MemberExpression should be updated
// eg 'foo = React.PropTypes.string'
j(path.parent).replaceWith(
j.identifier('PropTypes')
);
}
});

return hasModifications;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const React = require('react');

// These are no longer needed after the transform
const PropTypes = React.PropTypes;
const {PropTypes} = React;

// This should remain, modified
const string = React.PropTypes.string;
const bool = PropTypes.bool;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const PropTypes = require('prop-types');
const React = require('react');

// This should remain, modified
const string = PropTypes.string;
const bool = PropTypes.bool;
1 change: 1 addition & 0 deletions transforms/__tests__/React-PropTypes-to-prop-types-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'use strict';

const tests = [
'assigned-from-react-var',
'default-and-named-import',
'default-import',
'destructured-proptypes-import',
Expand Down