Skip to content
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

[pure-component] Transformation error (Could not replace path) #288

Open
oleggrishechkin opened this issue Mar 24, 2021 · 1 comment
Open

Comments

@oleggrishechkin
Copy link

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;
@tnagorra
Copy link

tnagorra commented Jun 8, 2021

Can confirm! It does work if you remove all the static properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants