Skip to content

Class mod breaks on arrow function getInitialState #62

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

Closed
iamricard opened this issue Jul 7, 2016 · 3 comments
Closed

Class mod breaks on arrow function getInitialState #62

iamricard opened this issue Jul 7, 2016 · 3 comments

Comments

@iamricard
Copy link

Hi!

So I ran into an issue where running the mod when getInitialState is an arrow
function it breaks (code has been changed due to corporate IP...):

export default React.createClass({
  displayName: 'MyComponent',

  getInitialState: () => ({
    stateThingOne: 'beep',
    stateThingTwo: 'boop'
  }),

  // ...
})

The error message would be this:

TypeError: Cannot read property 'map' of undefined
    at inlineGetInitialState (class.js:294:12)
    at createConstructor (class.js:343:15)
    at createESClass (class.js:362:11)
    at updateToClass (class.js:477:7)
    at NodePath.<anonymous> (class.js:507:31)
    at __paths.forEach (/Users/ricard.sole/.nvm/versions/node/v6.2.2/lib/node_modules/jscodeshift/dist/Collection.js:71:36)
    at Array.forEach (native)
    at Collection.forEach (/Users/ricard.sole/.nvm/versions/node/v6.2.2/lib/node_modules/jscodeshift/dist/Collection.js:70:18)
    at apply (class.js:507:10)
    at module.exports (class.js:514:7)
@reergymerej
Copy link
Contributor

Thanks for the info, @rcsole. Will you be able to submit a PR to fix it?

The scripts in this repository are provided in the hope that they are useful, but they are not officially maintained, and we generally will not fix community-reported issues.
https://github.com/reactjs/react-codemod#support-and-contributing

@keyz
Copy link
Member

keyz commented Jul 7, 2016

Thanks @reergymerej and @rcsole. Please notice that the class codemod will be replaced by #54 (comment) soon.

As @reergymerej mentioned, most of the codemods in this repo are used by Facebook internally -- we try to support the community's needs as much as possible but unfortunately we won't be able to cover every edge case. Internally at Facebook we don't have code like this; given that the level of robustness required for codemods (they are used internally across our entire front end code base), I guess we won't take a PR unless it has been intensively battle-tested. Thanks!

@keyz keyz closed this as completed Jul 7, 2016
@cpojer
Copy link
Member

cpojer commented Jul 7, 2016

Just to clear it up: we are happy to take all and any PRs on this repo as long as there are proper tests for it and the code is in a good shape :)

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

4 participants