Skip to content

fix(core): Avoid using Array.findIndex() as it is ES5 incompatible #7400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/core/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function getIntegrationsToSetup(options: Options): Integration[] {
// `beforeSendTransaction`. It therefore has to run after all other integrations, so that the changes of all event
// processors will be reflected in the printed values. For lack of a more elegant way to guarantee that, we therefore
// locate it and, assuming it exists, pop it out of its current spot and shove it onto the end of the array.
const debugIndex = finalIntegrations.findIndex(integration => integration.name === 'Debug');
const debugIndex = findIndex(finalIntegrations, integration => integration.name === 'Debug');
if (debugIndex !== -1) {
const [debugInstance] = finalIntegrations.splice(debugIndex, 1);
finalIntegrations.push(debugInstance);
Expand Down Expand Up @@ -107,3 +107,14 @@ export function setupIntegration(integration: Integration, integrationIndex: Int
__DEBUG_BUILD__ && logger.log(`Integration installed: ${integration.name}`);
}
}

// Polyfill for Array.findIndex(), which is not supported in ES5
function findIndex<T>(arr: T[], callback: (item: T) => boolean): number {
for (let i = 0; i < arr.length; i++) {
if (callback(arr[i]) === true) {
return i;
}
}

return -1;
}