Skip to content

Commit

Permalink
Merge pull request #448 from styleguidist/revert-441-master
Browse files Browse the repository at this point in the history
Revert "Resolve issue with first displayName always being used"
  • Loading branch information
pvasek authored Sep 15, 2022
2 parents 599668e + 142c759 commit 287e701
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 76 deletions.
22 changes: 0 additions & 22 deletions src/__tests__/data/StatelessDisplayNameMultipleDisplayNames.tsx

This file was deleted.

This file was deleted.

26 changes: 0 additions & 26 deletions src/__tests__/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
17 changes: 1 addition & 16 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 287e701

Please sign in to comment.