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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const instance = new Component();
instance.componentWillMount();
instance.componentDidMount();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const instance = new Component();
instance.UNSAFE_componentWillMount();
instance.componentDidMount();
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const React = require('React');

class Component extends React.Component {
componentWillMount() {
this.componentWillReceiveProps(this.props);
}
componentWillReceiveProps() {}
render() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const React = require('React');

class Component extends React.Component {
UNSAFE_componentWillMount() {
this.UNSAFE_componentWillReceiveProps(this.props);
}
UNSAFE_componentWillReceiveProps() {}
render() {
return null;
}
}
2 changes: 2 additions & 0 deletions transforms/__tests__/rename-unsafe-lifecycles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const tests = [
'arrow-functions',
'create-react-class',
'instance-methods',
'manually-calling-lifecycles',
'one-lifecycle-calls-another',
'standalone-function',
'variable-within-class-method',
];
Expand Down
18 changes: 18 additions & 0 deletions transforms/rename-unsafe-lifecycles.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ export default (file, api, options) => {
}
};

const renameDeprecatedCallExpressions = path => {
if (!path.node.callee || !path.node.callee.property) {
return;
}

const name = path.node.callee.property.name;

if (DEPRECATED_APIS[name]) {
path.node.callee.property.name = DEPRECATED_APIS[name];
hasModifications = true;
}
};

// Class methods
root
.find(j.MethodDefinition)
Expand All @@ -51,6 +64,11 @@ export default (file, api, options) => {
.find(j.Property)
.forEach(renameDeprecatedApis);

// Function calls
root
.find(j.CallExpression)
.forEach(renameDeprecatedCallExpressions);

return hasModifications
? root.toSource(printOptions)
: null;
Expand Down