@@ -47,7 +47,7 @@ type HookLogEntry = {
47
47
stackError : Error ,
48
48
value : mixed ,
49
49
debugInfo : ReactDebugInfo | null ,
50
- dispatcherMethodName : string ,
50
+ dispatcherHookName : string ,
51
51
} ;
52
52
53
53
let hookLog : Array < HookLogEntry > = [ ] ;
@@ -210,7 +210,7 @@ function use<T>(usable: Usable<T>): T {
210
210
value : fulfilledValue ,
211
211
debugInfo :
212
212
thenable . _debugInfo === undefined ? null : thenable . _debugInfo ,
213
- dispatcherMethodName : 'use ' ,
213
+ dispatcherHookName : 'Use ' ,
214
214
} ) ;
215
215
return fulfilledValue ;
216
216
}
@@ -228,7 +228,7 @@ function use<T>(usable: Usable<T>): T {
228
228
value : thenable ,
229
229
debugInfo :
230
230
thenable . _debugInfo === undefined ? null : thenable . _debugInfo ,
231
- dispatcherMethodName : 'use ' ,
231
+ dispatcherHookName : 'Use ' ,
232
232
} );
233
233
throw SuspenseException;
234
234
} else if ( usable . $$typeof === REACT_CONTEXT_TYPE ) {
@@ -241,7 +241,7 @@ function use<T>(usable: Usable<T>): T {
241
241
stackError : new Error ( ) ,
242
242
value,
243
243
debugInfo : null ,
244
- dispatcherMethodName : 'use ' ,
244
+ dispatcherHookName : 'Use ' ,
245
245
} ) ;
246
246
247
247
return value ;
@@ -260,7 +260,7 @@ function useContext<T>(context: ReactContext<T>): T {
260
260
stackError : new Error ( ) ,
261
261
value : value ,
262
262
debugInfo : null ,
263
- dispatcherMethodName : 'useContext ' ,
263
+ dispatcherHookName : 'Context ' ,
264
264
} ) ;
265
265
return value ;
266
266
}
@@ -282,7 +282,7 @@ function useState<S>(
282
282
stackError : new Error ( ) ,
283
283
value : state ,
284
284
debugInfo : null ,
285
- dispatcherMethodName : 'useState ' ,
285
+ dispatcherHookName : 'State ' ,
286
286
} ) ;
287
287
return [ state , ( action : BasicStateAction < S > ) => { } ] ;
288
288
}
@@ -305,7 +305,7 @@ function useReducer<S, I, A>(
305
305
stackError : new Error ( ) ,
306
306
value : state ,
307
307
debugInfo : null ,
308
- dispatcherMethodName : 'useReducer ' ,
308
+ dispatcherHookName : 'Reducer ' ,
309
309
} ) ;
310
310
return [ state , ( action : A ) => { } ] ;
311
311
}
@@ -319,7 +319,7 @@ function useRef<T>(initialValue: T): {current: T} {
319
319
stackError : new Error ( ) ,
320
320
value : ref . current ,
321
321
debugInfo : null ,
322
- dispatcherMethodName : 'useRef ' ,
322
+ dispatcherHookName : 'Ref ' ,
323
323
} ) ;
324
324
return ref ;
325
325
}
@@ -332,7 +332,7 @@ function useCacheRefresh(): () => void {
332
332
stackError : new Error ( ) ,
333
333
value : hook !== null ? hook . memoizedState : function refresh ( ) { } ,
334
334
debugInfo : null ,
335
- dispatcherMethodName : 'useCacheRefresh ' ,
335
+ dispatcherHookName : 'CacheRefresh ' ,
336
336
} ) ;
337
337
return ( ) = > { } ;
338
338
}
@@ -348,7 +348,7 @@ function useLayoutEffect(
348
348
stackError : new Error ( ) ,
349
349
value : create ,
350
350
debugInfo : null ,
351
- dispatcherMethodName : 'useLayoutEffect ' ,
351
+ dispatcherHookName : 'LayoutEffect ' ,
352
352
} ) ;
353
353
}
354
354
@@ -363,7 +363,7 @@ function useInsertionEffect(
363
363
stackError : new Error ( ) ,
364
364
value : create ,
365
365
debugInfo : null ,
366
- dispatcherMethodName : 'useInsertionEffect ' ,
366
+ dispatcherHookName : 'InsertionEffect ' ,
367
367
} ) ;
368
368
}
369
369
@@ -378,7 +378,7 @@ function useEffect(
378
378
stackError : new Error ( ) ,
379
379
value : create ,
380
380
debugInfo : null ,
381
- dispatcherMethodName : 'useEffect ' ,
381
+ dispatcherHookName : 'Effect ' ,
382
382
} ) ;
383
383
}
384
384
@@ -402,7 +402,7 @@ function useImperativeHandle<T>(
402
402
stackError : new Error ( ) ,
403
403
value : instance ,
404
404
debugInfo : null ,
405
- dispatcherMethodName : 'useImperativeHandle ' ,
405
+ dispatcherHookName : 'ImperativeHandle ' ,
406
406
} );
407
407
}
408
408
@@ -413,7 +413,7 @@ function useDebugValue(value: any, formatterFn: ?(value: any) => any) {
413
413
stackError : new Error ( ) ,
414
414
value : typeof formatterFn === 'function' ? formatterFn ( value ) : value ,
415
415
debugInfo : null ,
416
- dispatcherMethodName : 'useDebugValue ' ,
416
+ dispatcherHookName : 'DebugValue ' ,
417
417
} ) ;
418
418
}
419
419
@@ -425,7 +425,7 @@ function useCallback<T>(callback: T, inputs: Array<mixed> | void | null): T {
425
425
stackError : new Error ( ) ,
426
426
value : hook !== null ? hook . memoizedState [ 0 ] : callback ,
427
427
debugInfo : null ,
428
- dispatcherMethodName : 'useCallback ' ,
428
+ dispatcherHookName : 'Callback ' ,
429
429
} ) ;
430
430
return callback ;
431
431
}
@@ -442,7 +442,7 @@ function useMemo<T>(
442
442
stackError : new Error ( ) ,
443
443
value,
444
444
debugInfo : null ,
445
- dispatcherMethodName : 'useMemo ' ,
445
+ dispatcherHookName : 'Memo ' ,
446
446
} ) ;
447
447
return value ;
448
448
}
@@ -464,7 +464,7 @@ function useSyncExternalStore<T>(
464
464
stackError : new Error ( ) ,
465
465
value,
466
466
debugInfo : null ,
467
- dispatcherMethodName : 'useSyncExternalStore ' ,
467
+ dispatcherHookName : 'SyncExternalStore ' ,
468
468
} ) ;
469
469
return value ;
470
470
}
@@ -487,7 +487,7 @@ function useTransition(): [
487
487
stackError : new Error ( ) ,
488
488
value : isPending ,
489
489
debugInfo : null ,
490
- dispatcherMethodName : 'useTransition ' ,
490
+ dispatcherHookName : 'Transition ' ,
491
491
} ) ;
492
492
return [ isPending , ( ) => { } ] ;
493
493
}
@@ -501,7 +501,7 @@ function useDeferredValue<T>(value: T, initialValue?: T): T {
501
501
stackError : new Error ( ) ,
502
502
value : prevValue ,
503
503
debugInfo : null ,
504
- dispatcherMethodName : 'useDeferredValue ' ,
504
+ dispatcherHookName : 'DeferredValue ' ,
505
505
} ) ;
506
506
return prevValue ;
507
507
}
@@ -515,7 +515,7 @@ function useId(): string {
515
515
stackError : new Error ( ) ,
516
516
value : id ,
517
517
debugInfo : null ,
518
- dispatcherMethodName : 'useId ' ,
518
+ dispatcherHookName : 'Id ' ,
519
519
} ) ;
520
520
return id ;
521
521
}
@@ -566,7 +566,7 @@ function useOptimistic<S, A>(
566
566
stackError : new Error ( ) ,
567
567
value : state ,
568
568
debugInfo : null ,
569
- dispatcherMethodName : 'useOptimistic ' ,
569
+ dispatcherHookName : 'Optimistic ' ,
570
570
} ) ;
571
571
return [ state , ( action : A ) => { } ] ;
572
572
}
@@ -626,7 +626,7 @@ function useFormState<S, P>(
626
626
stackError : stackError ,
627
627
value : value ,
628
628
debugInfo : debugInfo ,
629
- dispatcherMethodName : 'useFormState ' ,
629
+ dispatcherHookName : 'FormState ' ,
630
630
} );
631
631
632
632
if (error !== null) {
@@ -696,7 +696,7 @@ function useActionState<S, P>(
696
696
stackError : stackError ,
697
697
value : value ,
698
698
debugInfo : debugInfo ,
699
- dispatcherMethodName : 'useActionState ' ,
699
+ dispatcherHookName : 'ActionState ' ,
700
700
} );
701
701
702
702
if (error !== null) {
@@ -835,16 +835,7 @@ function findCommonAncestorIndex(rootStack: any, hookStack: any) {
835
835
}
836
836
837
837
function isReactWrapper ( functionName : any , wrapperName : string ) {
838
- if ( ! functionName ) {
839
- return false ;
840
- }
841
- if (functionName.length < wrapperName . length ) {
842
- return false ;
843
- }
844
- return (
845
- functionName . lastIndexOf ( wrapperName ) ===
846
- functionName . length - wrapperName . length
847
- ) ;
838
+ return parseHookName ( functionName ) === wrapperName ;
848
839
}
849
840
850
841
function findPrimitiveIndex(hookStack: any, hook: HookLogEntry) {
@@ -860,13 +851,13 @@ function findPrimitiveIndex(hookStack: any, hook: HookLogEntry) {
860
851
// This prohibits nesting dispatcher calls in hooks.
861
852
if (
862
853
i < hookStack . length - 1 &&
863
- isReactWrapper ( hookStack [ i ] . functionName , hook . dispatcherMethodName )
854
+ isReactWrapper ( hookStack [ i ] . functionName , hook . dispatcherHookName )
864
855
) {
865
856
i ++ ;
866
857
}
867
858
if (
868
859
i < hookStack . length - 1 &&
869
- isReactWrapper ( hookStack [ i ] . functionName , hook . dispatcherMethodName )
860
+ isReactWrapper ( hookStack [ i ] . functionName , hook . dispatcherHookName )
870
861
) {
871
862
i ++ ;
872
863
}
@@ -904,7 +895,15 @@ function parseHookName(functionName: void | string): string {
904
895
if ( ! functionName ) {
905
896
return '';
906
897
}
907
- let startIndex = functionName . lastIndexOf ( '. ');
898
+ let startIndex = functionName . lastIndexOf ( '[ as ') ;
899
+
900
+ if ( startIndex !== - 1 ) {
901
+ // Workaround for sourcemaps in Jest and Chrome.
902
+ // In `node --enable-source-maps`, we don't see "Object.useHostTransitionStatus [as useFormStatus]" but "Object.useFormStatus"
903
+ // "Object.useHostTransitionStatus [as useFormStatus]" -> "useFormStatus"
904
+ return parseHookName ( functionName . slice ( startIndex + '[as ' . length , - 1 ) ) ;
905
+ }
906
+ startIndex = functionName . lastIndexOf ( '. ') ;
908
907
if ( startIndex = = = - 1 ) {
909
908
startIndex = 0 ;
910
909
} else {
@@ -939,7 +938,7 @@ function buildTree(
939
938
parseHookName ( primitiveFrame . functionName ) ||
940
939
// Older versions of React do not have sourcemaps.
941
940
// In those versions there was always a 1:1 mapping between wrapper and dispatcher method.
942
- parseHookName ( hook . dispatcherMethodName ) ;
941
+ parseHookName ( hook . dispatcherHookName ) ;
943
942
}
944
943
if ( stack !== null ) {
945
944
// Note: The indices 0 <= n < length-1 will contain the names.
0 commit comments