@@ -28,6 +28,9 @@ export type Options = PluginPass & {
2828export const isComponent = ( str : string ) => {
2929 return / ^ [ \$ _ \d ] * [ A - Z ] / . test ( str )
3030}
31+ export const isHookName = ( str : string ) : boolean => {
32+ return / ^ u s e [ 0 - 9 A - Z $ _ ] / . test ( str )
33+ }
3134
3235export const isDomElement = ( str : string ) => {
3336 return / ^ [ a - z ] / . test ( str )
@@ -149,6 +152,7 @@ const debugComponentTraverse = (p: NodePath, state: Options, component: string)
149152 if ( innerComment ) {
150153 if ( p . isCallExpression ( ) ) {
151154 p . node . arguments . push ( t . stringLiteral ( component ) )
155+ p . node . arguments . push ( t . stringLiteral ( state . filename ?. replace ( `${ state . cwd } /` , '' ) ?? '' ) )
152156 innerComment . value = REPLACE_COMMENT
153157 }
154158 } else {
@@ -158,6 +162,9 @@ const debugComponentTraverse = (p: NodePath, state: Options, component: string)
158162 if ( trailingComment ) {
159163 if ( p . parentPath ?. isCallExpression ( ) ) {
160164 p . parentPath . node . arguments . push ( t . stringLiteral ( component ) )
165+ p . parentPath . node . arguments . push (
166+ t . stringLiteral ( state . filename ?. replace ( `${ state . cwd } /` , '' ) ?? '' )
167+ )
161168 trailingComment . value = REPLACE_COMMENT
162169 }
163170 }
@@ -240,9 +247,14 @@ const componentVisitor: PluginObj<Options> = {
240247
241248 if ( arrowFunction ) {
242249 if ( t . isIdentifier ( declarator . node . id ) ) {
243- if ( isComponent ( declarator . node . id . name ) ) {
250+ if ( isHookName ( declarator . node . id . name ) ) {
251+ const hookName = declarator . node . id . name
252+ debugComponentTraverse ( arrowFunction , state , hookName )
253+ } else if ( isComponent ( declarator . node . id . name ) ) {
244254 const componentName = declarator . node . id . name
255+
245256 debugComponentTraverse ( arrowFunction , state , componentName )
257+
246258 const wrap = ( { importName, importSource } : Import ) => {
247259 let actualImport = state . actualImports . get ( importName )
248260 if ( ! actualImport ) {
0 commit comments