@visulima/error 3.1.0 → 3.1.1
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.
- package/CHANGELOG.md +7 -0
- package/dist/chunk-CCMH6IHO.js +10 -0
- package/dist/chunk-CCMH6IHO.js.map +1 -0
- package/dist/code-frame/index.d.ts +2 -1
- package/dist/code-frame/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-EGCQFTZA.js +0 -10
- package/dist/chunk-EGCQFTZA.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## @visulima/error [3.1.1](https://github.com/visulima/visulima/compare/@visulima/error@3.1.0...@visulima/error@3.1.1) (2024-03-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **error:** fixed color option override ([467f1dc](https://github.com/visulima/visulima/commit/467f1dc979b6d4bca102589d330be083fd44e43e))
|
|
7
|
+
|
|
1
8
|
## @visulima/error [3.1.0](https://github.com/visulima/visulima/compare/@visulima/error@3.0.7...@visulima/error@3.1.0) (2024-03-09)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -0,0 +1,10 @@
|
|
|
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-CCMH6IHO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,GAAIA,KAAYH,EAEZ,OAAOA,EAAaG,CAAQ,CAIpC,CACJ,CAAC,EAEMC,EAAQH,ECVf,IAAMI,EAAiB,CACnBC,EACAC,EACAC,EACAC,IAMC,CACD,IAAMC,EAA8B,CAChC,OAAQ,EAER,KAAM,GACN,GAAGJ,EAAI,KACX,EACMK,EAA4B,CAC9B,GAAGD,EACH,GAAGJ,EAAI,GACX,EACMM,EAAYF,EAAS,KACrBG,EAAcH,EAAS,OACvBI,EAAUH,EAAO,KACjBI,EAAYJ,EAAO,OAErBK,EAAQ,KAAK,IAAIJ,GAAaJ,EAAa,GAAI,CAAC,EAChDS,EAAM,KAAK,IAAIV,EAAO,OAAQO,EAAUL,CAAU,EAElDG,IAAc,KACdI,EAAQ,GAGRF,IAAY,KACZG,EAAMV,EAAO,QAGjB,IAAMW,EAAWJ,EAAUF,EACrBO,EAA2B,CAAC,EAElC,GAAID,EAEA,QAASE,EAAQ,EAAGA,GAASF,EAAUE,IAAS,CAC5C,IAAMC,EAAaD,EAAQR,EAE3B,GAAI,CAACC,EAEDM,EAAYE,CAAU,EAAI,WACnBD,IAAU,EAAG,CACpB,IAAME,EAAef,EAAOc,EAAa,CAA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alizeLF;\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"]}
|
|
@@ -21,6 +21,7 @@ type CodeFrameOptions = {
|
|
|
21
21
|
tabWidth?: number | false;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
declare const CODE_FRAME_POINTER: string;
|
|
24
25
|
declare const codeFrame: (source: string, loc: CodeFrameNodeLocation, options?: CodeFrameOptions) => string;
|
|
25
26
|
|
|
26
|
-
export { type CodeFrameLocation, type CodeFrameNodeLocation, type CodeFrameOptions, type ColorizeMethod, codeFrame };
|
|
27
|
+
export { CODE_FRAME_POINTER, type CodeFrameLocation, type CodeFrameNodeLocation, type CodeFrameOptions, type ColorizeMethod, codeFrame };
|
package/dist/code-frame/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CodeFrameLocation, CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod, codeFrame } from './code-frame/index.js';
|
|
1
|
+
export { CODE_FRAME_POINTER, CodeFrameLocation, CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod, codeFrame } from './code-frame/index.js';
|
|
2
2
|
export { ErrorHint, ErrorLocation, ErrorProperties, VisulimaError, getErrorCauses, isVisulimaError } from './error/index.js';
|
|
3
3
|
export { loadSourceMap } from './sourcemap/index.js';
|
|
4
4
|
export { TraceMap, generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from '@jridgewell/trace-mapping';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as codeFrame } from './chunk-
|
|
1
|
+
export { a as CODE_FRAME_POINTER, b as codeFrame } from './chunk-CCMH6IHO.js';
|
|
2
2
|
export { c as VisulimaError, a as getErrorCauses, b as isVisulimaError } from './chunk-HAVTTG7L.js';
|
|
3
3
|
export { b as generatedPositionFor, a as loadSourceMap, c as originalPositionFor, d as sourceContentFor, e as traceSegment } from './chunk-7G4U7I4C.js';
|
|
4
4
|
export { a as parseStacktrace } from './chunk-57YC2IM6.js';
|
package/package.json
CHANGED
package/dist/chunk-EGCQFTZA.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
var A=s=>s.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
|
|
2
|
-
`),x=A;var O=globalThis.process||Object.create(null),y={versions:{}},v=new Proxy(O,{get(s,r){if(r in s)return s[r];if(r in y)return y[r]}}),F=v;var S=(s,r,h,t)=>{let g={column:0,line:-1,...s.start},m={...g,...s.end},i=g.line,n=g.column,l=m.line,d=m.column,u=Math.max(i-(h+1),0),f=Math.min(r.length,l+t);i===-1&&(u=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 c=r[a-1]?.length;o[a]=[n,(c??0)-n+1];}else if(e===p)o[a]=[0,d];else {let c=r[a-e]?.length;o[a]=[0,c];}}else n===d?o[i]=n?[n,0]:!0:o[i]=[n,(d??0)-(n??0)];return {end:f,markerLines:o,start:u}},$=S;var W=F.platform==="win32"&&!F.env?.WT_SESSION?">":"\u276F",q=(s,r,h)=>{let t={color:{gutter:e=>e,marker:e=>e,message:e=>e,...h?.color},linesAbove:2,linesBelow:3,showGutter:!0,showLineNumbers:!0,tabWidth:4,...h},g=r.start&&typeof r.start.column=="number",m=x(s).split(`
|
|
3
|
-
`);typeof t?.tabWidth=="number"&&(m=m.map(e=>e.replaceAll(" "," ".repeat(t.tabWidth))));let{end:i,markerLines:n,start:l}=$(r,m,t.linesAbove,t.linesBelow),d=String(i).length,{gutter:u,marker:f,message:p}=t.color,o=m.slice(l,i).map((e,a)=>{let c=l+1+a,L=n[c],z=` ${c}`.slice(-d),N=!n[c+1],b=` ${z}${t.showGutter?" |":""}`;if(L){let C="";if(Array.isArray(L)){let P=e.replaceAll(/[^\t]/g," ").slice(0,Math.max(L[0]-1,0)),w=L[1]||1;C=[`
|
|
4
|
-
`,u(b.replaceAll(/\d/g," "))," ",P,f("^").repeat(w)].join(""),N&&t.message&&(C+=` ${p(t.message)}`);}return [f(W),u(b),e.length>0?` ${e}`:"",C].join("")}return ` ${u(b)}${e.length>0?` ${e}`:""}`}).join(`
|
|
5
|
-
`);return t.message&&!g&&(o=`${" ".repeat(d+1)}${t.message}
|
|
6
|
-
${o}`),o};
|
|
7
|
-
|
|
8
|
-
export { q as a };
|
|
9
|
-
//# sourceMappingURL=out.js.map
|
|
10
|
-
//# sourceMappingURL=chunk-EGCQFTZA.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","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,GAAIA,KAAYH,EAEZ,OAAOA,EAAaG,CAAQ,CAIpC,CACJ,CAAC,EAEMC,EAAQH,ECVf,IAAMI,EAAiB,CACnBC,EACAC,EACAC,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G,EAAE,OAAOW,CAAe,CAAC,EAAE,KACjI,EACJ,EAEIJ,GAAkBd,EAAO,UACzBgB,GAAc,IAAIR,EAAgBR,EAAO,OAAO,CAAC,GAEzD,CAEA,MAAO,CAACO,EAAeV,CAAO,EAAGS,EAAeS,CAAM,EAAGL,EAAK,OAAS,EAAI,IAAIA,CAAI,GAAK,GAAIM,CAAU,EAAE,KAAK,EAAE,CACnH,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, ColorizeMethod } from \"./types\";\n\nconst 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 color: {\n gutter: (value: string) => value,\n marker: (value: string) => value,\n message: (value: string) => value,\n ...options?.color,\n },\n linesAbove: 2,\n linesBelow: 3,\n showGutter: true,\n showLineNumbers: true,\n tabWidth: 4,\n ...options,\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\n const {\n gutter: colorizeGutter,\n marker: colorizeMarker,\n message: colorizeMessage,\n } = config.color as {\n gutter: ColorizeMethod;\n marker: ColorizeMethod;\n message: ColorizeMethod;\n };\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(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"]}
|