/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at . */
import { getFrameUrl } from "./getFrameUrl";
import { getLibraryFromUrl } from "./getLibraryFromUrl";
export function annotateFrames(frames) {
const annotatedFrames = frames.map(f => annotateFrame(f, frames));
return annotateBabelAsyncFrames(annotatedFrames);
}
function annotateFrame(frame, frames) {
const library = getLibraryFromUrl(frame, frames);
if (library) {
return { ...frame, library };
}
return frame;
}
function annotateBabelAsyncFrames(frames) {
const babelFrameIndexes = getBabelFrameIndexes(frames);
const isBabelFrame = frameIndex => babelFrameIndexes.includes(frameIndex);
return frames.map((frame, frameIndex) =>
isBabelFrame(frameIndex) ? { ...frame, library: "Babel" } : frame
);
}
/**
* Returns all the indexes that are part of a babel async call stack.
*
* @param {Array