Skip to content

Commit 64bf1aa

Browse files
committed
Fix tempalte literals handling
1 parent 6b6bdf7 commit 64bf1aa

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/slimy-donkeys-bow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-docgen": patch
3+
---
4+
5+
Fix handling of template literals

packages/react-docgen/src/utils/__tests__/getMemberExpressionValuePath-test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ describe('getMemberExpressionValuePath', () => {
3838
);
3939
});
4040

41+
test('handles template literals', () => {
42+
const def = parse.statement(`
43+
var Foo = function Bar() {};
44+
Foo[\`some\${template}\`] = () => {};
45+
`);
46+
47+
expect(getMemberExpressionValuePath(def, 'something')).toBeNull();
48+
});
49+
4150
test('ignores computed property definitions with expression', () => {
4251
const def = parse.statement(`
4352
var Foo = function Bar() {};

packages/react-docgen/src/utils/getMemberExpressionValuePath.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const explodedVisitors = visitors.explode<TraverseState>({
8787
const property = memberPath.get('property');
8888

8989
if (
90-
(!memberPath.node.computed || property.isLiteral()) &&
90+
(!memberPath.node.computed || property.isStringLiteral() || property.isNumericLiteral()) &&
9191
getNameOrValue(property) === state.memberName &&
9292
toString(memberPath.get('object')) === state.localName
9393
) {

0 commit comments

Comments
 (0)