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

Add shouldExtractValueFromUnion and fix default value bug #21

Merged
merged 2 commits into from
Sep 24, 2020
Merged

Add shouldExtractValueFromUnion and fix default value bug #21

merged 2 commits into from
Sep 24, 2020

Conversation

DSil
Copy link
Collaborator

@DSil DSil commented Sep 9, 2020

This PR includes two commits:

  • one bumps the react-docgen-typescript dependency to the latest version
  • the second:
    • Adds support for shouldExtractValueFromUnion parser option Note 1
    • Fixes a bug with non-string default values Note 2
Screenshots

Before:
Screen Shot 2020-09-09 at 12 36 26 AM

Now:
Screen Shot 2020-09-09 at 12 15 03 AM

Note 1:

shouldExtractValueFromUnion allows a more complete parsing than shouldExtractLiteralValuesFromEnum. It supports union types with multiple types (not only strings). I believe the latter is no longer needed, since the first covers the same scenarios, but I prefer to avoid a breaking change and keep supporting both, since react-docgen-typescript also supports both.

Note 2:

When using a default value that is not a string, the babel parser simply could not compile, as it was always expecting a string as default value. This is now fixed by transforming the value into a string. (See Problem with tests)

Problem with tests:

Running the tests locally was not a problem (using node 12). However, the pre-commit also runs the tests and it constantly failed because of a known bug with node and the toString method (implicitly called in the template string transformation). I was not able to enforce this to run on node 11.12.0 or above (the version that fixes this issue). Are you able to add this? Or is this not an issue, since the tests run locally with no problem?

Changelog and README:

I updated them as I thought it should be but you're free to update them as it best suits you.

Thanks.

Daniel Sil added 2 commits September 9, 2020 01:38
Also fixes a problem with non-string default values
Tests updated
@DSil
Copy link
Collaborator Author

DSil commented Sep 11, 2020

Hi @strothj are you still maintaining this project?

@strothj
Copy link
Owner

strothj commented Sep 11, 2020

Unfortunately I’ve had no time as I’ve been stuck in a mix of travel and work. I don’t use this project myself personally. I can pass the reigns to you if you’re interested.

@DSil
Copy link
Collaborator Author

DSil commented Sep 16, 2020

I would really appreciate if I could just use this with these features, so that I don’t need to build something similar on my side. I guess I can take the reigns if you’re open to it. There doesn’t seem to be much going around anyway :)

@strothj
Copy link
Owner

strothj commented Sep 17, 2020

@DSil I've invited you as a collaborator to this repository. I couldn't transfer you the repository yet because you have an existing fork on your account. I'm guessing the pull requests will need to be taken care of first. What is your NPM username?

@DSil
Copy link
Collaborator Author

DSil commented Sep 17, 2020

I do not have an NPM account. I’ll take a moment to do that later today

@DSil
Copy link
Collaborator Author

DSil commented Sep 17, 2020

My npm username is the same as github: dsil

@strothj
Copy link
Owner

strothj commented Sep 17, 2020

I invited you in npm. You should now be able to handle the repo and npm package.

@DSil
Copy link
Collaborator Author

DSil commented Sep 24, 2020

Thank you @strothj, I'll handle it.

@DSil DSil merged commit 6cb2558 into strothj:master Sep 24, 2020
@DSil DSil deleted the new-parser-and-defaut-value-fix branch September 24, 2020 17:29
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.

2 participants