Skip to content

Commit

Permalink
chore(formatting): Fix "check annotations" (#10722)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored and Josh-Walker-GM committed Jun 6, 2024
1 parent 1a8c521 commit 1c77535
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/internal/src/generate/typeDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ declare module '@storybook/react' {
)

const hasCliStorybookVite = Object.keys(
packageJson['devDependencies']
packageJson['devDependencies'],
).includes('@redwoodjs/cli-storybook-vite')

if (hasCliStorybook || hasCliStorybookVite) {
Expand Down
41 changes: 24 additions & 17 deletions packages/storybook/src/plugins/docgen-handlers/actualNameHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,53 @@
* directly from displayNameHandler, using the same approach as babel-plugin-react-docgen.
*/

import type { Handler, NodePath, babelTypes as t } from 'react-docgen';
import { utils } from 'react-docgen';
import type { Handler, NodePath, babelTypes as t } from 'react-docgen'
import { utils } from 'react-docgen'

const { getNameOrValue, isReactForwardRefCall } = utils;
const { getNameOrValue, isReactForwardRefCall } = utils

const actualNameHandler: Handler = function actualNameHandler(documentation, componentDefinition) {
const actualNameHandler: Handler = function actualNameHandler(
documentation,
componentDefinition,
) {
if (
(componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) &&
(componentDefinition.isClassDeclaration() ||
componentDefinition.isFunctionDeclaration()) &&
componentDefinition.has('id')
) {
documentation.set(
'actualName',
getNameOrValue(componentDefinition.get('id') as NodePath<t.Identifier>)
);
getNameOrValue(componentDefinition.get('id') as NodePath<t.Identifier>),
)
} else if (
componentDefinition.isArrowFunctionExpression() ||
componentDefinition.isFunctionExpression() ||
isReactForwardRefCall(componentDefinition)
) {
let currentPath: NodePath = componentDefinition;
let currentPath: NodePath = componentDefinition

while (currentPath.parentPath) {
if (currentPath.parentPath.isVariableDeclarator()) {
documentation.set('actualName', getNameOrValue(currentPath.parentPath.get('id')));
return;
documentation.set(
'actualName',
getNameOrValue(currentPath.parentPath.get('id')),
)
return
}
if (currentPath.parentPath.isAssignmentExpression()) {
const leftPath = currentPath.parentPath.get('left');
const leftPath = currentPath.parentPath.get('left')

if (leftPath.isIdentifier() || leftPath.isLiteral()) {
documentation.set('actualName', getNameOrValue(leftPath));
return;
documentation.set('actualName', getNameOrValue(leftPath))
return
}
}

currentPath = currentPath.parentPath;
currentPath = currentPath.parentPath
}
// Could not find an actual name
documentation.set('actualName', '');
documentation.set('actualName', '')
}
};
}

export default actualNameHandler;
export default actualNameHandler

0 comments on commit 1c77535

Please sign in to comment.