Skip to content
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

Extract decorated functions as top level variables #69

Open
danbovey opened this issue Nov 28, 2017 · 7 comments
Open

Extract decorated functions as top level variables #69

danbovey opened this issue Nov 28, 2017 · 7 comments

Comments

@danbovey
Copy link

Could we get an option in .babelrc to extract each decorated function individually as it's own variable. Reason being is that react-hot-loader requires the OG decorated function (react component) to be its own top level variable. See their docs for the full explanation.

Currently this plugin transforms decorators to something like this:

const SuperComponent = 
     connect()(         <-- last HoC
       withSomeStuff(   <-- first HoC
         Component      <-- a real component
       )
     );

But with a "topLevel": true plugin option in .babelrc (just in development env section in my case), this plugin could transform decorators like this:

 const WithSomeStuffComponent = withSomeStuff(Component);
 const SuperComponent = connect()(WithSomeStuffComponent);

Would this be possible?

@loganfsmyth
Copy link
Owner

I'm not sure I fully follow the details, but this seems like the type of thing that could be implemented as a separate plugin that would run before this one, if you wanted that behavior. I'm not sure it is something that this plugin would do on its own?

@sirrodgepodge
Copy link

I believe this is exactly what I'm attempting here :),

https://www.npmjs.com/package/babel-plugin-undecorate

I'm assuming the reason you'd want this is for testability of the underlying class/method (that's why I wanted it).

@danbovey
Copy link
Author

danbovey commented Jul 2, 2018

Closing as this is probably solved by babel-plugin-undecorate!

@danbovey danbovey closed this as completed Jul 2, 2018
@vdh
Copy link

vdh commented Jul 3, 2018

@danbovey Woah woah hey, it's not actually solved yet, it was only raised as a hypothetical solution

@danbovey
Copy link
Author

danbovey commented Jul 3, 2018

@vdh As @loganfsmyth said, this issue doesn't have to be solved in this plugin, it's a little bit out of scope. I no longer need this so I haven't tested @sirrodgepodge's plugin but I assume that's the repo we can open an issue on if that doesn't solve this feature request.

@vdh
Copy link

vdh commented Jul 4, 2018

@danbovey The problematic code is directly created by this babel plugin. Relying on yet another plugin to make further changes over the top of how it already behaves is an unstable attempt at solving the code generation issue.

@danbovey
Copy link
Author

danbovey commented Jul 5, 2018

OK, reopening to be looked at by @loganfsmyth

@danbovey danbovey reopened this Jul 5, 2018
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