Skip to content

Parse displayName for stateless components whose name dont match the file name #368

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

Merged
merged 1 commit into from
Jul 25, 2021

Conversation

roddds
Copy link
Contributor

@roddds roddds commented Jun 16, 2021

I noticed that when stateless components are declared as const Component = (props) => ... their displayName property didn't get parsed correctly when the component is a default export.

This is my first PR to this repo so I hope I did everything right! Let me know if this can be improved in any way. I'm not too hot on the test fixture filename or displayName so I'm open to suggestions, I just picked a name that would stress the difference between the file's name and the component's displayName.

Thanks for reviewing!

@roddds
Copy link
Contributor Author

roddds commented Jun 23, 2021

@pvasek Let me know if there's anything missing or that can be improved!

@roddds
Copy link
Contributor Author

roddds commented Jul 22, 2021

@pvasek bumping this for visibility.

@pvasek pvasek merged commit 8c99ccf into styleguidist:master Jul 25, 2021
@jzempel
Copy link

jzempel commented Aug 16, 2021

This appears to be a breaking change. For example, on this file the non-exported AddItemComponent display name is parsed rather than the exported AddItem display name parsed in v2.0.0.

@roddds
Copy link
Contributor Author

roddds commented Aug 17, 2021

@jzempel can you provide:

  • The react-docgen-typescript configuration you're using
  • A minimal repro case or;
  • A failing test in this repo that passes when you revert f42ed3f

I ask because I wasn't able to get RDT to parse anything out of that file, on either 2.0.0 or 2.1.0. The repro steps I took:

~$ mkdir rdt-repro && cd rdt-repro
~/rdt-repro$ npm init -y
Wrote to /home/rodrigo/rdt-repro/package.json:

{
  "name": "rdt-repro",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "Rodrigo Deodoro",
  "license": "ISC"
}


~/rdt-repro$ npm install --save [email protected] 'typescript@>=4.3.x'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

+ [email protected]
+ [email protected]
added 2 packages from 1 contributor and audited 2 packages in 0.941s
found 0 vulnerabilities

~/rdt-repro$ wget https://github.com/raw/zendeskgarden/react-components/main/packages/dropdowns/src/elements/Menu/Items/AddItem.tsx
--2021-08-16 17:21:12--  https://github.com/raw/zendeskgarden/react-components/main/packages/dropdowns/src/elements/Menu/Items/AddItem.tsx
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.110.133, 185.199.109.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1277 (1.2K) [text/plain]
Saving to: ‘AddItem.tsx’

AddItem.tsx                       100%[==========================================================>]   1.25K  --.-KB/s    in 0s      

2021-08-16 17:21:13 (73.4 MB/s) - ‘AddItem.tsx’ saved [1277/1277]

~/rdt-repro$ node -e 'console.log(require("react-docgen-typescript").parse("./AddItem.tsx"))'
[]

@jzempel
Copy link

jzempel commented Aug 17, 2021

Parsing happens here in order to produce component documentation seen under https://garden.zendesk.com/components/menu#additem for example.

@jzempel
Copy link

jzempel commented Nov 2, 2021

@roddds I added simplified, detailed steps to reproduce in #395.

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.

3 participants