Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Does this plugin work for Babel@7 & FunctionalComponents? #9

Open
fbartho opened this issue Apr 29, 2019 · 10 comments
Open

Does this plugin work for Babel@7 & FunctionalComponents? #9

fbartho opened this issue Apr 29, 2019 · 10 comments

Comments

@fbartho
Copy link

fbartho commented Apr 29, 2019

We went to babel7 a while ago, but we're just starting to use FunctionalComponents much more heavily, and as a result we're starting to see more <Unknown> in our component tree.

@gajus
Copy link

gajus commented May 29, 2019

@fbartho
Copy link
Author

fbartho commented May 29, 2019

@gajus -- the documentation for that one doesn't look like it supports Functional Components -- is that true?

@fbartho
Copy link
Author

fbartho commented May 29, 2019

To be honest, I'd be fine with a transform that attaches displayName to every loose function/arrow-function in a JSX-enabled file (.tsx in my project). Presumably that would make it easier? (I'm just a babel newbie)

@isaachinman
Copy link

Any update on this? I would be happy to work on dev for a plugin that does work in v7, but don't want to duplicate work if such a thing already exists. Would be very grateful for any tips/advice.

@gajus
Copy link

gajus commented Dec 9, 2019

It looks like I have sometime ago released a plugin to solve this problem.

https://github.com/gajus/babel-plugin-react-display-name

@isaachinman
Copy link

@gajus Yes, but that only covers createClass, right? Very few people are writing new React code like that.

@gajus
Copy link

gajus commented Dec 9, 2019

Good point. I haven't touched that code for a long time.

https://github.com/gajus/babel-plugin-transform-export-default-name

This would work for default exports, though.

@isaachinman
Copy link

Okay, that's good reference to have. My particular use case requires use of named exports. Are you aware of any way of statically determining the return type of a function (eg jsx) within a Babel plugin?

If that's possible, it should be pretty straightforward to loop over all exports and append displayName as necessary.

@gajus
Copy link

gajus commented Dec 9, 2019

Okay, that's good reference to have. My particular use case requires use of named exports. Are you aware of any way of statically determining the return type of a function (eg jsx) within a Babel plugin?

I am not. I don't think that is possible either (accurately), unless you are using strict types (like Flow or TS).

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

No branches or pull requests

3 participants