@remotex-labs/xmap 3.0.5 → 4.0.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.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/components/parser.component.ts"],
4
- "sourceRoot": "https://github.com/remotex-lab/xmap/tree/v3.0.5/",
5
- "sourcesContent": ["/**\n * Export interfaces\n */\n\nexport type * from '@components/interfaces/parse-component.interface';\n\n/**\n * Import will remove at compile time\n */\n\nimport type { ParsedStackTrace, StackFrame } from '@components/interfaces/parse-component.interface';\n\n/**\n * Regular expression patterns for different JavaScript engines' stack traces\n *\n * @since 2.1.0\n */\n\nconst PATTERNS = {\n V8: {\n GLOBAL: /at\\s(.*):(\\d+):(\\d+)/,\n STANDARD: /at\\s(.*?)\\((?:(.+?):(\\d+):(\\d+)|(native))\\)/,\n EVAL: /^at\\s(.+?)\\s\\(eval\\sat\\s(.+?)\\s?\\((.*):(\\d+):(\\d+)\\),\\s(.+?):(\\d+):(\\d+)\\)$/\n },\n SPIDERMONKEY: {\n EVAL: /^(.*)@(.+?):(\\d+):(\\d+),\\s(.+?)@(.+?):(\\d+):(\\d+)$/,\n STANDARD: /^(.*)@(.*?)(?:(\\[native code\\])|:(\\d+):(\\d+))$/\n },\n JAVASCRIPT_CORE: {\n STANDARD: /^(?:(global|eval)\\s)?(.*)@(.*?)(?::(\\d+)(?::(\\d+))?)?$/\n }\n};\n\n/**\n * Enumeration of JavaScript engines that can be detected from stack traces\n *\n * @since 2.1.0\n */\n\nexport const enum JSEngines {\n V8,\n SPIDERMONKEY,\n JAVASCRIPT_CORE,\n UNKNOWN\n}\n\n/**\n * Detects the JavaScript engine based on the format of a stack trace line\n *\n * @param stack - The stack trace to analyze\n * @returns The identified JavaScript engine type\n *\n * @example\n * ```ts\n * const engine = detectJSEngine(\"at functionName (/path/to/file.js:10:15)\");\n * if (engine === JSEngines.V8) {\n * // Handle V8 specific logic\n * }\n * ```\n *\n * @since 2.1.0\n */\n\nexport function detectJSEngine(stack: string): JSEngines {\n if (stack.startsWith(' at ') || stack.startsWith('at '))\n return JSEngines.V8;\n\n if (stack.includes('@'))\n return /(?:global|eval) code@/.test(stack)\n ? JSEngines.JAVASCRIPT_CORE : JSEngines.SPIDERMONKEY;\n\n return JSEngines.UNKNOWN;\n}\n\n/**\n * Normalizes file paths from various formats to a standard format\n *\n * @param filePath - The file path to normalize, which may include protocol prefixes\n * @returns A normalized file path with consistent separators and without protocol prefixes\n *\n * @remarks\n * Handles both Windows and Unix-style paths, as well as file:// protocol URLs.\n * Converts all backslashes to forward slashes for consistency.\n *\n * @example\n * ```ts\n * // Windows file URL to a normal path\n * normalizePath(\"file:///C:/path/to/file.js\"); // \"C:/path/to/file.js\"\n *\n * // Unix file URL to a normal path\n * normalizePath(\"file:///path/to/file.js\"); // \"/path/to/file.js\"\n *\n * // Windows backslashes to forward slashes\n * normalizePath(\"C:\\\\path\\\\to\\\\file.js\"); // \"C:/path/to/file.js\"\n * ```\n *\n * @since 2.1.0\n */\n\nexport function normalizePath(filePath: string): string {\n // Handle file:// protocol URLs\n if (filePath.startsWith('file://')) {\n // Handle Windows file:/// format\n if (filePath.startsWith('file:///') && /^file:\\/\\/\\/[A-Za-z]:/.test(filePath)) {\n // Windows absolute path: file:///C:/path/to/file.js\n return filePath.substring(8);\n }\n\n // Handle *nix file:// format\n return filePath.substring(7);\n }\n\n // Handle Windows-style paths with backward slashes\n filePath = filePath.replace(/\\\\/g, '/');\n\n return filePath;\n}\n\n/**\n * Creates a default stack frame object with initial values\n *\n * @param source - The original source line from the stack trace\n * @returns A new StackFrame object with default null values\n *\n * @see ParsedStackTrace\n * @see StackFrame\n *\n * @since 2.1.0\n */\n\nexport function createDefaultFrame(source: string): StackFrame {\n return {\n source,\n eval: false,\n async: false,\n native: false,\n constructor: false\n };\n}\n\n/**\n * Safely parses a string value to an integer, handling undefined and null cases\n *\n * @param value - The string value to parse\n * @returns The parsed integer or null if the input is undefined/null\n *\n * @example\n * ```ts\n * safeParseInt(\"42\"); // 42\n * safeParseInt(undefined); // null\n * safeParseInt(null); // null\n * ```\n *\n * @since 2.1.0\n */\n\nexport function safeParseInt(value: string | undefined | null): number | undefined {\n return value && value.trim() !== '' ? parseInt(value, 10) : undefined;\n}\n\n/**\n * Parses a V8 JavaScript engine stack trace line into a structured StackFrame object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Handles both standard V8 stack frames and eval-generated stack frames which\n * have a more complex structure with nested origin information.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseV8StackLine(\"at functionName (/path/to/file.js:10:15)\");\n *\n * // Eval frame\n * parseV8StackLine(\"at eval (eval at evalFn (/source.js:5:10), <anonymous>:1:5)\");\n * ```\n *\n * @throws Error - If the line format doesn't match any known V8 pattern\n *\n * @see StackFrame\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\n\nexport function parseV8StackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n\n // Common flags that apply to all formats\n if (line.toLowerCase().includes('new')) frame.constructor = true;\n if (line.toLowerCase().includes('async')) frame.async = true;\n\n // Try to match against each pattern\n const evalMatch = line.match(PATTERNS.V8.EVAL);\n const globalMatch = line.match(PATTERNS.V8.GLOBAL);\n const standardMatch = !evalMatch && line.match(PATTERNS.V8.STANDARD);\n\n if (evalMatch) {\n // Handle eval format\n frame.eval = true;\n frame.functionName = evalMatch[1] || undefined;\n\n // Add eval origin information\n frame.evalOrigin = {\n line: safeParseInt(evalMatch[4]) ?? undefined,\n column: safeParseInt(evalMatch[5]) ?? undefined,\n fileName: evalMatch[3] ? normalizePath(evalMatch[3]) : undefined,\n functionName: evalMatch[2] || '<anonymous>'\n };\n\n // Position inside evaluated code\n frame.line = safeParseInt(evalMatch[7]) ?? undefined;\n frame.column = safeParseInt(evalMatch[8]) ?? undefined;\n frame.fileName = evalMatch[6] ? normalizePath(evalMatch[6]) : undefined;\n } else if (standardMatch) {\n // Handle standard format\n frame.functionName = standardMatch[1] ? standardMatch[1].trim() : undefined;\n\n if (standardMatch[5] === 'native') {\n frame.native = true;\n frame.fileName = '[native code]';\n } else {\n frame.line = safeParseInt(standardMatch[3]) ?? undefined;\n frame.column = safeParseInt(standardMatch[4]) ?? undefined;\n frame.fileName = standardMatch[2] ? normalizePath(standardMatch[2]) : undefined;\n if(frame.fileName?.includes('node:')) frame.native = true;\n }\n } else if (globalMatch) {\n frame.fileName = globalMatch[1] ? normalizePath(globalMatch[1]) : undefined;\n frame.line = safeParseInt(globalMatch[2]) ?? undefined;\n frame.column = safeParseInt(globalMatch[3]) ?? undefined;\n }\n\n return frame;\n}\n\n/**\n * Parses a SpiderMonkey JavaScript engine stack trace line into a structured StackFrame object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Handles both standard SpiderMonkey stack frames and eval/Function-generated stack frames\n * which contain additional evaluation context information.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseSpiderMonkeyStackLine(\"functionName@/path/to/file.js:10:15\");\n *\n * // Eval frame\n * parseSpiderMonkeyStackLine(\"evalFn@/source.js line 5 > eval:1:5\");\n * ```\n *\n * @see StackFrame\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\n\nexport function parseSpiderMonkeyStackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n\n // Check for eval/Function format\n const evalMatch = line.match(PATTERNS.SPIDERMONKEY.EVAL);\n if (evalMatch) {\n frame.eval = true;\n frame.functionName = evalMatch[1] ? evalMatch[1] : undefined;\n\n if (line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n\n if (line.toLowerCase().includes('async'))\n frame.async = true;\n\n // Add eval origin information\n frame.evalOrigin = {\n line: safeParseInt(evalMatch[7]) ?? undefined,\n column: safeParseInt(evalMatch[8]) ?? undefined,\n fileName: normalizePath(evalMatch[6]),\n functionName: evalMatch[5] ? evalMatch[5] : undefined\n };\n\n // Position inside evaluated code\n frame.line = safeParseInt(evalMatch[3]) ?? undefined;\n frame.column = safeParseInt(evalMatch[4]) ?? undefined;\n\n return frame;\n }\n\n // Standard SpiderMonkey format\n const match = line.match(PATTERNS.SPIDERMONKEY.STANDARD);\n if (match) {\n frame.functionName = match[1] ? match[1] : undefined;\n frame.fileName = normalizePath(match[2]);\n\n if (match[3] === '[native code]') {\n frame.fileName = '[native code]';\n } else {\n frame.line = safeParseInt(match[4]) ?? undefined;\n frame.column = safeParseInt(match[5]) ?? undefined;\n }\n }\n\n return frame;\n}\n\n/**\n * Parses a JavaScriptCore engine stack trace line into a structured StackFrame object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Handles both standard JavaScriptCore stack frames and eval-generated stack frames.\n * Special handling is provided for \"global code\" references and native code.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseJavaScriptCoreStackLine(\"functionName@/path/to/file.js:10:15\");\n *\n * // Eval frame\n * parseJavaScriptCoreStackLine(\"eval code@\");\n * ```\n *\n * @see StackFrame\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\n\nexport function parseJavaScriptCoreStackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n\n // Standard JavaScriptCore format\n const match = line.match(PATTERNS.JAVASCRIPT_CORE.STANDARD);\n if (match) {\n frame.functionName = match[2];\n frame.eval = (match[1] === 'eval' || match[3] === 'eval');\n\n if (line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n\n if (line.toLowerCase().includes('async'))\n frame.async = true;\n\n if (match[3] === '[native code]') {\n frame.native = true;\n frame.fileName = '[native code]';\n } else {\n frame.line = safeParseInt(match[4]) ?? undefined;\n frame.column = safeParseInt(match[5]) ?? undefined;\n frame.fileName = normalizePath(match[3]);\n }\n }\n\n return frame;\n}\n\n/**\n * Parses a stack trace line based on the detected JavaScript engine\n *\n * @param line - The stack trace line to parse\n * @param engine - The JavaScript engine type that generated the stack trace\n * @returns A StackFrame object containing the parsed information\n *\n * @remarks\n * Delegates to the appropriate parsing function based on the JavaScript engine.\n * Defaults to V8 parsing if the engine is unknown.\n *\n * @example\n * ```ts\n * const engine = detectJSEngine(stackLine);\n * const frame = parseStackLine(stackLine, engine);\n * ```\n *\n * @see JSEngines\n * @see parseV8StackLine\n * @see parseSpiderMonkeyStackLine\n * @see parseJavaScriptCoreStackLine\n *\n * @since 2.1.0\n */\n\nexport function parseStackLine(line: string, engine: JSEngines): StackFrame {\n switch (engine) {\n case JSEngines.SPIDERMONKEY:\n return parseSpiderMonkeyStackLine(line);\n case JSEngines.JAVASCRIPT_CORE:\n return parseJavaScriptCoreStackLine(line);\n case JSEngines.V8:\n default:\n return parseV8StackLine(line);\n }\n}\n\n/**\n * Parses a complete error stack trace into a structured format\n *\n * @param error - Error object or error message string to parse\n * @returns A ParsedStackTrace object containing structured stack trace information\n *\n * @remarks\n * Automatically detects the JavaScript engine from the stack format.\n * Filters out redundant information like the error name/message line.\n * Handles both Error objects and string error messages.\n *\n * @example\n * ```ts\n * try {\n * throw new Error (\"Something went wrong\");\n * } catch (error) {\n * const parsedStack = parseErrorStack(error);\n * console.log(parsedStack.name); // \"Error\"\n * console.log(parsedStack.message); // \"Something went wrong\"\n * console.log(parsedStack.stack); // Array of StackFrame objects\n * }\n * ```\n *\n * @see ParsedStackTrace\n * @see StackFrame\n * @see parseStackLine\n * @see detectJSEngine\n *\n * @since 2.1.0\n */\n\nexport function parseErrorStack(error: Error | string): ParsedStackTrace {\n const errorObj = typeof error === 'string' ? new Error(error) : error;\n const stack = errorObj.stack || '';\n const message = errorObj.message || '';\n const name = errorObj.name || 'Error';\n\n const engine = detectJSEngine(stack);\n const stackLines = stack.split('\\n')\n .map(line => line.trim())\n .filter(line => line.trim() !== '')\n .slice(1);\n\n return {\n name,\n message,\n stack: stackLines.map(line => parseStackLine(line, engine)),\n rawStack: stack\n };\n}\n"],
6
- "mappings": "AAkBA,IAAMA,EAAW,CACb,GAAI,CACA,OAAQ,uBACR,SAAU,8CACV,KA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AAcS,EAA+B,CACxE,OAAQA,EAAQ,CACZ,IAAK,GACD,OAAOJ,EAA2BL,CAAI,EAC1C,IAAK,GACD,OAAOO,EAA6BP,CAAI,EAC5C,IAAK,GACL,QACI,OAAOD,EAAiBC,CAAI,CACpC,CACJ,CAiCO,SAASU,EAAgBC,EAAyC,CACrE,IAAMC,EAAW,OAAOD,GAAU,SAAW,IAAI,MAAMA,CAAK,EAAIA,EAC1DnB,EAAQoB,EAAS,OAAS,GAC1BC,EAAUD,EAAS,SAAW,GAC9BE,EAAOF,EAAS,MAAQ,QAExBH,EAASlB,EAAeC,CAAK,EAC7BuB,EAAavB,EAAM,MAAM;AAAA,CAAI,EAC9B,IAAIQ,GAAQA,EAAK,KAAK,CAAC,EACvB,OAAOA,GAAQA,EAAK,KAAK,IAAM,EAAE,EACjC,MAAM,CAAC,EAEZ,MAAO,CACH,KAAAc,EACA,QAAAD,EACA,MAAOE,EAAW,IAAIf,GAAQQ,EAAeR,EAAMS,CAAM,CAAC,EAC1D,SAAUjB,CACd,CACJ",
4
+ "sourceRoot": "https://github.com/remotex-lab/xmap/tree/v4.0.0/",
5
+ "sourcesContent": ["/**\n * Export interfaces\n */\n\nexport type * from '@components/interfaces/parse-component.interface';\n\n/**\n * Import will remove at compile time\n */\n\nimport type { ParsedStackTraceInterface, StackFrameInterface } from '@components/interfaces/parse-component.interface';\n\n/**\n * Regular expression patterns for different JavaScript engines' stack traces\n *\n * @since 2.1.0\n */\n\nconst PATTERNS = {\n V8: {\n GLOBAL: /at\\s(.*):(\\d+):(\\d+)/,\n STANDARD: /at\\s(.*?)\\((?:(.+?):(\\d+):(\\d+)|(native))\\)/,\n EVAL: /^at\\s(.+?)\\s\\(eval\\sat\\s(.+?)\\s?\\((.*):(\\d+):(\\d+)\\),\\s(.+?):(\\d+):(\\d+)\\)$/\n },\n SPIDERMONKEY: {\n EVAL: /^(.*)@(.+?):(\\d+):(\\d+),\\s(.+?)@(.+?):(\\d+):(\\d+)$/,\n STANDARD: /^(.*)@(.*?)(?:(\\[native code\\])|:(\\d+):(\\d+))$/\n },\n JAVASCRIPT_CORE: {\n STANDARD: /^(?:(global|eval)\\s)?(.*)@(.*?)(?::(\\d+)(?::(\\d+))?)?$/\n }\n};\n\n/**\n * Enumeration of JavaScript engines that can be detected from stack traces\n *\n * @since 2.1.0\n */\n\nexport const enum JSEngines {\n V8,\n SPIDERMONKEY,\n JAVASCRIPT_CORE,\n UNKNOWN\n}\n\n/**\n * Detects the JavaScript engine based on the format of a stack trace line\n *\n * @param stack - The stack trace to analyze\n * @returns The identified JavaScript engine type\n *\n * @example\n * ```ts\n * const engine = detectJSEngine(\"at functionName (/path/to/file.js:10:15)\");\n * if (engine === JSEngines.V8) {\n * // Handle V8 specific logic\n * }\n * ```\n *\n * @since 2.1.0\n */\n\nexport function detectJSEngine(stack: string): JSEngines {\n if (stack.startsWith(' at ') || stack.startsWith('at '))\n return JSEngines.V8;\n\n if (stack.includes('@'))\n return /(?:global|eval) code@/.test(stack)\n ? JSEngines.JAVASCRIPT_CORE : JSEngines.SPIDERMONKEY;\n\n return JSEngines.UNKNOWN;\n}\n\n/**\n * Normalizes file paths from various formats to a standard format\n *\n * @param filePath - The file path to normalize, which may include protocol prefixes\n * @returns A normalized file path with consistent separators and without protocol prefixes\n *\n * @remarks\n * Handles both Windows and Unix-style paths, as well as file:// protocol URLs.\n * Converts all backslashes to forward slashes for consistency.\n *\n * @example\n * ```ts\n * // Windows file URL to a normal path\n * normalizePath(\"file:///C:/path/to/file.js\"); // \"C:/path/to/file.js\"\n *\n * // Unix file URL to a normal path\n * normalizePath(\"file:///path/to/file.js\"); // \"/path/to/file.js\"\n *\n * // Windows backslashes to forward slashes\n * normalizePath(\"C:\\\\path\\\\to\\\\file.js\"); // \"C:/path/to/file.js\"\n * ```\n *\n * @since 2.1.0\n */\n\nexport function normalizePath(filePath: string): string {\n // Handle file:// protocol URLs\n if (filePath.startsWith('file://')) {\n // Handle Windows file:/// format\n if (filePath.startsWith('file:///') && /^file:\\/\\/\\/[A-Za-z]:/.test(filePath)) {\n // Windows absolute path: file:///C:/path/to/file.js\n return filePath.substring(8);\n }\n\n // Handle *nix file:// format\n return filePath.substring(7);\n }\n\n // Handle Windows-style paths with backward slashes\n filePath = filePath.replace(/\\\\/g, '/');\n\n return filePath;\n}\n\n/**\n * Creates a default stack frame object with initial values\n *\n * @param source - The original source line from the stack trace\n * @returns A new StackFrameInterface object with default null values\n *\n * @see ParsedStackTraceInterface\n * @see StackFrameInterface\n *\n * @since 2.1.0\n */\n\nexport function createDefaultFrame(source: string): StackFrameInterface {\n return {\n source,\n eval: false,\n async: false,\n native: false,\n constructor: false\n };\n}\n\n/**\n * Safely parses a string value to an integer, handling undefined and null cases\n *\n * @param value - The string value to parse\n * @returns The parsed integer or null if the input is undefined/null\n *\n * @example\n * ```ts\n * safeParseInt(\"42\"); // 42\n * safeParseInt(undefined); // null\n * safeParseInt(null); // null\n * ```\n *\n * @since 2.1.0\n */\n\nexport function safeParseInt(value: string | undefined | null): number | undefined {\n return value && value.trim() !== '' ? parseInt(value, 10) : undefined;\n}\n\n/**\n * Parses a V8 JavaScript engine stack trace line into a structured StackFrameInterface object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrameInterface object containing the parsed information\n *\n * @remarks\n * Handles both standard V8 stack frames and eval-generated stack frames which\n * have a more complex structure with nested origin information.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseV8StackLine(\"at functionName (/path/to/file.js:10:15)\");\n *\n * // Eval frame\n * parseV8StackLine(\"at eval (eval at evalFn (/source.js:5:10), <anonymous>:1:5)\");\n * ```\n *\n * @throws Error - If the line format doesn't match any known V8 pattern\n *\n * @see StackFrameInterface\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\n\nexport function parseV8StackLine(line: string): StackFrameInterface {\n const frame = createDefaultFrame(line);\n\n // Common flags that apply to all formats\n if (line.toLowerCase().includes('new')) frame.constructor = true;\n if (line.toLowerCase().includes('async')) frame.async = true;\n\n // Try to match against each pattern\n const evalMatch = line.match(PATTERNS.V8.EVAL);\n const globalMatch = line.match(PATTERNS.V8.GLOBAL);\n const standardMatch = !evalMatch && line.match(PATTERNS.V8.STANDARD);\n\n if (evalMatch) {\n // Handle eval format\n frame.eval = true;\n frame.functionName = evalMatch[1] || undefined;\n\n // Add eval origin information\n frame.evalOrigin = {\n line: safeParseInt(evalMatch[4]) ?? undefined,\n column: safeParseInt(evalMatch[5]) ?? undefined,\n fileName: evalMatch[3] ? normalizePath(evalMatch[3]) : undefined,\n functionName: evalMatch[2] || '<anonymous>'\n };\n\n // Position inside evaluated code\n frame.line = safeParseInt(evalMatch[7]) ?? undefined;\n frame.column = safeParseInt(evalMatch[8]) ?? undefined;\n frame.fileName = evalMatch[6] ? normalizePath(evalMatch[6]) : undefined;\n } else if (standardMatch) {\n // Handle standard format\n frame.functionName = standardMatch[1] ? standardMatch[1].trim() : undefined;\n\n if (standardMatch[5] === 'native') {\n frame.native = true;\n frame.fileName = '[native code]';\n } else {\n frame.line = safeParseInt(standardMatch[3]) ?? undefined;\n frame.column = safeParseInt(standardMatch[4]) ?? undefined;\n frame.fileName = standardMatch[2] ? normalizePath(standardMatch[2]) : undefined;\n if(frame.fileName?.includes('node:')) frame.native = true;\n }\n } else if (globalMatch) {\n frame.fileName = globalMatch[1] ? normalizePath(globalMatch[1]) : undefined;\n frame.line = safeParseInt(globalMatch[2]) ?? undefined;\n frame.column = safeParseInt(globalMatch[3]) ?? undefined;\n }\n\n return frame;\n}\n\n/**\n * Parses a SpiderMonkey JavaScript engine stack trace line into a structured StackFrameInterface object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrameInterface object containing the parsed information\n *\n * @remarks\n * Handles both standard SpiderMonkey stack frames and eval/Function-generated stack frames\n * which contain additional evaluation context information.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseSpiderMonkeyStackLine(\"functionName@/path/to/file.js:10:15\");\n *\n * // Eval frame\n * parseSpiderMonkeyStackLine(\"evalFn@/source.js line 5 > eval:1:5\");\n * ```\n *\n * @see StackFrameInterface\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\n\nexport function parseSpiderMonkeyStackLine(line: string): StackFrameInterface {\n const frame = createDefaultFrame(line);\n\n // Check for eval/Function format\n const evalMatch = line.match(PATTERNS.SPIDERMONKEY.EVAL);\n if (evalMatch) {\n frame.eval = true;\n frame.functionName = evalMatch[1] ? evalMatch[1] : undefined;\n\n if (line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n\n if (line.toLowerCase().includes('async'))\n frame.async = true;\n\n // Add eval origin information\n frame.evalOrigin = {\n line: safeParseInt(evalMatch[7]) ?? undefined,\n column: safeParseInt(evalMatch[8]) ?? undefined,\n fileName: normalizePath(evalMatch[6]),\n functionName: evalMatch[5] ? evalMatch[5] : undefined\n };\n\n // Position inside evaluated code\n frame.line = safeParseInt(evalMatch[3]) ?? undefined;\n frame.column = safeParseInt(evalMatch[4]) ?? undefined;\n\n return frame;\n }\n\n // Standard SpiderMonkey format\n const match = line.match(PATTERNS.SPIDERMONKEY.STANDARD);\n if (match) {\n frame.functionName = match[1] ? match[1] : undefined;\n frame.fileName = normalizePath(match[2]);\n\n if (match[3] === '[native code]') {\n frame.fileName = '[native code]';\n } else {\n frame.line = safeParseInt(match[4]) ?? undefined;\n frame.column = safeParseInt(match[5]) ?? undefined;\n }\n }\n\n return frame;\n}\n\n/**\n * Parses a JavaScriptCore engine stack trace line into a structured StackFrameInterface object\n *\n * @param line - The stack trace line to parse\n * @returns A StackFrameInterface object containing the parsed information\n *\n * @remarks\n * Handles both standard JavaScriptCore stack frames and eval-generated stack frames.\n * Special handling is provided for \"global code\" references and native code.\n *\n * @example\n * ```ts\n * // Standard frame\n * parseJavaScriptCoreStackLine(\"functionName@/path/to/file.js:10:15\");\n *\n * // Eval frame\n * parseJavaScriptCoreStackLine(\"eval code@\");\n * ```\n *\n * @see StackFrameInterface\n * @see createDefaultFrame\n *\n * @since 2.1.0\n */\n\nexport function parseJavaScriptCoreStackLine(line: string): StackFrameInterface {\n const frame = createDefaultFrame(line);\n\n // Standard JavaScriptCore format\n const match = line.match(PATTERNS.JAVASCRIPT_CORE.STANDARD);\n if (match) {\n frame.functionName = match[2];\n frame.eval = (match[1] === 'eval' || match[3] === 'eval');\n\n if (line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n\n if (line.toLowerCase().includes('async'))\n frame.async = true;\n\n if (match[3] === '[native code]') {\n frame.native = true;\n frame.fileName = '[native code]';\n } else {\n frame.line = safeParseInt(match[4]) ?? undefined;\n frame.column = safeParseInt(match[5]) ?? undefined;\n frame.fileName = normalizePath(match[3]);\n }\n }\n\n return frame;\n}\n\n/**\n * Parses a stack trace line based on the detected JavaScript engine\n *\n * @param line - The stack trace line to parse\n * @param engine - The JavaScript engine type that generated the stack trace\n * @returns A StackFrameInterface object containing the parsed information\n *\n * @remarks\n * Delegates to the appropriate parsing function based on the JavaScript engine.\n * Defaults to V8 parsing if the engine is unknown.\n *\n * @example\n * ```ts\n * const engine = detectJSEngine(stackLine);\n * const frame = parseStackLine(stackLine, engine);\n * ```\n *\n * @see JSEngines\n * @see parseV8StackLine\n * @see parseSpiderMonkeyStackLine\n * @see parseJavaScriptCoreStackLine\n *\n * @since 2.1.0\n */\n\nexport function parseStackLine(line: string, engine: JSEngines): StackFrameInterface {\n switch (engine) {\n case JSEngines.SPIDERMONKEY:\n return parseSpiderMonkeyStackLine(line);\n case JSEngines.JAVASCRIPT_CORE:\n return parseJavaScriptCoreStackLine(line);\n case JSEngines.V8:\n default:\n return parseV8StackLine(line);\n }\n}\n\n/**\n * Parses a complete error stack trace into a structured format\n *\n * @param error - Error object or error message string to parse\n * @returns A ParsedStackTraceInterface object containing structured stack trace information\n *\n * @remarks\n * Automatically detects the JavaScript engine from the stack format.\n * Filters out redundant information like the error name/message line.\n * Handles both Error objects and string error messages.\n *\n * @example\n * ```ts\n * try {\n * throw new Error (\"Something went wrong\");\n * } catch (error) {\n * const parsedStack = parseErrorStack(error);\n * console.log(parsedStack.name); // \"Error\"\n * console.log(parsedStack.message); // \"Something went wrong\"\n * console.log(parsedStack.stack); // Array of StackFrameInterface objects\n * }\n * ```\n *\n * @see ParsedStackTraceInterface\n * @see StackFrameInterface\n * @see parseStackLine\n * @see detectJSEngine\n *\n * @since 2.1.0\n */\n\nexport function parseErrorStack(error: Error | string): ParsedStackTraceInterface {\n const errorObj = typeof error === 'string' ? new Error(error) : error;\n const stack = errorObj.stack || '';\n const message = errorObj.message || '';\n const name = errorObj.name || 'Error';\n\n const engine = detectJSEngine(stack);\n const stackLines = stack.split('\\n')\n .map(line => line.trim())\n .filter(line => line.trim() !== '')\n .slice(1);\n\n return {\n name,\n message,\n stack: stackLines.map(line => parseStackLine(line, engine)),\n rawStack: stack\n };\n}\n"],
6
+ "mappings": "AAkBA,IAAMA,EAAW,CACb,GAAI,CACA,OAAQ,uBACR,SAAU,8CACV,KAAM,6EACV,EACA,aAAc,CACV,KAAM,qDACN,SAAU,gDACd,EACA,gBAAiB,CACb,SAAU,wDACd,CACJ,EAQkBC,OACdA,IAAA,WACAA,IAAA,+BACAA,IAAA,qCACAA,IAAA,qBAJcA,OAAA,IAwBX,SAASC,EAAeC,EAA0B,CACrD,OAAIA,EAAM,WAAW,SAAS,GAAKA,EAAM,WAAW,KAAK,EAC9C,EAEPA,EAAM,SAAS,GAAG,EACX,wBAAwB,KAAKA,CAAK,EACnC,EAA4B,EAE/B,CACX,CA2BO,SAASC,EAAcC,EAA0B,CAEpD,OAAIA,EAAS,WAAW,SAAS,EAEzBA,EAAS,WAAW,UAAU,GAAK,wBAAwB,KAAKA,CAAQ,EAEjEA,EAAS,UAAU,CAAC,EAIxBA,EAAS,UAAU,CAAC,GAI/BA,EAAWA,EAAS,QAAQ,MAAO,GAAG,EAE/BA,EACX,CAcO,SAASC,EAAmBC,EAAqC,CACpE,MAAO,CACH,OAAAA,EACA,KAAM,GACN,MAAO,GACP,OAAQ,GACR,YAAa,EACjB,CACJ,CAkBO,SAASC,EAAaC,E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detectJSEngine", "stack", "normalizePath", "filePath", "createDefaultFrame", "source", "safeParseInt", "value", "parseV8StackLine", "line", "frame", "evalMatch", "globalMatch", "standardMatch", "parseSpiderMonkeyStackLine", "match", "parseJavaScriptCoreStackLine", "parseStackLine", "engine", "parseErrorStack", "error", "errorObj", "message", "name", "stackLines"]
8
8
  }
