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

It seems it does not work when importing modules #14

Closed
romainneutron opened this issue Apr 13, 2016 · 5 comments
Closed

It seems it does not work when importing modules #14

romainneutron opened this issue Apr 13, 2016 · 5 comments
Labels

Comments

@romainneutron
Copy link

If I use this syntax, it works perfectly:

import React from 'react';

export default class MyComp extends React.Component {
    render() { 
        //...
    }
}

MyComp.propTypes = {
    name: React.PropTypes.object
}

however, it does not work like this:

import React, { Component } from 'react';

export default class MyComp extends Component {
    render() { 
        //...
    }
}

MyComp.propTypes = {
    name: React.PropTypes.object
}
@romainneutron
Copy link
Author

For the record, I'm using React 15, and I've spotted the issue down to

if (superClass.matchesPattern('React.Component') || superClass.matchesPattern('Component')) {
  path.remove();
}

In AssignmentExpression : superClass.matchesPattern('Component') returns false because of the second line of the matchesPattern function that return false at line 2:

if (!this.isMemberExpression()) return false;

Changing superClass.matchesPattern('Component') to superClass.node.name === 'Component' solves my issue but I guess it's a wrong fix :)

@oliviertassinari
Copy link
Owner

@romainneutron Thanks for this feedback.
Can you confirm that this pattern is working?

import React, { Component } from 'react';

export default class MyComp extends Component {
    static propTypes = {
        name: React.PropTypes.object
    };

    render() { 
        //...
    }
}

That sounds like the right direction.
We should refactor the AssignmentExpression to use some part of the ClassProperty logic.

@romainneutron
Copy link
Author

I confirm @oliviertassinari , it works better using your snippet

@oliviertassinari
Copy link
Owner

@romainneutron I have just merged a fix.

@romainneutron
Copy link
Author

Thanks for your fast response

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

No branches or pull requests

2 participants