Skip to content

Commit 8b0d536

Browse files
authored
fix(core): Avoid using Array.findIndex() as it is ES5 incompatible (#7400)
1 parent cc26081 commit 8b0d536

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/core/src/integration.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function getIntegrationsToSetup(options: Options): Integration[] {
6969
// `beforeSendTransaction`. It therefore has to run after all other integrations, so that the changes of all event
7070
// processors will be reflected in the printed values. For lack of a more elegant way to guarantee that, we therefore
7171
// locate it and, assuming it exists, pop it out of its current spot and shove it onto the end of the array.
72-
const debugIndex = finalIntegrations.findIndex(integration => integration.name === 'Debug');
72+
const debugIndex = findIndex(finalIntegrations, integration => integration.name === 'Debug');
7373
if (debugIndex !== -1) {
7474
const [debugInstance] = finalIntegrations.splice(debugIndex, 1);
7575
finalIntegrations.push(debugInstance);
@@ -107,3 +107,14 @@ export function setupIntegration(integration: Integration, integrationIndex: Int
107107
__DEBUG_BUILD__ && logger.log(`Integration installed: ${integration.name}`);
108108
}
109109
}
110+
111+
// Polyfill for Array.findIndex(), which is not supported in ES5
112+
function findIndex<T>(arr: T[], callback: (item: T) => boolean): number {
113+
for (let i = 0; i < arr.length; i++) {
114+
if (callback(arr[i]) === true) {
115+
return i;
116+
}
117+
}
118+
119+
return -1;
120+
}

0 commit comments

Comments
 (0)