Repository navigation
fix: keep template-literal default values in defaultPropsHandler - #1206
Open
ItsShivam05 wants to merge 1 commit into
Open
ItsShivam05 wants to merge 1 commit into
ItsShivam05 wants to merge 1 commit into
Conversation
👷 Deploy request for react-docgen pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 8afa853 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1203
Problem
getDefaultValue()indefaultPropsHandlerhandles literals viapath.isLiteral()and readspath.node.extra?.raw. Babel includesTemplateLiteralin theLiteralalias, but template literals have noextra.raw, so the value came backundefinedand the default was dropped:function A({ a = 1, tpl = \Save` }):tpldisappeared from the output entirely (untyped props with an empty descriptor are skipped byDocumentation.toObject()`)tpl?: string) lost theirdefaultValuedefaultPropsFix
A
path.isTemplateLiteral()branch before the genericisLiteral()one, usingpath.getSource(). I used the exact source rather thanprintValue, becauseprintValuere-indents lines after the first one, and inside a template literal that whitespace is part of the string value.computedisfalse, consistent with how'Hi ' + nameand other composite expressions are already reported (computedonly looks at the outermost expression).Tests
New
template literalsblock indefaultPropsHandler-test.ts(all 6 fail before the fix):They use
toEqualrather than new snapshots, so they assert the expected output instead of recording whatever the code produces.pnpm test: all passing (react-docgen 1520, core 23, babel 2, typescript 156, hermes 111, cli 60)pnpm test:coverage: thresholds metpnpm build(tsc): 7/7 packagesChangeset added (patch for
react-docgen). This is based onmain; happy to open a backport to8.xif you'd like.