@@ -28,6 +28,9 @@ export type Options = PluginPass & {
28
28
export const isComponent = ( str : string ) => {
29
29
return / ^ [ \$ _ \d ] * [ A - Z ] / . test ( str )
30
30
}
31
+ export const isHookName = ( str : string ) : boolean => {
32
+ return / ^ u s e [ 0 - 9 A - Z $ _ ] / . test ( str )
33
+ }
31
34
32
35
export const isDomElement = ( str : string ) => {
33
36
return / ^ [ a - z ] / . test ( str )
@@ -149,6 +152,7 @@ const debugComponentTraverse = (p: NodePath, state: Options, component: string)
149
152
if ( innerComment ) {
150
153
if ( p . isCallExpression ( ) ) {
151
154
p . node . arguments . push ( t . stringLiteral ( component ) )
155
+ p . node . arguments . push ( t . stringLiteral ( state . filename ?. replace ( `${ state . cwd } /` , '' ) ?? '' ) )
152
156
innerComment . value = REPLACE_COMMENT
153
157
}
154
158
} else {
@@ -158,6 +162,9 @@ const debugComponentTraverse = (p: NodePath, state: Options, component: string)
158
162
if ( trailingComment ) {
159
163
if ( p . parentPath ?. isCallExpression ( ) ) {
160
164
p . parentPath . node . arguments . push ( t . stringLiteral ( component ) )
165
+ p . parentPath . node . arguments . push (
166
+ t . stringLiteral ( state . filename ?. replace ( `${ state . cwd } /` , '' ) ?? '' )
167
+ )
161
168
trailingComment . value = REPLACE_COMMENT
162
169
}
163
170
}
@@ -240,9 +247,14 @@ const componentVisitor: PluginObj<Options> = {
240
247
241
248
if ( arrowFunction ) {
242
249
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 ) ) {
244
254
const componentName = declarator . node . id . name
255
+
245
256
debugComponentTraverse ( arrowFunction , state , componentName )
257
+
246
258
const wrap = ( { importName, importSource } : Import ) => {
247
259
let actualImport = state . actualImports . get ( importName )
248
260
if ( ! actualImport ) {
0 commit comments