@@ -1,68 +1,79 @@
1
+
1
2
  /**
2
- * A callback function for formatting code lines
3
- *
4
- * @param lineString - The content of the line to be formatted
5
- * @param padding - The amount of padding to be applied to the line
6
- * @param line - The line number of the line to be formatted
7
- * @returns Formatted line string
8
- *
9
- * @since 1.0.0
3
+ * This file was automatically generated by xBuild.
4
+ * DO NOT EDIT MANUALLY.
5
+ */
6
+ /**
7
+ * Import will remove at compile time
10
8
  */
11
- export type FormatCodeCallbackType = (lineString: string, padding: number, line: number) => string;
12
9
  /**
13
- * Configuration options for formatting code
10
+ * Export interfaces
11
+ */
12
+ /**
13
+ * Formats a code snippet with optional line padding and custom actions
14
+ *
15
+ * @param code - The source code | stack to be formatted
16
+ * @param options - Configuration options for formatting the code
17
+ * @returns A formatted string of the code snippet with applied padding and custom actions
18
+ *
19
+ * @remarks
20
+ * This function takes a code string and an options object to format the code snippet.
21
+ * It applies padding to line numbers and can trigger custom actions for specific lines.
22
+ * Options include padding (default 10), startLine (default 0), and custom actions for specific lines.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const formattedCode = formatCode(code, {
27
+ * padding: 8,
28
+ * startLine: 5,
29
+ * action: {
30
+ * triggerLine: 7,
31
+ * callback: (lineString, padding, lineNumber) => {
32
+ * return `Custom formatting for line ${lineNumber}: ${lineString}`;
33
+ * }
34
+ * }
35
+ * });
36
+ * ```
14
37
  *
15
38
  * @since 1.0.0
16
39
  */
