1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.INTERNAL_CALLSITES_REGEX = void 0;
7exports.getDefaultCustomizeFrame = getDefaultCustomizeFrame;
8function _url() {
9  const data = require("url");
10  _url = function () {
11    return data;
12  };
13  return data;
14}
15// Copyright 2023-present 650 Industries (Expo). All rights reserved.
16
17// Import only the types here, the values will be imported from the project, at runtime.
18const INTERNAL_CALLSITES_REGEX = new RegExp(['/Libraries/Renderer/implementations/.+\\.js$', '/Libraries/BatchedBridge/MessageQueue\\.js$', '/Libraries/YellowBox/.+\\.js$', '/Libraries/LogBox/.+\\.js$', '/Libraries/Core/Timers/.+\\.js$', 'node_modules/react-devtools-core/.+\\.js$', 'node_modules/react-refresh/.+\\.js$', 'node_modules/scheduler/.+\\.js$',
19// Metro replaces `require()` with a different method,
20// we want to omit this method from the stack trace.
21// This is akin to most React tooling.
22'/metro/.*/polyfills/require.js$',
23// Hide frames related to a fast refresh.
24'/metro/.*/lib/bundle-modules/.+\\.js$', 'node_modules/react-native/Libraries/Utilities/HMRClient.js$', 'node_modules/eventemitter3/index.js', 'node_modules/event-target-shim/dist/.+\\.js$',
25// Improve errors thrown by invariant (ex: `Invariant Violation: "main" has not been registered`).
26'node_modules/invariant/.+\\.js$',
27// Remove babel runtime additions
28'node_modules/regenerator-runtime/.+\\.js$',
29// Remove react native setImmediate ponyfill
30'node_modules/promise/setimmediate/.+\\.js$',
31// Babel helpers that implement language features
32'node_modules/@babel/runtime/.+\\.js$',
33// Hide Hermes internal bytecode
34'/InternalBytecode/InternalBytecode\\.js$',
35// Block native code invocations
36`\\[native code\\]`,
37// Hide react-dom (web)
38'node_modules/react-dom/.+\\.js$',
39// Hide node.js evaluation code
40'node_modules/require-from-string/.+\\.js$',
41// Block expo's metro-runtime
42'@expo/metro-runtime/.+\\.ts',
43// Block upstream metro-runtime
44'/metro-runtime/.+\\.js$'].join('|'));
45exports.INTERNAL_CALLSITES_REGEX = INTERNAL_CALLSITES_REGEX;
46function isUrl(value) {
47  try {
48    // eslint-disable-next-line no-new
49    new (_url().URL)(value);
50    return true;
51  } catch {
52    return false;
53  }
54}
55
56/**
57 * The default frame processor. This is used to modify the stack traces.
58 * This method attempts to collapse all frames that aren't relevant to
59 * the user by default.
60 */
61function getDefaultCustomizeFrame() {
62  return frame => {
63    if (frame.file && isUrl(frame.file)) {
64      return {
65        ...frame,
66        // HACK: This prevents Metro from attempting to read the invalid file URL it sent us.
67        lineNumber: null,
68        column: null,
69        // This prevents the invalid frame from being shown by default.
70        collapse: true
71      };
72    }
73    let collapse = Boolean(frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file));
74    if (!collapse) {
75      var _frame$file;
76      // This represents the first frame of the stacktrace.
77      // Often this looks like: `__r(0);`.
78      // The URL will also be unactionable in the app and therefore not very useful to the developer.
79      if (frame.column === 3 && frame.methodName === 'global code' && (_frame$file = frame.file) !== null && _frame$file !== void 0 && _frame$file.match(/^https?:\/\//g)) {
80        collapse = true;
81      }
82    }
83    return {
84      ...(frame || {}),
85      collapse
86    };
87  };
88}
89//# sourceMappingURL=customizeFrame.js.map