react-codemod
react-codemod copied to clipboard
[pure-component] Transformation error (Could not replace path)
I have PureComponent
only with static propTypes
and render
I run
npx react-codemod pure-component path_to_component
and I get error
Unable to destructure ComponentName props.
ERR path_to_component Transformation error (Could not replace path)
Error: Could not replace path
at NodePath.replace (path_to_project/node_modules/ast-types/lib/path.js:324:19)
at NodePath.NPp.replace (path_to_project/node_modules/ast-types/lib/node-path.js:62:39)
at NodePath.<anonymous> (path_to_project/node_modules/jscodeshift/src/collections/Node.js:143:20)
at path_to_project/node_modules/jscodeshift/src/Collection.js:75:36
at Array.forEach (<anonymous>)
at Collection.forEach path_to_project/node_modules/jscodeshift/src/Collection.js:74:18)
at Collection.replaceWith (path_to_project/node_modules/jscodeshift/src/collections/Node.js:140:17)
at Collection.replaceWith path_to_project/node_modules/jscodeshift/src/Collection.js:413:43)
at module.exports (path_to_project/node_modules/react-codemod/transforms/pure-component.js:290:15)
Component code example:
import { PureComponent } from 'react';
import { PropTypes } from 'prop-types';
import theme from './theme.module.css'; // css modules
export class ComponentName extends PureComponent {
static propTypes = {
prop: PropTypes.string
};
render() {
const { prop } = this.props;
return (
<div className={theme.componentName}>
<div className={theme.prop}>{prop}</div>
</div>
);
}
};
export default ComponentName;
Can confirm! It does work if you remove all the static properties.