17
- export interface FormatCodeInterface {
18
- /**
19
- * The amount of padding to be applied to each line
20
- * @since 1.0.0
21
- */
22
- padding?: number;
23
- /**
24
- * The starting line number for formatting
25
- * @since 1.0.0
26
- */
27
- startLine?: number;
28
- /**
29
- * An optional action object specifying a line where a callback function should be triggered.
30
- * @since 1.0.0
31
- */
32
- action?: {
33
- /**
34
- * The line number at which the callback function should be triggered.
35
- * @since 1.0.0
36
- */
37
- triggerLine: number;
38
- /**
39
- * The callback function to be executed when the trigger line is encountered.
40
- * @since 1.0.0
41
- */
42
- callback: FormatCodeCallbackType;
43
- };
44
- }
40
+ export declare function formatCode(code: string, options?: FormatCodeInterface): string;
45
41
  /**
46
- * Configuration for ANSI color styling of error pointers
42
+ * Formats a code snippet around an error location with special highlighting
43
+ *
44
+ * @param sourcePosition - An object containing information about the source code and error location
45
+ * @param ansiOption - Optional configuration for ANSI color codes
46
+ * @returns A formatted string representing the relevant code snippet with error highlighting
47
+ *
48
+ * @throws Error - If the provided sourcePosition object has invalid line or column numbers
49
+ *
50
+ * @remarks
51
+ * This function takes a sourcePosition object with code content and error location information,
52
+ * then uses formatCode to format and highlight the relevant code snippet around the error.
53
+ * The sourcePosition object should contain code (string), line (number), column (number),
54
+ * and optional startLine (number, defaults to 1).
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const formattedErrorCode = formatErrorCode({
59
+ * code: "const x = 1;\nconst y = x.undefined;\n",
60
+ * line: 2,
61
+ * column: 15,
62
+ * startLine: 1
63
+ * });
64
+ * ```
65
+ *
66
+ * @see formatCode - The underlying function used for basic code formatting
67
+ *
47
68
  * @since 1.0.0
48
69
  */
