react-docgen-typescript icon indicating copy to clipboard operation
react-docgen-typescript copied to clipboard

Invalid `displayName` parsing starting with v2.1.0

Open jzempel opened this issue 3 years ago • 8 comments

After the removal of the parsing filter in #368, the first displayName encountered is selected, whether or not its component is exported. To test, add the following lines to the end of https://github.com/styleguidist/react-docgen-typescript/blob/master/examples/react-styleguidist-example/components/HocComponent.tsx:

Component.displayName = 'DisplayNameError';
HocComponent.displayName = 'DisplayNameSuccess';

Invalid results based on v2.1.0, tested via node -e 'console.log(require("react-docgen-typescript").parse("./ModifiedHocComponent.tsx"))'...

[
  {
    tags: {},
    filePath: './ModifiedHocComponent.tsx',
    description: '',
    displayName: 'DisplayNameError',
    methods: [],
    props: {}
  }
]

Valid results based on v2.0.0, testing the same...

[
  {
    tags: {},
    filePath: './ModifiedHocComponent.tsx',
    description: '',
    displayName: 'hoc',
    methods: [],
    props: {}
  },
  {
    tags: {},
    filePath: './ModifiedHocComponent.tsx',
    description: 'This example shows HocComponent',
    displayName: 'DisplayNameSuccess',
    methods: [],
    props: {
      prop1: [Object],
      prop2: [Object],
      prop3: [Object],
      prop4: [Object]
    }
  }
]

jzempel avatar Nov 02 '21 12:11 jzempel

I am surprised that this wasn't included in our test cases before :( You are right that as PR #368 fixed one thing, it broke this one.

pvasek avatar Nov 28 '21 09:11 pvasek

Is this the same issue as in https://github.com/styleguidist/react-docgen-typescript/issues/437? And would the suggested fix there, also fix this case?

jesstelford avatar May 27 '22 00:05 jesstelford

Can you re-open this @pvasek - it was closed with #441

kylemh avatar Sep 17 '22 10:09 kylemh

@kylemh thanks for pointing that out.

pvasek avatar Sep 17 '22 11:09 pvasek

There was no activity for a long time. The issue will be closed soon.

github-actions[bot] avatar Sep 18 '23 10:09 github-actions[bot]

This issue has an open PR awaiting code review.

kylemh avatar Sep 18 '23 14:09 kylemh