Skip to content

Commit d25d262

Browse files
yungstersdanez
authored andcommitted
fix: Ignore assignment to non-identifier/literals (#305)
1 parent ffe2de6 commit d25d262

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/handlers/__tests__/displayNameHandler-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,5 +223,14 @@ describe('defaultPropsHandler', () => {
223223
expect(() => displayNameHandler(documentation, definition)).not.toThrow();
224224
expect(documentation.displayName).toBe('Bar');
225225
});
226+
227+
it('ignores assignment to non-literal/identifier', () => {
228+
const definition = statement('Foo.Bar = () => {};').get(
229+
'expression',
230+
'right',
231+
);
232+
expect(() => displayNameHandler(documentation, definition)).not.toThrow();
233+
expect(documentation.displayName).not.toBeDefined();
234+
});
226235
});
227236
});

src/handlers/displayNameHandler.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ export default function displayNameHandler(
4848
);
4949
return;
5050
} else if (types.AssignmentExpression.check(currentPath.parent.node)) {
51-
documentation.set(
52-
'displayName',
53-
getNameOrValue(currentPath.parent.get('left')),
54-
);
55-
return;
51+
const leftPath = currentPath.parent.get('left');
52+
if (
53+
types.Identifier.check(leftPath.node) ||
54+
types.Literal.check(leftPath.node)
55+
) {
56+
documentation.set('displayName', getNameOrValue(leftPath));
57+
return;
58+
}
5659
}
5760
currentPath = currentPath.parent;
5861
}

0 commit comments

Comments
 (0)