Skip to content

pure-component: support Type Annotations & Class Properties#84

Merged
keyz merged 2 commits intoreactjs:masterfrom
danharper:typeAnnotations
Nov 7, 2016
Merged

pure-component: support Type Annotations & Class Properties#84
keyz merged 2 commits intoreactjs:masterfrom
danharper:typeAnnotations

Conversation

@danharper
Copy link
Contributor

@danharper danharper commented Oct 3, 2016

I was going to split this into a few PRs, but they're kinda related.

Firstly, it now treats any Component with a ClassProperty which isn't props as being impure.

Secondly, it retains any static ClassPropertys.

Finally, it retains props type annotations when transforming to a function.

I haven't used jscodeshift before, so happy to make any changes if there's a cleaner way of accomplishing it :)

// input
class PureWithTypes extends React.Component {
  props: { foo: string };
  render() {
    return <div className={this.props.foo} />;
  }
}

// output
const PureWithTypes = (props: { foo: string }) => {
  return <div className={props.foo} />;
}

@danharper
Copy link
Contributor Author

danharper commented Oct 3, 2016

Oh, this completely errors when running on my own project.. I guess the default parser of jscodeshift is Babylon, but not in the tests?

Edit: the Babylon errors might just be an existing issue, actually (#78).

@cpojer
Copy link
Member

cpojer commented Nov 6, 2016

@keyanzhang can you take a look at this one? :)

@keyz
Copy link
Member

keyz commented Nov 7, 2016

Thanks @danharper, the code looks solid. Note: I manually restarted the build on travis to double check; all the errors are from #88 and not pure-component, so this is good to merge!

@keyz keyz merged commit d0b9a63 into reactjs:master Nov 7, 2016
@danharper
Copy link
Contributor Author

👍 thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants