1/**
2 * Copyright (c) 650 Industries.
3 * Copyright (c) Meta Platforms, Inc. and affiliates.
4 *
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8import symbolicateStackTrace from '../modules/symbolicateStackTrace';
9const cache = new Map();
10/**
11 * Sanitize because sometimes, `symbolicateStackTrace` gives us invalid values.
12 */
13const sanitize = ({ stack: maybeStack, codeFrame, }) => {
14    if (!Array.isArray(maybeStack)) {
15        throw new Error('Expected stack to be an array.');
16    }
17    const stack = [];
18    for (const maybeFrame of maybeStack) {
19        let collapse = false;
20        if ('collapse' in maybeFrame) {
21            if (typeof maybeFrame.collapse !== 'boolean') {
22                throw new Error('Expected stack frame `collapse` to be a boolean.');
23            }
24            collapse = maybeFrame.collapse;
25        }
26        stack.push({
27            arguments: [],
28            column: maybeFrame.column,
29            file: maybeFrame.file,
30            lineNumber: maybeFrame.lineNumber,
31            methodName: maybeFrame.methodName,
32            collapse,
33        });
34    }
35    return { stack, codeFrame };
36};
37export function deleteStack(stack) {
38    cache.delete(stack);
39}
40export function symbolicate(stack) {
41    let promise = cache.get(stack);
42    if (promise == null) {
43        promise = symbolicateStackTrace(stack).then(sanitize);
44        cache.set(stack, promise);
45    }
46    return promise;
47}
48//# sourceMappingURL=LogBoxSymbolication.js.map