diff --git a/packages/plugin-react-refresh/index.js b/packages/plugin-react-refresh/index.js index fc4f47da6a0d30..876577af59a634 100644 --- a/packages/plugin-react-refresh/index.js +++ b/packages/plugin-react-refresh/index.js @@ -200,22 +200,33 @@ function isRefreshBoundary(ast) { return true } const { declaration, specifiers } = node - if (declaration && declaration.type === 'VariableDeclaration') { - return declaration.declarations.every( - ({ id }) => id.type === 'Identifier' && isComponentishName(id.name) - ) + if (declaration) { + if (declaration.type === 'VariableDeclaration') { + return declaration.declarations.every( + (variable) => isComponentLikeIdentifier(variable.id) + ) + } + if (declaration.type === 'FunctionDeclaration') { + return isComponentLikeIdentifier(declaration.id) + } } - return specifiers.every( - ({ exported }) => - exported.type === 'Identifier' && isComponentishName(exported.name) - ) + return specifiers.every((spec) => { + return isComponentLikeIdentifier(spec.exported) + }) }) } +/** + * @param {import('@babel/types').Node} node + */ +function isComponentLikeIdentifier(node) { + return node.type === 'Identifier' && isComponentLikeName(node.name) +} + /** * @param {string} name */ -function isComponentishName(name) { +function isComponentLikeName(name) { return typeof name === 'string' && name[0] >= 'A' && name[0] <= 'Z' }