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

feat: Print function children #607

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

gabiseabra
Copy link

There was another attempt to fix this (#338) which I suppose wasn't merged because the author didn't address an issue raised about calling function children in order to print them.

This is fine for pure functions that return react elements, but you can't guarantee that function children always behave like this, so this could cause problems for users who have unconventional function children.

Another approach could be printing the function's source, but since sources are subject to transpilation by babel before runtime, just printing the function's body wouldn't yield JSX.
Or you could use source maps to print the original code instead, but printing JSX code as string has its own limitations as the output isn't parsed and formatted by this library.

As each of these methods have their own trade-offs, I've decided to go for a less opinionated solution and leave this decision up to the library user. Functions as children will work the same as if they were any other prop, users can choose how to format them using functionValue and showFunctions options.
Additionally, I've altered both these options to provide more granularity on if and how each function prints since users may want to handle render props differently than other function props.

What I did:

  • Fixed indentation of deeply nested multi-line functions
  • Parse function children (typeof children === 'function', not otherwise)
  • Allow more granularity for rendering of functions
    • Added prop param to functionValue option
    • Added showFunctions function option to filter prop by prop

@gabiseabra gabiseabra changed the title feature(formatting) print function children feat: Print function children Apr 26, 2021
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

Successfully merging this pull request may close these issues.

None yet

1 participant