Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

static class property displayName not taken into account for displayName #15

Open
nikgraf opened this issue Sep 8, 2015 · 2 comments
Open

Comments

@nikgraf
Copy link

nikgraf commented Sep 8, 2015

While upgrading to react-transform I noticed in case displayName is defined as a class property the name is not taken into account e.g.

class CustomDisplayNameComponent {
  static displayName = 'Custom Name';
  render() {}
}

Here out in the wild: https://github.com/nikgraf/belle/blob/75aa7dad0a2ba03ad755a97efe3193bdcf76b3a3/src/components/Card.jsx#L27
For Belle we will migrate the display names, but others might run into the same issue.

I investigated and learned that findDisplayName takes the name in case it's a class node and has an ID or leverages the arguments from createClass. I couldn't figure out how to get the properties from a class node. Any hint? I'm happy to submit a PR.

@gaearon
Copy link
Owner

gaearon commented Mar 5, 2016

Yep, a PR for supporting this would be great.

@nfcampos
Copy link
Collaborator

nfcampos commented Mar 5, 2016

if someone wants to submit a PR it should be something like this:
out of all the paths of the body of the class declaration find one (if any) that satisfies path.isClassProperty(), and is static path.node.static, and is called displayName path.node.key == 'displayName'. Its path.node.value should then be the displayName
This probably doesn't work exactly like this but it should get you some of the way there.
(look here for inspiration https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-class-properties/src/index.js#L33)

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

No branches or pull requests

3 participants