Skip to content

Commit

Permalink
Fix tempalte literals handling
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Jan 8, 2024
1 parent 6b6bdf7 commit 64bf1aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slimy-donkeys-bow.md
@@ -0,0 +1,5 @@
---
"react-docgen": patch
---

Fix handling of template literals
Expand Up @@ -38,6 +38,15 @@ describe('getMemberExpressionValuePath', () => {
);
});

test('handles template literals', () => {
const def = parse.statement(`
var Foo = function Bar() {};
Foo[\`some\${template}\`] = () => {};
`);

expect(getMemberExpressionValuePath(def, 'something')).toBeNull();
});

test('ignores computed property definitions with expression', () => {
const def = parse.statement(`
var Foo = function Bar() {};
Expand Down
Expand Up @@ -87,7 +87,7 @@ const explodedVisitors = visitors.explode<TraverseState>({
const property = memberPath.get('property');

if (
(!memberPath.node.computed || property.isLiteral()) &&
(!memberPath.node.computed || property.isStringLiteral() || property.isNumericLiteral()) &&

Check failure on line 90 in packages/react-docgen/src/utils/getMemberExpressionValuePath.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·property.isStringLiteral()·||` with `⏎··········property.isStringLiteral()·||⏎·········`
getNameOrValue(property) === state.memberName &&
toString(memberPath.get('object')) === state.localName
) {
Expand Down

0 comments on commit 64bf1aa

Please sign in to comment.