@visulima/error 4.4.11 → 4.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/code-frame/index.cjs +136 -6
  3. package/dist/code-frame/index.mjs +131 -6
  4. package/dist/error/index.cjs +18 -1
  5. package/dist/error/index.d.cts +2 -2
  6. package/dist/error/index.d.mts +2 -2
  7. package/dist/error/index.d.ts +2 -2
  8. package/dist/error/index.mjs +5 -1
  9. package/dist/index.cjs +25 -1
  10. package/dist/index.mjs +8 -1
  11. package/dist/packem_shared/captureRawStackTrace-CAQrHENg.mjs +12 -0
  12. package/dist/packem_shared/captureRawStackTrace-DjD7FUtZ.cjs +14 -0
  13. package/dist/packem_shared/getErrorCauses-CG_JRE6j.mjs +24 -0
  14. package/dist/packem_shared/getErrorCauses-miTeYJEG.cjs +26 -0
  15. package/dist/packem_shared/indexToLineColumn-DjmjeiIY.cjs +56 -0
  16. package/dist/packem_shared/indexToLineColumn-Dx91YDU1.mjs +54 -0
  17. package/dist/packem_shared/isVisulimaError-BVLWvREw.cjs +45 -0
  18. package/dist/packem_shared/isVisulimaError-H6TqEA42.mjs +40 -0
  19. package/dist/packem_shared/parseStacktrace-B-BUrkkI.mjs +280 -0
  20. package/dist/packem_shared/parseStacktrace-CPbfvO-n.cjs +282 -0
  21. package/dist/packem_shared/renderError-DV9rZ4rp.mjs +163 -0
  22. package/dist/packem_shared/renderError-NCKbKLok.cjs +167 -0
  23. package/dist/packem_shared/serializeError-BNAsxuJ_.mjs +153 -0
  24. package/dist/packem_shared/serializeError-C3BTAUm5.cjs +157 -0
  25. package/dist/stacktrace/index.cjs +9 -1
  26. package/dist/stacktrace/index.mjs +1 -1
  27. package/package.json +7 -7
  28. package/dist/packem_shared/captureRawStackTrace-B7M10xhx.mjs +0 -1
  29. package/dist/packem_shared/captureRawStackTrace-Dle60tQN.cjs +0 -1
  30. package/dist/packem_shared/getErrorCauses--fuy5DYb.cjs +0 -1
  31. package/dist/packem_shared/getErrorCauses-D025FGyO.mjs +0 -1
  32. package/dist/packem_shared/indexToLineColumn-BUaHBIUg.cjs +0 -1
  33. package/dist/packem_shared/indexToLineColumn-BxCJ9Cey.mjs +0 -1
  34. package/dist/packem_shared/isVisulimaError-7lgjv56R.mjs +0 -1
  35. package/dist/packem_shared/isVisulimaError-DYPrVHSe.cjs +0 -1
  36. package/dist/packem_shared/parseStacktrace-CUC_6mhC.mjs +0 -2
  37. package/dist/packem_shared/parseStacktrace-DuzLAkHs.cjs +0 -2
  38. package/dist/packem_shared/renderError-Bul-oz45.mjs +0 -18
  39. package/dist/packem_shared/renderError-DAUdGdkA.cjs +0 -18
  40. package/dist/packem_shared/serializeError-BX2VPOX2.cjs +0 -1
  41. package/dist/packem_shared/serializeError-Ddx6s06r.mjs +0 -1
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ const isVisulimaError = /* @__PURE__ */ __name((error) => error instanceof Error && error.type === "VisulimaError", "isVisulimaError");
8
+ class VisulimaError extends Error {
9
+ static {
10
+ __name(this, "VisulimaError");
11
+ }
12
+ loc;
13
+ title;
14
+ /**
15
+ * A message that explains to the user how they can fix the error.
16
+ */
17
+ hint;
18
+ type = "VisulimaError";
19
+ constructor({ cause, hint, location, message, name, stack, title }) {
20
+ super(message, {
21
+ cause
22
+ });
23
+ this.title = title;
24
+ this.name = name;
25
+ this.stack = stack ?? this.stack;
26
+ this.loc = location;
27
+ this.hint = hint;
28
+ Error.captureStackTrace(this, this.constructor);
29
+ }
30
+ setLocation(location) {
31
+ this.loc = location;
32
+ }
33
+ setName(name) {
34
+ this.name = name;
35
+ }
36
+ setMessage(message) {
37
+ this.message = message;
38
+ }
39
+ setHint(hint) {
40
+ this.hint = hint;
41
+ }
42
+ }
43
+
44
+ exports.VisulimaError = VisulimaError;
45
+ exports.isVisulimaError = isVisulimaError;
@@ -0,0 +1,40 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ const isVisulimaError = /* @__PURE__ */ __name((error) => error instanceof Error && error.type === "VisulimaError", "isVisulimaError");
4
+ class VisulimaError extends Error {
5
+ static {
6
+ __name(this, "VisulimaError");
7
+ }
8
+ loc;
9
+ title;
10
+ /**
11
+ * A message that explains to the user how they can fix the error.
12
+ */
13
+ hint;
14
+ type = "VisulimaError";
15
+ constructor({ cause, hint, location, message, name, stack, title }) {
16
+ super(message, {
17
+ cause
18
+ });
19
+ this.title = title;
20
+ this.name = name;
21
+ this.stack = stack ?? this.stack;
22
+ this.loc = location;
23
+ this.hint = hint;
24
+ Error.captureStackTrace(this, this.constructor);
25
+ }
26
+ setLocation(location) {
27
+ this.loc = location;
28
+ }
29
+ setName(name) {
30
+ this.name = name;
31
+ }
32
+ setMessage(message) {
33
+ this.message = message;
34
+ }
35
+ setHint(hint) {
36
+ this.hint = hint;
37
+ }
38
+ }
39
+
40
+ export { VisulimaError, isVisulimaError };
@@ -0,0 +1,280 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ const debugLog = /* @__PURE__ */ __name((message, ...arguments_) => {
4
+ if (process.env.DEBUG && String(process.env.DEBUG) === "true") {
5
+ console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);
6
+ }
7
+ }, "debugLog");
8
+ const UNKNOWN_FUNCTION = "<unknown>";
9
+ const CHROMIUM_REGEX = (
10
+ // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-super-linear-backtracking
11
+ /^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i
12
+ );
13
+ const CHROMIUM_EVAL_REGEX = /\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/;
14
+ const CHROMIUM_MAPPED = /(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/;
15
+ const WINDOWS_EVAL_REGEX = /(eval)\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*(<anonymous>)?:(\d+)?:(\d+)/;
16
+ const NODE_REGEX = /^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/;
17
+ const NODE_NESTED_REGEX = /in\s(.*)\s\(at\s(.+)\)\sat/;
18
+ const REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\d+):(\d+)$/;
19
+ const GECKO_REGEX = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
20
+ const GECKO_EVAL_REGEX = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
21
+ const FIREFOX_REGEX = /(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/;
22
+ const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
23
+ const extractSafariExtensionDetails = /* @__PURE__ */ __name((methodName, url) => {
24
+ const isSafariExtension = methodName.includes("safari-extension");
25
+ const isSafariWebExtension = methodName.includes("safari-web-extension");
26
+ return isSafariExtension || isSafariWebExtension ? [
27
+ methodName.includes("@") ? methodName.split("@")[0] : UNKNOWN_FUNCTION,
28
+ isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`
29
+ ] : [methodName, url];
30
+ }, "extractSafariExtensionDetails");
31
+ const parseMapped = /* @__PURE__ */ __name((trace, maybeMapped) => {
32
+ const match = CHROMIUM_MAPPED.exec(maybeMapped);
33
+ if (match) {
34
+ trace.file = match[1];
35
+ trace.line = +match[2];
36
+ trace.column = +match[3];
37
+ }
38
+ }, "parseMapped");
39
+ const parseNode = /* @__PURE__ */ __name((line) => {
40
+ const nestedNode = NODE_NESTED_REGEX.exec(line);
41
+ if (nestedNode) {
42
+ debugLog(`parse nested node error stack line: "${line}"`, `found: ${JSON.stringify(nestedNode)}`);
43
+ const split = nestedNode[2].split(":");
44
+ return {
45
+ column: split[2] ? +split[2] : undefined,
46
+ file: split[0],
47
+ line: split[1] ? +split[1] : undefined,
48
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
49
+ methodName: nestedNode[1] || UNKNOWN_FUNCTION,
50
+ raw: line,
51
+ type: undefined
52
+ };
53
+ }
54
+ const node = NODE_REGEX.exec(line);
55
+ if (node) {
56
+ debugLog(`parse node error stack line: "${line}"`, `found: ${JSON.stringify(node)}`);
57
+ const trace = {
58
+ column: node[4] ? +node[4] : undefined,
59
+ file: node[2] ? node[2].replace(/at\s/, "") : undefined,
60
+ line: node[3] ? +node[3] : undefined,
61
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
62
+ methodName: node[1] || UNKNOWN_FUNCTION,
63
+ raw: line,
64
+ type: line.startsWith("internal") ? "internal" : undefined
65
+ };
66
+ parseMapped(trace, node[2] + ":" + node[3] + ":" + node[4]);
67
+ return trace;
68
+ }
69
+ return undefined;
70
+ }, "parseNode");
71
+ const parseChromium = /* @__PURE__ */ __name((line) => {
72
+ const parts = CHROMIUM_REGEX.exec(line);
73
+ if (parts) {
74
+ debugLog(`parse chrome error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
75
+ const isNative = parts[2]?.startsWith("native");
76
+ const isEval = parts[2]?.startsWith("eval") || parts[1]?.startsWith("eval");
77
+ let evalOrigin;
78
+ let windowsParts;
79
+ if (isEval) {
80
+ const subMatch = CHROMIUM_EVAL_REGEX.exec(line);
81
+ if (subMatch) {
82
+ const split = /(\S+):(\d+):(\d+)|(\S+):(\d+)$/.exec(subMatch[1]);
83
+ if (split) {
84
+ parts[2] = split[4] ?? split[1];
85
+ parts[3] = split[5] ?? split[2];
86
+ parts[4] = split[3];
87
+ } else if (subMatch[2]) {
88
+ parts[2] = subMatch[1];
89
+ }
90
+ if (subMatch[2]) {
91
+ evalOrigin = {
92
+ column: subMatch[4] ? +subMatch[4] : undefined,
93
+ file: subMatch[2],
94
+ line: subMatch[3] ? +subMatch[3] : undefined,
95
+ methodName: "eval",
96
+ raw: line,
97
+ type: "eval"
98
+ };
99
+ }
100
+ } else {
101
+ const windowsSubMatch = WINDOWS_EVAL_REGEX.exec(line);
102
+ if (windowsSubMatch) {
103
+ windowsParts = {
104
+ column: windowsSubMatch[5] ? +windowsSubMatch[5] : undefined,
105
+ file: windowsSubMatch[3],
106
+ line: windowsSubMatch[4] ? +windowsSubMatch[4] : undefined
107
+ };
108
+ evalOrigin = {
109
+ column: windowsSubMatch[8] ? +windowsSubMatch[8] : undefined,
110
+ file: windowsSubMatch[2],
111
+ line: windowsSubMatch[7] ? +windowsSubMatch[7] : undefined,
112
+ methodName: "eval",
113
+ raw: windowsSubMatch[0],
114
+ type: "eval"
115
+ };
116
+ }
117
+ }
118
+ }
119
+ const [methodName, file] = extractSafariExtensionDetails(
120
+ // Normalize IE's 'Anonymous function'
121
+ parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
122
+ parts[2]
123
+ );
124
+ const trace = {
125
+ column: parts[4] ? +parts[4] : undefined,
126
+ evalOrigin,
127
+ file,
128
+ line: parts[3] ? +parts[3] : undefined,
129
+ methodName,
130
+ raw: line,
131
+ type: isEval ? "eval" : isNative ? "native" : undefined
132
+ };
133
+ if (windowsParts) {
134
+ trace.column = windowsParts.column;
135
+ trace.file = windowsParts.file;
136
+ trace.line = windowsParts.line;
137
+ } else {
138
+ parseMapped(trace, file + ":" + parts[3] + ":" + parts[4]);
139
+ }
140
+ return trace;
141
+ }
142
+ return undefined;
143
+ }, "parseChromium");
144
+ const parseGecko = /* @__PURE__ */ __name((line, topFrameMeta) => {
145
+ const parts = GECKO_REGEX.exec(line);
146
+ if (parts) {
147
+ debugLog(`parse gecko error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
148
+ const isEval = parts[3]?.includes(" > eval");
149
+ const subMatch = isEval && parts[3] && GECKO_EVAL_REGEX.exec(parts[3]);
150
+ let evalOrigin;
151
+ if (isEval && subMatch) {
152
+ parts[3] = subMatch[1];
153
+ evalOrigin = {
154
+ column: parts[5] ? +parts[5] : undefined,
155
+ file: parts[3],
156
+ line: parts[4] ? +parts[4] : undefined,
157
+ methodName: "eval",
158
+ raw: line,
159
+ type: "eval"
160
+ };
161
+ parts[4] = subMatch[2];
162
+ }
163
+ const [methodName, file] = extractSafariExtensionDetails(
164
+ // Normalize IE's 'Anonymous function'
165
+ parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
166
+ parts[3]
167
+ );
168
+ let column;
169
+ if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.column) {
170
+ column = topFrameMeta.column;
171
+ } else if (!isEval && parts[5]) {
172
+ column = +parts[5];
173
+ }
174
+ let lineNumber;
175
+ if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.line) {
176
+ lineNumber = topFrameMeta.line;
177
+ } else if (parts[4]) {
178
+ lineNumber = +parts[4];
179
+ }
180
+ return {
181
+ column,
182
+ evalOrigin,
183
+ file,
184
+ line: lineNumber,
185
+ methodName,
186
+ raw: line,
187
+ type: isEval ? "eval" : file.includes("[native code]") ? "native" : undefined
188
+ };
189
+ }
190
+ return undefined;
191
+ }, "parseGecko");
192
+ const parseFirefox = /* @__PURE__ */ __name((line, topFrameMeta) => {
193
+ const parts = FIREFOX_REGEX.exec(line);
194
+ const isEval = parts ? parts[2].includes(" > eval") : false;
195
+ if (!isEval && parts) {
196
+ debugLog(`parse firefox error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
197
+ return {
198
+ column: parts[4] ? +parts[4] : topFrameMeta?.column ?? undefined,
199
+ file: parts[2],
200
+ line: parts[3] ? +parts[3] : topFrameMeta?.line ?? undefined,
201
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
202
+ methodName: parts[1] || UNKNOWN_FUNCTION,
203
+ raw: line,
204
+ type: undefined
205
+ };
206
+ }
207
+ return undefined;
208
+ }, "parseFirefox");
209
+ const parseReactAndroidNative = /* @__PURE__ */ __name((line) => {
210
+ const parts = REACT_ANDROID_NATIVE_REGEX.exec(line);
211
+ if (parts) {
212
+ debugLog(`parse react android native error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
213
+ return {
214
+ column: parts[3] ? +parts[3] : undefined,
215
+ file: parts[1],
216
+ line: parts[2] ? +parts[2] : undefined,
217
+ methodName: UNKNOWN_FUNCTION,
218
+ raw: line,
219
+ type: undefined
220
+ };
221
+ }
222
+ return undefined;
223
+ }, "parseReactAndroidNative");
224
+ const parse = /* @__PURE__ */ __name((error, { filter, frameLimit = 50 } = {}) => {
225
+ let lines = (error.stacktrace ?? error.stack ?? "").split("\n").map((line) => {
226
+ const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, "$1") : line;
227
+ return cleanedLine.replace(/^\s+|\s+$/g, "");
228
+ }).filter((line) => !/\S*(?:Error: |AggregateError:)/.test(line) && line !== "eval code");
229
+ if (filter) {
230
+ lines = lines.filter((element) => filter(element));
231
+ }
232
+ lines = lines.slice(0, frameLimit);
233
+ return lines.reduce((stack, line, currentIndex) => {
234
+ if (!line) {
235
+ return stack;
236
+ }
237
+ if (line.length > 1024) {
238
+ return stack;
239
+ }
240
+ let parseResult;
241
+ if (/^\s*in\s.*/.test(line)) {
242
+ parseResult = parseNode(line);
243
+ } else if (/^.*?\s*at\s.*/.test(line)) {
244
+ parseResult = parseChromium(line);
245
+ } else if (/^.*?\s*@.*|\[native code\]/.test(line)) {
246
+ let topFrameMeta;
247
+ if (currentIndex === 0) {
248
+ if (error.columnNumber || error.lineNumber) {
249
+ topFrameMeta = {
250
+ // @ts-expect-error columnNumber and columnNumber property only exists on Firefox
251
+ column: error.columnNumber,
252
+ // @ts-expect-error columnNumber and lineNumber property only exists on Firefox
253
+ line: error.lineNumber,
254
+ type: "firefox"
255
+ };
256
+ } else if (error.line || error.column) {
257
+ topFrameMeta = {
258
+ // @ts-expect-error column property only exists on safari
259
+ column: error.column,
260
+ // @ts-expect-error line property only exists on safari
261
+ line: error.line,
262
+ type: "safari"
263
+ };
264
+ }
265
+ }
266
+ parseResult = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
267
+ parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);
268
+ } else {
269
+ parseResult = parseReactAndroidNative(line);
270
+ }
271
+ if (parseResult) {
272
+ stack.push(parseResult);
273
+ } else {
274
+ debugLog(`parse error stack line: "${line}"`, "not parser found");
275
+ }
276
+ return stack;
277
+ }, []);
278
+ }, "parse");
279
+
280
+ export { parse as default };
@@ -0,0 +1,282 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ const debugLog = /* @__PURE__ */ __name((message, ...arguments_) => {
6
+ if (process.env.DEBUG && String(process.env.DEBUG) === "true") {
7
+ console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);
8
+ }
9
+ }, "debugLog");
10
+ const UNKNOWN_FUNCTION = "<unknown>";
11
+ const CHROMIUM_REGEX = (
12
+ // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-super-linear-backtracking
13
+ /^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i
14
+ );
15
+ const CHROMIUM_EVAL_REGEX = /\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/;
16
+ const CHROMIUM_MAPPED = /(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/;
17
+ const WINDOWS_EVAL_REGEX = /(eval)\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*(<anonymous>)?:(\d+)?:(\d+)/;
18
+ const NODE_REGEX = /^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/;
19
+ const NODE_NESTED_REGEX = /in\s(.*)\s\(at\s(.+)\)\sat/;
20
+ const REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\d+):(\d+)$/;
21
+ const GECKO_REGEX = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
22
+ const GECKO_EVAL_REGEX = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
23
+ const FIREFOX_REGEX = /(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/;
24
+ const WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
25
+ const extractSafariExtensionDetails = /* @__PURE__ */ __name((methodName, url) => {
26
+ const isSafariExtension = methodName.includes("safari-extension");
27
+ const isSafariWebExtension = methodName.includes("safari-web-extension");
28
+ return isSafariExtension || isSafariWebExtension ? [
29
+ methodName.includes("@") ? methodName.split("@")[0] : UNKNOWN_FUNCTION,
30
+ isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`
31
+ ] : [methodName, url];
32
+ }, "extractSafariExtensionDetails");
33
+ const parseMapped = /* @__PURE__ */ __name((trace, maybeMapped) => {
34
+ const match = CHROMIUM_MAPPED.exec(maybeMapped);
35
+ if (match) {
36
+ trace.file = match[1];
37
+ trace.line = +match[2];
38
+ trace.column = +match[3];
39
+ }
40
+ }, "parseMapped");
41
+ const parseNode = /* @__PURE__ */ __name((line) => {
42
+ const nestedNode = NODE_NESTED_REGEX.exec(line);
43
+ if (nestedNode) {
44
+ debugLog(`parse nested node error stack line: "${line}"`, `found: ${JSON.stringify(nestedNode)}`);
45
+ const split = nestedNode[2].split(":");
46
+ return {
47
+ column: split[2] ? +split[2] : undefined,
48
+ file: split[0],
49
+ line: split[1] ? +split[1] : undefined,
50
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
51
+ methodName: nestedNode[1] || UNKNOWN_FUNCTION,
52
+ raw: line,
53
+ type: undefined
54
+ };
55
+ }
56
+ const node = NODE_REGEX.exec(line);
57
+ if (node) {
58
+ debugLog(`parse node error stack line: "${line}"`, `found: ${JSON.stringify(node)}`);
59
+ const trace = {
60
+ column: node[4] ? +node[4] : undefined,
61
+ file: node[2] ? node[2].replace(/at\s/, "") : undefined,
62
+ line: node[3] ? +node[3] : undefined,
63
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
64
+ methodName: node[1] || UNKNOWN_FUNCTION,
65
+ raw: line,
66
+ type: line.startsWith("internal") ? "internal" : undefined
67
+ };
68
+ parseMapped(trace, node[2] + ":" + node[3] + ":" + node[4]);
69
+ return trace;
70
+ }
71
+ return undefined;
72
+ }, "parseNode");
73
+ const parseChromium = /* @__PURE__ */ __name((line) => {
74
+ const parts = CHROMIUM_REGEX.exec(line);
75
+ if (parts) {
76
+ debugLog(`parse chrome error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
77
+ const isNative = parts[2]?.startsWith("native");
78
+ const isEval = parts[2]?.startsWith("eval") || parts[1]?.startsWith("eval");
79
+ let evalOrigin;
80
+ let windowsParts;
81
+ if (isEval) {
82
+ const subMatch = CHROMIUM_EVAL_REGEX.exec(line);
83
+ if (subMatch) {
84
+ const split = /(\S+):(\d+):(\d+)|(\S+):(\d+)$/.exec(subMatch[1]);
85
+ if (split) {
86
+ parts[2] = split[4] ?? split[1];
87
+ parts[3] = split[5] ?? split[2];
88
+ parts[4] = split[3];
89
+ } else if (subMatch[2]) {
90
+ parts[2] = subMatch[1];
91
+ }
92
+ if (subMatch[2]) {
93
+ evalOrigin = {
94
+ column: subMatch[4] ? +subMatch[4] : undefined,
95
+ file: subMatch[2],
96
+ line: subMatch[3] ? +subMatch[3] : undefined,
97
+ methodName: "eval",
98
+ raw: line,
99
+ type: "eval"
100
+ };
101
+ }
102
+ } else {
103
+ const windowsSubMatch = WINDOWS_EVAL_REGEX.exec(line);
104
+ if (windowsSubMatch) {
105
+ windowsParts = {
106
+ column: windowsSubMatch[5] ? +windowsSubMatch[5] : undefined,
107
+ file: windowsSubMatch[3],
108
+ line: windowsSubMatch[4] ? +windowsSubMatch[4] : undefined
109
+ };
110
+ evalOrigin = {
111
+ column: windowsSubMatch[8] ? +windowsSubMatch[8] : undefined,
112
+ file: windowsSubMatch[2],
113
+ line: windowsSubMatch[7] ? +windowsSubMatch[7] : undefined,
114
+ methodName: "eval",
115
+ raw: windowsSubMatch[0],
116
+ type: "eval"
117
+ };
118
+ }
119
+ }
120
+ }
121
+ const [methodName, file] = extractSafariExtensionDetails(
122
+ // Normalize IE's 'Anonymous function'
123
+ parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
124
+ parts[2]
125
+ );
126
+ const trace = {
127
+ column: parts[4] ? +parts[4] : undefined,
128
+ evalOrigin,
129
+ file,
130
+ line: parts[3] ? +parts[3] : undefined,
131
+ methodName,
132
+ raw: line,
133
+ type: isEval ? "eval" : isNative ? "native" : undefined
134
+ };
135
+ if (windowsParts) {
136
+ trace.column = windowsParts.column;
137
+ trace.file = windowsParts.file;
138
+ trace.line = windowsParts.line;
139
+ } else {
140
+ parseMapped(trace, file + ":" + parts[3] + ":" + parts[4]);
141
+ }
142
+ return trace;
143
+ }
144
+ return undefined;
145
+ }, "parseChromium");
146
+ const parseGecko = /* @__PURE__ */ __name((line, topFrameMeta) => {
147
+ const parts = GECKO_REGEX.exec(line);
148
+ if (parts) {
149
+ debugLog(`parse gecko error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
150
+ const isEval = parts[3]?.includes(" > eval");
151
+ const subMatch = isEval && parts[3] && GECKO_EVAL_REGEX.exec(parts[3]);
152
+ let evalOrigin;
153
+ if (isEval && subMatch) {
154
+ parts[3] = subMatch[1];
155
+ evalOrigin = {
156
+ column: parts[5] ? +parts[5] : undefined,
157
+ file: parts[3],
158
+ line: parts[4] ? +parts[4] : undefined,
159
+ methodName: "eval",
160
+ raw: line,
161
+ type: "eval"
162
+ };
163
+ parts[4] = subMatch[2];
164
+ }
165
+ const [methodName, file] = extractSafariExtensionDetails(
166
+ // Normalize IE's 'Anonymous function'
167
+ parts[1] ? parts[1].replace(/^Anonymous function$/, "<anonymous>") : UNKNOWN_FUNCTION,
168
+ parts[3]
169
+ );
170
+ let column;
171
+ if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.column) {
172
+ column = topFrameMeta.column;
173
+ } else if (!isEval && parts[5]) {
174
+ column = +parts[5];
175
+ }
176
+ let lineNumber;
177
+ if ((topFrameMeta?.type === "safari" || !isEval && topFrameMeta?.type === "firefox") && topFrameMeta.line) {
178
+ lineNumber = topFrameMeta.line;
179
+ } else if (parts[4]) {
180
+ lineNumber = +parts[4];
181
+ }
182
+ return {
183
+ column,
184
+ evalOrigin,
185
+ file,
186
+ line: lineNumber,
187
+ methodName,
188
+ raw: line,
189
+ type: isEval ? "eval" : file.includes("[native code]") ? "native" : undefined
190
+ };
191
+ }
192
+ return undefined;
193
+ }, "parseGecko");
194
+ const parseFirefox = /* @__PURE__ */ __name((line, topFrameMeta) => {
195
+ const parts = FIREFOX_REGEX.exec(line);
196
+ const isEval = parts ? parts[2].includes(" > eval") : false;
197
+ if (!isEval && parts) {
198
+ debugLog(`parse firefox error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
199
+ return {
200
+ column: parts[4] ? +parts[4] : topFrameMeta?.column ?? undefined,
201
+ file: parts[2],
202
+ line: parts[3] ? +parts[3] : topFrameMeta?.line ?? undefined,
203
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
204
+ methodName: parts[1] || UNKNOWN_FUNCTION,
205
+ raw: line,
206
+ type: undefined
207
+ };
208
+ }
209
+ return undefined;
210
+ }, "parseFirefox");
211
+ const parseReactAndroidNative = /* @__PURE__ */ __name((line) => {
212
+ const parts = REACT_ANDROID_NATIVE_REGEX.exec(line);
213
+ if (parts) {
214
+ debugLog(`parse react android native error stack line: "${line}"`, `found: ${JSON.stringify(parts)}`);
215
+ return {
216
+ column: parts[3] ? +parts[3] : undefined,
217
+ file: parts[1],
218
+ line: parts[2] ? +parts[2] : undefined,
219
+ methodName: UNKNOWN_FUNCTION,
220
+ raw: line,
221
+ type: undefined
222
+ };
223
+ }
224
+ return undefined;
225
+ }, "parseReactAndroidNative");
226
+ const parse = /* @__PURE__ */ __name((error, { filter, frameLimit = 50 } = {}) => {
227
+ let lines = (error.stacktrace ?? error.stack ?? "").split("\n").map((line) => {
228
+ const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, "$1") : line;
229
+ return cleanedLine.replace(/^\s+|\s+$/g, "");
230
+ }).filter((line) => !/\S*(?:Error: |AggregateError:)/.test(line) && line !== "eval code");
231
+ if (filter) {
232
+ lines = lines.filter((element) => filter(element));
233
+ }
234
+ lines = lines.slice(0, frameLimit);
235
+ return lines.reduce((stack, line, currentIndex) => {
236
+ if (!line) {
237
+ return stack;
238
+ }
239
+ if (line.length > 1024) {
240
+ return stack;
241
+ }
242
+ let parseResult;
243
+ if (/^\s*in\s.*/.test(line)) {
244
+ parseResult = parseNode(line);
245
+ } else if (/^.*?\s*at\s.*/.test(line)) {
246
+ parseResult = parseChromium(line);
247
+ } else if (/^.*?\s*@.*|\[native code\]/.test(line)) {
248
+ let topFrameMeta;
249
+ if (currentIndex === 0) {
250
+ if (error.columnNumber || error.lineNumber) {
251
+ topFrameMeta = {
252
+ // @ts-expect-error columnNumber and columnNumber property only exists on Firefox
253
+ column: error.columnNumber,
254
+ // @ts-expect-error columnNumber and lineNumber property only exists on Firefox
255
+ line: error.lineNumber,
256
+ type: "firefox"
257
+ };
258
+ } else if (error.line || error.column) {
259
+ topFrameMeta = {
260
+ // @ts-expect-error column property only exists on safari
261
+ column: error.column,
262
+ // @ts-expect-error line property only exists on safari
263
+ line: error.line,
264
+ type: "safari"
265
+ };
266
+ }
267
+ }
268
+ parseResult = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
269
+ parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);
270
+ } else {
271
+ parseResult = parseReactAndroidNative(line);
272
+ }
273
+ if (parseResult) {
274
+ stack.push(parseResult);
275
+ } else {
276
+ debugLog(`parse error stack line: "${line}"`, "not parser found");
277
+ }
278
+ return stack;
279
+ }, []);
280
+ }, "parse");
281
+
282
+ module.exports = parse;