Skip to content

Conversation

jamiebuilds
Copy link
Contributor

This is all I have time for now so I'm throwing it up into a PR.

Trying to figure out why Jest won't run.

Re: https://twitter.com/cpojer/status/656602748050247680

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@zpao
Copy link
Member

zpao commented Oct 20, 2015

FWIW: tests look like they are running for me, but there are a few pre-existing failures

@zpao
Copy link
Member

zpao commented Oct 20, 2015

Oh actually I bet it isn't wouldn't be running - add your case in https://github.com/reactjs/react-codemod/blob/master/test/__tests__/transform-tests.js. That won't solve general issues with jest not running but will make sure your test does run when you work that out.

@cpojer
Copy link
Member

cpojer commented Oct 20, 2015

yeah I'll take a look soon-ish at why the tests are failing.

@thejameskyle awesome work! :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should do a didTransform kinda thing and only return a non-null value if the .size() of this collection is > 0.

See https://github.com/reactjs/react-codemod/blob/master/transforms/pure-render-mixin.js#L172

@cpojer
Copy link
Member

cpojer commented Oct 21, 2015

This is a good start! The tests should be fixed on master now.

  • Maybe take a look at the pure-render-mixin and class transforms in this file for the general structure. I think this codemod should be defensive and only inline actually pure components. It could print a console.warn that says that it skipped a class (class.js has a nice copy-paste-able warning thing).
  • Move everything into module.exports to make it actually work
  • Maybe add this: https://github.com/reactjs/react-codemod/blob/master/transforms/pure-render-mixin.js#L168 for safety!
@fkling
Copy link
Member

fkling commented Oct 21, 2015

It could print a console.warn that says that it skipped a class (class.js has a nice copy-paste-able warning thing).

There is also the stats function. It's basically a keyed counter. If you do a dry run, it prints how often stats was called with that argument. E.g. if a class with more than a render function is encountered, you could call api.stats('complex class') and it would print something like complex class: 4 in the dry run.

Useful for collecting statistics about your codebase / codemod.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@jamiebuilds
Copy link
Contributor Author

Threw together a Babel plugin as well. Thought it'd be a useful optimization to run in a production build https://github.com/thejameskyle/babel-plugin-react-pure-components

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this variant should probably take the argument of the ReturnStatement if the length of renderBody.body is one and it only contains a return statement :)

@cpojer
Copy link
Member

cpojer commented Oct 21, 2015

Yay! Would you mind flattening your commits into a single one before I merge? :)

@cpojer
Copy link
Member

cpojer commented Oct 29, 2015

Dammit, I missed this because github doesn't notify me about force pushes to PRs.

cpojer added a commit that referenced this pull request Oct 29, 2015
@cpojer cpojer merged commit c4bb692 into reactjs:master Oct 29, 2015
@jamiebuilds jamiebuilds deleted the tjk/pure-component branch October 29, 2015 23:46
@jamiebuilds
Copy link
Contributor Author

Sorry, I knew that, should've pinged you.

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

5 participants