49
- export interface AnsiOptionInterface {
50
- /**
51
- * ANSI color code to apply to the error pointer
52
- * @since 1.0.0
53
- */
54
- color: string;
55
- /**
56
- * ANSI reset code to restore default styling after the error pointer
57
- * @since 1.0.0
58
- */
59
- reset: string;
60
- }
70
+ export declare function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string;
71
+
61
72
  /**
62
73
  * Represents a source map structure used for mapping code within a file to its original source
63
74
  * @since 1.0.0
64
75
  */
65
- export interface SourceMapInterface {
76
+ interface SourceMapInterface {
66
77
  /**
67
78
  * The generated file's name that the source map is associated with
68
79
  * @since 1.0.0
@@ -103,7 +114,7 @@ export interface SourceMapInterface {
103
114
  * Represents a position in source code with mapping information
104
115
  * @since 1.0.0
105
116
  */
106
- export interface PositionInterface {
117
+ interface PositionInterface {
107
118
  /**
108
119
  * Name of the identifier at this position
109
120
  * @since 1.0.0
@@ -151,7 +162,7 @@ export interface PositionInterface {
151
162
  * @see PositionInterface
152
163
  * @since 1.0.0
153
164
  */
154
- export interface PositionWithContentInterface extends PositionInterface {
165
+ interface PositionWithContentInterface extends PositionInterface {
155
166
  /**
156
167
  * Content of the original source file
157
168
  * @since 1.0.0
@@ -164,7 +175,7 @@ export interface PositionWithContentInterface extends PositionInterface {
164
175
  * @see PositionInterface
165
176
  * @since 1.0.0
166
177
  */
167
- export interface PositionWithCodeInterface extends PositionInterface {
178
+ interface PositionWithCodeInterface extends PositionInterface {
168
179
  /**
169
180
  * Code fragment from the original source
170
181
  * @since 1.0.0
@@ -185,7 +196,7 @@ export interface PositionWithCodeInterface extends PositionInterface {
185
196
  * Options for retrieving source code context
186
197
  * @since 1.0.0
187
198
  */
188
- export interface SourceOptionsInterface {
199
+ interface SourceOptionsInterface {
189
200
  /**
190
201
  * Number of lines to include after the target line
191
202
  * @since 1.0.0
@@ -197,62 +208,212 @@ export interface SourceOptionsInterface {
197
208
  */
198
209
  linesBefore?: number;
199
210
  }
211
+
200
212
  /**
201
- * Formats a code snippet with optional line padding and custom actions
213
+ * Import will remove at compile time
214
+ */
215
+ /**
216
+ * A callback function for formatting code lines
202
217
  *
203
- * @param code - The source code | stack to be formatted
204
- * @param options - Configuration options for formatting the code
205
- * @returns A formatted string of the code snippet with applied padding and custom actions
218
+ * @param lineString - The content of the line to be formatted
219
+ * @param padding - The amount of padding to be applied to the line
220
+ * @param line - The line number of the line to be formatted
221
+ * @returns Formatted line string
206
222
  *
207
- * @remarks
208
- * This function takes a code string and an options object to format the code snippet.
209
- * It applies padding to line numbers and can trigger custom actions for specific lines.
210
- * Options include padding (default 10), startLine (default 0), and custom actions for specific lines.
223
+ * @since 1.0.0
224
+ */
225
+ export type FormatCodeCallbackType = (lineString: string, padding: number, line: number) => string;
226
+ /**
227
+ * Configuration options for formatting code
211
228
  *
212
- * @example
213
- * ```ts
214
- * const formattedCode = formatCode(code, {
215
- * padding: 8,
216
- * startLine: 5,
217
- * action: {
218
- * triggerLine: 7,
219
- * callback: (lineString, padding, lineNumber) => {
220
- * return `Custom formatting for line ${lineNumber}: ${lineString}`;
221
- * }
222
- * }
223
- * });
224
- * ```
229
+ * @since 1.0.0
230
+ */
231
+ export interface FormatCodeInterface {
232
+ /**
233
+ * The amount of padding to be applied to each line
234
+ * @since 1.0.0
235
+ */
236
+ padding?: number;
237
+ /**
238
+ * The starting line number for formatting
239
+ * @since 1.0.0
240
+ */
241
+ startLine?: number;
242
+ /**
243
+ * An optional action object specifying a line where a callback function should be triggered.
244
+ * @since 1.0.0
245
+ */
246
+ action?: {
247
+ /**
248
+ * The line number at which the callback function should be triggered.
249
+ * @since 1.0.0
250
+ */
251
+ triggerLine: number;
252
+ /**
253
+ * The callback function to be executed when the trigger line is encountered.
254
+ * @since 1.0.0
255
+ */
256
+ callback: FormatCodeCallbackType;
257
+ };
258
+ }
259
+ /**
260
+ * Configuration for ANSI color styling of error pointers
261
+ * @since 1.0.0
262
+ */
263
+ export interface AnsiOptionInterface {
264
+ /**
265
+ * ANSI color code to apply to the error pointer
266
+ * @since 1.0.0
267
+ */
268
+ color: ColorFunctionType;
269
+ }
270
+
271
+ /**
272
+ * Represents a function that applies coloring or formatting to strings.
273
+ *
274
+ * @param args - Strings to be formatted
275
+ * @returns The formatted string
225
276
  *
226
277
  * @since 1.0.0
227
278
  */
228
- export declare function formatCode(code: string, options?: FormatCodeInterface): string;
279
+ type ColorFunctionType = (...args: Array<string>) => string;
229
280
  /**
230
- * Formats a code snippet around an error location with special highlighting
281
+ * Defines a color scheme for syntax highlighting various code elements.
231
282
  *
232
- * @param sourcePosition - An object containing information about the source code and error location
233
- * @param ansiOption - Optional configuration for ANSI color codes
234
- * @returns A formatted string representing the relevant code snippet with error highlighting
283
+ * @remarks
284
+ * Each property is a {@link ColorFunctionType} that formats a specific type of syntax element,
285
+ * such as enums, classes, keywords, or literals.
235
286
  *
236
- * @throws Error - If the provided sourcePosition object has invalid line or column numbers
287
+ * @see ColorFunctionType
288
+ * @since 1.0.0
289
+ */
290
+ interface HighlightSchemeInterface {
291
+ /**
292
+ * Color function for enum names.
293
+ * @since 1.0.0
294
+ */
295
+ enumColor: ColorFunctionType;
296
+ /**
297
+ * Color function for type names.
298
+ * @since 1.0.0
299
+ */
300
+ typeColor: ColorFunctionType;
301
+ /**
302
+ * Color function for class names.
303
+ * @since 1.0.0
304
+ */
305
+ classColor: ColorFunctionType;
306
+ /**
307
+ * Color function for string literals.
308
+ * @since 1.0.0
309
+ */
310
+ stringColor: ColorFunctionType;
311
+ /**
312
+ * Color function for language keywords.
313
+ * @since 1.0.0
314
+ */
315
+ keywordColor: ColorFunctionType;
316
+ /**
317
+ * Color function for comments.
318
+ * @since 1.0.0
319
+ */
320
+ commentColor: ColorFunctionType;
321
+ /**
322
+ * Color function for function names.
323
+ * @since 1.0.0
324
+ */
325
+ functionColor: ColorFunctionType;
326
+ /**
327
+ * Color function for variable names.
328
+ * @since 1.0.0
329
+ */
330
+ variableColor: ColorFunctionType;
331
+ /**
332
+ * Color function for interface names.
333
+ * @since 1.0.0
334
+ */
335
+ interfaceColor: ColorFunctionType;
336
+ /**
337
+ * Color function for function/method parameters.
338
+ * @since 1.0.0
339
+ */
340
+ parameterColor: ColorFunctionType;
341
+ /**
342
+ * Color function for getter accessor names.
343
+ * @since 1.0.0
344
+ */
345
+ getAccessorColor: ColorFunctionType;
346
+ /**
347
+ * Color function for numeric literals.
348
+ * @since 1.0.0
349
+ */
350
+ numericLiteralColor: ColorFunctionType;
351
+ /**
352
+ * Color function for method signatures.
353
+ * @since 1.0.0
354
+ */
355
+ methodSignatureColor: ColorFunctionType;
356
+ /**
357
+ * Color function for regular expressions.
358
+ * @since 1.0.0
359
+ */
360
+ regularExpressionColor: ColorFunctionType;
361
+ /**
362
+ * Color function for property assignments.
363
+ * @since 1.0.0
364
+ */
365
+ propertyAssignmentColor: ColorFunctionType;
366
+ /**
367
+ * Color function for property access expressions.
368
+ * @since 1.0.0
369
+ */
370
+ propertyAccessExpressionColor: ColorFunctionType;
371
+ /**
372
+ * Color function for expressions with type arguments.
373
+ * @since 1.0.0
374
+ */
375
+ expressionWithTypeArgumentsColor: ColorFunctionType;
376
+ }
377
+ /**
378
+ * Represents a segment of source code to be highlighted with specific styling.
237
379
  *
238
380
  * @remarks
239
- * This function takes a sourcePosition object with code content and error location information,
240
- * then uses formatCode to format and highlight the relevant code snippet around the error.
241
- * The sourcePosition object should contain code (string), line (number), column (number),
242
- * and optional startLine (number, defaults to 1).
381
+ * Segments are the fundamental units of the highlighting system.
382
+ * Each segment represents a portion of text that should receive specific styling.
383
+ * When the source code is processed for display,
384
+ * these segments are used to insert the appropriate color/style codes at the correct positions.
385
+ *
386
+ * The highlighter maintains a collection of these segments and applies them
387
+ * in position order to create the complete highlighted output.
243
388
  *
244
389
  * @example
245
390
  * ```ts
246
- * const formattedErrorCode = formatErrorCode({
247
- * code: "const x = 1;\nconst y = x.undefined;\n",
248
- * line: 2,
249
- * column: 15,
250
- * startLine: 1
251
- * });
391
+ * const keywordSegment: HighlightNodeSegmentInterface = {
392
+ * start: 0,
393
+ * end: 6,
394
+ * color: xterm.red
395
+ * };
252
396
  * ```
253
397
  *
254
- * @see formatCode - The underlying function used for basic code formatting
398
+ * @see addSegment
399
+ * @see HighlightSchemeInterface
255
400
  *
256
401
  * @since 1.0.0
257
402
  */
258
- export declare function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string;
403
+ interface HighlightNodeSegmentInterface {
404
+ /**
405
+ * The starting character position of the segment in the source text.
406
+ * @since 1.0.0
407
+ */
408
+ start: number;
409
+ /**
410
+ * The ending character position of the segment in the source text.
411
+ * @since 1.0.0
412
+ */
413
+ end: number;
414
+ /**
415
+ * The color or style code to apply to this segment.
416
+ * @since 1.0.0
417
+ */
418
+ color: ColorFunctionType;
419
+ }