Skip to content

Class mod breaks on arrow function getInitialState #62

Description

@iamricard

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)

Activity

  1. reergymerej commented on Jul 7, 2016

    @reergymerej
    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

  2. keyz commented on Jul 7, 2016

    @keyz
    Contributor

    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!

  3. cpojer commented on Jul 7, 2016

    @cpojer
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions