@visulima/error 3.2.11 → 4.1.0

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 (43) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE.md +27 -0
  3. package/README.md +20 -17
  4. package/dist/code-frame/index.cjs +6 -0
  5. package/dist/code-frame/index.d.cts +27 -0
  6. package/dist/code-frame/index.d.mts +27 -0
  7. package/dist/code-frame/index.mjs +6 -0
  8. package/dist/error/index.cjs +1 -0
  9. package/dist/error/index.d.cts +51 -0
  10. package/dist/error/index.d.mts +51 -0
  11. package/dist/error/index.d.ts +21 -1
  12. package/dist/error/index.mjs +1 -0
  13. package/dist/index.cjs +1 -0
  14. package/dist/index.d.cts +12 -0
  15. package/dist/index.d.mts +12 -0
  16. package/dist/index.d.ts +1 -3
  17. package/dist/index.mjs +1 -0
  18. package/dist/shared/error.CVJAi2IP.mjs +1 -0
  19. package/dist/shared/error.uFKIz5VX.cjs +1 -0
  20. package/dist/stacktrace/index.cjs +2 -0
  21. package/dist/stacktrace/index.d.cts +16 -0
  22. package/dist/stacktrace/index.d.mts +16 -0
  23. package/dist/stacktrace/index.mjs +2 -0
  24. package/package.json +41 -37
  25. package/dist/chunk-BKLPSU5H.js +0 -10
  26. package/dist/chunk-BKLPSU5H.js.map +0 -1
  27. package/dist/chunk-D22N6ARA.js +0 -13
  28. package/dist/chunk-D22N6ARA.js.map +0 -1
  29. package/dist/chunk-HAVTTG7L.js +0 -7
  30. package/dist/chunk-HAVTTG7L.js.map +0 -1
  31. package/dist/chunk-ZMWUTAJM.js +0 -6
  32. package/dist/chunk-ZMWUTAJM.js.map +0 -1
  33. package/dist/code-frame/index.js +0 -3
  34. package/dist/code-frame/index.js.map +0 -1
  35. package/dist/error/index.js +0 -3
  36. package/dist/error/index.js.map +0 -1
  37. package/dist/index.js +0 -10
  38. package/dist/index.js.map +0 -1
  39. package/dist/sourcemap/index.d.ts +0 -6
  40. package/dist/sourcemap/index.js +0 -3
  41. package/dist/sourcemap/index.js.map +0 -1
  42. package/dist/stacktrace/index.js +0 -3
  43. package/dist/stacktrace/index.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ ## @visulima/error [4.1.0](https://github.com/visulima/visulima/compare/@visulima/error@4.0.0...@visulima/error@4.1.0) (2024-07-01)
2
+
3
+ ### Features
4
+
5
+ * **error:** added new error serialize ([#443](https://github.com/visulima/visulima/issues/443)) ([b6f109b](https://github.com/visulima/visulima/commit/b6f109b108e608e310ec1bc95de7e249763ad095))
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * updated dev dependencies ([c889486](https://github.com/visulima/visulima/commit/c889486f8980741f459b993648c1b6d0815e3d66))
10
+
11
+ ## @visulima/error [4.0.0](https://github.com/visulima/visulima/compare/@visulima/error@3.2.11...@visulima/error@4.0.0) (2024-06-16)
12
+
13
+ ### ⚠ BREAKING CHANGES
14
+
15
+ * **error:** moved source-map handling into a new package @visulima/source-map
16
+ Signed-off-by: prisis <d.bannert@anolilab.de>
17
+
18
+ Signed-off-by: prisis <d.bannert@anolilab.de>
19
+
20
+ ### Features
21
+
22
+ * **error:** removed source-map handling ([716ef11](https://github.com/visulima/visulima/commit/716ef11a054fd9405f58ba448a868054b5368b50))
23
+ * **source-map:** new source-map package ([d4114c6](https://github.com/visulima/visulima/commit/d4114c6e7cd73bacf14ba7d8df509507d8daa3ee))
24
+
25
+ ### Bug Fixes
26
+
27
+ * **error:** fixed new eval syntax on windows ([e50a816](https://github.com/visulima/visulima/commit/e50a8164d6b2f15818b77d67ac876bbe638bba8a))
28
+
29
+ ### Miscellaneous Chores
30
+
31
+ * **error:** added missing @visulima/path as dev dep ([c83d103](https://github.com/visulima/visulima/commit/c83d1035209a9b0f4674ede207918b403efc5fbf))
32
+ * **source-map:** moved fixtures from error to source-map ([664b287](https://github.com/visulima/visulima/commit/664b2870d4405fb27b65f7dc264b89f1bf29306d))
33
+ * updated all dev deps ([ef143ce](https://github.com/visulima/visulima/commit/ef143ce2e15952a0910aa5c8bd78d25de9ebd7f3))
34
+
35
+ ### Build System
36
+
37
+ * fixed found audit error, updated all dev package deps, updated deps in apps and examples ([4c51950](https://github.com/visulima/visulima/commit/4c519500dc5504579d35725572920658999885cb))
38
+
1
39
  ## @visulima/error [3.2.11](https://github.com/visulima/visulima/compare/@visulima/error@3.2.10...@visulima/error@3.2.11) (2024-06-06)
2
40
 
3
41
 
package/LICENSE.md CHANGED
@@ -19,3 +19,30 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
+
23
+ <!-- DEPENDENCIES -->
24
+
25
+ # Licenses of bundled dependencies
26
+ The published @visulima/error artifact additionally contains code with the following licenses:
27
+ MIT
28
+
29
+ # Bundled dependencies:
30
+ ## is-plain-obj
31
+ License: MIT
32
+ By: Sindre Sorhus
33
+ Repository: sindresorhus/is-plain-obj
34
+
35
+ > MIT License
36
+ >
37
+ > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
38
+ >
39
+ > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
40
+ >
41
+ > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
42
+ >
43
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44
+
45
+ <!-- DEPENDENCIES -->
46
+
47
+ <!-- TYPE_DEPENDENCIES -->
48
+ <!-- TYPE_DEPENDENCIES -->
package/README.md CHANGED
@@ -228,29 +228,32 @@ console.log(stack);
228
228
  // ];
229
229
  ```
230
230
 
231
- ## Source Map
231
+ ## `serialize` an error object
232
+
233
+ - Ensures errors are safe to serialize with JSON
234
+ - Can be used as error.toJSON()
235
+ - Deep serialization, including transforming
236
+ - Custom serialization (e.g. YAML or process.send())
237
+ - Keeps both native (TypeError, etc.) and custom error classes
238
+ - Preserves errors' additional properties
239
+ - Can keep constructor's arguments
240
+ - Works recursively with error.cause and AggregateError
241
+ - Buffer properties are replaced with [object Buffer]
242
+ - Circular references are handled.
243
+ - If the input object has a .toJSON() method, then it's called instead of serializing the object's properties.
244
+ - It's up to .toJSON() implementation to handle circular references and enumerability of the properties.
232
245
 
233
246
  ```ts
234
- import { loadSourceMap, originalPositionFor, sourceContentFor } from "@visulima/error";
247
+ import { serializeError } from "@visulima/error";
235
248
 
236
- const sourceMap = loadSourceMap("your_path/src/index.js"); // returns a TraceMap
249
+ const error = new TypeError("example");
250
+ const errorObject = serializeError(error);
251
+ // Plain object: { name: 'TypeError', message: 'example', stack: '...' }
237
252
 
238
- const traced = originalPositionFor(sourceMap, { column: 13, line: 30 });
239
-
240
- console.log(traced);
241
-
242
- // {
243
- // column: 9,
244
- // line: 15,
245
- // name: "setState",
246
- // source: "your_path/src/index.js"
247
- // }
248
-
249
- console.log(sourceContentFor(sourceMap, traced.source)); // 'content for your_path/src/index.js'
253
+ const errorString = JSON.stringify(errorObject);
254
+ const newErrorObject = JSON.parse(errorString);
250
255
  ```
251
256
 
252
- For more information about the TraceMap see [@jridgewell/trace-mapping](https://github.com/jridgewell/trace-mapping)
253
-
254
257
  ## Supported Node.js Versions
255
258
 
256
259
  Libraries in this ecosystem make the best effort to track [Node.js’ release schedule](https://github.com/nodejs/release#release-schedule).
@@ -0,0 +1,6 @@
1
+ "use strict";var P=Object.defineProperty;var v=(t,e)=>P(t,"name",{value:e,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var F=Object.defineProperty,S=v((t,e)=>F(t,"name",{value:e,configurable:!0}),"r$1");const N=S(t=>t.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
2
+ `),"normalizeLF"),T=globalThis.process||Object.create(null),O={versions:{}},j=new Proxy(T,{get(t,e){if(e in t)return t[e];if(e in O)return O[e]}});var _=Object.defineProperty,C=v((t,e)=>_(t,"name",{value:e,configurable:!0}),"b");const R=C((t,e,d,n)=>{const f={column:0,line:-1,...t.start},i={...f,...t.end},o=f.line,l=f.column,m=i.line,u=i.column;let g=Math.max(o-(d+1),0),b=Math.min(e.length,m+n);o===-1&&(g=0),m===-1&&(b=e.length);const p=m-o,a={};if(p)for(let r=0;r<=p;r++){const s=r+o;if(!l)a[s]=!0;else if(r===0){const c=e[s-1]?.length;a[s]=[l,(c??0)-l+1]}else if(r===p)a[s]=[0,u];else{const c=e[s-r]?.length;a[s]=[0,c]}}else l===u?a[o]=l?[l,0]:!0:a[o]=[l,(u??0)-(l??0)];return{end:b,markerLines:a,start:g}},"getMarkerLines");var W=Object.defineProperty,$=v((t,e)=>W(t,"name",{value:e,configurable:!0}),"o");const k=j.platform==="win32"&&!j.env?.WT_SESSION?">":"❯",x=$((t,e,d)=>{const n={linesAbove:2,linesBelow:3,showGutter:!0,showLineNumbers:!0,tabWidth:4,...d,color:{gutter:$(r=>r,"gutter"),marker:$(r=>r,"marker"),message:$(r=>r,"message"),...d?.color}},f=e.start&&typeof e.start.column=="number";let i=N(t).split(`
3
+ `);typeof n?.tabWidth=="number"&&(i=i.map(r=>r.replaceAll(" "," ".repeat(n.tabWidth))));const{end:o,markerLines:l,start:m}=R(e,i,n.linesAbove,n.linesBelow),u=String(o).length,{gutter:g,marker:b,message:p}=n.color;let a=i.slice(m,o).map((r,s)=>{const c=m+1+s,h=l[c],M=` ${c}`.slice(-u),w=!l[c+1],y=` ${M}${n.showGutter?" |":""}`;if(h){let A="";if(Array.isArray(h)){const E=r.replaceAll(/[^\t]/g," ").slice(0,Math.max(h[0]-1,0)),L=h[1]||1;A=[`
4
+ `,g(y.replaceAll(/\d/g," "))," ",E,b("^").repeat(L)].join(""),w&&n.message&&(A+=` ${p(n.message)}`)}return[b(k),g(y),r.length>0?` ${r}`:"",A].join("")}return` ${g(y)}${r.length>0?` ${r}`:""}`}).join(`
5
+ `);return n.message&&!f&&(a=`${" ".repeat(u+1)}${n.message}
6
+ ${a}`),a},"codeFrame");exports.CODE_FRAME_POINTER=k;exports.codeFrame=x;
@@ -0,0 +1,27 @@
1
+ type CodeFrameLocation = {
2
+ column?: number;
3
+ line: number;
4
+ };
5
+ type CodeFrameNodeLocation = {
6
+ end?: CodeFrameLocation;
7
+ start: CodeFrameLocation;
8
+ };
9
+ type ColorizeMethod = (value: string) => string;
10
+ type CodeFrameOptions = {
11
+ color?: {
12
+ gutter?: ColorizeMethod;
13
+ marker?: ColorizeMethod;
14
+ message?: ColorizeMethod;
15
+ };
16
+ linesAbove?: number;
17
+ linesBelow?: number;
18
+ message?: string;
19
+ showGutter?: boolean;
20
+ showLineNumbers?: boolean;
21
+ tabWidth?: number | false;
22
+ };
23
+
24
+ declare const CODE_FRAME_POINTER: string;
25
+ declare const codeFrame: (source: string, loc: CodeFrameNodeLocation, options?: CodeFrameOptions) => string;
26
+
27
+ export { CODE_FRAME_POINTER, type CodeFrameLocation, type CodeFrameNodeLocation, type CodeFrameOptions, type ColorizeMethod, codeFrame };
@@ -0,0 +1,27 @@
1
+ type CodeFrameLocation = {
2
+ column?: number;
3
+ line: number;
4
+ };
5
+ type CodeFrameNodeLocation = {
6
+ end?: CodeFrameLocation;
7
+ start: CodeFrameLocation;
8
+ };
9
+ type ColorizeMethod = (value: string) => string;
10
+ type CodeFrameOptions = {
11
+ color?: {
12
+ gutter?: ColorizeMethod;
13
+ marker?: ColorizeMethod;
14
+ message?: ColorizeMethod;
15
+ };
16
+ linesAbove?: number;
17
+ linesBelow?: number;
18
+ message?: string;
19
+ showGutter?: boolean;
20
+ showLineNumbers?: boolean;
21
+ tabWidth?: number | false;
22
+ };
23
+
24
+ declare const CODE_FRAME_POINTER: string;
25
+ declare const codeFrame: (source: string, loc: CodeFrameNodeLocation, options?: CodeFrameOptions) => string;
26
+
27
+ export { CODE_FRAME_POINTER, type CodeFrameLocation, type CodeFrameNodeLocation, type CodeFrameOptions, type ColorizeMethod, codeFrame };
@@ -0,0 +1,6 @@
1
+ var P=Object.defineProperty;var v=(t,e)=>P(t,"name",{value:e,configurable:!0});var x=Object.defineProperty,E=v((t,e)=>x(t,"name",{value:e,configurable:!0}),"r$1");const F=E(t=>t.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
2
+ `),"normalizeLF"),N=globalThis.process||Object.create(null),k={versions:{}},j=new Proxy(N,{get(t,e){if(e in t)return t[e];if(e in k)return k[e]}});var S=Object.defineProperty,W=v((t,e)=>S(t,"name",{value:e,configurable:!0}),"b");const C=W((t,e,h,n)=>{const f={column:0,line:-1,...t.start},i={...f,...t.end},o=f.line,l=f.column,m=i.line,u=i.column;let g=Math.max(o-(h+1),0),p=Math.min(e.length,m+n);o===-1&&(g=0),m===-1&&(p=e.length);const b=m-o,a={};if(b)for(let r=0;r<=b;r++){const s=r+o;if(!l)a[s]=!0;else if(r===0){const c=e[s-1]?.length;a[s]=[l,(c??0)-l+1]}else if(r===b)a[s]=[0,u];else{const c=e[s-r]?.length;a[s]=[0,c]}}else l===u?a[o]=l?[l,0]:!0:a[o]=[l,(u??0)-(l??0)];return{end:p,markerLines:a,start:g}},"getMarkerLines");var T=Object.defineProperty,$=v((t,e)=>T(t,"name",{value:e,configurable:!0}),"o");const _=j.platform==="win32"&&!j.env?.WT_SESSION?">":"❯",G=$((t,e,h)=>{const n={linesAbove:2,linesBelow:3,showGutter:!0,showLineNumbers:!0,tabWidth:4,...h,color:{gutter:$(r=>r,"gutter"),marker:$(r=>r,"marker"),message:$(r=>r,"message"),...h?.color}},f=e.start&&typeof e.start.column=="number";let i=F(t).split(`
3
+ `);typeof n?.tabWidth=="number"&&(i=i.map(r=>r.replaceAll(" "," ".repeat(n.tabWidth))));const{end:o,markerLines:l,start:m}=C(e,i,n.linesAbove,n.linesBelow),u=String(o).length,{gutter:g,marker:p,message:b}=n.color;let a=i.slice(m,o).map((r,s)=>{const c=m+1+s,d=l[c],w=` ${c}`.slice(-u),L=!l[c+1],A=` ${w}${n.showGutter?" |":""}`;if(d){let y="";if(Array.isArray(d)){const O=r.replaceAll(/[^\t]/g," ").slice(0,Math.max(d[0]-1,0)),M=d[1]||1;y=[`
4
+ `,g(A.replaceAll(/\d/g," "))," ",O,p("^").repeat(M)].join(""),L&&n.message&&(y+=` ${b(n.message)}`)}return[p(_),g(A),r.length>0?` ${r}`:"",y].join("")}return` ${g(A)}${r.length>0?` ${r}`:""}`}).join(`
5
+ `);return n.message&&!f&&(a=`${" ".repeat(u+1)}${n.message}
6
+ ${a}`),a},"codeFrame");export{_ as CODE_FRAME_POINTER,G as codeFrame};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../shared/error.uFKIz5VX.cjs");exports.VisulimaError=r.VisulimaError;exports.getErrorCauses=r.i;exports.isVisulimaError=r.isVisulimaError;exports.serializeError=r.serialize;
@@ -0,0 +1,51 @@
1
+ declare const getErrorCauses: <E = unknown>(error: E) => E[];
2
+
3
+ type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
4
+ aggregateErrors?: SerializedError<ErrorType>[];
5
+ cause?: unknown;
6
+ code?: string;
7
+ message: string;
8
+ name: string;
9
+ raw?: ErrorType;
10
+ stack?: string;
11
+ };
12
+
13
+ interface JsonError extends Error {
14
+ toJSON: () => SerializedError;
15
+ }
16
+ type Options = {
17
+ exclude?: string[];
18
+ maxDepth?: number;
19
+ useToJSON?: boolean;
20
+ };
21
+ declare const serialize: (error: AggregateError | Error | JsonError, options?: Options) => SerializedError;
22
+
23
+ interface ErrorProperties {
24
+ hint?: ErrorHint;
25
+ location?: ErrorLocation;
26
+ message?: string;
27
+ name: string;
28
+ stack?: string;
29
+ title?: string;
30
+ }
31
+ interface ErrorLocation {
32
+ column?: number;
33
+ file?: string;
34
+ line?: number;
35
+ }
36
+ type ErrorHint = string[] | string;
37
+
38
+ declare const isVisulimaError: (error: unknown) => error is VisulimaError;
39
+ declare class VisulimaError extends Error {
40
+ loc: ErrorLocation | undefined;
41
+ title: string | undefined;
42
+ hint: ErrorHint | undefined;
43
+ type: string;
44
+ constructor(properties: ErrorProperties, ...parameters: any);
45
+ setLocation(location: ErrorLocation): void;
46
+ setName(name: string): void;
47
+ setMessage(message: string): void;
48
+ setHint(hint: ErrorHint): void;
49
+ }
50
+
51
+ export { type ErrorHint, type ErrorLocation, type ErrorProperties, type Options as ErrorWithCauseSerializerOptions, type SerializedError, VisulimaError, getErrorCauses, isVisulimaError, serialize as serializeError };
@@ -0,0 +1,51 @@
1
+ declare const getErrorCauses: <E = unknown>(error: E) => E[];
2
+
3
+ type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
4
+ aggregateErrors?: SerializedError<ErrorType>[];
5
+ cause?: unknown;
6
+ code?: string;
7
+ message: string;
8
+ name: string;
9
+ raw?: ErrorType;
10
+ stack?: string;
11
+ };
12
+
13
+ interface JsonError extends Error {
14
+ toJSON: () => SerializedError;
15
+ }
16
+ type Options = {
17
+ exclude?: string[];
18
+ maxDepth?: number;
19
+ useToJSON?: boolean;
20
+ };
21
+ declare const serialize: (error: AggregateError | Error | JsonError, options?: Options) => SerializedError;
22
+
23
+ interface ErrorProperties {
24
+ hint?: ErrorHint;
25
+ location?: ErrorLocation;
26
+ message?: string;
27
+ name: string;
28
+ stack?: string;
29
+ title?: string;
30
+ }
31
+ interface ErrorLocation {
32
+ column?: number;
33
+ file?: string;
34
+ line?: number;
35
+ }
36
+ type ErrorHint = string[] | string;
37
+
38
+ declare const isVisulimaError: (error: unknown) => error is VisulimaError;
39
+ declare class VisulimaError extends Error {
40
+ loc: ErrorLocation | undefined;
41
+ title: string | undefined;
42
+ hint: ErrorHint | undefined;
43
+ type: string;
44
+ constructor(properties: ErrorProperties, ...parameters: any);
45
+ setLocation(location: ErrorLocation): void;
46
+ setName(name: string): void;
47
+ setMessage(message: string): void;
48
+ setHint(hint: ErrorHint): void;
49
+ }
50
+
51
+ export { type ErrorHint, type ErrorLocation, type ErrorProperties, type Options as ErrorWithCauseSerializerOptions, type SerializedError, VisulimaError, getErrorCauses, isVisulimaError, serialize as serializeError };
@@ -1,5 +1,25 @@
1
1
  declare const getErrorCauses: <E = unknown>(error: E) => E[];
2
2
 
3
+ type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
4
+ aggregateErrors?: SerializedError<ErrorType>[];
5
+ cause?: unknown;
6
+ code?: string;
7
+ message: string;
8
+ name: string;
9
+ raw?: ErrorType;
10
+ stack?: string;
11
+ };
12
+
13
+ interface JsonError extends Error {
14
+ toJSON: () => SerializedError;
15
+ }
16
+ type Options = {
17
+ exclude?: string[];
18
+ maxDepth?: number;
19
+ useToJSON?: boolean;
20
+ };
21
+ declare const serialize: (error: AggregateError | Error | JsonError, options?: Options) => SerializedError;
22
+
3
23
  interface ErrorProperties {
4
24
  hint?: ErrorHint;
5
25
  location?: ErrorLocation;
@@ -28,4 +48,4 @@ declare class VisulimaError extends Error {
28
48
  setHint(hint: ErrorHint): void;
29
49
  }
30
50
 
31
- export { type ErrorHint, type ErrorLocation, type ErrorProperties, VisulimaError, getErrorCauses, isVisulimaError };
51
+ export { type ErrorHint, type ErrorLocation, type ErrorProperties, type Options as ErrorWithCauseSerializerOptions, type SerializedError, VisulimaError, getErrorCauses, isVisulimaError, serialize as serializeError };
@@ -0,0 +1 @@
1
+ import{V as a,i,a as o,s as e}from"../shared/error.CVJAi2IP.mjs";export{a as VisulimaError,i as getErrorCauses,o as isVisulimaError,e as serializeError};
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var y=Object.defineProperty;var c=(r,e)=>y(r,"name",{value:e,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./code-frame/index.cjs"),s=require("./shared/error.uFKIz5VX.cjs"),f=require("./stacktrace/index.cjs");var g=Object.defineProperty,o=c((r,e)=>g(r,"name",{value:e,configurable:!0}),"l");const u=o((r,e)=>{let i=0,n=e.length-2;for(;i<n;){const t=i+(n-i>>1);if(r<e[t])n=t-1;else if(r>=e[t+1])i=t+1;else{i=t;break}}return i},"binarySearch"),E=o(r=>r.split(/\n|\r(?!\n)/).reduce((e,i)=>(e.push(e.at(-1)+i.length+1),e),[0]),"getLineStartIndexes"),d=o((r,e,i)=>{const n=i?.skipChecks??!1;if(!n&&(!Array.isArray(r)&&typeof r!="string"||(typeof r=="string"||Array.isArray(r))&&r.length===0))return{column:0,line:0};if(!n&&(typeof e!="number"||typeof r=="string"&&e>=r.length||Array.isArray(r)&&e+1>=r.at(-1)))return{column:0,line:0};if(typeof r=="string"){const a=E(r),l=u(e,a);return{column:e-a[l]+1,line:l+1}}const t=u(e,r);return{column:e-r[t]+1,line:t+1}},"indexToLineColumn"),p=d;exports.CODE_FRAME_POINTER=m.CODE_FRAME_POINTER;exports.codeFrame=m.codeFrame;exports.VisulimaError=s.VisulimaError;exports.getErrorCauses=s.i;exports.isVisulimaError=s.isVisulimaError;exports.serializeError=s.serialize;exports.parseStacktrace=f.parseStacktrace;exports.indexToLineColumn=p;
@@ -0,0 +1,12 @@
1
+ export { CODE_FRAME_POINTER, CodeFrameLocation, CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod, codeFrame } from './code-frame/index.cjs';
2
+ export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, SerializedError, VisulimaError, getErrorCauses, isVisulimaError, serializeError } from './error/index.cjs';
3
+ export { Trace, TraceType, parseStacktrace } from './stacktrace/index.cjs';
4
+
5
+ declare const indexToLineColumn: (input: number[] | string, index: number, options?: {
6
+ skipChecks: boolean;
7
+ }) => {
8
+ column: number;
9
+ line: number;
10
+ };
11
+
12
+ export { indexToLineColumn };
@@ -0,0 +1,12 @@
1
+ export { CODE_FRAME_POINTER, CodeFrameLocation, CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod, codeFrame } from './code-frame/index.mjs';
2
+ export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, SerializedError, VisulimaError, getErrorCauses, isVisulimaError, serializeError } from './error/index.mjs';
3
+ export { Trace, TraceType, parseStacktrace } from './stacktrace/index.mjs';
4
+
5
+ declare const indexToLineColumn: (input: number[] | string, index: number, options?: {
6
+ skipChecks: boolean;
7
+ }) => {
8
+ column: number;
9
+ line: number;
10
+ };
11
+
12
+ export { indexToLineColumn };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export { CODE_FRAME_POINTER, CodeFrameLocation, CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod, codeFrame } from './code-frame/index.js';
2
- export { ErrorHint, ErrorLocation, ErrorProperties, VisulimaError, getErrorCauses, isVisulimaError } from './error/index.js';
3
- export { loadSourceMap } from './sourcemap/index.js';
4
- export { TraceMap, generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from '@jridgewell/trace-mapping';
2
+ export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, SerializedError, VisulimaError, getErrorCauses, isVisulimaError, serializeError } from './error/index.js';
5
3
  export { Trace, TraceType, parseStacktrace } from './stacktrace/index.js';
6
4
 
7
5
  declare const indexToLineColumn: (input: number[] | string, index: number, options?: {
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var l=(r,e)=>c(r,"name",{value:e,configurable:!0});import{CODE_FRAME_POINTER as A,codeFrame as E}from"./code-frame/index.mjs";import{V as d,i as C,a as k,s as v}from"./shared/error.CVJAi2IP.mjs";import{parseStacktrace as O}from"./stacktrace/index.mjs";var f=Object.defineProperty,s=l((r,e)=>f(r,"name",{value:e,configurable:!0}),"l");const u=s((r,e)=>{let n=0,o=e.length-2;for(;n<o;){const t=n+(o-n>>1);if(r<e[t])o=t-1;else if(r>=e[t+1])n=t+1;else{n=t;break}}return n},"binarySearch"),m=s(r=>r.split(/\n|\r(?!\n)/).reduce((e,n)=>(e.push(e.at(-1)+n.length+1),e),[0]),"getLineStartIndexes"),p=s((r,e,n)=>{const o=n?.skipChecks??!1;if(!o&&(!Array.isArray(r)&&typeof r!="string"||(typeof r=="string"||Array.isArray(r))&&r.length===0))return{column:0,line:0};if(!o&&(typeof e!="number"||typeof r=="string"&&e>=r.length||Array.isArray(r)&&e+1>=r.at(-1)))return{column:0,line:0};if(typeof r=="string"){const i=m(r),a=u(e,i);return{column:e-i[a]+1,line:a+1}}const t=u(e,r);return{column:e-r[t]+1,line:t+1}},"indexToLineColumn"),g=p;export{A as CODE_FRAME_POINTER,d as VisulimaError,E as codeFrame,C as getErrorCauses,g as indexToLineColumn,k as isVisulimaError,O as parseStacktrace,v as serializeError};
@@ -0,0 +1 @@
1
+ var h=Object.defineProperty;var a=(e,t)=>h(e,"name",{value:t,configurable:!0});import{inspect as y}from"node:util";var d=Object.defineProperty,O=a((e,t)=>d(e,"name",{value:t,configurable:!0}),"a");const S=O(e=>{const t=new Set,o=[];let r=e;for(;r;){if(t.has(r)){console.error(`Circular reference detected in error causes: ${y(e)}`);break}if(o.push(r),t.add(r),!r.cause)break;r=r.cause}return o},"getErrorCauses"),w=S;function g(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}a(g,"isPlainObject");const v=Object.create({},{cause:{enumerable:!0,value:void 0,writable:!0},code:{enumerable:!0,value:void 0,writable:!0},errors:{enumerable:!0,value:void 0,writable:!0},message:{enumerable:!0,value:void 0,writable:!0},name:{enumerable:!0,value:void 0,writable:!0},stack:{enumerable:!0,value:void 0,writable:!0}});var E=Object.defineProperty,u=a((e,t)=>E(e,"name",{value:t,configurable:!0}),"c");const l=new WeakSet,j=u(e=>{l.add(e);const t=e.toJSON();return l.delete(e),t},"toJSON"),f=u((e,t,o,r)=>{if(e&&e instanceof Uint8Array&&e.constructor.name==="Buffer")return"[object Buffer]";if(e!==null&&typeof e=="object"&&typeof e.pipe=="function")return"[object Stream]";if(e instanceof Error)return t.includes(e)?"[Circular]":(o+=1,c(e,r,t,o));if(r.useToJSON&&typeof e.toJSON=="function")return e.toJSON();if(typeof e=="object"&&e instanceof Date)return e.toISOString();if(typeof e=="function")return"[Function: "+(e.name||"anonymous")+"]";if(g(e)){if(o+=1,r.maxDepth&&o>=r.maxDepth)return{};const n={};for(const s in e)n[s]=f(e[s],t,o,r);return n}try{return e}catch{return"[Not Available]"}},"serializeValue"),c=u((e,t,o,r)=>{if(o.push(e),t.maxDepth===0)return{};if(t.useToJSON&&typeof e.toJSON=="function"&&!l.has(e))return j(e);const n=Object.create(v);if(n.name=Object.prototype.toString.call(e.constructor)==="[object Function]"?e.constructor.name:e.name,n.message=e.message,n.stack=e.stack,Array.isArray(e.errors)){const s=[];for(const i of e.errors){if(!(i instanceof Error))throw new TypeError("All errors in the 'errors' property must be instances of Error");if(o.includes(i))return n.errors=[],n;s.push(c(i,t,o,r))}n.errors=s}e.cause instanceof Error&&!o.includes(e.cause)&&(n.cause=c(e.cause,t,o,r));for(const s in e)if(n[s]===void 0){const i=e[s];n[s]=f(i,o,r,t)}if(Array.isArray(t.exclude)&&t.exclude.length>0)for(const s of t.exclude)try{delete n[s]}catch{}return n},"_serialize"),J=u((e,t={})=>c(e,{exclude:t.exclude??[],maxDepth:t.maxDepth??Number.POSITIVE_INFINITY,useToJSON:t.useToJSON??!1},[],0),"serialize");var N=Object.defineProperty,m=a((e,t)=>N(e,"name",{value:t,configurable:!0}),"t");const T=m(e=>e instanceof Error&&e.type==="VisulimaError","isVisulimaError");class V extends Error{static{a(this,"VisulimaError")}static{m(this,"VisulimaError")}loc;title;hint;type="VisulimaError";constructor(t,...o){super(...o);const{hint:r,location:n,message:s,name:i,stack:b,title:p}=t;this.title=p,this.name=i,s&&(this.message=s),this.stack=b??this.stack,this.loc=n,this.hint=r,Error.captureStackTrace(this,this.constructor)}setLocation(t){this.loc=t}setName(t){this.name=t}setMessage(t){this.message=t}setHint(t){this.hint=t}}export{V,T as a,w as i,J as s};
@@ -0,0 +1 @@
1
+ "use strict";var h=Object.defineProperty;var a=(e,t)=>h(e,"name",{value:t,configurable:!0});const d=require("node:util");var y=Object.defineProperty,O=a((e,t)=>y(e,"name",{value:t,configurable:!0}),"a");const E=O(e=>{const t=new Set,o=[];let r=e;for(;r;){if(t.has(r)){console.error(`Circular reference detected in error causes: ${d.inspect(e)}`);break}if(o.push(r),t.add(r),!r.cause)break;r=r.cause}return o},"getErrorCauses"),S=E;function g(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}a(g,"isPlainObject");const v=Object.create({},{cause:{enumerable:!0,value:void 0,writable:!0},code:{enumerable:!0,value:void 0,writable:!0},errors:{enumerable:!0,value:void 0,writable:!0},message:{enumerable:!0,value:void 0,writable:!0},name:{enumerable:!0,value:void 0,writable:!0},stack:{enumerable:!0,value:void 0,writable:!0}});var j=Object.defineProperty,u=a((e,t)=>j(e,"name",{value:t,configurable:!0}),"c");const l=new WeakSet,N=u(e=>{l.add(e);const t=e.toJSON();return l.delete(e),t},"toJSON"),f=u((e,t,o,r)=>{if(e&&e instanceof Uint8Array&&e.constructor.name==="Buffer")return"[object Buffer]";if(e!==null&&typeof e=="object"&&typeof e.pipe=="function")return"[object Stream]";if(e instanceof Error)return t.includes(e)?"[Circular]":(o+=1,c(e,r,t,o));if(r.useToJSON&&typeof e.toJSON=="function")return e.toJSON();if(typeof e=="object"&&e instanceof Date)return e.toISOString();if(typeof e=="function")return"[Function: "+(e.name||"anonymous")+"]";if(g(e)){if(o+=1,r.maxDepth&&o>=r.maxDepth)return{};const n={};for(const s in e)n[s]=f(e[s],t,o,r);return n}try{return e}catch{return"[Not Available]"}},"serializeValue"),c=u((e,t,o,r)=>{if(o.push(e),t.maxDepth===0)return{};if(t.useToJSON&&typeof e.toJSON=="function"&&!l.has(e))return N(e);const n=Object.create(v);if(n.name=Object.prototype.toString.call(e.constructor)==="[object Function]"?e.constructor.name:e.name,n.message=e.message,n.stack=e.stack,Array.isArray(e.errors)){const s=[];for(const i of e.errors){if(!(i instanceof Error))throw new TypeError("All errors in the 'errors' property must be instances of Error");if(o.includes(i))return n.errors=[],n;s.push(c(i,t,o,r))}n.errors=s}e.cause instanceof Error&&!o.includes(e.cause)&&(n.cause=c(e.cause,t,o,r));for(const s in e)if(n[s]===void 0){const i=e[s];n[s]=f(i,o,r,t)}if(Array.isArray(t.exclude)&&t.exclude.length>0)for(const s of t.exclude)try{delete n[s]}catch{}return n},"_serialize"),x=u((e,t={})=>c(e,{exclude:t.exclude??[],maxDepth:t.maxDepth??Number.POSITIVE_INFINITY,useToJSON:t.useToJSON??!1},[],0),"serialize");var k=Object.defineProperty,m=a((e,t)=>k(e,"name",{value:t,configurable:!0}),"t");const w=m(e=>e instanceof Error&&e.type==="VisulimaError","isVisulimaError");class V extends Error{static{a(this,"VisulimaError")}static{m(this,"VisulimaError")}loc;title;hint;type="VisulimaError";constructor(t,...o){super(...o);const{hint:r,location:n,message:s,name:i,stack:b,title:p}=t;this.title=p,this.name=i,s&&(this.message=s),this.stack=b??this.stack,this.loc=n,this.hint=r,Error.captureStackTrace(this,this.constructor)}setLocation(t){this.loc=t}setName(t){this.name=t}setMessage(t){this.message=t}setHint(t){this.hint=t}}exports.VisulimaError=V;exports.i=S;exports.isVisulimaError=w;exports.serialize=x;
@@ -0,0 +1,2 @@
1
+ "use strict";var x=Object.defineProperty;var v=(i,e)=>x(i,"name",{value:e,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var N=Object.defineProperty,d=v((i,e)=>N(i,"name",{value:e,configurable:!0}),"u");const u=d((i,...e)=>{process.env.DEBUG&&String(process.env.DEBUG)==="true"&&console.debug(`error:parse-stacktrace: ${i}`,...e)},"debugLog"),f="<unknown>",g=/^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,h=/\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/,S=/(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/,b=/(eval)\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*(<anonymous>)?:(\d+)?:(\d+)/,k=/^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/,w=/in\s(.*)\s\(at\s(.+)\)\sat/,O=/^(?:.*@)?(.*):(\d+):(\d+)$/,J=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i,E=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,A=/(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/,p=/\(error: (.*)\)/,y=d((i,e)=>{const n=i.includes("safari-extension"),o=i.includes("safari-web-extension");return n||o?[i.includes("@")?i.split("@")[0]:f,n?`safari-extension:${e}`:`safari-web-extension:${e}`]:[i,e]},"extractSafariExtensionDetails"),$=d((i,e)=>{const n=S.exec(e);n&&(i.file=n[1],i.line=+n[2],i.column=+n[3])},"parseMapped"),G=d(i=>{const e=w.exec(i);if(e){u(`parse nested node error stack line: "${i}"`,`found: ${JSON.stringify(e)}`);const o=e[2].split(":");return{column:o[2]?+o[2]:void 0,file:o[0],line:o[1]?+o[1]:void 0,methodName:e[1]||f,raw:i,type:void 0}}const n=k.exec(i);if(n){u(`parse node error stack line: "${i}"`,`found: ${JSON.stringify(n)}`);const o={column:n[4]?+n[4]:void 0,file:n[2]?n[2].replace(/at\s/,""):void 0,line:n[3]?+n[3]:void 0,methodName:n[1]||f,raw:i,type:i.startsWith("internal")?"internal":void 0};return $(o,`${n[2]}:${n[3]}:${n[4]}`),o}},"parseNode"),W=d(i=>{const e=g.exec(i);if(e){u(`parse chrome error stack line: "${i}"`,`found: ${JSON.stringify(e)}`);const n=e[2]&&e[2].startsWith("native"),o=e[2]&&e[2].startsWith("eval")||e[1]&&e[1].startsWith("eval");let r,t;if(o){const s=h.exec(i);if(s){const a=/(\S+):(\d+):(\d+)|(\S+):(\d+)$/.exec(s[1]);a?(e[2]=a[4]??a[1],e[3]=a[5]??a[2],e[4]=a[3]):s[2]&&(e[2]=s[1]),s[2]&&(r={column:s[4]?+s[4]:void 0,file:s[2],line:s[3]?+s[3]:void 0,methodName:"eval",raw:i,type:"eval"})}else{const a=b.exec(i);a&&(t={column:a[5]?+a[5]:void 0,file:a[3],line:a[4]?+a[4]:void 0},r={column:a[8]?+a[8]:void 0,file:a[2],line:a[7]?+a[7]:void 0,methodName:"eval",raw:a[0],type:"eval"})}}const[m,c]=y(e[1]?e[1].replace(/^Anonymous function$/,"<anonymous>"):f,e[2]),l={column:e[4]?+e[4]:void 0,evalOrigin:r,file:c,line:e[3]?+e[3]:void 0,methodName:m,raw:i,type:o?"eval":n?"native":void 0};return t?(l.column=t.column,l.file=t.file,l.line=t.line):$(l,`${c}:${e[3]}:${e[4]}`),l}},"parseChromium"),j=d((i,e)=>{const n=J.exec(i);if(n){u(`parse gecko error stack line: "${i}"`,`found: ${JSON.stringify(n)}`);const o=n[3]?.includes(" > eval"),r=o&&n[3]&&E.exec(n[3]);let t;o&&r&&(n[3]=r[1],t={column:n[5]?+n[5]:void 0,file:n[3],line:n[4]?+n[4]:void 0,methodName:"eval",raw:i,type:"eval"},n[4]=r[2]);const[m,c]=y(n[1]?n[1].replace(/^Anonymous function$/,"<anonymous>"):f,n[3]);let l;(e?.type==="safari"||!o&&e?.type==="firefox")&&e.column?l=e.column:!o&&n[5]&&(l=+n[5]);let s;return(e?.type==="safari"||!o&&e?.type==="firefox")&&e.line?s=e.line:n[4]&&(s=+n[4]),{column:l,evalOrigin:t,file:c,line:s,methodName:m,raw:i,type:o?"eval":c.includes("[native code]")?"native":void 0}}},"parseGecko"),D=d((i,e)=>{const n=A.exec(i);if(!(n&&n[2].includes(" > eval"))&&n)return u(`parse firefox error stack line: "${i}"`,`found: ${JSON.stringify(n)}`),{column:n[4]?+n[4]:e?.column??void 0,file:n[2],line:n[3]?+n[3]:e?.line??void 0,methodName:n[1]||f,raw:i,type:void 0}},"parseFirefox"),z=d(i=>{const e=O.exec(i);if(e)return u(`parse react android native error stack line: "${i}"`,`found: ${JSON.stringify(e)}`),{column:e[3]?+e[3]:void 0,file:e[1],line:e[2]?+e[2]:void 0,methodName:f,raw:i,type:void 0}},"parseReactAndroidNative"),B=d((i,e={})=>{const{frameLimit:n=50}=e;let o=(i.stacktrace??i.stack??"").split(`
2
+ `).map(r=>(p.test(r)?r.replace(p,"$1"):r).replace(/^\s+|\s+$/g,"")).filter(r=>!/\S*Error: /.test(r)&&r!=="eval code");return o.length>n&&(o=o.slice(0,n)),o.reduce((r,t,m)=>{if(!t||t.length>1024)return r;let c;if(/^\s*in\s.*/.test(t))c=G(t);else if(/^.*?\s*at\s.*/.test(t))c=W(t);else if(/^.*?\s*@.*|\[native code\]/.test(t)){let l;m===0&&(i.columnNumber||i.lineNumber?l={column:i.columnNumber,line:i.lineNumber,type:"firefox"}:(i.line||i.column)&&(l={column:i.column,line:i.line,type:"safari"})),c=D(t,l)||j(t,l)}else c=z(t);return c?r.push(c):u(`parse error stack line: "${t}"`,"not parser found"),r},[])},"parse"),L=B;exports.parseStacktrace=L;
@@ -0,0 +1,16 @@
1
+ type TraceType = "eval" | "internal" | "native" | undefined;
2
+ interface Trace {
3
+ column: number | undefined;
4
+ evalOrigin?: Trace | undefined;
5
+ file: string | undefined;
6
+ line: number | undefined;
7
+ methodName: string | undefined;
8
+ raw: string;
9
+ type?: TraceType | undefined;
10
+ }
11
+
12
+ declare const parse: (error: Error, options?: Partial<{
13
+ frameLimit: number;
14
+ }>) => Trace[];
15
+
16
+ export { type Trace, type TraceType, parse as parseStacktrace };
@@ -0,0 +1,16 @@
1
+ type TraceType = "eval" | "internal" | "native" | undefined;
2
+ interface Trace {
3
+ column: number | undefined;
4
+ evalOrigin?: Trace | undefined;
5
+ file: string | undefined;
6
+ line: number | undefined;
7
+ methodName: string | undefined;
8
+ raw: string;
9
+ type?: TraceType | undefined;
10
+ }
11
+
12
+ declare const parse: (error: Error, options?: Partial<{
13
+ frameLimit: number;
14
+ }>) => Trace[];
15
+
16
+ export { type Trace, type TraceType, parse as parseStacktrace };
@@ -0,0 +1,2 @@
1
+ var x=Object.defineProperty;var v=(i,e)=>x(i,"name",{value:e,configurable:!0});var N=Object.defineProperty,d=v((i,e)=>N(i,"name",{value:e,configurable:!0}),"u");const u=d((i,...e)=>{process.env.DEBUG&&String(process.env.DEBUG)==="true"&&console.debug(`error:parse-stacktrace: ${i}`,...e)},"debugLog"),f="<unknown>",h=/^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,g=/\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/,S=/(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/,k=/(eval)\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*(<anonymous>)?:(\d+)?:(\d+)/,w=/^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/,b=/in\s(.*)\s\(at\s(.+)\)\sat/,O=/^(?:.*@)?(.*):(\d+):(\d+)$/,J=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i,E=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,A=/(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/,p=/\(error: (.*)\)/,$=d((i,e)=>{const n=i.includes("safari-extension"),o=i.includes("safari-web-extension");return n||o?[i.includes("@")?i.split("@")[0]:f,n?`safari-extension:${e}`:`safari-web-extension:${e}`]:[i,e]},"extractSafariExtensionDetails"),y=d((i,e)=>{const n=S.exec(e);n&&(i.file=n[1],i.line=+n[2],i.column=+n[3])},"parseMapped"),G=d(i=>{const e=b.exec(i);if(e){u(`parse nested node error stack line: "${i}"`,`found: ${JSON.stringify(e)}`);const o=e[2].split(":");return{column:o[2]?+o[2]:void 0,file:o[0],line:o[1]?+o[1]:void 0,methodName:e[1]||f,raw:i,type:void 0}}const n=w.exec(i);if(n){u(`parse node error stack line: "${i}"`,`found: ${JSON.stringify(n)}`);const o={column:n[4]?+n[4]:void 0,file:n[2]?n[2].replace(/at\s/,""):void 0,line:n[3]?+n[3]:void 0,methodName:n[1]||f,raw:i,type:i.startsWith("internal")?"internal":void 0};return y(o,`${n[2]}:${n[3]}:${n[4]}`),o}},"parseNode"),W=d(i=>{const e=h.exec(i);if(e){u(`parse chrome error stack line: "${i}"`,`found: ${JSON.stringify(e)}`);const n=e[2]&&e[2].startsWith("native"),o=e[2]&&e[2].startsWith("eval")||e[1]&&e[1].startsWith("eval");let r,t;if(o){const s=g.exec(i);if(s){const a=/(\S+):(\d+):(\d+)|(\S+):(\d+)$/.exec(s[1]);a?(e[2]=a[4]??a[1],e[3]=a[5]??a[2],e[4]=a[3]):s[2]&&(e[2]=s[1]),s[2]&&(r={column:s[4]?+s[4]:void 0,file:s[2],line:s[3]?+s[3]:void 0,methodName:"eval",raw:i,type:"eval"})}else{const a=k.exec(i);a&&(t={column:a[5]?+a[5]:void 0,file:a[3],line:a[4]?+a[4]:void 0},r={column:a[8]?+a[8]:void 0,file:a[2],line:a[7]?+a[7]:void 0,methodName:"eval",raw:a[0],type:"eval"})}}const[m,c]=$(e[1]?e[1].replace(/^Anonymous function$/,"<anonymous>"):f,e[2]),l={column:e[4]?+e[4]:void 0,evalOrigin:r,file:c,line:e[3]?+e[3]:void 0,methodName:m,raw:i,type:o?"eval":n?"native":void 0};return t?(l.column=t.column,l.file=t.file,l.line=t.line):y(l,`${c}:${e[3]}:${e[4]}`),l}},"parseChromium"),D=d((i,e)=>{const n=J.exec(i);if(n){u(`parse gecko error stack line: "${i}"`,`found: ${JSON.stringify(n)}`);const o=n[3]?.includes(" > eval"),r=o&&n[3]&&E.exec(n[3]);let t;o&&r&&(n[3]=r[1],t={column:n[5]?+n[5]:void 0,file:n[3],line:n[4]?+n[4]:void 0,methodName:"eval",raw:i,type:"eval"},n[4]=r[2]);const[m,c]=$(n[1]?n[1].replace(/^Anonymous function$/,"<anonymous>"):f,n[3]);let l;(e?.type==="safari"||!o&&e?.type==="firefox")&&e.column?l=e.column:!o&&n[5]&&(l=+n[5]);let s;return(e?.type==="safari"||!o&&e?.type==="firefox")&&e.line?s=e.line:n[4]&&(s=+n[4]),{column:l,evalOrigin:t,file:c,line:s,methodName:m,raw:i,type:o?"eval":c.includes("[native code]")?"native":void 0}}},"parseGecko"),j=d((i,e)=>{const n=A.exec(i);if(!(n&&n[2].includes(" > eval"))&&n)return u(`parse firefox error stack line: "${i}"`,`found: ${JSON.stringify(n)}`),{column:n[4]?+n[4]:e?.column??void 0,file:n[2],line:n[3]?+n[3]:e?.line??void 0,methodName:n[1]||f,raw:i,type:void 0}},"parseFirefox"),z=d(i=>{const e=O.exec(i);if(e)return u(`parse react android native error stack line: "${i}"`,`found: ${JSON.stringify(e)}`),{column:e[3]?+e[3]:void 0,file:e[1],line:e[2]?+e[2]:void 0,methodName:f,raw:i,type:void 0}},"parseReactAndroidNative"),B=d((i,e={})=>{const{frameLimit:n=50}=e;let o=(i.stacktrace??i.stack??"").split(`
2
+ `).map(r=>(p.test(r)?r.replace(p,"$1"):r).replace(/^\s+|\s+$/g,"")).filter(r=>!/\S*Error: /.test(r)&&r!=="eval code");return o.length>n&&(o=o.slice(0,n)),o.reduce((r,t,m)=>{if(!t||t.length>1024)return r;let c;if(/^\s*in\s.*/.test(t))c=G(t);else if(/^.*?\s*at\s.*/.test(t))c=W(t);else if(/^.*?\s*@.*|\[native code\]/.test(t)){let l;m===0&&(i.columnNumber||i.lineNumber?l={column:i.columnNumber,line:i.lineNumber,type:"firefox"}:(i.line||i.column)&&(l={column:i.column,line:i.line,type:"safari"})),c=j(t,l)||D(t,l)}else c=z(t);return c?r.push(c):u(`parse error stack line: "${t}"`,"not parser found"),r},[])},"parse"),R=B;export{R as parseStacktrace};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@visulima/error",
3
- "version": "3.2.11",
4
- "description": "Error with more than just a message, stacktrace parsing and sourcemap loading.",
3
+ "version": "4.1.0",
4
+ "description": "Error with more than just a message, stacktrace parsing.",
5
5
  "keywords": [
6
6
  "anolilab",
7
7
  "character",
@@ -18,7 +18,6 @@
18
18
  "location",
19
19
  "parser",
20
20
  "position",
21
- "source-map",
22
21
  "stack",
23
22
  "stack-trace",
24
23
  "stacktrace",
@@ -53,37 +52,49 @@
53
52
  "type": "module",
54
53
  "exports": {
55
54
  ".": {
55
+ "require": {
56
+ "types": "./dist/index.d.cts",
57
+ "default": "./dist/index.cjs"
58
+ },
56
59
  "import": {
57
- "types": "./dist/index.d.ts",
58
- "default": "./dist/index.js"
60
+ "types": "./dist/index.d.mts",
61
+ "default": "./dist/index.mjs"
59
62
  }
60
63
  },
61
64
  "./code-frame": {
65
+ "require": {
66
+ "types": "./dist/code-frame/index.d.cts",
67
+ "default": "./dist/code-frame/index.cjs"
68
+ },
62
69
  "import": {
63
- "types": "./dist/code-frame/index.d.ts",
64
- "default": "./dist/code-frame/index.js"
70
+ "types": "./dist/code-frame/index.d.mts",
71
+ "default": "./dist/code-frame/index.mjs"
65
72
  }
66
73
  },
67
74
  "./error": {
75
+ "require": {
76
+ "types": "./dist/error/index.d.cts",
77
+ "default": "./dist/error/index.cjs"
78
+ },
68
79
  "import": {
69
- "types": "./dist/error/index.d.ts",
70
- "default": "./dist/error/index.js"
71
- }
72
- },
73
- "./sourcemap": {
74
- "import": {
75
- "types": "./dist/sourcemap/index.d.ts",
76
- "default": "./dist/sourcemap/index.js"
80
+ "types": "./dist/error/index.d.mts",
81
+ "default": "./dist/error/index.mjs"
77
82
  }
78
83
  },
79
84
  "./stacktrace": {
85
+ "require": {
86
+ "types": "./dist/stacktrace/index.d.cts",
87
+ "default": "./dist/stacktrace/index.cjs"
88
+ },
80
89
  "import": {
81
- "types": "./dist/stacktrace/index.d.ts",
82
- "default": "./dist/stacktrace/index.js"
90
+ "types": "./dist/stacktrace/index.d.mts",
91
+ "default": "./dist/stacktrace/index.mjs"
83
92
  }
84
93
  },
85
94
  "./package.json": "./package.json"
86
95
  },
96
+ "main": "dist/index.cjs",
97
+ "module": "dist/index.mjs",
87
98
  "types": "dist/index.d.ts",
88
99
  "files": [
89
100
  "dist",
@@ -91,16 +102,12 @@
91
102
  "CHANGELOG.md",
92
103
  "LICENSE.md"
93
104
  ],
94
- "dependencies": {
95
- "@jridgewell/trace-mapping": "^0.3.25",
96
- "@visulima/path": "1.0.2"
97
- },
98
105
  "devDependencies": {
99
106
  "@anolilab/eslint-config": "^15.0.3",
100
107
  "@anolilab/prettier-config": "^5.0.14",
101
- "@anolilab/semantic-release-pnpm": "^1.1.0",
102
- "@anolilab/semantic-release-preset": "^8.1.0",
103
- "@babel/core": "^7.24.6",
108
+ "@anolilab/semantic-release-pnpm": "^1.1.3",
109
+ "@anolilab/semantic-release-preset": "^9.0.0",
110
+ "@babel/core": "^7.24.7",
104
111
  "@eslint-types/deprecation": "^2.0.0",
105
112
  "@eslint-types/import": "^2.29.1",
106
113
  "@eslint-types/jsdoc": "^48.2.2",
@@ -109,21 +116,25 @@
109
116
  "@rushstack/eslint-plugin-security": "^0.8.1",
110
117
  "@total-typescript/ts-reset": "^0.5.1",
111
118
  "@types/command-line-args": "^5.2.3",
112
- "@types/node": "18.18.14",
119
+ "@types/node": "18.19.15",
113
120
  "@visulima/nextra-theme-docs": "4.0.26",
121
+ "@visulima/path": "1.0.2",
114
122
  "@vitest/coverage-v8": "^1.6.0",
115
123
  "@vitest/ui": "^1.6.0",
124
+ "conventional-changelog-conventionalcommits": "8.0.0",
116
125
  "cross-env": "^7.0.3",
117
126
  "eslint": "^8.57.0",
118
127
  "eslint-plugin-deprecation": "^3.0.0",
119
128
  "eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
120
129
  "eslint-plugin-mdx": "^3.1.5",
130
+ "is-plain-obj": "^4.1.0",
121
131
  "eslint-plugin-vitest": "^0.4.1",
122
132
  "eslint-plugin-vitest-globals": "^1.5.0",
123
- "prettier": "^3.3.0",
133
+ "prettier": "^3.3.2",
124
134
  "rimraf": "^5.0.7",
125
- "semantic-release": "23.1.1",
126
- "tsup": "^8.1.0",
135
+ "semantic-release": "24.0.0",
136
+ "@visulima/packem": "^1.0.0-alpha.46",
137
+ "esbuild": "^0.21.5",
127
138
  "typescript": "^5.4.5",
128
139
  "vitest": "^1.6.0"
129
140
  },
@@ -152,16 +163,9 @@
152
163
  "info_on_disabling_etc_no_deprecated": false
153
164
  }
154
165
  },
155
- "sources": [
156
- "src/index.ts",
157
- "src/code-frame/index.ts",
158
- "src/error/index.ts",
159
- "src/sourcemap/index.ts",
160
- "src/stacktrace/index.ts"
161
- ],
162
166
  "scripts": {
163
- "build": "cross-env NODE_ENV=development tsup",
164
- "build:prod": "cross-env NODE_ENV=production tsup",
167
+ "build": "cross-env NODE_ENV=development packem build",
168
+ "build:prod": "cross-env NODE_ENV=production packem build",
165
169
  "clean": "rimraf node_modules dist .eslintcache",
166
170
  "dev": "pnpm run build --watch",
167
171
  "lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs",
@@ -1,10 +0,0 @@
1
- var w=s=>s.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
2
- `),x=w;var v=globalThis.process||Object.create(null),y={versions:{}},z=new Proxy(v,{get(s,r){if(r in s)return s[r];if(r in y)return y[r]}}),M=z;var S=(s,r,L,t)=>{let g={column:0,line:-1,...s.start},c={...g,...s.end},i=g.line,n=g.column,l=c.line,u=c.column,d=Math.max(i-(L+1),0),f=Math.min(r.length,l+t);i===-1&&(d=0),l===-1&&(f=r.length);let p=l-i,o={};if(p)for(let e=0;e<=p;e++){let a=e+i;if(!n)o[a]=!0;else if(e===0){let m=r[a-1]?.length;o[a]=[n,(m??0)-n+1];}else if(e===p)o[a]=[0,u];else {let m=r[a-e]?.length;o[a]=[0,m];}}else n===u?o[i]=n?[n,0]:!0:o[i]=[n,(u??0)-(n??0)];return {end:f,markerLines:o,start:d}},$=S;var W=M.platform==="win32"&&!M.env?.WT_SESSION?">":"\u276F",q=(s,r,L)=>{let t={linesAbove:2,linesBelow:3,showGutter:!0,showLineNumbers:!0,tabWidth:4,...L,color:{gutter:e=>e,marker:e=>e,message:e=>e,...L?.color}},g=r.start&&typeof r.start.column=="number",c=x(s).split(`
3
- `);typeof t?.tabWidth=="number"&&(c=c.map(e=>e.replaceAll(" "," ".repeat(t.tabWidth))));let{end:i,markerLines:n,start:l}=$(r,c,t.linesAbove,t.linesBelow),u=String(i).length,{gutter:d,marker:f,message:p}=t.color,o=c.slice(l,i).map((e,a)=>{let m=l+1+a,b=n[m],N=` ${m}`.slice(-u),A=!n[m+1],h=` ${N}${t.showGutter?" |":""}`;if(b){let k="";if(Array.isArray(b)){let O=e.replaceAll(/[^\t]/g," ").slice(0,Math.max(b[0]-1,0)),P=b[1]||1;k=[`
4
- `,d(h.replaceAll(/\d/g," "))," ",O,f("^").repeat(P)].join(""),A&&t.message&&(k+=` ${p(t.message)}`);}return [f(W),d(h),e.length>0?` ${e}`:"",k].join("")}return ` ${d(h)}${e.length>0?` ${e}`:""}`}).join(`
5
- `);return t.message&&!g&&(o=`${" ".repeat(u+1)}${t.message}
6
- ${o}`),o};
7
-
8
- export { W as a, q as b };
9
- //# sourceMappingURL=out.js.map
10
- //# sourceMappingURL=chunk-BKLPSU5H.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/util/normalize-lf.ts","../src/util/process.ts","../src/code-frame/get-marker-lines.ts","../src/code-frame/index.ts"],"names":["normalizeLF","code","normalize_lf_default","_process","processShims","process","target","property","process_default","getMarkerLines","loc","source","linesAbove","linesBelow","startLoc","endLoc","startLine","startColumn","endLine","endColumn","start","end","lineDiff","markerLines","index","lineNumber","sourceLength","get_marker_lines_default","CODE_FRAME_POINTER","codeFrame","options","config","value","hasColumns","lines","ln","numberMaxWidth","colorizeGutter","colorizeMarker","colorizeMessage","frame","line","number","hasMarker","paddedNumber","lastMarkerLine","gutter","markerLine","markerSpacing","numberOfMarkers"],"mappings":"AAAA,IAAMA,EAAeC,GAAyBA,EAAK,WAAW,qBAAsB;AAAA,CAAI,EAEjFC,EAAQF,ECGf,IAAMG,EAAY,WAAW,SAAW,OAAO,OAAO,IAAI,EAEpDC,EAAiC,CACnC,SAAU,CAAC,CACf,EAEMC,EAAU,IAAI,MAAeF,EAAU,CACzC,IAAIG,EAAQC,EAAyB,CACjC,GAAIA,KAAYD,EAEZ,OAAOA,EAAOC,CAAQ,EAG1B,G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AkBN,EAAU,CAAC,GAAK,EAExCI,EAAa,CAAC;AAAA,GAAOV,EAAeS,EAAO,WAAW,MAAO,GAAG,CAAC,EAAG,IAAKE,EAAeV,EAAe,GAAG,EAAE,OAAOW,CAAe,CAAC,EAAE,KACjI,EACJ,EAEIJ,GAAkBd,EAAO,UACzBgB,GAAc,IAAIR,EAAgBR,EAAO,OAAO,CAAC,GAEzD,CAEA,MAAO,CAACO,EAAeV,CAAkB,EAAGS,EAAeS,CAAM,EAAGL,EAAK,OAAS,EAAI,IAAIA,CAAI,GAAK,GAAIM,CAAU,EAAE,KAAK,EAAE,CAC9H,CAEA,MAAO,IAAIV,EAAeS,CAAM,CAAC,GAAGL,EAAK,OAAS,EAAI,IAAIA,CAAI,GAAK,EAAE,EACzE,CAAC,EACA,KAAK;AAAA,CAAI,EAEd,OAAIV,EAAO,SAAW,CAACE,IACnBO,EAAQ,GAAG,IAAI,OAAOJ,EAAiB,CAAC,CAAC,GAAGL,EAAO,OAAO;AAAA,EAAKS,CAAK,IAGjEA,CACX","sourcesContent":["const normalizeLF = (code: string): string => code.replaceAll(/\\r\\n|\\r(?!\\n)|\\n/gu, \"\\n\");\n\nexport default normalizeLF;\n","interface Process extends Partial<Omit<typeof globalThis.process, \"versions\">> {\n versions: Record<string, string>;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/no-unnecessary-condition,no-underscore-dangle\nconst _process = (globalThis.process || Object.create(null)) as unknown as Process;\n\nconst processShims: Partial<Process> = {\n versions: {},\n};\n\nconst process = new Proxy<Process>(_process, {\n get(target, property: keyof Process) {\n if (property in target) {\n // eslint-disable-next-line security/detect-object-injection\n return target[property];\n }\n\n if (property in processShims) {\n // eslint-disable-next-line security/detect-object-injection\n return processShims[property];\n }\n\n return undefined;\n },\n});\n\nexport default process;\n","// eslint-disable-next-line no-secrets/no-secrets\n/**\n * This is a copy of the codeFrame function from Babel\n * @see https://github.com/babel/babel/blob/85e649203b61b7c908eb04c05511a0d35f893e8e/packages/babel-code-frame/src/index.ts#L68-L143\n *\n * MIT License\n *\n * Copyright (c) 2014-present Sebastian McKenzie and other contributors\n */\n\n/**\n * Extract what lines should be marked and highlighted.\n */\nimport type { CodeFrameLocation, CodeFrameNodeLocation } from \"./types\";\n\ntype MarkerLines = Record<number, true | [number | undefined, number | undefined]>;\n\nconst getMarkerLines = (\n loc: CodeFrameNodeLocation,\n source: string[],\n linesAbove: number,\n linesBelow: number,\n): {\n end: number;\n markerLines: MarkerLines;\n start: number;\n // eslint-disable-next-line sonarjs/cognitive-complexity\n} => {\n const startLoc: CodeFrameLocation = {\n column: 0,\n // @ts-expect-error Can be overwritten\n line: -1,\n ...loc.start,\n };\n const endLoc: CodeFrameLocation = {\n ...startLoc,\n ...loc.end,\n };\n const startLine = startLoc.line;\n const startColumn = startLoc.column;\n const endLine = endLoc.line;\n const endColumn = endLoc.column;\n\n let start = Math.max(startLine - (linesAbove + 1), 0);\n let end = Math.min(source.length, endLine + linesBelow);\n\n if (startLine === -1) {\n start = 0;\n }\n\n if (endLine === -1) {\n end = source.length;\n }\n\n const lineDiff = endLine - startLine;\n const markerLines: MarkerLines = {};\n\n if (lineDiff) {\n // eslint-disable-next-line no-plusplus,no-loops/no-loops\n for (let index = 0; index <= lineDiff; index++) {\n const lineNumber = index + startLine;\n\n if (!startColumn) {\n // eslint-disable-next-line security/detect-object-injection\n markerLines[lineNumber] = true;\n } else if (index === 0) {\n const sourceLength = source[lineNumber - 1]?.length;\n\n // eslint-disable-next-line security/detect-object-injection\n markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];\n } else if (index === lineDiff) {\n // eslint-disable-next-line security/detect-object-injection\n markerLines[lineNumber] = [0, endColumn];\n } else {\n const sourceLength = source[lineNumber - index]?.length;\n\n // eslint-disable-next-line security/detect-object-injection\n markerLines[lineNumber] = [0, sourceLength];\n }\n }\n } else if (startColumn === endColumn) {\n // eslint-disable-next-line security/detect-object-injection\n markerLines[startLine] = startColumn ? [startColumn, 0] : true;\n } else {\n // eslint-disable-next-line security/detect-object-injection\n markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];\n }\n\n return { end, markerLines, start };\n};\n\nexport default getMarkerLines;\n","// eslint-disable-next-line no-secrets/no-secrets\n/**\n * This is a modified copy of the codeFrameColumns function from Babel\n * @see https://github.com/babel/babel/blob/85e649203b61b7c908eb04c05511a0d35f893e8e/packages/babel-code-frame/src/index.ts#L145-L217\n *\n * MIT License\n *\n * Copyright (c) 2014-present Sebastian McKenzie and other contributors\n */\n\nimport normalizeLF from \"../util/normalize-lf\";\nimport process from \"../util/process\";\nimport getMarkerLines from \"./get-marker-lines\";\nimport type { CodeFrameNodeLocation, CodeFrameOptions } from \"./types\";\n\nexport const CODE_FRAME_POINTER = process.platform === \"win32\" && !process.env?.WT_SESSION ? \">\" : \"❯\";\n\n/** Generate a code frame from string and an error location */\nexport const codeFrame = (\n source: string,\n loc: CodeFrameNodeLocation,\n options?: CodeFrameOptions,\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): string => {\n // grab 2 lines before, and 3 lines after focused line\n const config = {\n linesAbove: 2,\n linesBelow: 3,\n showGutter: true,\n showLineNumbers: true,\n tabWidth: 4,\n ...options,\n color: {\n gutter: (value: string) => value,\n marker: (value: string) => value,\n message: (value: string) => value,\n ...options?.color,\n },\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const hasColumns = loc.start && typeof loc.start.column === \"number\";\n\n let lines = normalizeLF(source).split(\"\\n\");\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (typeof config?.tabWidth === \"number\") {\n lines = lines.map((ln) => ln.replaceAll(\"\\t\", \" \".repeat(config.tabWidth as number)));\n }\n\n const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);\n\n const numberMaxWidth = String(end).length;\n const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;\n\n let frame = lines\n .slice(start, end)\n .map((line, index) => {\n const number = start + 1 + index;\n // eslint-disable-next-line security/detect-object-injection\n const hasMarker = markerLines[number];\n const paddedNumber = ` ${number}`.slice(-numberMaxWidth);\n const lastMarkerLine = !markerLines[number + 1];\n\n const gutter = ` ${paddedNumber}${config.showGutter ? ` |` : \"\"}`;\n\n if (hasMarker) {\n let markerLine = \"\";\n\n if (Array.isArray(hasMarker)) {\n const markerSpacing = line.replaceAll(/[^\\t]/g, \" \").slice(0, Math.max((hasMarker[0] as number) - 1, 0));\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n const numberOfMarkers = hasMarker[1] || 1;\n\n markerLine = [\"\\n \", colorizeGutter(gutter.replaceAll(/\\d/g, \" \")), \" \", markerSpacing, colorizeMarker(\"^\").repeat(numberOfMarkers)].join(\n \"\",\n );\n\n if (lastMarkerLine && config.message) {\n markerLine += ` ${colorizeMessage(config.message)}`;\n }\n }\n\n return [colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : \"\", markerLine].join(\"\");\n }\n\n return ` ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : \"\"}`;\n })\n .join(\"\\n\");\n\n if (config.message && !hasColumns) {\n frame = `${\" \".repeat(numberMaxWidth + 1)}${config.message}\\n${frame}`;\n }\n\n return frame;\n};\n\nexport type { CodeFrameLocation, CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod } from \"./types\";\n"]}
@@ -1,13 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { AnyMap } from '@jridgewell/trace-mapping';
3
- export { generatedPositionFor as b, originalPositionFor as c, sourceContentFor as d, traceSegment as e } from '@jridgewell/trace-mapping';
4
- import { dirname, resolve } from '@visulima/path';
5
-
6
- var l=/^data:application\/json[^,]+base64,/,f=/\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+)[ \t]*$|\/\*[@#][ \t]+sourceMappingURL=([^*]+?)[ \t]*\*\/[ \t]*$/,c=e=>l.test(e),m=(e,n)=>{let o=e.split(/\r?\n/),t=null;for(let r=o.length-1;r>=0&&!t;r--)t=f.exec(o[r]);if(t)return c(t[1])?t[1]:resolve(n,t[1])},M=e=>{let n=e.slice(e.indexOf(",")+1);return Buffer.from(n,"base64").toString()},y=e=>{let n;try{n=readFileSync(e,{encoding:"utf8"});}catch(r){throw r.message=`Error reading sourcemap for file "${e}":
7
- ${r.message}`,r}let o=m(n,dirname(e));if(!o)return;let t;if(c(o))t=M(o);else try{t=readFileSync(o,{encoding:"utf8"});}catch(r){throw r.message=`Error reading sourcemap for file "${e}":
8
- ${r.message}`,r}try{return new AnyMap(t,o)}catch(r){throw r.message=`Error parsing sourcemap for file "${e}":
9
- ${r.message}`,r}},p=y;
10
-
11
- export { p as a };
12
- //# sourceMappingURL=out.js.map
13
- //# sourceMappingURL=chunk-D22N6ARA.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/sourcemap/load-source-map.ts","../src/sourcemap/sourcemap.ts"],"names":["readFileSync","AnyMap","dirname","resolve","INLINE_SOURCEMAP_REGEX","SOURCEMAP_REGEX","isInlineMap","url","resolveSourceMapUrl","sourceFile","sourcePath","lines","sourceMapUrl","index","decodeInlineMap","data","rawData","loadSourceMap","filename","sourceMapContent","error","traceMapContent","load_source_map_default","generatedPositionFor","originalPositionFor","sourceContentFor","traceSegment"],"mappings":"AAAA,OAAS,gBAAAA,MAAoB,UAG7B,OAAS,UAAAC,MAAc,4BACvB,OAAS,WAAAC,EAAS,WAAAC,MAAe,iBAEjC,IAAMC,EAAyB,sCAEzBC,EAAkB,4GAElBC,EAAeC,GAAyBH,EAAuB,KAAKG,CAAG,EAEvEC,EAAsB,CAACC,EAAoBC,IAA2C,CACxF,IAAMC,EAAQF,EAAW,MAAM,OAAO,EAElCG,EAAe,KAGnB,QAASC,EAAQF,EAAM,OAAS,EAAGE,GAAS,GAAK,CAACD,EAAcC,IAE5DD,EAAeP,EAAgB,KAAKM,EAAME,CAAK,CAAW,EAG9D,GAAKD,EAIL,OAAON,EAAYM,EAAa,CAAC,CAAW,EAAKA,EAAa,CAAC,EAAgBT,EAAQO,EAAYE,EAAa,CAAC,CAAW,CAChI,EAEME,EAAmBC,GAAiB,CACtC,IAAMC,EAAUD,EAAK,MAAMA,EAAK,QAAQ,GAAG,EAAI,CAAC,EAEhD,OAAO,OAAO,KAAKC,EAAS,QAAQ,EAAE,SAAS,CACnD,EAEMC,EAAiBC,GAA2C,CAC9D,IAAIC,EAEJ,GAAI,CAEAA,EAAmBnB,EAAakB,EAAU,CAAE,SAAU,MAAO,CAAC,CAElE,OAASE,EAAY,CACjB,MAAAA,EAAM,QAAU,qCAAqCF,CAAQ;AAAA,EAAOE,EAAM,OAAO,GAE3EA,CACV,CAEA,IAAMR,EAAeJ,EAAoBW,EAAkBjB,EAAQgB,CAAQ,CAAC,EAE5E,GAAI,CAACN,EACD,OAGJ,IAAIS,EAGJ,GAAIf,EAAYM,CAAY,EACxBS,EAAkBP,EAAgBF,CAAY,MAE9C,IAAI,CAGAS,EAAkBrB,EAAaY,EAAc,CAAE,SAAU,MAAO,CAAC,CAErE,OAASQ,EAAY,CACjB,MAAAA,EAAM,QAAU,qCAAqCF,CAAQ;AAAA,EAAOE,EAAM,OAAO,GAE3EA,CACV,CAGJ,GAAI,CACA,OAAO,IAAInB,EAAOoB,EAAiBT,CAAY,CAEnD,OAASQ,EAAY,CACjB,MAAAA,EAAM,QAAU,qCAAqCF,CAAQ;AAAA,EAAOE,EAAM,OAAO,GAE3EA,CACV,CACJ,EAEOE,EAAQL,ECjFf,OAAS,wBAAAM,EAAsB,uBAAAC,EAAqB,oBAAAC,EAAkB,gBAAAC,MAAoB","sourcesContent":["import { readFileSync } from \"node:fs\";\n\nimport type { TraceMap } from \"@jridgewell/trace-mapping\";\nimport { AnyMap } from \"@jridgewell/trace-mapping\";\nimport { dirname, resolve } from \"@visulima/path\";\n\nconst INLINE_SOURCEMAP_REGEX = /^data:application\\/json[^,]+base64,/;\n// eslint-disable-next-line regexp/no-unused-capturing-group,regexp/no-super-linear-backtracking\nconst SOURCEMAP_REGEX = /\\/\\/[@#][ \\t]+sourceMappingURL=([^\\s'\"]+)[ \\t]*$|\\/\\*[@#][ \\t]+sourceMappingURL=([^*]+?)[ \\t]*\\*\\/[ \\t]*$/;\n\nconst isInlineMap = (url: string): boolean => INLINE_SOURCEMAP_REGEX.test(url);\n\nconst resolveSourceMapUrl = (sourceFile: string, sourcePath: string): string | undefined => {\n const lines = sourceFile.split(/\\r?\\n/);\n\n let sourceMapUrl = null;\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let index = lines.length - 1; index >= 0 && !sourceMapUrl; index--) {\n // eslint-disable-next-line security/detect-object-injection\n sourceMapUrl = SOURCEMAP_REGEX.exec(lines[index] as string);\n }\n\n if (!sourceMapUrl) {\n return undefined;\n }\n\n return isInlineMap(sourceMapUrl[1] as string) ? (sourceMapUrl[1] as string) : (resolve(sourcePath, sourceMapUrl[1] as string) as string);\n};\n\nconst decodeInlineMap = (data: string) => {\n const rawData = data.slice(data.indexOf(\",\") + 1);\n\n return Buffer.from(rawData, \"base64\").toString();\n};\n\nconst loadSourceMap = (filename: string): TraceMap | undefined => {\n let sourceMapContent: string | undefined;\n\n try {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n sourceMapContent = readFileSync(filename, { encoding: \"utf8\" });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n error.message = `Error reading sourcemap for file \"${filename}\":\\n${error.message}`;\n\n throw error;\n }\n\n const sourceMapUrl = resolveSourceMapUrl(sourceMapContent, dirname(filename));\n\n if (!sourceMapUrl) {\n return undefined;\n }\n\n let traceMapContent: string | undefined;\n\n // If it's an inline map, decode it and pass it through the same consumer factory\n if (isInlineMap(sourceMapUrl)) {\n traceMapContent = decodeInlineMap(sourceMapUrl);\n } else {\n try {\n // Load actual source map from given path\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n traceMapContent = readFileSync(sourceMapUrl, { encoding: \"utf8\" });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n error.message = `Error reading sourcemap for file \"${filename}\":\\n${error.message}`;\n\n throw error;\n }\n }\n\n try {\n return new AnyMap(traceMapContent, sourceMapUrl);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n error.message = `Error parsing sourcemap for file \"${filename}\":\\n${error.message}`;\n\n throw error;\n }\n};\n\nexport default loadSourceMap;\n","export { default as loadSourceMap } from \"./load-source-map\";\nexport type { TraceMap } from \"@jridgewell/trace-mapping\";\nexport { generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from \"@jridgewell/trace-mapping\";\n"]}
@@ -1,7 +0,0 @@
1
- import { inspect } from 'node:util';
2
-
3
- var m=i=>{let r=new Set,e=[],t=i;for(;t;){if(r.has(t)){console.error(`Circular reference detected in error causes: ${inspect(i)}`);break}if(e.push(t),r.add(t),!t.cause)break;t=t.cause;}return e},h=m;var d=i=>i instanceof Error&&i.type==="VisulimaError",s=class extends Error{loc;title;hint;type="VisulimaError";constructor(r,...e){super(...e);let{hint:t,location:c,message:o,name:u,stack:l,title:p}=r;this.title=p,this.name=u,o&&(this.message=o),this.stack=l??this.stack,this.loc=c,this.hint=t,Error.captureStackTrace(this,this.constructor);}setLocation(r){this.loc=r;}setName(r){this.name=r;}setMessage(r){this.message=r;}setHint(r){this.hint=r;}};
4
-
5
- export { h as a, d as b, s as c };
6
- //# sourceMappingURL=out.js.map
7
- //# sourceMappingURL=chunk-HAVTTG7L.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/error/get-error-causes.ts","../src/error/visulima-error.ts"],"names":["inspect","getErrorCauses","error","seen","causes","currentError","get_error_causes_default","isVisulimaError","VisulimaError","properties","parameters","hint","location","message","name","stack","title"],"mappings":"AAAA,OAAS,WAAAA,MAAe,YAQxB,IAAMC,EAAuDC,GAAkB,CAC3E,IAAMC,EAAO,IAAI,IACXC,EAAS,CAAC,EAGZC,EAAwBH,EAG5B,KAAOG,GAAc,CAEjB,GAAIF,EAAK,IAAIE,CAAY,EAAG,CAExB,QAAQ,MAAM,gDAAgDL,EAAQE,CAAK,CAAC,EAAE,EAE9E,KACJ,CAKA,GAHAE,EAAO,KAAKC,CAAY,EACxBF,EAAK,IAAIE,CAAY,EAEjB,CAACA,EAAa,MACd,MAGJA,EAAeA,EAAa,KAChC,CAEA,OAAOD,CACX,EAEOE,EAAQL,ECpCR,IAAMM,EAAmBL,GAA2CA,aAAiB,OAAUA,EAAwB,OAAS,gBAE1HM,EAAN,cAA4B,KAAM,CAC9B,IAEA,MAKA,KAEA,KAAO,gBAGP,YAAYC,KAAgCC,EAAiB,CAEhE,MAAM,GAAGA,CAAU,EAEnB,GAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,KAAAC,EAAM,MAAAC,EAAO,MAAAC,CAAM,EAAIP,EACxD,KAAK,MAAQO,EACb,KAAK,KAAOF,EAERD,IACA,KAAK,QAAUA,GAInB,KAAK,MAAQE,GAAU,KAAK,MAC5B,KAAK,IAAMH,EACX,KAAK,KAAOD,EAEZ,MAAM,kBAAkB,KAAM,KAAK,WAAW,CAClD,CAEO,YAAYC,EAA+B,CAC9C,KAAK,IAAMA,CACf,CAEO,QAAQE,EAAoB,CAC/B,KAAK,KAAOA,CAChB,CAEO,WAAWD,EAAuB,CACrC,KAAK,QAAUA,CACnB,CAEO,QAAQF,EAAuB,CAClC,KAAK,KAAOA,CAChB,CACJ","sourcesContent":["import { inspect } from \"node:util\";\n\nimport type { VisulimaError } from \"./visulima-error\";\n\n/**\n * Will return an array of all causes in the error in the order they occurred.\n */\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\nconst getErrorCauses = <E = Error | VisulimaError | unknown>(error: E): E[] => {\n const seen = new Set();\n const causes = [];\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-redundant-type-constituents\n let currentError: E | any = error;\n\n // eslint-disable-next-line no-loops/no-loops\n while (currentError) {\n // Check for circular reference\n if (seen.has(currentError)) {\n // eslint-disable-next-line no-console\n console.error(`Circular reference detected in error causes: ${inspect(error)}`);\n\n break;\n }\n\n causes.push(currentError);\n seen.add(currentError);\n\n if (!currentError.cause) {\n break;\n }\n\n currentError = currentError.cause;\n }\n\n return causes as E[];\n};\n\nexport default getErrorCauses;\n","import type { ErrorHint, ErrorLocation, ErrorProperties } from \"./types\";\n\nexport const isVisulimaError = (error: unknown): error is VisulimaError => error instanceof Error && (error as VisulimaError).type === \"VisulimaError\";\n\nexport class VisulimaError extends Error {\n public loc: ErrorLocation | undefined;\n\n public title: string | undefined;\n\n /**\n * A message that explains to the user how they can fix the error.\n */\n public hint: ErrorHint | undefined;\n\n public type = \"VisulimaError\";\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any\n public constructor(properties: ErrorProperties, ...parameters: any) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n super(...parameters);\n\n const { hint, location, message, name, stack, title } = properties;\n this.title = title;\n this.name = name;\n\n if (message) {\n this.message = message;\n }\n\n // Only set this if we actually have a stack passed, otherwise uses Error's\n this.stack = stack ?? (this.stack as string);\n this.loc = location;\n this.hint = hint;\n\n Error.captureStackTrace(this, this.constructor);\n }\n\n public setLocation(location: ErrorLocation): void {\n this.loc = location;\n }\n\n public setName(name: string): void {\n this.name = name;\n }\n\n public setMessage(message: string): void {\n this.message = message;\n }\n\n public setHint(hint: ErrorHint): void {\n this.hint = hint;\n }\n}\n"]}
@@ -1,6 +0,0 @@
1
- var o=(s,...e)=>{process.env.DEBUG&&String(process.env.DEBUG)==="true"&&console.debug(`error:parse-stacktrace: ${s}`,...e);},f="<unknown>",y=/^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,T=/\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/,v=/(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/,$=/^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/,N=/in\s(.*)\s\(at\s(.+)\)\sat/,x=/^(?:.*@)?(.*):(\d+):(\d+)$/,b=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i,O=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,R=/(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/,l=/\(error: (.*)\)/,p=(s,e)=>{let n=s.includes("safari-extension"),t=s.includes("safari-web-extension");return n||t?[s.includes("@")?s.split("@")[0]:f,n?`safari-extension:${e}`:`safari-web-extension:${e}`]:[s,e]},m=(s,e)=>{let n=v.exec(e);n&&(s.file=n[1],s.line=+n[2],s.column=+n[3]);},S=s=>{let e=N.exec(s);if(e){o(`parse nested node error stack line: "${s}"`,`found: ${JSON.stringify(e)}`);let t=e[2].split(":");return {column:t[2]?+t[2]:void 0,file:t[0],line:t[1]?+t[1]:void 0,methodName:e[1]||f,raw:s,type:void 0}}let n=$.exec(s);if(n){o(`parse node error stack line: "${s}"`,`found: ${JSON.stringify(n)}`);let t={column:n[4]?+n[4]:void 0,file:n[2]?n[2].replace(/at\s/,""):void 0,line:n[3]?+n[3]:void 0,methodName:n[1]||f,raw:s,type:s.startsWith("internal")?"internal":void 0};return m(t,`${n[2]}:${n[3]}:${n[4]}`),t}},_=s=>{let e=y.exec(s);if(e){o(`parse chrome error stack line: "${s}"`,`found: ${JSON.stringify(e)}`);let n=e[2]&&e[2].startsWith("native"),t=e[2]&&e[2].startsWith("eval")||e[1]&&e[1].startsWith("eval"),r;if(t){let i=T.exec(s);if(i){let c=/(\S+):(\d+):(\d+)|(\S+):(\d+)$/.exec(i[1]);c?(e[2]=c[4]??c[1],e[3]=c[5]??c[2],e[4]=c[3]):i[2]&&(e[2]=i[1]),i[2]&&(r={column:i[4]?+i[4]:void 0,file:i[2],line:i[3]?+i[3]:void 0,methodName:"eval",raw:s,type:"eval"});}}let[a,u]=p(e[1]?e[1].replace(/^Anonymous function$/,"<anonymous>"):f,e[2]),d={column:e[4]?+e[4]:void 0,evalOrigin:r,file:u,line:e[3]?+e[3]:void 0,methodName:a,raw:s,type:t?"eval":n?"native":void 0};return m(d,`${u}:${e[3]}:${e[4]}`),d}},h=(s,e)=>{let n=b.exec(s);if(n){o(`parse gecko error stack line: "${s}"`,`found: ${JSON.stringify(n)}`);let t=n[3]?.includes(" > eval"),r=t&&n[3]&&O.exec(n[3]),a;t&&r&&(n[3]=r[1],a={column:n[5]?+n[5]:void 0,file:n[3],line:n[4]?+n[4]:void 0,methodName:"eval",raw:s,type:"eval"},n[4]=r[2]);let[u,d]=p(n[1]?n[1].replace(/^Anonymous function$/,"<anonymous>"):f,n[3]),i;(e?.type==="safari"||!t&&e?.type==="firefox")&&e.column?i=e.column:!t&&n[5]&&(i=+n[5]);let c;return (e?.type==="safari"||!t&&e?.type==="firefox")&&e.line?c=e.line:n[4]&&(c=+n[4]),{column:i,evalOrigin:a,file:d,line:c,methodName:u,raw:s,type:t?"eval":d.includes("[native code]")?"native":void 0}}},G=(s,e)=>{let n=R.exec(s);if(!(n?n[2].includes(" > eval"):!1)&&n)return o(`parse firefox error stack line: "${s}"`,`found: ${JSON.stringify(n)}`),{column:n[4]?+n[4]:e?.column??void 0,file:n[2],line:n[3]?+n[3]:e?.line??void 0,methodName:n[1]||f,raw:s,type:void 0}},w=s=>{let e=x.exec(s);if(e)return o(`parse react android native error stack line: "${s}"`,`found: ${JSON.stringify(e)}`),{column:e[3]?+e[3]:void 0,file:e[1],line:e[2]?+e[2]:void 0,methodName:f,raw:s,type:void 0}},k=(s,e={})=>{let{frameLimit:n=50}=e,t=(s.stacktrace??s.stack??"").split(`
2
- `).map(r=>(l.test(r)?r.replace(l,"$1"):r).replace(/^\s+|\s+$/g,"")).filter(r=>!/\S*Error: /.test(r)&&r!=="eval code");return t.length>n&&(t=t.slice(0,n)),t.reduce((r,a,u)=>{if(!a||a.length>1024)return r;let d;if(/^\s*in\s.*/.test(a))d=S(a);else if(/^.*?\s*at\s.*/.test(a))d=_(a);else if(/^.*?\s*@.*|\[native code\]/.test(a)){let i;u===0&&(s.columnNumber||s.lineNumber?i={column:s.columnNumber,line:s.lineNumber,type:"firefox"}:(s.line||s.column)&&(i={column:s.column,line:s.line,type:"safari"})),d=G(a,i)||h(a,i);}else d=w(a);return d?r.push(d):o(`parse error stack line: "${a}"`,"not parser found"),r},[])},A=k;
3
-
4
- export { A as a };
5
- //# sourceMappingURL=out.js.map
6
- //# sourceMappingURL=chunk-ZMWUTAJM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/stacktrace/parse-stacktrace.ts"],"names":["debugLog","message","arguments_","UNKNOWN_FUNCTION","CHROMIUM_REGEX","CHROMIUM_EVAL_REGEX","CHROMIUM_MAPPED","NODE_REGEX","NODE_NESTED_REGEX","REACT_ANDROID_NATIVE_REGEX","GECKO_REGEX","GECKO_EVAL_REGEX","FIREFOX_REGEX","WEBPACK_ERROR_REGEXP","extractSafariExtensionDetails","methodName","url","isSafariExtension","isSafariWebExtension","parseMapped","trace","maybeMapped","match","parseNode","line","nestedNode","split","node","parseChromium","parts","isNative","isEval","evalOrigin","subMatch","file","parseGecko","topFrameMeta","column","lineNumber","parseFirefox","parseReactAndroidNative","parse","error","options","frameLimit","lines","stack","currentIndex","parseResult","parse_stacktrace_default"],"mappings":"AAQA,IAAMA,EAAW,CAACC,KAAoBC,IAAgC,CAC9D,QAAQ,IAAI,OAAS,OAAO,QAAQ,IAAI,KAAK,IAAM,QAEnD,QAAQ,MAAM,2BAA2BD,CAAO,GAAI,GAAGC,CAAU,CAEzE,EAEMC,EAA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,CAAI,IAAK,kBAAkB,EAG7DsB,CACX,EAAG,CAAC,CAAC,CACT,EAEOG,EAAQR","sourcesContent":["import type { Trace, TraceType } from \"./types\";\n\ntype TopFrameMeta = {\n column?: number;\n line?: number;\n type: \"firefox\" | \"safari\";\n};\n\nconst debugLog = (message: string, ...arguments_: unknown[]): void => {\n if (process.env.DEBUG && String(process.env.DEBUG) === \"true\") {\n // eslint-disable-next-line no-console\n console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);\n }\n};\n\nconst UNKNOWN_FUNCTION = \"<unknown>\";\n\n// at <SomeFramework>\n// at <SomeFramework>:123:39\n// -----------------\n// at about:blank:1:7\n// at index.js:23\n// >= Chrome 99\n// at /projects/foo.test.js:689:1 <- /projects/foo.test.js:10:1\n// -----------------\n// at bar (<anonymous>:1:19 <- <anonymous>:2:3)\n// -----------------\n// at foo.bar(bob) (foo.bar.js:123:39)\n// at foo.bar(bob) (foo.bar.js:123:39 <- original.js:123:34)\n// -----------------\n// >= Chrome 88\n// spy() at Component.Foo [as constructor] (original.js:123:34)\n// spy() at Component.Foo [as constructor] (foo.bar.js:123:39 <- original.js:123:34)\n// -----------------\n// at Module.load (internal/modules/cjs/loader.js:641:32)\n// -----------------\n// Chromium based browsers: Chrome, Brave, new Opera, new Edge\nconst CHROMIUM_REGEX =\n // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-super-linear-backtracking\n /^.*?\\s*at\\s(?:(.+?\\)(?:\\s\\[.+\\])?|\\(?.*?)\\s?\\((?:address\\sat\\s)?)?(?:async\\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\\/)?.*?)(?::(\\d+))?(?::(\\d+))?\\)?\\s*$/i;\n// eslint-disable-next-line security/detect-unsafe-regex\nconst CHROMIUM_EVAL_REGEX = /\\((\\S+)\\),\\s(<[^>]+>)?:(\\d+)?:(\\d+)?\\)?/;\n// foo.bar.js:123:39\n// foo.bar.js:123:39 <- original.js:123:34\n// eslint-disable-next-line security/detect-unsafe-regex,regexp/no-unused-capturing-group\nconst CHROMIUM_MAPPED = /(.*?):(\\d+):(\\d+)(\\s<-\\s(.+):(\\d+):(\\d+))?/;\n\n// in AppProviders (at App.tsx:28)\n// eslint-disable-next-line security/detect-unsafe-regex\nconst NODE_REGEX = /^\\s*in\\s(?:([^\\\\/]+(?:\\s\\[as\\s\\S+\\])?)\\s\\(?)?\\(at?\\s?(.*?):(\\d+)(?::(\\d+))?\\)?\\s*$/;\nconst NODE_NESTED_REGEX = /in\\s(.*)\\s\\(at\\s(.+)\\)\\sat/;\n\n// eslint-disable-next-line security/detect-unsafe-regex,regexp/no-super-linear-backtracking\nconst REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\\d+):(\\d+)$/;\n\n// gecko regex: `(?:bundle|\\d+\\.js)`: `bundle` is for react native, `\\d+\\.js` also but specifically for ram bundles because it\n// generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js\n// We need this specific case for now because we want no other regex to match.\n// eslint-disable-next-line regexp/no-super-linear-backtracking,security/detect-unsafe-regex,regexp/no-optional-assertion,regexp/no-trivially-nested-quantifier,regexp/no-useless-escape,no-useless-escape,regexp/optimal-quantifier-concatenation\nconst GECKO_REGEX = /^\\s*(.*?)(?:\\((.*?)\\))?(?:^|@)?((?:[-a-z]+)?:\\/.*?|\\[native code\\]|[^@]*(?:bundle|\\d+\\.js)|\\/[\\w\\-. \\/=]+)(?::(\\d+))?(?::(\\d+))?\\s*$/i;\n// eslint-disable-next-line security/detect-unsafe-regex\nconst GECKO_EVAL_REGEX = /(\\S+) line (\\d+)(?: > eval line \\d+)* > eval/i;\n\n// @http://localhost:8080/file.js:33:9\n// foo@debugger eval code:1:27\n// obj[\"@fn\"]@Scratchpad/1:10:29\n// eslint-disable-next-line regexp/no-super-linear-backtracking\nconst FIREFOX_REGEX = /(\\S[^\\s[]*\\[.*\\]|.*?)@(.*):(\\d+):(\\d+)/;\n\n// Used to sanitize webpack (error: *) wrapped stack errors\nconst WEBPACK_ERROR_REGEXP = /\\(error: (.*)\\)/;\n\n/**\n * Safari web extensions, starting version unknown, can produce \"frames-only\" stacktraces.\n * What it means, is that instead of format like:\n *\n * Error: wat\n * at function@url:row:col\n * at function@url:row:col\n * at function@url:row:col\n *\n * it produces something like:\n *\n * function@url:row:col\n * function@url:row:col\n * function@url:row:col\n *\n * Because of that, it won't be captured by `chrome` RegExp and will fall into `Gecko` branch.\n * This function is extracted so that we can use it in both places without duplicating the logic.\n * Unfortunately \"just\" changing RegExp is too complicated now and making it pass all tests\n * and fix this case seems like an impossible, or at least way too time-consuming task.\n */\nconst extractSafariExtensionDetails = (methodName: string, url: string): [string, string] => {\n const isSafariExtension = methodName.includes(\"safari-extension\");\n const isSafariWebExtension = methodName.includes(\"safari-web-extension\");\n\n return isSafariExtension || isSafariWebExtension\n ? [\n methodName.includes(\"@\") ? (methodName.split(\"@\")[0] as string) : UNKNOWN_FUNCTION,\n isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`,\n ]\n : [methodName, url];\n};\n\nconst parseMapped = (trace: Trace, maybeMapped: string) => {\n const match = CHROMIUM_MAPPED.exec(maybeMapped);\n\n if (match) {\n // eslint-disable-next-line no-param-reassign,prefer-destructuring\n trace.file = match[1];\n // eslint-disable-next-line no-param-reassign\n trace.line = +(<string>match[2]);\n // eslint-disable-next-line no-param-reassign\n trace.column = +(<string>match[3]);\n }\n};\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst parseNode = (line: string): Trace | undefined => {\n const nestedNode = NODE_NESTED_REGEX.exec(line);\n\n if (nestedNode) {\n debugLog(`parse nested node error stack line: \"${line}\"`, `found: ${JSON.stringify(nestedNode)}`);\n\n const split = (nestedNode[2] as string).split(\":\");\n\n return {\n column: split[2] ? +split[2] : undefined,\n file: split[0],\n line: split[1] ? +split[1] : undefined,\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n methodName: nestedNode[1] || UNKNOWN_FUNCTION,\n raw: line,\n type: undefined,\n };\n }\n\n const node = NODE_REGEX.exec(line);\n\n if (node) {\n debugLog(`parse node error stack line: \"${line}\"`, `found: ${JSON.stringify(node)}`);\n\n const trace = {\n column: node[4] ? +node[4] : undefined,\n file: node[2] ? node[2].replace(/at\\s/, \"\") : undefined,\n line: node[3] ? +node[3] : undefined,\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n methodName: node[1] || UNKNOWN_FUNCTION,\n raw: line,\n type: line.startsWith(\"internal\") ? (\"internal\" as TraceType) : undefined,\n };\n\n parseMapped(trace, `${node[2]}:${node[3]}:${node[4]}`);\n\n return trace;\n }\n\n return undefined;\n};\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst parseChromium = (line: string): Trace | undefined => {\n const parts = CHROMIUM_REGEX.exec(line) as (string | undefined)[] | null;\n\n if (parts) {\n debugLog(`parse chrome error stack line: \"${line}\"`, `found: ${JSON.stringify(parts)}`);\n\n const isNative = parts[2] && parts[2].startsWith(\"native\"); // start of line\n const isEval = (parts[2] && parts[2].startsWith(\"eval\")) || (parts[1] && parts[1].startsWith(\"eval\")); // start of line\n\n let evalOrigin: Trace | undefined;\n\n if (isEval) {\n const subMatch = CHROMIUM_EVAL_REGEX.exec(line);\n\n if (subMatch) {\n // can be index.js:123:39 or index.js:123 or index.js\n const split = /(\\S+):(\\d+):(\\d+)|(\\S+):(\\d+)$/.exec(subMatch[1] as string);\n\n if (split) {\n // throw out eval line/column and use top-most line/column number\n parts[2] = split[4] ?? split[1]; // url\n parts[3] = split[5] ?? split[2]; // line\n // eslint-disable-next-line prefer-destructuring\n parts[4] = split[3]; // column\n } else if (subMatch[2]) {\n // eslint-disable-next-line prefer-destructuring\n parts[2] = subMatch[1];\n }\n\n if (subMatch[2]) {\n evalOrigin = {\n column: subMatch[4] ? +subMatch[4] : undefined,\n file: subMatch[2],\n line: subMatch[3] ? +subMatch[3] : undefined,\n methodName: \"eval\",\n raw: line,\n type: \"eval\" as TraceType,\n };\n }\n }\n }\n\n const [methodName, file] = extractSafariExtensionDetails(\n // Normalize IE's 'Anonymous function'\n parts[1] ? parts[1].replace(/^Anonymous function$/, \"<anonymous>\") : UNKNOWN_FUNCTION,\n parts[2] as string,\n );\n\n const trace = {\n column: parts[4] ? +parts[4] : undefined,\n evalOrigin,\n file,\n line: parts[3] ? +parts[3] : undefined,\n // Normalize IE's 'Anonymous function'\n methodName,\n raw: line,\n type: (isEval ? \"eval\" : isNative ? \"native\" : undefined) as TraceType,\n };\n\n parseMapped(trace, `${file}:${parts[3]}:${parts[4]}`);\n\n return trace;\n }\n\n return undefined;\n};\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst parseGecko = (line: string, topFrameMeta?: TopFrameMeta): Trace | undefined => {\n const parts = GECKO_REGEX.exec(line);\n\n if (parts) {\n debugLog(`parse gecko error stack line: \"${line}\"`, `found: ${JSON.stringify(parts)}`);\n\n const isEval = parts[3]?.includes(\" > eval\");\n const subMatch = isEval && parts[3] && GECKO_EVAL_REGEX.exec(parts[3]);\n\n let evalOrigin: Trace | undefined;\n\n if (isEval && subMatch) {\n // overwrite file\n parts[3] = <string>subMatch[1];\n\n evalOrigin = {\n column: parts[5] ? +parts[5] : undefined,\n file: parts[3],\n line: parts[4] ? +parts[4] : undefined,\n methodName: \"eval\",\n raw: line,\n type: \"eval\" as TraceType,\n };\n\n // overwrite line\n parts[4] = <string>subMatch[2];\n }\n\n const [methodName, file] = extractSafariExtensionDetails(\n // Normalize IE's 'Anonymous function'\n parts[1] ? parts[1].replace(/^Anonymous function$/, \"<anonymous>\") : UNKNOWN_FUNCTION,\n parts[3] as string,\n );\n\n let column: number | undefined; // no column when eval\n\n if ((topFrameMeta?.type === \"safari\" || (!isEval && topFrameMeta?.type === \"firefox\")) && topFrameMeta.column) {\n column = topFrameMeta.column;\n } else if (!isEval && parts[5]) {\n column = +parts[5];\n }\n\n let lineNumber: number | undefined; // no line when eval\n\n if ((topFrameMeta?.type === \"safari\" || (!isEval && topFrameMeta?.type === \"firefox\")) && topFrameMeta.line) {\n lineNumber = topFrameMeta.line;\n } else if (parts[4]) {\n lineNumber = +parts[4];\n }\n\n return {\n column,\n evalOrigin,\n file,\n line: lineNumber,\n methodName,\n raw: line,\n type: isEval ? \"eval\" : file.includes(\"[native code]\") ? \"native\" : undefined,\n };\n }\n\n return undefined;\n};\n\nconst parseFirefox = (line: string, topFrameMeta?: TopFrameMeta): Trace | undefined => {\n const parts = FIREFOX_REGEX.exec(line);\n\n const isEval = parts ? (parts[2] as string).includes(\" > eval\") : false;\n\n if (!isEval && parts) {\n debugLog(`parse firefox error stack line: \"${line}\"`, `found: ${JSON.stringify(parts)}`);\n\n return {\n column: parts[4] ? +parts[4] : topFrameMeta?.column ?? undefined,\n file: parts[2],\n line: parts[3] ? +parts[3] : topFrameMeta?.line ?? undefined,\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n methodName: parts[1] || UNKNOWN_FUNCTION,\n raw: line,\n type: undefined,\n };\n }\n\n return undefined;\n};\n\nconst parseReactAndroidNative = (line: string): Trace | undefined => {\n const parts = REACT_ANDROID_NATIVE_REGEX.exec(line);\n\n if (parts) {\n debugLog(`parse react android native error stack line: \"${line}\"`, `found: ${JSON.stringify(parts)}`);\n\n return {\n column: parts[3] ? +parts[3] : undefined,\n file: parts[1],\n line: parts[2] ? +parts[2] : undefined,\n methodName: UNKNOWN_FUNCTION,\n raw: line,\n type: undefined,\n };\n }\n\n return undefined;\n};\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst parse = (error: Error, options: Partial<{ frameLimit: number }> = {}): Trace[] => {\n const { frameLimit = 50 } = options;\n\n // @ts-expect-error missing stacktrace property\n let lines = (error.stacktrace ?? error.stack ?? \"\")\n .split(\"\\n\")\n .map((line: string): string => {\n // https://github.com/getsentry/sentry-javascript/issues/5459\n // Remove webpack (error: *) wrappers\n const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, \"$1\") : line;\n\n // eslint-disable-next-line unicorn/prefer-string-replace-all\n return cleanedLine.replace(/^\\s+|\\s+$/g, \"\");\n })\n // https://github.com/getsentry/sentry-javascript/issues/7813\n // Skip Error: lines\n // Skip eval code without more context\n .filter((line: string): boolean => !/\\S*Error: /.test(line) && line !== \"eval code\");\n\n if (lines.length > frameLimit) {\n lines = lines.slice(0, frameLimit);\n }\n\n // eslint-disable-next-line unicorn/no-array-reduce,@typescript-eslint/no-unsafe-return\n return lines.reduce((stack: Trace[], line: string, currentIndex: number): Trace[] => {\n if (!line) {\n return stack;\n }\n\n // Ignore lines over 1kb as they are unlikely to be stack frames.\n // Many of the regular expressions use backtracking which results in run time that increases exponentially with\n // input size. Huge strings can result in hangs/Denial of Service:\n // https://github.com/getsentry/sentry-javascript/issues/2286\n if (line.length > 1024) {\n return stack;\n }\n\n let parseResult: Trace | undefined;\n\n if (/^\\s*in\\s.*/.test(line)) {\n parseResult = parseNode(line);\n // eslint-disable-next-line regexp/no-super-linear-backtracking\n } else if (/^.*?\\s*at\\s.*/.test(line)) {\n parseResult = parseChromium(line);\n // eslint-disable-next-line regexp/no-super-linear-backtracking\n } else if (/^.*?\\s*@.*|\\[native code\\]/.test(line)) {\n let topFrameMeta: TopFrameMeta | undefined;\n\n if (currentIndex === 0) {\n // @ts-expect-error columnNumber and lineNumber property only exists on Firefox\n if (error.columnNumber || error.lineNumber) {\n topFrameMeta = {\n // @ts-expect-error columnNumber and columnNumber property only exists on Firefox\n column: error.columnNumber,\n // @ts-expect-error columnNumber and lineNumber property only exists on Firefox\n line: error.lineNumber,\n type: \"firefox\",\n };\n // @ts-expect-error line and column property only exists on safari\n } else if (error.line || error.column) {\n topFrameMeta = {\n // @ts-expect-error column property only exists on safari\n column: error.column,\n // @ts-expect-error line property only exists on safari\n line: error.line,\n type: \"safari\",\n };\n }\n }\n\n parseResult =\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);\n } else {\n parseResult = parseReactAndroidNative(line);\n }\n\n if (parseResult) {\n stack.push(parseResult);\n } else {\n debugLog(`parse error stack line: \"${line}\"`, \"not parser found\");\n }\n\n return stack;\n }, []);\n};\n\nexport default parse;\n"]}
@@ -1,3 +0,0 @@
1
- export { a as CODE_FRAME_POINTER, b as codeFrame } from '../chunk-BKLPSU5H.js';
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- export { c as VisulimaError, a as getErrorCauses, b as isVisulimaError } from '../chunk-HAVTTG7L.js';
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
package/dist/index.js DELETED
@@ -1,10 +0,0 @@
1
- export { a as CODE_FRAME_POINTER, b as codeFrame } from './chunk-BKLPSU5H.js';
2
- export { c as VisulimaError, a as getErrorCauses, b as isVisulimaError } from './chunk-HAVTTG7L.js';
3
- export { b as generatedPositionFor, a as loadSourceMap, c as originalPositionFor, d as sourceContentFor, e as traceSegment } from './chunk-D22N6ARA.js';
4
- export { a as parseStacktrace } from './chunk-ZMWUTAJM.js';
5
-
6
- var m=(r,e)=>{let o=0,t=e.length-2;for(;o<t;){let n=o+(t-o>>1);if(r<e[n])t=n-1;else if(r>=e[n+1])o=n+1;else {o=n;break}}return o},E=r=>r.split(/\n|\r(?!\n)/).reduce((e,o)=>(e.push(e.at(-1)+o.length+1),e),[0]),x=(r,e,o)=>{let t=o?.skipChecks??!1;if(!t&&(!Array.isArray(r)&&typeof r!="string"||(typeof r=="string"||Array.isArray(r))&&r.length===0))return {column:0,line:0};if(!t&&(typeof e!="number"||typeof r=="string"&&e>=r.length||Array.isArray(r)&&e+1>=r.at(-1)))return {column:0,line:0};if(typeof r=="string"){let s=E(r),a=m(e,s);return {column:e-s[a]+1,line:a+1}}let n=m(e,r);return {column:e-r[n]+1,line:n+1}},F=x;
7
-
8
- export { F as indexToLineColumn };
9
- //# sourceMappingURL=out.js.map
10
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/code-frame/index-to-line-column.ts"],"names":["binarySearch","element","array","m","n","key","getLineStartIndexes","string_","accumulator","current","indexToLineColumn","input","index","options","skipChecks","startIndexesOfEachLine","line","index_to_line_column_default"],"mappings":"iNAAA,IAAMA,EAAe,CAACC,EAAiBC,IAA4B,CAC/D,IAAIC,EAAI,EACJC,EAAIF,EAAM,OAAS,EAGvB,KAAOC,EAAIC,GAAG,CAEV,IAAMC,EAAMF,GAAMC,EAAID,GAAM,GAE5B,GAAIF,EAAWC,EAAMG,CAAG,EACpBD,EAAIC,EAAM,UACHJ,GAAYC,EAAMG,EAAM,CAAC,EAChCF,EAAIE,EAAM,MACP,CACHF,EAAIE,EACJ,KACJ,CACJ,CAEA,OAAOF,CACX,EAIMG,EAAuBC,GAEzBA,EAAQ,MAAM,aAAa,EAAE,OACzB,CAACC,EAAuBC,KACpBD,EAAY,KAAMA,EAAY,GAAG,EAAE,EAAeC,EAAQ,OAAS,CAAC,EAE7DD,GAEX,CAAC,CAAC,CACN,EAEEE,EAAoB,CACtBC,EACAC,EACAC,IAMC,CACD,IAAMC,EAAaD,GAAS,YAAc,GAE1C,GAAI,CAACC,IAAgB,CAAC,MAAM,QAAQH,CAAK,GAAK,OAAOA,GAAU,WAAe,OAAOA,GAAU,UAAY,MAAM,QAAQA,CAAK,IAAMA,EAAM,SAAW,GACjJ,MAAO,CAAE,OAAQ,EAAG,KAAM,CAAE,EAGhC,GACI,CAACG,IACA,OAAOF,GAAU,UAAa,OAAOD,GAAU,UAAYC,GAASD,EAAM,QAAY,MAAM,QAAQA,CAAK,GAAKC,EAAQ,GAAMD,EAAM,GAAG,EAAE,GAExI,MAAO,CAAE,OAAQ,EAAG,KAAM,CAAE,EAIhC,GAAI,OAAOA,GAAU,SAAU,CAE3B,IAAMI,EAAyBT,EAAoBK,CAAK,EAClDK,EAAOhB,EAAaY,EAAOG,CAAsB,EAEvD,MAAO,CAEH,OAAQH,EAASG,EAAuBC,CAAI,EAAe,EAC3D,KAAMA,EAAO,CACjB,CACJ,CAGA,IAAMA,EAAOhB,EAAaY,EAAOD,CAAK,EAEtC,MAAO,CAEH,OAAQC,EAASD,EAAMK,CAAI,EAAe,EAC1C,KAAMA,EAAO,CACjB,CACJ,EAEOC,EAAQP","sourcesContent":["const binarySearch = (element: number, array: number[]): number => {\n let m = 0;\n let n = array.length - 2;\n\n // eslint-disable-next-line no-loops/no-loops\n while (m < n) {\n // eslint-disable-next-line no-bitwise\n const key = m + ((n - m) >> 1);\n // eslint-disable-next-line security/detect-object-injection\n if (element < (array[key] as number)) {\n n = key - 1;\n } else if (element >= (array[key + 1] as number)) {\n m = key + 1;\n } else {\n m = key;\n break;\n }\n }\n\n return m;\n};\n\n// split by line break characters, CR, LF or CRLF\n// compile an array of indexes, where each line starts\nconst getLineStartIndexes = (string_: string): number[] =>\n // eslint-disable-next-line unicorn/no-array-reduce\n string_.split(/\\n|\\r(?!\\n)/).reduce(\n (accumulator: number[], current) => {\n accumulator.push((accumulator.at(-1) as number) + current.length + 1);\n\n return accumulator;\n },\n [0],\n );\n\nconst indexToLineColumn = (\n input: number[] | string,\n index: number,\n options?: {\n skipChecks: boolean;\n },\n): {\n column: number;\n line: number;\n} => {\n const skipChecks = options?.skipChecks ?? false;\n\n if (!skipChecks && ((!Array.isArray(input) && typeof input !== \"string\") || ((typeof input === \"string\" || Array.isArray(input)) && input.length === 0))) {\n return { column: 0, line: 0 };\n }\n\n if (\n !skipChecks &&\n (typeof index !== \"number\" || (typeof input === \"string\" && index >= input.length) || (Array.isArray(input) && index + 1 >= (input.at(-1) as number)))\n ) {\n return { column: 0, line: 0 };\n }\n\n // it depends, pre-cached input was given or a string\n if (typeof input === \"string\") {\n // not cached - calculate the line start indexes\n const startIndexesOfEachLine = getLineStartIndexes(input);\n const line = binarySearch(index, startIndexesOfEachLine);\n\n return {\n // eslint-disable-next-line security/detect-object-injection\n column: index - (startIndexesOfEachLine[line] as number) + 1,\n line: line + 1,\n };\n }\n\n // ELSE - cached line start indexes - we don't even need the string source!\n const line = binarySearch(index, input);\n\n return {\n // eslint-disable-next-line security/detect-object-injection\n column: index - (input[line] as number) + 1,\n line: line + 1,\n };\n};\n\nexport default indexToLineColumn;\n"]}
@@ -1,6 +0,0 @@
1
- import { TraceMap } from '@jridgewell/trace-mapping';
2
- export { TraceMap, generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from '@jridgewell/trace-mapping';
3
-
4
- declare const loadSourceMap: (filename: string) => TraceMap | undefined;
5
-
6
- export { loadSourceMap };
@@ -1,3 +0,0 @@
1
- export { b as generatedPositionFor, a as loadSourceMap, c as originalPositionFor, d as sourceContentFor, e as traceSegment } from '../chunk-D22N6ARA.js';
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- export { a as parseStacktrace } from '../chunk-ZMWUTAJM.js';
2
- //# sourceMappingURL=out.js.map
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}