Repository: styleguidist/react-docgen-typescript
Pull request #448 (2022-09-15 20:09:39)

Revert "Resolve issue with first displayName always being used"
Sorry, accidentally merge it but didn't noticed the test are failing.

Reverts styleguidist/react-docgen-typescript#441


Patch:
diff --git a/src/parser.ts b/src/parser.ts
index 087e1c1..47a86e5 100644
--- a/src/parser.ts
+++ b/src/parser.ts
@@ -1200,26 +1200,11 @@ function getTextValueOfFunctionProperty(
     .filter(statement => {
       const expr = (statement as ts.ExpressionStatement)
         .expression as ts.BinaryExpression;
-
-      /**
-       * Ensure the .displayName is for the currently processing function.
-       *
-       * This avoids the following situations:
-       *
-       *  - A file has multiple functions, one has `.displayName`, and all
-       *    functions ends up with that same `.displayName` value.
-       *
-       *  - A file has multiple functions, each with a different
-       *    `.displayName`, but the first is applied to all of them.
-       */
-      const flowNodeNameEscapedText = (statement as any)?.flowNode?.node?.name
-        ?.escapedText as false | ts.__String | undefined;
-
       return (
         expr.left &&
         (expr.left as ts.PropertyAccessExpression).name &&
         (expr.left as ts.PropertyAccessExpression).name.escapedText ===
-          (propertyName && flowNodeNameEscapedText === exp.escapedName)
+          propertyName
       );
     })
     .filter(statement => {


Test patch:
diff --git a/src/__tests__/data/StatelessDisplayNameMultipleDisplayNames.tsx b/src/__tests__/data/StatelessDisplayNameMultipleDisplayNames.tsx
deleted file mode 100644
index 8c89283..0000000
--- a/src/__tests__/data/StatelessDisplayNameMultipleDisplayNames.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import * as React from 'react';
-
-interface ButtonProps
-  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'type'> {}
-
-export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
-  (props, ref) => <button {...props} ref={ref} type="button" />
-);
-
-Button.displayName = 'First';
-
-export const SubmitButton = React.forwardRef<HTMLButtonElement, ButtonProps>(
-  (props, ref) => <button {...props} ref={ref} type="submit" />
-);
-
-SubmitButton.displayName = 'Second';
-
-export const ResetButton = React.forwardRef<HTMLButtonElement, ButtonProps>(
-  (props, ref) => <button {...props} ref={ref} type="reset" />
-);
-
-ResetButton.displayName = 'Third';
diff --git a/src/__tests__/data/StatelessDisplayNameMultipleFnsOneDisplayName.tsx b/src/__tests__/data/StatelessDisplayNameMultipleFnsOneDisplayName.tsx
deleted file mode 100644
index 9b7981b..0000000
--- a/src/__tests__/data/StatelessDisplayNameMultipleFnsOneDisplayName.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import * as React from 'react';
-
-interface ButtonProps
-  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'type'> {}
-
-export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
-  (props, ref) => <button {...props} ref={ref} type="button" />
-);
-
-Button.displayName = 'First';
-
-export const someSeparateFunction = () => {};
diff --git a/src/__tests__/parser.ts b/src/__tests__/parser.ts
index dec2d96..fab7b73 100644
--- a/src/__tests__/parser.ts
+++ b/src/__tests__/parser.ts
@@ -989,32 +989,6 @@ describe('parser', () => {
       const [parsed] = parse(fixturePath('StatefulDisplayNameFolder/index'));
       assert.equal(parsed.displayName, 'StatefulDisplayNameFolder');
     });
-
-    it('should get all displayNames from single file when multiple functions have the property defined', () => {
-      const [parsed1, parsed2, parsed3] = parse(
-        fixturePath('StatelessDisplayNameMultipleDisplayNames')
-      );
-
-      // parsed1.displayName === 'Button'?
-      // parsed1.displayName === 'SubmitButton'?
-      // parsed1.displayName === 'ResetButton'?
-
-      assert.equal(parsed1.displayName, 'First');
-      assert.equal(parsed2.displayName, 'Second');
-      assert.equal(parsed3.displayName, 'Third');
-    });
-
-    it('should get all displayNames from single file when multiple functions have the property defined', () => {
-      const [parsed1, parsed2] = parse(
-        fixturePath('StatelessDisplayNameMultipleFnsOneDisplayName')
-      );
-
-      // parsed1.displayName === 'Button'?
-      // parsed2 is `undefined`?
-
-      assert.equal(parsed1.displayName, 'First');
-      assert.equal(parsed2.displayName, 'someSeparateFunction');
-    });
   });
 
   describe('Parser options', () => {