@@ -2,11 +2,7 @@ import type { DebugImage, StackParser } from '@sentry/types';
22import { GLOBAL_OBJ } from './worldwide' ;
33
44type StackString = string ;
5-
6- interface CachedResult {
7- filename : string ;
8- debugId : string ;
9- }
5+ type CachedResult = [ string , string ] ;
106
117let debugIdStackParserCache : WeakMap < StackParser , Map < StackString , CachedResult > > | undefined ;
128
@@ -25,8 +21,8 @@ function getCacheForStackParser(stackParser: StackParser): Map<StackString, Cach
2521 return result ;
2622}
2723
28- let lastDebugIdKeyCount = 0 ;
29- let cachedFilenameToDebugId : Map < string , string > | undefined ;
24+ let lastCount = 0 ;
25+ let cachedFilenameDebugIds : Map < string , string > | undefined ;
3026
3127/**
3228 * Returns a map of filenames to debug identifiers.
@@ -41,17 +37,19 @@ export function getFilenameToDebugIdMap(stackParser: StackParser): Map<string, s
4137
4238 // If the count of registered globals hasn't changed since the last call, we
4339 // can just return the cached result.
44- if ( debugIdKeys . length === lastDebugIdKeyCount && cachedFilenameToDebugId ) {
45- return cachedFilenameToDebugId ;
40+ if ( cachedFilenameDebugIds && debugIdKeys . length === lastCount ) {
41+ return cachedFilenameDebugIds ;
4642 }
4743
4844 const debugIdStackFramesCache = getCacheForStackParser ( stackParser ) ;
4945
5046 // Build a map of filename -> debug_id.
51- const output = debugIdKeys . reduce < Map < string , string > > ( ( acc , debugIdStackTrace ) => {
52- let result = debugIdStackFramesCache . get ( debugIdStackTrace ) ;
47+ cachedFilenameDebugIds = debugIdKeys . reduce < Map < string , string > > ( ( acc , debugIdStackTrace ) => {
48+ const result = debugIdStackFramesCache . get ( debugIdStackTrace ) ;
5349
54- if ( ! result ) {
50+ if ( result ) {
51+ acc . set ( result [ 0 ] , result [ 1 ] ) ;
52+ } else {
5553 const parsedStack = stackParser ( debugIdStackTrace ) ;
5654
5755 for ( let i = parsedStack . length - 1 ; i >= 0 ; i -- ) {
@@ -60,24 +58,19 @@ export function getFilenameToDebugIdMap(stackParser: StackParser): Map<string, s
6058 const debugId = debugIdMap [ debugIdStackTrace ] ;
6159
6260 if ( filename && debugId ) {
63- result = { filename, debugId } ;
61+ acc . set ( filename , debugId ) ;
6462 debugIdStackFramesCache . set ( debugIdStackTrace , result ) ;
6563 break ;
6664 }
6765 }
6866 }
6967
70- if ( result ) {
71- acc . set ( result . filename , result . debugId ) ;
72- }
73-
7468 return acc ;
7569 } , new Map ( ) ) ;
7670
77- lastDebugIdKeyCount = Object . keys ( debugIdMap ) . length ;
78- cachedFilenameToDebugId = output ;
71+ lastCount = debugIdKeys . length ;
7972
80- return output ;
73+ return cachedFilenameDebugIds ;
8174}
8275
8376/**
0 commit comments