@remotex-labs/xmap 2.0.4 → 3.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.
- package/README.md +23 -27
- package/dist/cjs/formatter.component.js +5 -0
- package/dist/cjs/formatter.component.js.map +8 -0
- package/dist/cjs/highlighter.component.js +2 -0
- package/dist/cjs/highlighter.component.js.map +8 -0
- package/dist/cjs/index.js +3 -7
- package/dist/cjs/index.js.map +5 -5
- package/dist/cjs/parser.component.js +3 -0
- package/dist/cjs/parser.component.js.map +8 -0
- package/dist/components/base64.component.d.ts +58 -14
- package/dist/components/formatter.component.d.ts +37 -35
- package/dist/components/highlighter.component.d.ts +228 -74
- package/dist/components/interfaces/{formatter.interface.d.ts → formatter-component.interface.d.ts} +27 -9
- package/dist/components/interfaces/highlighter-component.interface.d.ts +94 -0
- package/dist/components/interfaces/parse-component.interface.d.ts +52 -0
- package/dist/components/parser.component.d.ts +216 -5
- package/dist/esm/formatter.component.js +5 -0
- package/dist/esm/formatter.component.js.map +8 -0
- package/dist/esm/highlighter.component.js +2 -0
- package/dist/esm/highlighter.component.js.map +8 -0
- package/dist/esm/index.js +3 -7
- package/dist/esm/index.js.map +5 -5
- package/dist/esm/parser.component.js +3 -0
- package/dist/esm/parser.component.js.map +8 -0
- package/dist/index.d.ts +3 -9
- package/dist/providers/interfaces/mapping-provider.interface.d.ts +141 -0
- package/dist/providers/mapping.provider.d.ts +258 -174
- package/dist/services/interfaces/source-service.interface.d.ts +139 -0
- package/dist/services/source.service.d.ts +96 -97
- package/package.json +37 -11
- package/dist/components/interfaces/highlighter.interface.d.ts +0 -48
- package/dist/components/interfaces/parse.interface.d.ts +0 -31
- package/dist/providers/interfaces/mapping.interface.d.ts +0 -52
- package/dist/services/interfaces/source.interface.d.ts +0 -53
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts", "../../src/components/
|
|
4
|
-
"sourceRoot": "https://github.com/remotex-lab/xmap/tree/
|
|
5
|
-
"sourcesContent": ["// export components interfaces\nexport type * from '@components/interfaces/parse.interface';\nexport type * from '@components/interfaces/formatter.interface';\nexport type * from '@components/interfaces/highlighter.interface';\n\n// export services interfaces\nexport type * from '@services/interfaces/source.interface';\n\n// Export components\nexport * from '@components/parser.component';\nexport * from '@components/base64.component';\nexport * from '@components/formatter.component';\nexport * from '@components/highlighter.component';\n\n// export service\nexport * from '@services/source.service';\n", "/**\n * Import will remove at compile time\n */\n\nimport type { StackEntryInterface } from '@components/interfaces/parse.interface';\n\n/**\n * Parses an error stack trace and returns an object with a message and an array of stack entries.\n *\n * @param stackString - The error stack trace.\n * @returns The parsed stack trace object.\n */\n\nexport function parseErrorStack(stackString: string): Array<StackEntryInterface> {\n const lines = stackString.split('\\n').slice(1);\n const regex = /^\\s*at\\s+(.*?)\\s+\\((.*?):(\\d+):(\\d+)\\)$|^\\s*at\\s+(.*?):(\\d+):(\\d+)$/;\n const evalRegex = /eval\\s+at\\s+([^\\s(]+).+\\((.+):(\\d+):(\\d+)\\),\\s(.+)/;\n const stack: Array<StackEntryInterface> = [];\n\n lines.forEach((line) => {\n const match = line.match(regex);\n if (!match) return;\n\n let args: Array<string> = match.slice(1);\n if(!match[2]) {\n args = match.slice(4);\n }\n\n const [ at, file, lineNum, colNum ] = args;\n const lineNumber = parseInt(lineNum, 10);\n const columnNumber = parseInt(colNum, 10);\n\n if (line.includes('eval')) {\n const evalMatch = file.match(evalRegex)?.slice(1);\n if (evalMatch) {\n const [ evalAt, evalFile, evalLineNum, evalColNum, evalAnonFile ] = evalMatch;\n stack.push({\n at,\n file: evalAnonFile,\n line: lineNumber,\n column: columnNumber,\n executor: {\n at: evalAt,\n file: evalFile,\n line: parseInt(evalLineNum, 10),\n column: parseInt(evalColNum, 10)\n }\n });\n\n return;\n }\n }\n\n stack.push({\n at: at || '<anonymous>',\n file,\n line: lineNumber,\n column: columnNumber,\n executor: null\n });\n });\n\n return stack;\n}\n", "// Bitmask to extract the lower 5 bits (continuation bit removed) - 0b11111\nconst CONTINUATION_BIT_REMOVE = 0x1F;\n\n// Bitmask to set the continuation bit - 0b100000\nconst CONTINUATION_BIT_POSITION = 0x20;\n\n// Mapping of Base64 characters to their indices\nconst base64Map: { [key: string]: number } = {};\n\n// Array of Base64 characters\nconst base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');\n\n// Populate the base64Map with characters and their corresponding indices\nbase64Chars.forEach((char, index) => {\n base64Map[char] = index;\n});\n\n/**\n * Encodes a given number using Variable-Length Quantity (VLQ) encoding.\n * Negative numbers are encoded by converting to a non-negative representation.\n * The continuation bit is used to indicate if more bytes follow.\n *\n * @param value - The number to be encoded.\n * @returns The VLQ encoded string.\n */\n\nexport function encodeVLQ(value: number): string {\n const isNegative = value < 0;\n\n /**\n * Bit Structure Representation:\n *\n * +--------------------------+\n * | C | Value | Sign |\n * +---+---+---+---+---+------+\n * | 1 | 1 | 0 | 0 | 1 | 0 |\n * +---+---+---+---+---+------+\n */\n\n let encoded = '';\n let vlq = isNegative ? ((-value) << 1) + 1 : (value << 1); // Shift left by 1 bit to encode the sign bit\n\n do {\n const digit = vlq & CONTINUATION_BIT_REMOVE; // Extract lower 5 bits\n vlq >>>= 5; // Right shift by 5 bits to process next chunk\n encoded += base64Chars[digit | (vlq > 0 ? CONTINUATION_BIT_POSITION : 0)]; // Combine digit and continuation bit\n } while (vlq > 0);\n\n return encoded;\n}\n\n/**\n * Encodes an array of numbers using VLQ encoding.\n * Each number in the array is individually encoded and the results are concatenated.\n *\n * @param values - The array of numbers to be encoded.\n * @returns The concatenated VLQ encoded string.\n */\n\nexport function encodeArrayVLQ(values: number[]): string {\n return values.map(encodeVLQ).join('');\n}\n\n/**\n * Decodes a VLQ encoded string back into an array of numbers.\n * Each character is decoded using the Base64 map and continuation bits are processed.\n *\n * @param data - The VLQ encoded string.\n * @returns The array of decoded numbers.\n * @throws Error If the string contains invalid Base64 characters.\n */\n\nexport function decodeVLQ(data: string): number[] {\n const result = [];\n let shift = 0;\n let value = 0;\n\n for (let i = 0; i < data.length; i++) {\n const digit = base64Map[data[i]];\n if (digit === undefined) {\n throw new Error(`Invalid Base64 character: ${data[i]}`);\n }\n\n const continuation = digit & CONTINUATION_BIT_POSITION; // Check if continuation bit is set\n value += (digit & CONTINUATION_BIT_REMOVE) << shift; // Add lower 5 bits to value\n if (continuation) {\n shift += 5; // Shift left by 5 for next chunk\n } else {\n const isNegative = (value & 1) === 1; // Check if the number is negative\n const shifted = value >> 1; // Remove the sign bit\n\n result.push(isNegative ? -shifted : shifted); // Convert back to signed integer\n value = shift = 0; // Reset for next number\n }\n }\n\n return result;\n}\n", "/**\n * Import will remove at compile time\n */\n\nimport type { PositionWithCodeInterface } from '@services/interfaces/source.interface';\nimport type { AnsiOptionInterface, FormatCodeInterface } from '@components/interfaces/formatter.interface';\n\n/**\n * Formats a code snippet with optional line padding and custom actions.\n *\n * This function takes a code string and an options object to format the code snippet.\n * It applies padding to line numbers and can trigger custom actions for specific lines.\n *\n * @param code - The source code | stack to be formatted.\n * @param options - Configuration options for formatting the code.\n * - `padding` (number, optional): Number of characters for line number padding. Defaults to 10.\n * - `startLine` (number, optional): The starting line number for formatting. Defaults to 1.\n * - `action` (object, optional): Custom actions to apply to specific lines.\n * - `triggerLine` (number): The line number where the action should be triggered.\n * - `callback` (function): A callback function to format the line string when `triggerLine` is matched.\n * The callback receives the formatted line string, the padding value, and the current line number as arguments.\n *\n * @returns A formatted string of the code snippet with applied padding and custom actions.\n *\n * @example\n * ```typescript\n * const formattedCode = formatCode(code, {\n * padding: 8,\n * startLine: 5,\n * action: {\n * triggerLine: 7,\n * callback: (lineString, padding, lineNumber) => {\n * return `Custom formatting for line ${lineNumber}: ${lineString}`;\n * }\n * }\n * });\n * console.log(formattedCode);\n * ```\n */\n\nexport function formatCode(code: string, options: FormatCodeInterface = {}): string {\n const lines = code.split('\\n');\n const padding = options.padding ?? 10;\n const startLine = options.startLine ?? 0;\n\n return lines.map((lineContent, index) => {\n const currentLineNumber = index + startLine + 1;\n const prefix = `${ currentLineNumber} | `;\n const string = `${ prefix.padStart(padding) }${ lineContent }`;\n\n if (options.action && currentLineNumber === options.action.triggerLine) {\n return options.action.callback(string, padding, currentLineNumber);\n }\n\n return string;\n }).join('\\n');\n}\n\n/**\n * Formats a code snippet around an error location with special highlighting.\n *\n * This function takes a `sourcePosition` object containing information about the source code\n * and error location, then uses `formatCode` to format and highlight the relevant code snippet.\n *\n * @param sourcePosition - An object containing information about the source code and error location.\n * - `code` (string): The entire source code content.\n * - `line` (number): The line number where the error occurred (1-based indexing).\n * - `column` (number): The column number within the line where the error occurred (1-based indexing).\n * - `startLine` (number, optional): The starting line number of the code snippet (defaults to 1).\n * @param ansiOption - Optional configuration for ANSI color codes.\n * - `color` (string): The ANSI escape sequence to colorize the error marker and prefix (e.g., `'\\x1b[38;5;160m'`).\n * - `reset` (string): The ANSI escape sequence to reset the color (e.g., `'\\x1b[0m'`).\n *\n * @throws Error - If the provided `sourcePosition` object has invalid line or column numbers,\n * or if the error line is outside the boundaries of the provided code content.\n *\n * @returns A formatted string representing the relevant code snippet around the error location,\n * including special highlighting for the error line and column.\n *\n * @example\n * ```typescript\n * const formattedErrorCode = formatErrorCode(sourcePosition);\n * console.log(formattedErrorCode);\n * ```\n */\n\nexport function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string {\n const { code, line: errorLine, column: errorColumn, startLine } = sourcePosition;\n\n // Validate line and column numbers\n if (errorLine < startLine || errorColumn < 1) {\n throw new Error('Invalid line or column number.');\n }\n\n return formatCode(code, {\n startLine,\n action: {\n triggerLine: errorLine,\n callback: (lineString, padding, line) => {\n let pointer = '^';\n let ansiPadding = padding - 1; // 1 size of the char we added\n let prefixPointer = '>';\n\n if (ansiOption) {\n pointer = `${ ansiOption.color }${ pointer }${ ansiOption.reset }`;\n ansiPadding += (ansiOption.color.length + ansiOption.reset.length);\n prefixPointer = `${ ansiOption.color }>${ ansiOption.reset }`;\n }\n\n const errorMarker = ' | '.padStart(padding) + ' '.repeat(errorColumn - 1) + `${ pointer }`;\n lineString = `${ prefixPointer } ${ line } |`.padStart(ansiPadding) + lineString.split('|')[1];\n\n return lineString + `\\n${ errorMarker }`;\n }\n }\n });\n}\n", "/**\n * Import will remove at compile time\n */\n\nimport type { HighlightSchemeInterface, HighlightNodeSegmentInterface } from '@components/interfaces/highlighter.interface';\n\n/**\n * Imports\n */\n\nimport * as ts from 'typescript';\nimport { SyntaxKind } from 'typescript';\n\n/**\n * An enum containing ANSI escape sequences for various colors.\n *\n * This enum is primarily intended for terminal output and won't work directly in JavaScript for web development.\n * It defines color codes for various colors and a reset code to return to\n * the default text color.\n *\n * @example\n * ```typescript\n * console.log(`${Colors.red}This the text will be red in the terminal.${Colors.reset}`);\n * ```\n *\n * This functionality is limited to terminal environments.\n * Consider alternative methods\n * for color highlighting in web development contexts, such as CSS classes.\n */\n\nexport const enum Colors {\n reset = '\\x1b[0m',\n gray = '\\x1b[38;5;243m',\n darkGray = '\\x1b[38;5;238m',\n lightCoral = '\\x1b[38;5;203m',\n lightOrange = '\\x1b[38;5;215m',\n oliveGreen = '\\x1b[38;5;149m',\n burntOrange = '\\x1b[38;5;208m',\n lightGoldenrodYellow = '\\x1b[38;5;221m',\n lightYellow = '\\x1b[38;5;230m',\n canaryYellow = '\\x1b[38;5;227m',\n deepOrange = '\\x1b[38;5;166m',\n lightGray = '\\x1b[38;5;252m',\n brightPink = '\\x1b[38;5;197m'\n}\n\n/**\n * Default color scheme for semantic highlighting.\n * This scheme uses red color for all code elements.\n *\n * @example\n * const scheme = defaultScheme;\n * console.log(scheme.typeColor); // Outputs: the red color code\n */\n\n\nconst defaultScheme: HighlightSchemeInterface = {\n enumColor: Colors.burntOrange,\n typeColor: Colors.lightGoldenrodYellow,\n classColor: Colors.lightOrange,\n stringColor: Colors.oliveGreen,\n keywordColor: Colors.lightCoral,\n commentColor: Colors.darkGray,\n functionColor: Colors.lightOrange,\n variableColor: Colors.burntOrange,\n interfaceColor: Colors.lightGoldenrodYellow,\n parameterColor: Colors.deepOrange,\n getAccessorColor: Colors.lightYellow,\n numericLiteralColor: Colors.lightGray,\n methodSignatureColor: Colors.burntOrange,\n regularExpressionColor: Colors.oliveGreen,\n propertyAssignmentColor: Colors.canaryYellow,\n propertyAccessExpressionColor: Colors.lightYellow,\n expressionWithTypeArgumentsColor: Colors.lightOrange\n};\n\n/**\n * Class responsible for applying semantic highlighting to a source code string based on a given color scheme.\n *\n * @class\n *\n * @param sourceFile - The TypeScript AST node representing the source file.\n * @param code - The source code string to be highlighted.\n * @param schema - The color scheme used for highlighting different elements in the code.\n *\n * const highlighter = new CodeHighlighter(sourceFile, code, schema);\n */\n\nexport class CodeHighlighter {\n\n /**\n * A Map of segments where the key is a combination of start and end positions,\n * and the value is an object containing the color and reset code.\n * This structure ensures unique segments and allows for fast lookups and updates.\n *\n * @example\n * this.segments = new Map([\n * ['0-10', { start: 1, end: 11, color: '\\x1b[31m', reset: '\\x1b[0m' }],\n * ['11-20', { start: 12, end: 20, color: '\\x1b[32m', reset: '\\x1b[0m' }]\n * ]);\n */\n\n private segments: Map<string, HighlightNodeSegmentInterface> = new Map();\n\n /**\n * Creates an instance of the CodeHighlighter class.\n *\n * @param sourceFile - The TypeScript AST node representing the source file.\n * @param code - The source code string to be highlighted.\n * @param schema - The color scheme used for highlighting different elements in the code.\n */\n\n constructor(private sourceFile: ts.Node, private code: string, private schema: HighlightSchemeInterface) {\n }\n\n /**\n * Parses a TypeScript AST node and processes its comments to identify segments that need highlighting.\n *\n * @param node - The TypeScript AST node to be parsed.\n */\n\n parseNode(node: ts.Node): void {\n this.processComments(node);\n this.processKeywords(node);\n this.processNode(node);\n }\n\n /**\n * Generates a string with highlighted code segments based on the provided color scheme.\n *\n * This method processes the stored segments, applies the appropriate colors to each segment,\n * and returns the resulting highlighted code as a single string.\n *\n * @returns The highlighted code as a string, with ANSI color codes applied to the segments.\n */\n\n highlight(): string {\n let previousSegmentEnd = 0;\n let parent: HighlightNodeSegmentInterface | undefined;\n\n const result: Array<string> = [];\n const segments = Array.from(\n this.segments.values()\n ).sort((a, b) => a.start - b.start || a.end - b.end);\n\n segments.forEach((segment) => {\n if (parent && segment.start < parent.end) {\n const lastSegment = result.pop();\n if (!lastSegment) return;\n\n const source = this.getSegmentSource(segment.start, segment.end);\n const combinedSource = `${ segment.color }${ source }${ parent.color }`;\n result.push(lastSegment.replace(source, combinedSource));\n\n return;\n }\n\n result.push(this.getSegmentSource(previousSegmentEnd, segment.start));\n result.push(`${ segment.color }${ this.getSegmentSource(segment.start, segment.end) }${ segment.reset }`);\n previousSegmentEnd = segment.end;\n parent = segment;\n });\n\n return result.join('') + this.getSegmentSource(previousSegmentEnd);\n }\n\n /**\n * Extracts a substring from the code based on the specified start and end positions.\n *\n * This method is used to retrieve the source code segment that corresponds to the\n * given start and end positions. It is primarily used for highlighting specific\n * segments of the code.\n *\n * @param start - The starting index of the segment to be extracted.\n * @param end - The ending index of the segment to be extracted.\n * @returns The extracted substring from the code.\n */\n\n private getSegmentSource(start: number, end?: number): string {\n return this.code.slice(start, end);\n }\n\n /**\n * Adds a new segment to the list of segments to be highlighted.\n * The segment is defined by its start and end positions, the color to apply, and an optional reset code.\n *\n * @param start - The starting index of the segment in the code string.\n * @param end - The ending index of the segment in the code string.\n * @param color - The color code to apply to the segment.\n * @param reset - The color reset code to apply after the segment, Defaults to the reset code defined in `Colors.reset`.\n */\n\n private addSegment(start: number, end: number, color: string, reset: string = Colors.reset) {\n const key = `${ start }-${ end }`;\n this.segments.set(key, { start, end, color, reset });\n }\n\n /**\n * Processes comments within a TypeScript AST node and adds segments for highlighting.\n * Extracts trailing and leading comments from the node and adds them as segments using the color defined in `this.colorSchema.comments`.\n *\n * @param node - The TypeScript AST node whose comments are to be processed.\n */\n\n private processComments(node: ts.Node): void {\n const comments = [\n ...ts.getTrailingCommentRanges(this.sourceFile.getFullText(), node.getFullStart()) || [],\n ...ts.getLeadingCommentRanges(this.sourceFile.getFullText(), node.getFullStart()) || []\n ];\n\n comments.forEach(comment => this.addSegment(comment.pos, comment.end, this.schema.commentColor));\n }\n\n /**\n * Processes the keywords within a TypeScript AST node and adds them as segments for highlighting.\n *\n * This method identifies potential keyword tokens within the provided node and adds them to the\n * list of segments with the color defined in `this.schema.keywordColor`.\n * The method considers the current node, its first token, and its last token to determine if they should be highlighted\n * as keywords.\n *\n * The method checks if the node's kind falls within the range of keyword kinds defined by TypeScript.\n * If the node or any of its tokens are identified as keywords, a segment is added to `this.segments`\n * with the start and end positions of the node and the specified color for keywords.\n *\n * @param node - The TypeScript AST node to be processed for keywords.\n */\n\n private processKeywords(node: ts.Node): void {\n if ([\n SyntaxKind.NullKeyword,\n SyntaxKind.VoidKeyword,\n SyntaxKind.StringKeyword,\n SyntaxKind.NumberKeyword,\n SyntaxKind.BooleanKeyword,\n SyntaxKind.UndefinedKeyword\n ].includes(node.kind)) {\n return this.addSegment(node.getStart(), node.getEnd(), this.schema.typeColor);\n }\n\n if (node && node.kind >= ts.SyntaxKind.FirstKeyword && node.kind <= ts.SyntaxKind.LastKeyword) {\n this.addSegment(node.getStart(), node.getEnd(), this.schema.keywordColor);\n }\n }\n\n /**\n * Processes identifiers within a TypeScript AST node and adds them as segments for highlighting\n * based on the node's parent type.\n *\n * This method determines the appropriate color for an identifier based on its parent node's kind.\n * If the parent node matches one of the specified kinds, the identifier is highlighted with a cyan color.\n * Supported parent kinds include various declarations, expressions, and signatures.\n *\n * @param node - The TypeScript AST node representing the identifier to be processed.\n */\n\n private processIdentifier(node: ts.Node): void {\n const end = node.getEnd();\n const start = node.getStart();\n\n switch (node.parent.kind) {\n case ts.SyntaxKind.EnumMember:\n return this.addSegment(start, end, this.schema.enumColor);\n case ts.SyntaxKind.CallExpression:\n case ts.SyntaxKind.EnumDeclaration:\n case ts.SyntaxKind.PropertySignature:\n case ts.SyntaxKind.ModuleDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.InterfaceDeclaration:\n return this.addSegment(start, end, this.schema.interfaceColor);\n case ts.SyntaxKind.GetAccessor:\n return this.addSegment(start, end, this.schema.getAccessorColor);\n case ts.SyntaxKind.PropertyAssignment:\n return this.addSegment(start, end, this.schema.propertyAssignmentColor);\n case ts.SyntaxKind.MethodSignature:\n return this.addSegment(start, end, this.schema.methodSignatureColor);\n case ts.SyntaxKind.MethodDeclaration:\n case ts.SyntaxKind.FunctionDeclaration:\n return this.addSegment(start, end, this.schema.functionColor);\n case ts.SyntaxKind.ClassDeclaration:\n return this.addSegment(start, end, this.schema.classColor);\n case ts.SyntaxKind.Parameter:\n return this.addSegment(start, end, this.schema.parameterColor);\n case ts.SyntaxKind.VariableDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.PropertyDeclaration:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.PropertyAccessExpression: {\n if (node.parent.getChildAt(0).getText() === node.getText()) {\n return this.addSegment(start, end, this.schema.variableColor);\n }\n\n return this.addSegment(start, end, this.schema.propertyAccessExpressionColor);\n }\n case ts.SyntaxKind.ExpressionWithTypeArguments:\n return this.addSegment(start, end, this.schema.expressionWithTypeArgumentsColor);\n case ts.SyntaxKind.BreakStatement:\n case ts.SyntaxKind.ShorthandPropertyAssignment:\n case ts.SyntaxKind.BindingElement:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.BinaryExpression:\n case ts.SyntaxKind.SwitchStatement:\n case ts.SyntaxKind.TemplateSpan:\n return this.addSegment(start, end, this.schema.variableColor);\n case ts.SyntaxKind.TypeReference:\n case ts.SyntaxKind.TypeAliasDeclaration:\n return this.addSegment(start, end, this.schema.typeColor);\n case ts.SyntaxKind.NewExpression:\n return this.addSegment(start, end, this.schema.variableColor);\n }\n }\n\n /**\n * Processes a TypeScript template expression and adds segments for highlighting its literal parts.\n *\n * This method adds a segment for the head of the template expression with the color specified in `this.schema.stringColor`.\n * It also processes each template span within the expression, adding\n * segments for each span's literal part.\n *\n * @param templateExpression - The TypeScript template expression to be processed.\n */\n\n private processTemplateExpression(templateExpression: ts.TemplateExpression): void {\n const start = templateExpression.head.getStart();\n const end = templateExpression.head.getEnd();\n this.addSegment(start, end, this.schema.stringColor);\n\n templateExpression.templateSpans.forEach(span => {\n const spanStart = span.literal.getStart();\n const spanEnd = span.literal.getEnd();\n this.addSegment(spanStart, spanEnd, this.schema.stringColor);\n });\n }\n\n /**\n * Processes a TypeScript AST node and adds segments for highlighting based on the node's kind.\n *\n * This method identifies the kind of the node and determines the appropriate color for highlighting.\n * It handles various node kinds including string literals, regular expressions, template expressions, and identifiers.\n * Specific methods are invoked for more complex node kinds, such as template expressions and identifiers.\n *\n * @param node - The TypeScript AST node to be processed.\n */\n\n private processNode(node: ts.Node): void {\n const start = node.getStart();\n const end = node.getEnd();\n\n switch (node.kind) {\n case ts.SyntaxKind.TypeParameter:\n return this.addSegment(start, start + (node as ts.TypeParameterDeclaration).name.text.length, this.schema.typeColor);\n case ts.SyntaxKind.TypeReference:\n return this.addSegment(start, end, this.schema.typeColor);\n case ts.SyntaxKind.StringLiteral:\n case ts.SyntaxKind.NoSubstitutionTemplateLiteral:\n return this.addSegment(start, end, this.schema.stringColor);\n case ts.SyntaxKind.RegularExpressionLiteral:\n return this.addSegment(start, end, this.schema.regularExpressionColor);\n case ts.SyntaxKind.TemplateExpression:\n return this.processTemplateExpression(node as ts.TemplateExpression);\n case ts.SyntaxKind.Identifier:\n return this.processIdentifier(node);\n case ts.SyntaxKind.BigIntLiteral:\n case ts.SyntaxKind.NumericLiteral:\n return this.addSegment(start, end, this.schema.numericLiteralColor);\n }\n }\n}\n\n/**\n * Applies semantic highlighting to the provided code string using the specified color scheme.\n *\n * @param code - The source code to be highlighted.\n * @param schema - An optional partial schema defining the color styles for various code elements.\n * Defaults to an empty object, which means no specific highlighting will be applied.\n *\n * @returns A string with the code elements wrapped in the appropriate color styles as specified by the schema.\n *\n * @example\n * const code = 'const x: number = 42;';\n * const schema = {\n * keywordColor: '\\x1b[34m', // Blue\n * stringColor: '\\x1b[32m', // Green\n * numberColor: '\\x1b[31m', // Red\n * reset: '\\x1b[0m' // Reset\n * };\n * const highlightedCode = highlightCode(code, schema);\n * console.log(highlightedCode);\n */\n\nexport function highlightCode(code: string, schema: Partial<HighlightSchemeInterface> = {}) {\n const sourceFile = ts.createSourceFile('temp.ts', code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const codeHighlighter = new CodeHighlighter(sourceFile, code, Object.assign(defaultScheme, schema));\n\n function walk(node: ts.Node): void {\n codeHighlighter.parseNode(node);\n\n for (let i = 0; i < node.getChildCount(); i++) {\n walk(node.getChildAt(i));\n }\n } ts.forEachChild(sourceFile, walk);\n\n return codeHighlighter.highlight();\n}\n", "/**\n * Import will remove at compile time\n */\n\nimport type { MapType, FrameType, SegmentInterface, SegmentOffsetInterface } from './interfaces/mapping.interface';\n\n/**\n * Imports\n */\n\nimport { Bias } from './interfaces/mapping.interface';\nimport { decodeVLQ, encodeArrayVLQ } from '@components/base64.component';\n\n/**\n * The `MappingProvider` class provides methods to encode and decode mappings\n * from a source map or mapping string to an internal structured representation.\n */\n\nexport class MappingProvider {\n /**\n * The internal mapping representation, where each index represents a frame of segments.\n */\n\n private mapping: MapType = [];\n\n /**\n * Constructor to initialize the `MappingProvider` with a mapping.\n * Can be initialized with either a mapping string or a structured mapping array.\n *\n * @param mapping - The mapping data, either as a string or structured array.\n * @param namesOffset - Optional offset for the names index.\n * @param sourceOffset - Optional offset for the sources index.\n *\n * @example\n * ```ts\n * const provider = new MappingProvider(\";;;AAiBO,SAAS,OAAO;AACnB,UAAQ,IAAI,MAAM;AACtB;;;ACjBA,QAAQ,IAAI,GAAG;AACf,KAAK;\", 0, 0);\n * const provider2 = new MappingProvider([\n * null,\n * [\n * {\n * line: 1,\n * column: 1,\n * nameIndex: null,\n * sourceIndex: 0,\n * generatedLine: 2,\n * generatedColumn: 1\n * }\n * ],\n * null\n * ], 0, 0);\n * ```\n */\n\n constructor(mapping: string, namesOffset?: number, sourceOffset?: number);\n constructor(mapping: MapType, namesOffset?: number, sourceOffset?: number);\n constructor(mapping: MappingProvider, namesOffset?: number, sourceOffset?: number);\n constructor(mapping: MappingProvider| MapType | string, namesOffset = 0, sourcesOffset = 0) {\n mapping = mapping instanceof MappingProvider ? mapping.mapping : mapping;\n if (Array.isArray(mapping)) {\n this.decodeMappingArray(mapping, namesOffset, sourcesOffset);\n } else {\n this.decodeMappingString(mapping, namesOffset, sourcesOffset);\n }\n }\n\n /**\n * Encodes the internal mapping array back into a mapping string.\n *\n * @returns {string} - The encoded mapping string.\n * @example\n * ```ts\n * const encoded = provider.encode();\n * console.log(encoded); // Outputs encoded mapping string\n * ```\n */\n\n encode(): string {\n return this.encodeMappings(this.mapping);\n }\n\n /**\n * Decodes a mapping from either a string or structured array into the internal mapping.\n *\n * @param mapping - The mapping data to decode.\n * @param namesOffset - Offset for the names index.\n * @param sourcesOffset - Offset for the sources index.\n * @example\n * ```ts\n * provider.decode(\";;;AAiBO,SAAS,OAAO;AACnB,UAAQ,IAAI,MAAM;AACtB;;;ACjBA,QAAQ,IAAI,GAAG;AACf,KAAK;\", 0, 0);\n * provider.decode([\n * null,\n * [\n * {\n * line: 1,\n * column: 1,\n * nameIndex: null,\n * sourceIndex: 0,\n * generatedLine: 2,\n * generatedColumn: 1\n * }\n * ],\n * null\n * ], 0, 0);\n * ```\n */\n\n decode(mapping: MappingProvider| MapType | string, namesOffset = 0, sourcesOffset = 0): void {\n mapping = mapping instanceof MappingProvider ? mapping.mapping : mapping;\n if (Array.isArray(mapping)) {\n this.decodeMappingArray(mapping, namesOffset, sourcesOffset);\n } else {\n this.decodeMappingString(mapping, namesOffset, sourcesOffset);\n }\n }\n\n /**\n * Retrieves a segment based on the provided generated line and column,\n * applying the specified bias when the exact match is not found.\n *\n * This method performs a binary search on the segments of the specified\n * generated line to efficiently locate the segment corresponding to\n * the provided generated column. If an exact match is not found,\n * the method returns the closest segment based on the specified bias:\n * - `Bias.BOUND`: No preference for column matching (returns the closest segment).\n * - `Bias.LOWER_BOUND`: Prefers the closest mapping with a lower column value.\n * - `Bias.UPPER_BOUND`: Prefers the closest mapping with a higher column value.\n *\n * @param generatedLine - The line number of the generated code (1-based index).\n * @param generatedColumn - The column number of the generated code (0-based index).\n * @param bias - The bias to use when the line matches, can be one of:\n * - `Bias.BOUND` (default): No preference for column matching.\n * - `Bias.LOWER_BOUND`: Prefer the closest mapping with a lower column value.\n * - `Bias.UPPER_BOUND`: Prefer the closest mapping with a higher column value.\n * @returns The matching segment if found;\n * returns null if no segments exist for the specified generated line\n * or if the generated line is out of bounds.\n *\n * @throws { Error } - Throws an error if the generated line is invalid\n * (out of bounds).\n *\n * @example\n * ```ts\n * const segment = sourceMap.getSegment(5, 10, Bias.UPPER_BOUND);\n * if (segment) {\n * console.log(`Found segment: line ${segment.line}, column ${segment.column}`);\n * } else {\n * console.log('No matching segment found.');\n * }\n * ```\n */\n\n getSegment(generatedLine: number, generatedColumn: number, bias: Bias = Bias.BOUND): SegmentInterface | null {\n const segments = this.mapping[generatedLine - 1];\n if (!segments || segments.length === 0)\n return null;\n\n let low = 0;\n let high = segments.length - 1;\n let closestSegment: SegmentInterface | null = null;\n while (low <= high) {\n const mid = Math.floor((low + high) / 2);\n const segment = segments[mid];\n\n if (segment.generatedColumn < generatedColumn) {\n low = mid + 1;\n closestSegment = bias === Bias.LOWER_BOUND ? segment : closestSegment;\n } else if (segment.generatedColumn > generatedColumn) {\n high = mid - 1;\n closestSegment = bias === Bias.UPPER_BOUND ? segment : closestSegment;\n } else {\n return segment;\n }\n }\n\n return closestSegment;\n }\n\n /**\n * Retrieves the original segment based on the provided line, column, and source index.\n *\n * This method searches for the original segment that corresponds to the specified\n * line, column, and source index. It uses binary search to find the closest segment\n * based on the provided bias.\n *\n * @param line - The line number of the original code (1-based index).\n * @param column - The column number of the original code (0-based index).\n * @param sourceIndex - The index of the source file in the source map.\n * @param bias - The bias to apply when multiple segments match; defaults to `Bias.BOUND`.\n * @returns {SegmentInterface | null} - The matching original segment if found;\n * returns null if no segments exist for the specified line and source index.\n *\n * @example\n * ```ts\n * const originalSegment = sourceMap.getOriginalSegment(3, 5, 0, Bias.LOWER_BOUND);\n * if (originalSegment) {\n * console.log(`Found original segment: line ${originalSegment.line}, column ${originalSegment.column}`);\n * } else {\n * console.log('No matching original segment found.');\n * }\n * ```\n */\n\n getOriginalSegment(line: number, column: number, sourceIndex: number, bias: Bias = Bias.BOUND): SegmentInterface | null {\n let closestSegment: SegmentInterface | null = null;\n for (const segments of this.mapping) {\n if (!segments)\n continue;\n\n let low = 0;\n let high = segments.length - 1;\n while (low <= high) {\n const mid = Math.floor((low + high) / 2);\n const midSegment = segments[mid];\n\n if (midSegment.sourceIndex < sourceIndex || midSegment.line < line) {\n low = mid + 1;\n } else if (midSegment.sourceIndex > sourceIndex || midSegment.line > line) {\n high = mid - 1;\n } else if (midSegment.column < column) {\n low = mid + 1;\n closestSegment = bias === Bias.LOWER_BOUND ? midSegment : closestSegment;\n } else if (midSegment.column > column) {\n high = mid - 1;\n closestSegment = bias === Bias.UPPER_BOUND ? midSegment : closestSegment;\n } else {\n return midSegment;\n }\n }\n }\n\n return closestSegment;\n }\n\n /**\n * Initializes the segment offsets used to track the current decoding position.\n *\n * @param namesOffset - The offset for the names index.\n * @param sourceIndex - The offset for the source index.\n * @returns { SegmentOffsetInterface } - The initialized segment offset.\n */\n\n private initPositionOffsets(namesOffset: number = 0, sourceIndex: number = 0): SegmentOffsetInterface {\n return {\n line: 0,\n column: 0,\n nameIndex: namesOffset,\n sourceIndex: sourceIndex,\n generatedLine: 0,\n generatedColumn: 0\n };\n }\n\n /**\n * Validates the format of an encoded mapping string.\n *\n * @param encodedSourceMap - The encoded source map string to validate.\n * @returns Returns `true` if the format is valid, otherwise `false`.\n */\n\n private validateMappingString(encodedSourceMap: string): boolean {\n // /^(;+)?([a-z0-9+/]{1,10}(,|;+)?)+$/\n return /^[a-zA-Z0-9+/,;]+$/.test(encodedSourceMap);\n }\n\n /**\n * Validates the properties of a segment to ensure they conform to expected types.\n *\n * This method checks that the segment's properties are finite numbers and that\n * the nameIndex, if provided, is either a finite number or null.\n * An error is thrown if any of the properties do not meet the specified criteria.\n *\n * @param segment - The segment object to validate, which must conform to the\n * SegmentInterface structure, including:\n * - line: number (finite)\n * - column: number (finite)\n * - nameIndex: number | null (if not null, must be finite)\n * - sourceIndex: number (finite)\n * - generatedLine: number (finite)\n * - generatedColumn: number (finite)\n *\n * @throws {Error} - Throws an error if any property of the segment is invalid.\n * The error message will specify which property is invalid\n * and the value that was received.\n */\n\n private validateSegment(segment: SegmentInterface): void {\n if (!Number.isFinite(segment.line)) {\n throw new Error(`Invalid segment: line must be a finite number, received ${segment.line}`);\n }\n if (!Number.isFinite(segment.column)) {\n throw new Error(`Invalid segment: column must be a finite number, received ${segment.column}`);\n }\n if (segment.nameIndex !== null && !Number.isFinite(segment.nameIndex)) {\n throw new Error(`Invalid segment: nameIndex must be a number or null, received ${segment.nameIndex}`);\n }\n if (!Number.isFinite(segment.sourceIndex)) {\n throw new Error(`Invalid segment: sourceIndex must be a finite number, received ${segment.sourceIndex}`);\n }\n if (!Number.isFinite(segment.generatedLine)) {\n throw new Error(`Invalid segment: generatedLine must be a finite number, received ${segment.generatedLine}`);\n }\n if (!Number.isFinite(segment.generatedColumn)) {\n throw new Error(`Invalid segment: generatedColumn must be a finite number, received ${segment.generatedColumn}`);\n }\n }\n\n /**\n * Encodes a segment into a VLQ-encoded string based on the segment offsets.\n *\n * @param segmentOffset - The current segment offset.\n * @param segmentObject - The segment to encode.\n * @returns The encoded segment string.\n */\n\n private encodeSegment(segmentOffset: SegmentOffsetInterface, segmentObject: SegmentInterface): string {\n const { line, column, generatedColumn, nameIndex, sourceIndex } = segmentObject;\n const adjustedLine = line - 1;\n const adjustedColumn = column - 1;\n const adjustedGeneratedColumn = generatedColumn - 1;\n\n const segment: Array<number> = [\n adjustedGeneratedColumn - segmentOffset.generatedColumn, // generatedColumn difference\n sourceIndex !== segmentOffset.sourceIndex ? sourceIndex - segmentOffset.sourceIndex : 0, // sourceIndex difference\n adjustedLine - segmentOffset.line, // line difference\n adjustedColumn - segmentOffset.column // column difference\n ];\n\n if (nameIndex !== null && nameIndex !== undefined) {\n segment[4] = nameIndex - segmentOffset.nameIndex; // nameIndex difference\n segmentOffset.nameIndex = nameIndex;\n }\n\n segmentOffset.line = adjustedLine;\n segmentOffset.column = adjustedColumn;\n segmentOffset.generatedColumn = adjustedGeneratedColumn;\n segmentOffset.sourceIndex = sourceIndex;\n\n return encodeArrayVLQ(segment);\n }\n\n /**\n * Encodes the entire mapping array into a VLQ-encoded mapping string.\n *\n * @param map - The mapping array to encode.\n * @returns The encoded mapping string.\n */\n\n private encodeMappings(map: MapType): string {\n const positionOffset = this.initPositionOffsets();\n\n return map.map(frame => {\n if (!frame)\n return '';\n\n positionOffset.generatedColumn = 0;\n const segments = frame.map(segment => this.encodeSegment(positionOffset, segment));\n\n return segments.join(',');\n }).join(';');\n }\n\n /**\n * Decodes a VLQ-encoded segment into a segment object based on the current offset.\n *\n * @param segmentOffset - The current segment offset.\n * @param decodedSegment - The decoded VLQ segment values.\n * @returns The decoded segment object.\n */\n\n private decodedSegment(segmentOffset: SegmentOffsetInterface, decodedSegment: Array<number>): SegmentInterface {\n const [ generatedColumn, sourceIndex, sourceLine, sourceColumn, nameIndex ] = decodedSegment;\n segmentOffset.line += sourceLine;\n segmentOffset.column += sourceColumn;\n segmentOffset.nameIndex += nameIndex ?? 0;\n segmentOffset.sourceIndex += sourceIndex;\n segmentOffset.generatedColumn += generatedColumn;\n\n return {\n line: segmentOffset.line + 1,\n column: segmentOffset.column + 1,\n nameIndex: nameIndex !== undefined ? segmentOffset.nameIndex : null,\n sourceIndex: segmentOffset.sourceIndex,\n generatedLine: segmentOffset.generatedLine + 1,\n generatedColumn: segmentOffset.generatedColumn + 1\n };\n }\n\n /**\n * Decodes a VLQ-encoded mapping string into the internal mapping representation.\n *\n * @param encodedMap - The VLQ-encoded mapping string.\n * @param namesOffset - Offset for the names index.\n * @param sourceOffset - Offset for the sources index.\n * @throws { Error } - Throws an error if the mapping string is invalid.\n */\n\n private decodeMappingString(encodedMap: string, namesOffset: number, sourceOffset: number): void {\n if (!this.validateMappingString(encodedMap))\n throw new Error('Invalid Mappings string format: the provided string does not conform to expected VLQ format.');\n\n const frames = encodedMap.split(';');\n const linesOffset = this.mapping.length;\n const positionOffset = this.initPositionOffsets(namesOffset, sourceOffset);\n try {\n frames.forEach((frame, index) => {\n if (!frame) {\n this.mapping.push(null);\n\n return;\n }\n\n positionOffset.generatedColumn = 0;\n positionOffset.generatedLine = linesOffset + index;\n const segmentsArray: Array<SegmentInterface> = frame.split(',')\n .map(segment => this.decodedSegment(positionOffset, decodeVLQ(segment)));\n\n this.mapping.push(segmentsArray);\n });\n } catch (error) {\n throw new Error(`Error decoding mappings at frame index ${frames.length}: ${(<Error>error).message}`);\n }\n }\n\n /**\n * Decodes a mapping array into the internal mapping representation, adjusting for offsets.\n *\n * This method processes each frame in the provided structured mapping array,\n * validating each segment within the frame and adjusting the indices based on the\n * specified offsets for names and sources. If a frame is invalid or not an array,\n * an error will be thrown.\n *\n * @param encodedMap - The structured mapping array, which should be an array of frames,\n * where each frame is an array of segments. Each segment must conform\n * to the SegmentInterface.\n * @param namesOffset - Offset for the names index, which will be added to each segment's nameIndex.\n * @param sourceOffset - Offset for the sources index, which will be added to each segment's sourceIndex.\n * @throws { Error } - Throws an error if:\n * - The mapping array is invalid (not an array).\n * - Any frame is not an array.\n * - Any segment does not conform to the SegmentInterface.\n */\n\n private decodeMappingArray(encodedMap: MapType, namesOffset: number, sourceOffset: number): void {\n const linesOffset = this.mapping.length;\n if (!Array.isArray(encodedMap))\n throw new Error('Invalid encoded map: expected an array of frames.');\n\n try {\n encodedMap.forEach((frame, index) => {\n if (!frame) {\n this.mapping.push(frame);\n\n return;\n }\n\n if (!Array.isArray(frame))\n throw new Error(`Invalid Mappings array format at frame index ${index}: expected an array, received ${typeof frame}.`);\n\n const segments: FrameType = frame.map(segment => {\n this.validateSegment(segment);\n\n return {\n ...segment,\n nameIndex: (typeof segment.nameIndex === 'number') ? segment.nameIndex + namesOffset : null,\n sourceIndex: segment.sourceIndex + sourceOffset,\n generatedLine: segment.generatedLine + linesOffset\n };\n });\n\n this.mapping.push(segments);\n });\n } catch (error: unknown) {\n const errorMessage = (error instanceof Error) ? error.message : 'Unknown error';\n throw new Error(`Error decoding mappings: ${errorMessage}`);\n }\n }\n}\n", "/**\n * Import will remove at compile time\n */\n\nimport type {\n PositionInterface,\n SourceMapInterface,\n SourceOptionsInterface,\n PositionWithCodeInterface,\n PositionWithContentInterface\n} from '@services/interfaces/source.interface';\n\n/**\n * Imports\n */\n\nimport { MappingProvider } from '@providers/mapping.provider';\nimport { Bias } from '@providers/interfaces/mapping.interface';\n\n/**\n * A service for validating and processing source maps.\n * This class allows parsing and manipulation of source maps, providing functionality such as\n * retrieving position mappings between original and generated code, concatenating source maps,\n * and getting code snippets based on mappings.\n *\n * @example\n * ```ts\n * const sourceMapJSON = '{\"version\": 3, \"file\": \"bundle.js\", \"sources\": [\"foo.ts\"], \"names\": [], \"mappings\": \"AAAA\"}';\n * const sourceService = new SourceService(sourceMapJSON);\n *\n * console.log(sourceService.file); // Outputs: 'bundle.js'\n * ```\n */\n\nexport class SourceService {\n /**\n * The name of the generated file (bundle) that this source map applies to.\n *\n * @example\n * ```ts\n * console.log(sourceService.file); // 'bundle.js'\n * ```\n */\n\n readonly file: string | null;\n\n /**\n * A MappingProvider instance of base64 VLQ-encoded mappings.\n */\n\n readonly mappings: MappingProvider;\n\n /**\n * The root URL for the sources, if present in the source map.\n */\n\n readonly sourceRoot: string | null;\n\n /**\n * A list of symbol names used by the \u201Cmappings\u201D entry.\n */\n\n readonly names: Array<string>;\n\n /**\n * An array of source file paths.\n */\n\n readonly sources: Array<string>;\n\n /**\n * An array of source files contents.\n */\n\n readonly sourcesContent: Array<string>;\n\n /**\n * Creates a new instance of the `SourceService` class.\n *\n * This constructor initializes the class using either a `SourceMapInterface` object,\n * a JSON string representing the source map, or an existing `SourceService` instance.\n * It validates the source map and populates its properties such as `file`, `sources`, and `mappings`.\n *\n * @param source - Can be one of the following:\n * - An object conforming to the `SourceMapInterface`.\n * - A JSON string representing the source map.\n * - A `SourceService` instance to copy the properties.\n * @param file - (Optional) A string representing the file name of the generated bundle.\n * Defaults to `null`. It will overwrite any existing `file` property in the source map.\n * @throws {Error} - If the source map does not contain required properties or has an invalid format.\n *\n * @example\n * ```ts\n * const sourceMapJSON = '{\"version\": 3, \"file\": \"bundle.js\", \"sources\": [\"foo.ts\"], \"names\": [], \"mappings\": \"AAAA\"}';\n * const sourceService = new SourceService(sourceMapJSON);\n * ```\n */\n\n constructor(source: SourceService);\n constructor(source: SourceMapInterface | string, file?: string | null);\n constructor(source: SourceService | SourceMapInterface | string, file: string | null = null) {\n if (typeof source === 'string') {\n source = <SourceMapInterface> JSON.parse(source);\n }\n\n source = <SourceMapInterface> source;\n this.validateSourceMap(source);\n this.file = source.file ?? file;\n this.names = [ ...source.names ?? [] ];\n this.sources = [ ...source.sources ?? [] ];\n this.sourceRoot = source.sourceRoot ?? null;\n this.sourcesContent = source.sourcesContent ? [ ...source.sourcesContent ] : [];;\n this.mappings = new MappingProvider(source.mappings);\n }\n\n /**\n * Converts the current source map data into a plain object format.\n *\n * @returns The source map json object.\n *\n * @example\n * ```ts\n * const mapObject = sourceService.getMapObject();\n * console.log(mapObject.file); // 'bundle.js'\n * ```\n */\n\n getMapObject(): SourceMapInterface {\n const sourceMap: SourceMapInterface = {\n version: 3,\n names: this.names,\n sources: this.sources,\n mappings: this.mappings.encode(),\n sourcesContent: this.sourcesContent\n };\n\n if (this.file)\n sourceMap.file = this.file;\n\n if (this.sourceRoot)\n sourceMap.sourceRoot = this.sourceRoot;\n\n return sourceMap;\n }\n\n /**\n * Concatenates one or more source maps to the current source map.\n *\n * This method merges additional source maps into the current source map,\n * updating the `mappings`, `names`, `sources`, and `sourcesContent` arrays.\n *\n * @param maps - An array of `SourceMapInterface` or `SourceService` instances to be concatenated.\n * @throws { Error } If no source maps are provided for concatenation.\n *\n * @example\n * ```ts\n * sourceService.concat(anotherSourceMap);\n * console.log(sourceService.sources); // Updated source paths\n * ```\n */\n\n concat(...maps: Array<SourceMapInterface | SourceService>): void {\n if (maps.length < 1)\n throw new Error('At least one map must be provided for concatenation.');\n\n for (const map of (maps as Array<SourceMapInterface>)) {\n this.mappings.decode(map.mappings, this.names.length, this.sources.length);\n this.names.push(...map.names);\n this.sources.push(...map.sources);\n this.sourcesContent.push(...map.sourcesContent ?? []);\n }\n }\n\n /**\n * Creates a new instance of `SourceService` with concatenated source maps.\n *\n * @param maps - An array of `SourceMapInterface` or `SourceService` instances to be concatenated.\n * @returns { SourceService } A new `SourceService` instance with the concatenated maps.\n * @throws { Error } If no source maps are provided.\n *\n * @example\n * ```ts\n * const newService = sourceService.concatNewMap(anotherSourceMap);\n * console.log(newService.file); // The file from the new source map\n * ```\n */\n\n concatNewMap(...maps: Array<SourceMapInterface | SourceService>): SourceService {\n if (maps.length < 1)\n throw new Error('At least one map must be provided for concatenation.');\n\n const sourceService = new SourceService(this);\n for (const map of (maps as Array<SourceMapInterface>)) {\n sourceService.mappings.decode(map.mappings, sourceService.names.length, sourceService.sources.length);\n sourceService.names.push(...map.names);\n sourceService.sources.push(...map.sources);\n sourceService.sourcesContent.push(...map.sourcesContent ?? []);\n }\n\n return sourceService;\n }\n\n /**\n * Retrieves the position information based on the original source line and column.\n *\n * @param line - The line number in the generated code.\n * @param column - The column number in the generated code.\n * @param sourceIndex - The index or file path of the original source.\n * @param bias - The bias to use when matching positions (`Bias.LOWER_BOUND`, `Bias.UPPER_BOUND`, or `Bias.BOUND`).\n * @returns { PositionInterface | null } The corresponding position in the original source, or `null` if not found.\n *\n * @example\n * ```ts\n * const position = sourceService.getPositionByOriginal(1, 10, 'foo.ts');\n * console.log(position?.line); // The line number in the original source\n * ```\n */\n\n getPositionByOriginal(line: number, column: number, sourceIndex: number | string, bias: Bias = Bias.BOUND): PositionInterface | null {\n let index = <number> sourceIndex;\n if (typeof sourceIndex === 'string')\n index = this.sources.findIndex(str => str.includes(sourceIndex));\n\n if (index < 0)\n return null;\n\n const segment = this.mappings.getOriginalSegment(line, column, index, bias);\n if (!segment)\n return null;\n\n return {\n name: this.names[segment.nameIndex ?? -1] ?? null,\n line: segment.line,\n column: segment.column,\n source: this.sources[segment.sourceIndex],\n sourceRoot: this.sourceRoot,\n sourceIndex: segment.sourceIndex,\n generatedLine: segment.generatedLine,\n generatedColumn: segment.generatedColumn\n };\n }\n\n /**\n * Retrieves the position in the original source code based on a given line and column\n * in the generated code.\n *\n * @param line - Line number in the generated code.\n * @param column - Column number in the generated code.\n * @param bias - The bias to use for matching positions. Defaults to `Bias.BOUND`.\n * @returns {PositionInterface | null} The position in the original source, or null if not found.\n *\n * @example\n * ```ts\n * const position = sourceService.getPosition(2, 15);\n * console.log(position?.source); // The original source file\n * ```\n */\n\n getPosition(line: number, column: number, bias: Bias = Bias.BOUND): PositionInterface | null {\n const segment = this.mappings.getSegment(line, column, bias);\n if (!segment)\n return null;\n\n return {\n name: this.names[segment.nameIndex ?? -1] ?? null,\n line: segment.line,\n column: segment.column,\n source: this.sources[segment.sourceIndex],\n sourceRoot: this.sourceRoot,\n sourceIndex: segment.sourceIndex,\n generatedLine: segment.generatedLine,\n generatedColumn: segment.generatedColumn\n };\n }\n\n /**\n * Retrieves the position and original source content for a given position in the generated code.\n *\n * @param line - Line number in the generated code.\n * @param column - Column number in the generated code.\n * @param bias - Bias used for position matching.\n * @returns { PositionWithContentInterface | null } The position and its associated content, or `null` if not found.\n *\n * @example\n * ```ts\n * const positionWithContent = sourceService.getPositionWithContent(3, 5);\n * console.log(positionWithContent?.sourcesContent); // The source code content\n * ```\n */\n\n getPositionWithContent(line: number, column: number, bias: Bias = Bias.BOUND): PositionWithContentInterface | null {\n const position = this.getPosition(line, column, bias);\n if (!position)\n return null;\n\n return {\n ...position,\n sourcesContent: this.sourcesContent[position.sourceIndex]\n };\n }\n\n /**\n * Retrieves the position and a code snippet from the original source based on the given\n * generated code position, with additional lines of code around the matching line.\n *\n * @param line - Line number in the generated code.\n * @param column - Column number in the generated code.\n * @param bias - Bias used for position matching.\n * @param options - (Optional) Extra options for the amount of surrounding lines to include.\n * @returns { PositionWithCodeInterface | null } The position and code snippet.\n *\n * @example\n * ```ts\n * const positionWithCode = sourceService.getPositionWithCode(4, 8, Bias.BOUND, { linesBefore: 2, linesAfter: 2 });\n * console.log(positionWithCode?.code); // The code snippet from the original source\n * ```\n */\n\n getPositionWithCode(line: number, column: number, bias: Bias = Bias.BOUND, options?: SourceOptionsInterface): PositionWithCodeInterface | null {\n const position = this.getPosition(line, column, bias);\n if (!position || !this.sourcesContent[position.sourceIndex])\n return null;\n\n const settings = Object.assign({\n linesAfter: 4,\n linesBefore: 3\n }, options);\n\n const code = this.sourcesContent[position.sourceIndex].split('\\n');\n const endLine = Math.min( (position.line ?? 1) + settings.linesAfter, code.length);\n const startLine = Math.max((position.line ?? 1) - settings.linesBefore, 0);\n const relevantCode = code.slice(startLine, Math.min(endLine + 1, code.length)).join('\\n');\n\n return {\n ...position,\n code: relevantCode,\n endLine: endLine,\n startLine: startLine\n };\n }\n\n /**\n * Converts the current source map object to a JSON string.\n *\n * @returns A stringified version of the source map object.\n *\n * @example\n * ```ts\n * console.log(sourceService.toString()); // JSON string of the source map\n * ```\n */\n\n toString(): string {\n return JSON.stringify(this.getMapObject());\n }\n\n /**\n * Validates the provided source map object.\n *\n * This method checks whether all required keys are present in the source map object.\n * It throws an error if any required keys are missing.\n *\n * @private\n * @param input - The source map object to be validated.\n * @throws Error If any required key is missing from the source map.\n *\n * @example\n * ```ts\n * const sourceMap = {\n * version: 3,\n * file: 'example.js',\n * names: ['src', 'maps', 'example', 'function', 'line', 'column'],\n * sources: ['source1.js', 'source2.js'],\n * mappings: 'AAAA,SAASA,CAAC,CAAC,CAAC;AAAA,CAAC,CAAC;AAAC,CAAC',\n * };\n * sourceService['validateSource'](sourceMap); // Throws if invalid\n * ```\n */\n\n private validateSourceMap(input: SourceMapInterface): void {\n const requiredKeys: (keyof SourceMapInterface)[] = [ 'sources', 'mappings', 'names' ];\n if (!requiredKeys.every(key => key in input)) {\n throw new Error('Missing required keys in SourceMap.');\n }\n }\n}\n"],
|
|
6
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,WAAAC,EAAA,kBAAAC,EAAA,cAAAC,EAAA,mBAAAC,EAAA,cAAAC,EAAA,eAAAC,EAAA,oBAAAC,EAAA,kBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAZ,GCaO,SAASa,EAAgBC,EAAiD,CAC7E,IAAMC,EAAQD,EAAY,MAAM;AAAA,CAAI,EAAE,MAAM,CAAC,EACvCE,EAAQ,sEACRC,EAAY,qDACZC,EAAoC,CAAC,EAE3C,OAAAH,EAAM,QAASI,GAAS,CACpB,IAAMC,EAAQD,EAAK,MAAMH,CAAK,EAC9B,GAAI,CAACI,EAAO,OAEZ,IAAIC,EAAsBD,EAAM,MAAM,CAAC,EACnCA,EAAM,CAAC,IACPC,EAAOD,EAAM,MAAM,CAAC,GAGxB,GAAM,CAAEE,EAAIC,EAAMC,EAASC,CAAO,EAAIJ,EAChCK,EAAa,SAASF,EAAS,EAAE,EACjCG,EAAe,SAASF,EAAQ,EAAE,EAExC,GAAIN,EAAK,SAAS,MAAM,EAAG,CACvB,IAAMS,EAAYL,EAAK,MAAMN,CAAS,GAAG,MAAM,CAAC,EAChD,GAAIW,EAAW,CACX,GAAM,CAAEC,EAAQC,EAAUC,EAAaC,EAAYC,CAAa,EAAIL,EACpEV,EAAM,KAAK,CACP,GAAAI,EACA,KAAMW,EACN,KAAMP,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AW,EAAE,MAAM;AAAA,CAAI,EAC3DI,EAAU,KAAK,KAAMJ,EAAS,MAAQ,GAAKE,EAAS,WAAYC,EAAK,MAAM,EAC3EE,EAAY,KAAK,KAAKL,EAAS,MAAQ,GAAKE,EAAS,YAAa,CAAC,EACnEI,EAAeH,EAAK,MAAME,EAAW,KAAK,IAAID,EAAU,EAAGD,EAAK,MAAM,CAAC,EAAE,KAAK;AAAA,CAAI,EAExF,MAAO,CACH,GAAGH,EACH,KAAMM,EACN,QAASF,EACT,UAAWC,CACf,CACJ,CAaA,UAAmB,CACf,OAAO,KAAK,UAAU,KAAK,aAAa,CAAC,CAC7C,CAyBQ,kBAAkBE,EAAiC,CAEvD,GAAI,CAD+C,CAAE,UAAW,WAAY,OAAQ,EAClE,MAAMC,GAAOA,KAAOD,CAAK,EACvC,MAAM,IAAI,MAAM,qCAAqC,CAE7D,CACJ",
|
|
7
|
-
"names": ["src_exports", "__export", "
|
|
3
|
+
"sources": ["../../src/index.ts", "../../src/components/base64.component.ts", "../../src/providers/mapping.provider.ts", "../../src/services/source.service.ts"],
|
|
4
|
+
"sourceRoot": "https://github.com/remotex-lab/xmap/tree/v3.0.0/",
|
|
5
|
+
"sourcesContent": ["// export services interfaces\nexport type { PositionInterface, SourceMapInterface, SourceOptionsInterface, PositionWithCodeInterface, PositionWithContentInterface } from '@services/interfaces/source-service.interface';\n// Export components\nexport { encodeVLQ, decodeVLQ, encodeArrayVLQ } from '@components/base64.component';\n// export service\nexport { SourceService } from '@services/source.service';\n", "// Bitmask to extract the lower 5 bits (continuation bit removed) - 0b11111\nconst CONTINUATION_BIT_REMOVE = 0x1F;\n// Bitmask to set the continuation bit - 0b100000\nconst CONTINUATION_BIT_POSITION = 0x20;\n// Mapping of Base64 characters to their indices\nconst base64Map: {\n [key: string]: number;\n} = {};\n// Array of Base64 characters\nconst base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');\n// Populate the base64Map with characters and their corresponding indices\nbase64Chars.forEach((char, index) => {\n base64Map[char] = index;\n});\n/**\n * Encodes a given number using Variable-Length Quantity (VLQ) encoding. Negative numbers are encoded by\n * converting to a non-negative representation and the continuation bit is used to indicate if more bytes follow.\n *\n * @param value - The number to be encoded\n * @returns The VLQ encoded string represented as Base64 characters\n *\n * @throws Error - If the value cannot be properly encoded\n *\n * @remarks The encoding process shifts the value left by 1 bit to accommodate a sign bit in the least significant position.\n * Negative values have their sign bit set to 1, while positive values have it set to 0.\n *\n * @example\n * ```ts\n * // Encoding a positive number\n * const encoded = encodeVLQ(25); // Returns \"Y\"\n *\n * // Encoding a negative number\n * const encodedNegative = encodeVLQ(-25); // Returns \"Z\"\n * ```\n *\n * @see decodeVLQ - For the corresponding decode function\n *\n * @since 1.0.0\n */\nexport function encodeVLQ(value: number): string {\n const isNegative = value < 0;\n /**\n * Bit Structure Representation:\n *\n * +--------------------------+\n * | C | Value | Sign |\n * +---+---+---+---+---+------+\n * | 1 | 1 | 0 | 0 | 1 | 0 |\n * +---+---+---+---+---+------+\n */\n let encoded = '';\n let vlq = isNegative ? ((-value) << 1) + 1 : (value << 1); // Shift left by 1 bit to encode the sign bit\n do {\n const digit = vlq & CONTINUATION_BIT_REMOVE; // Extract lower 5 bits\n vlq >>>= 5; // Right shift by 5 bits to process next chunk\n encoded += base64Chars[digit | (vlq > 0 ? CONTINUATION_BIT_POSITION : 0)]; // Combine digit and continuation bit\n } while (vlq > 0);\n return encoded;\n}\n/**\n * Encodes an array of numbers using VLQ encoding by individually encoding each number and concatenating the results.\n *\n * @param values - The array of numbers to be encoded\n * @returns The concatenated VLQ encoded string\n *\n * @example\n * ```ts\n * // Encoding multiple values\n * const encoded = encodeArrayVLQ([1, 0, -5]); // Returns \"CAAK\"\n * ```\n *\n * @see encodeVLQ - The underlying function used to encode each number\n *\n * @since 1.0.0\n */\nexport function encodeArrayVLQ(values: number[]): string {\n return values.map(encodeVLQ).join('');\n}\n/**\n * Decodes a VLQ encoded string back into an array of numbers by processing Base64 characters and continuation bits.\n *\n * @param data - The VLQ encoded string\n * @returns The array of decoded numbers\n *\n * @throws Error - If the string contains invalid Base64 characters\n *\n * @remarks The decoding process examines each Base64 character,\n * checking for continuation bits and progressively building up numeric values.\n * The sign bit is extracted from the least significant position\n * to determine if the original number was negative.\n *\n * @example\n * ```ts\n * // Decoding a simple VLQ string\n * const decoded = decodeVLQ(\"Y\"); // Returns [25]\n *\n * // Decoding multiple values\n * const multiDecoded = decodeVLQ(\"CAAK\"); // Returns [1, 0, -5]\n * ```\n *\n * @see encodeVLQ - For the corresponding encode function\n *\n * @since 1.0.0\n */\nexport function decodeVLQ(data: string): number[] {\n const result = [];\n let shift = 0;\n let value = 0;\n for (let i = 0; i < data.length; i++) {\n const digit = base64Map[data[i]];\n if (digit === undefined) {\n throw new Error(`Invalid Base64 character: ${data[i]}`);\n }\n const continuation = digit & CONTINUATION_BIT_POSITION; // Check if continuation bit is set\n value += (digit & CONTINUATION_BIT_REMOVE) << shift; // Add lower 5 bits to value\n if (continuation) {\n shift += 5; // Shift left by 5 for next chunk\n }\n else {\n const isNegative = (value & 1) === 1; // Check if the number is negative\n const shifted = value >> 1; // Remove the sign bit\n result.push(isNegative ? -shifted : shifted); // Convert back to signed integer\n value = shift = 0; // Reset for next number\n }\n }\n return result;\n}\n", "/**\n * Import will remove at compile time\n */\nimport type { MapType, FrameType, SegmentInterface, SegmentOffsetInterface } from './interfaces/mapping-provider.interface';\n/**\n * Imports\n */\nimport { Bias } from './interfaces/mapping-provider.interface';\nimport { decodeVLQ, encodeArrayVLQ } from '@components/base64.component';\n/**\n * Provides functionality for encoding and decoding source map mappings.\n *\n * The MappingProvider class handles the conversion between various mapping representations:\n * - String format (VLQ-encoded mappings)\n * - Structured array format (MapType)\n * - Internal structured representation\n *\n * It also provides methods to query and retrieve source map segments based on\n * generated or original source positions.\n *\n * @example\n * ```ts\n * // Create from VLQ-encoded mapping string\n * const provider = new MappingProvider(mappingString);\n *\n * // Get a segment by generated position\n * const segment = provider.getSegment(10, 15);\n *\n * // Convert back to mapping string\n * const encoded = provider.encode();\n * ```\n *\n * @since 1.0.0\n */\nexport class MappingProvider {\n private mapping: MapType = [];\n /**\n * Creates a new MappingProvider instance.\n *\n * @param mapping - Source map mapping data in one of three formats:\n * - VLQ-encoded string\n * - Structured array (MapType)\n * - Another MappingProvider instance (copy constructor)\n * @param namesOffset - Optional offset to apply to name indices (default: 0)\n * @param sourceOffset - Optional offset to apply to source indices (default: 0)\n *\n * @remarks\n * The constructor automatically detects the mapping format and decodes it accordingly.\n * When providing offsets, these values will be added to the corresponding indices\n * in the decoded mapping data, which is useful when concatenating multiple source maps.\n *\n * @since 1.0.0\n */\n constructor(mapping: string, namesOffset?: number, sourceOffset?: number);\n constructor(mapping: MapType, namesOffset?: number, sourceOffset?: number);\n constructor(mapping: MappingProvider, namesOffset?: number, sourceOffset?: number);\n constructor(mapping: MappingProvider | MapType | string, namesOffset = 0, sourcesOffset = 0) {\n mapping = mapping instanceof MappingProvider ? mapping.mapping : mapping;\n if (Array.isArray(mapping)) {\n this.decodeMappingArray(mapping, namesOffset, sourcesOffset);\n }\n else {\n this.decodeMappingString(mapping, namesOffset, sourcesOffset);\n }\n }\n /**\n * Encodes the internal mapping representation to a VLQ-encoded mapping string.\n *\n * @returns VLQ-encoded mapping string compatible with the source map format specification\n *\n * @remarks\n * This method converts the internal structured mapping representation into a compact\n * string format using Variable Length Quantity (VLQ) encoding.\n * The resulting string follows the source map v3 format for the 'mappings' field.\n *\n * @see https://sourcemaps.info/spec.html\n *\n * @since 1.0.0\n */\n encode(): string {\n return this.encodeMappings(this.mapping);\n }\n /**\n * Decodes mapping data into the internal representation.\n *\n * @param mapping - Mapping data to decode in one of three formats:\n * - VLQ-encoded string\n * - Structured array (MapType)\n * - Another MappingProvider instance\n * @param namesOffset - Optional offset for name indices (default: 0)\n * @param sourcesOffset - Optional offset for source indices (default: 0)\n *\n * @remarks\n * This method replaces the current internal mapping data with the newly decoded mapping.\n * The format of the input mapping is automatically detected and processed accordingly.\n *\n * @see MapType\n * @see MappingProvider\n *\n * @since 1.0.0\n */\n decode(mapping: MappingProvider | MapType | string, namesOffset = 0, sourcesOffset = 0): void {\n mapping = mapping instanceof MappingProvider ? mapping.mapping : mapping;\n if (Array.isArray(mapping)) {\n this.decodeMappingArray(mapping, namesOffset, sourcesOffset);\n }\n else {\n this.decodeMappingString(mapping, namesOffset, sourcesOffset);\n }\n }\n /**\n * Retrieves a segment based on a position in the generated code.\n *\n * @param generatedLine - Line number in generated code (1-based)\n * @param generatedColumn - Column number in generated code (0-based)\n * @param bias - Controls matching behavior when exact position not found:\n * - BOUND: No preference (default)\n * - LOWER_BOUND: Prefer segment with lower column\n * - UPPER_BOUND: Prefer segment with higher column\n * @returns Matching segment or null if not found\n *\n * @remarks\n * Uses binary search to efficiently locate matching segments.\n * When no exact match is found, the bias parameter determines which nearby segment to return.\n *\n * @since 1.0.0\n */\n getSegment(generatedLine: number, generatedColumn: number, bias: Bias = Bias.BOUND): SegmentInterface | null {\n const segments = this.mapping[generatedLine - 1];\n if (!segments || segments.length === 0)\n return null;\n let low = 0;\n let high = segments.length - 1;\n let closestSegment: SegmentInterface | null = null;\n while (low <= high) {\n const mid = Math.floor((low + high) / 2);\n const segment = segments[mid];\n if (segment.generatedColumn < generatedColumn) {\n low = mid + 1;\n closestSegment = bias === Bias.LOWER_BOUND ? segment : closestSegment;\n }\n else if (segment.generatedColumn > generatedColumn) {\n high = mid - 1;\n closestSegment = bias === Bias.UPPER_BOUND ? segment : closestSegment;\n }\n else {\n return segment;\n }\n }\n return closestSegment;\n }\n /**\n * Retrieves a segment based on a position in the original source code.\n *\n * @param line - Line number in original source (1-based)\n * @param column - Column number in original source (0-based)\n * @param sourceIndex - Index of source file in the sources array\n * @param bias - Controls matching behavior when exact position not found:\n * - BOUND: No preference (default)\n * - LOWER_BOUND: Prefer segment with lower column\n * - UPPER_BOUND: Prefer segment with higher column\n * @returns Matching segment or null if not found\n *\n * @remarks\n * Searches across all mapping segments to find those matching the specified original source position.\n * When multiple matches are possible, the bias\n * parameter determines which segment to return.\n *\n * This operation is more expensive than getSegment as it must potentially\n * scan the entire mapping structure.\n *\n * @since 1.0.0\n */\n getOriginalSegment(line: number, column: number, sourceIndex: number, bias: Bias = Bias.BOUND): SegmentInterface | null {\n let closestSegment: SegmentInterface | null = null;\n for (const segments of this.mapping) {\n if (!segments)\n continue;\n let low = 0;\n let high = segments.length - 1;\n while (low <= high) {\n const mid = Math.floor((low + high) / 2);\n const midSegment = segments[mid];\n if (midSegment.sourceIndex < sourceIndex || midSegment.line < line) {\n low = mid + 1;\n }\n else if (midSegment.sourceIndex > sourceIndex || midSegment.line > line) {\n high = mid - 1;\n }\n else if (midSegment.column < column) {\n low = mid + 1;\n closestSegment = bias === Bias.LOWER_BOUND ? midSegment : closestSegment;\n }\n else if (midSegment.column > column) {\n high = mid - 1;\n closestSegment = bias === Bias.UPPER_BOUND ? midSegment : closestSegment;\n }\n else {\n return midSegment;\n }\n }\n }\n return closestSegment;\n }\n /**\n * Initializes a new segment offset object with default values.\n *\n * @param namesOffset - Initial name index offset value (default: 0)\n * @param sourceIndex - Initial source index offset value (default: 0)\n * @returns A new segment offset object with initialized position tracking values\n *\n * @remarks\n * This method creates an object that tracks position data during mapping operations.\n * All position values (line, column, generatedLine, generatedColumn) are initialized to 0,\n * while the nameIndex and sourceIndex can be initialized with custom offsets.\n *\n * @since 1.0.0\n */\n private initPositionOffsets(namesOffset: number = 0, sourceIndex: number = 0): SegmentOffsetInterface {\n return {\n line: 0,\n column: 0,\n nameIndex: namesOffset,\n sourceIndex: sourceIndex,\n generatedLine: 0,\n generatedColumn: 0\n };\n }\n /**\n * Validates the format of an encoded mapping string.\n *\n * @param encodedSourceMap - The encoded source map string to validate\n * @returns `true` if the string contains only valid VLQ mapping characters, otherwise `false`\n *\n * @remarks\n * Checks if the string contains only characters valid in source map mappings:\n * - Base64 characters (a-z, A-Z, 0-9, +, /)\n * - Separators (commas for segments, semicolons for lines)\n *\n * This is a basic format validation and doesn't verify the semantic correctness\n * of the VLQ encoding itself.\n *\n * @since 1.0.0\n */\n private validateMappingString(encodedSourceMap: string): boolean {\n // /^(;+)?([a-z0-9+/]{1,10}(,|;+)?)+$/\n return /^[a-zA-Z0-9+/,;]+$/.test(encodedSourceMap);\n }\n /**\n * Validates that a segment's properties conform to expected types.\n *\n * @param segment - The segment object to validate\n *\n * @remarks\n * Performs the following validations on the segment properties:\n * - line: Must be a finite number\n * - column: Must be a finite number\n * - nameIndex: Must be either null or a finite number\n * - sourceIndex: Must be a finite number\n * - generatedLine: Must be a finite number\n * - generatedColumn: Must be a finite number\n *\n * This validation ensures that segments can be safely used in mapping operations\n * and prevents potential issues with non-numeric or infinite values.\n *\n * @throws Error - When any property of the segment is invalid, with a message\n * indicating which property failed validation and its value\n *\n * @since 1.0.0\n */\n private validateSegment(segment: SegmentInterface): void {\n if (!Number.isFinite(segment.line)) {\n throw new Error(`Invalid segment: line must be a finite number, received ${segment.line}`);\n }\n if (!Number.isFinite(segment.column)) {\n throw new Error(`Invalid segment: column must be a finite number, received ${segment.column}`);\n }\n if (segment.nameIndex !== null && !Number.isFinite(segment.nameIndex)) {\n throw new Error(`Invalid segment: nameIndex must be a number or null, received ${segment.nameIndex}`);\n }\n if (!Number.isFinite(segment.sourceIndex)) {\n throw new Error(`Invalid segment: sourceIndex must be a finite number, received ${segment.sourceIndex}`);\n }\n if (!Number.isFinite(segment.generatedLine)) {\n throw new Error(`Invalid segment: generatedLine must be a finite number, received ${segment.generatedLine}`);\n }\n if (!Number.isFinite(segment.generatedColumn)) {\n throw new Error(`Invalid segment: generatedColumn must be a finite number, received ${segment.generatedColumn}`);\n }\n }\n /**\n * Encodes a segment into a VLQ-encoded string based on relative offsets.\n *\n * @param segmentOffset - The current segment offset tracking state\n * @param segmentObject - The segment to encode\n * @returns A VLQ-encoded string representation of the segment\n *\n * @remarks\n * The encoding process:\n * 1. Adjusts line and column values (subtracts 1 to convert from 1-based to 0-based)\n * 2. Calculates relative differences between current values and previous offsets\n * 3. Creates an array with the following components:\n * - generatedColumn difference\n * - sourceIndex difference (0 if unchanged)\n * - line difference\n * - column difference\n * - nameIndex difference (only if nameIndex is present)\n * 4. Updates the segment offset state for the next encoding\n * 5. Returns the array as a VLQ-encoded string\n *\n * This method implements the source map V3 specification's delta encoding scheme\n * where values are stored as differences from previous positions.\n *\n * @since 1.0.0\n */\n private encodeSegment(segmentOffset: SegmentOffsetInterface, segmentObject: SegmentInterface): string {\n const { line, column, generatedColumn, nameIndex, sourceIndex } = segmentObject;\n const adjustedLine = line - 1;\n const adjustedColumn = column - 1;\n const adjustedGeneratedColumn = generatedColumn - 1;\n const segment: Array<number> = [\n adjustedGeneratedColumn - segmentOffset.generatedColumn, // generatedColumn difference\n sourceIndex !== segmentOffset.sourceIndex ? sourceIndex - segmentOffset.sourceIndex : 0, // sourceIndex difference\n adjustedLine - segmentOffset.line, // line difference\n adjustedColumn - segmentOffset.column // column difference\n ];\n if (nameIndex !== null && nameIndex !== undefined) {\n segment[4] = nameIndex - segmentOffset.nameIndex; // nameIndex difference\n segmentOffset.nameIndex = nameIndex;\n }\n segmentOffset.line = adjustedLine;\n segmentOffset.column = adjustedColumn;\n segmentOffset.generatedColumn = adjustedGeneratedColumn;\n segmentOffset.sourceIndex = sourceIndex;\n return encodeArrayVLQ(segment);\n }\n /**\n * Encodes a mapping array into a VLQ-encoded mapping string following the source map V3 spec.\n *\n * @param map - The mapping array to encode, organized by generated lines and segments\n * @returns A complete VLQ-encoded mapping string with line and segment separators\n *\n * @remarks\n * The encoding process:\n * 1. Initializes position offsets to track state across the entire mapping\n * 2. Processes each frame (line) in the mapping array:\n * - Resets generated column offset to 0 at the start of each line\n * - Encodes each segment within the line using relative VLQ encoding\n * - Joins segments with commas (,)\n * 3. Joins lines with semicolons (;)\n *\n * Empty frames are preserved as empty strings in the output to maintain\n * the correct line numbering in the resulting source map.\n *\n * @since 1.0.0\n */\n private encodeMappings(map: MapType): string {\n const positionOffset = this.initPositionOffsets();\n return map.map(frame => {\n if (!frame)\n return '';\n positionOffset.generatedColumn = 0;\n const segments = frame.map(segment => this.encodeSegment(positionOffset, segment));\n return segments.join(',');\n }).join(';');\n }\n /**\n * Converts a VLQ-decoded segment array into a structured segment object.\n *\n * @param segmentOffset - The current positional state tracking offsets\n * @param decodedSegment - Array of VLQ-decoded values representing relative offsets\n * @returns A complete segment object with absolute positions\n *\n * @remarks\n * The decoding process:\n * 1. Extracts position values from the decoded array:\n * - [0]: generatedColumn delta\n * - [1]: sourceIndex delta\n * - [2]: sourceLine delta\n * - [3]: sourceColumn delta\n * - [4]: nameIndex delta (optional)\n * 2. Updates the segmentOffset state by adding each delta\n * 3. Constructs a segment object with absolute positions (adding 1 to convert\n * from 0-based to 1-based coordinates)\n * 4. Handles nameIndex appropriately (null if not present in the input)\n *\n * This method implements the inverse operation of the delta encoding scheme\n * defined in the source map V3 specification.\n *\n * @since 1.0.0\n */\n private decodedSegment(segmentOffset: SegmentOffsetInterface, decodedSegment: Array<number>): SegmentInterface {\n const [generatedColumn, sourceIndex, sourceLine, sourceColumn, nameIndex] = decodedSegment;\n segmentOffset.line += sourceLine;\n segmentOffset.column += sourceColumn;\n segmentOffset.nameIndex += nameIndex ?? 0;\n segmentOffset.sourceIndex += sourceIndex;\n segmentOffset.generatedColumn += generatedColumn;\n return {\n line: segmentOffset.line + 1,\n column: segmentOffset.column + 1,\n nameIndex: nameIndex !== undefined ? segmentOffset.nameIndex : null,\n sourceIndex: segmentOffset.sourceIndex,\n generatedLine: segmentOffset.generatedLine + 1,\n generatedColumn: segmentOffset.generatedColumn + 1\n };\n }\n /**\n * Decodes a VLQ-encoded mapping string into the internal mapping data structure.\n *\n * @param encodedMap - The VLQ-encoded mapping string from a source map\n * @param namesOffset - Base offset for name indices in the global names array\n * @param sourceOffset - Base offset for source indices in the global sources array\n *\n * @remarks\n * The decoding process:\n * 1. Validates the mapping string format before processing\n * 2. Splits the string into frames using semicolons (;) as line separators\n * 3. Initializes position offsets with the provided name and source offsets\n * 4. For each frame (line):\n * - Adds `null` to the mapping array if the frame is empty\n * - Resets the generated column offset to 0 for each new line\n * - Sets the generated line index using the offset + current index\n * - Splits segments using commas (,) and decodes each segment\n * - Transforms each decoded segment into a segment object\n * 5. Updates the internal mapping array with the decoded data\n *\n * Error handling includes validation checks and descriptive error messages\n * indicating which frame caused a decoding failure.\n *\n * @throws Error - When the mapping string format is invalid or decoding fails\n *\n * @since 1.0.0\n */\n private decodeMappingString(encodedMap: string, namesOffset: number, sourceOffset: number): void {\n if (!this.validateMappingString(encodedMap))\n throw new Error('Invalid Mappings string format: the provided string does not conform to expected VLQ format.');\n const frames = encodedMap.split(';');\n const linesOffset = this.mapping.length;\n const positionOffset = this.initPositionOffsets(namesOffset, sourceOffset);\n try {\n frames.forEach((frame, index) => {\n if (!frame) {\n this.mapping.push(null);\n return;\n }\n positionOffset.generatedColumn = 0;\n positionOffset.generatedLine = linesOffset + index;\n const segmentsArray: Array<SegmentInterface> = frame.split(',')\n .map(segment => this.decodedSegment(positionOffset, decodeVLQ(segment)));\n this.mapping.push(segmentsArray);\n });\n }\n catch (error) {\n throw new Error(`Error decoding mappings at frame index ${frames.length}: ${(<Error>error).message}`);\n }\n }\n /**\n * Decodes a structured mapping array into the internal mapping representation.\n *\n * @param encodedMap - The structured mapping array (array of frames, with each frame being an array of segments)\n * @param namesOffset - Offset to add to each segment's nameIndex (for merging multiple source maps)\n * @param sourceOffset - Offset to add to each segment's sourceIndex (for merging multiple source maps)\n *\n * @remarks\n * The decoding process:\n * 1. Validates that the input is a properly structured array\n * 2. Tracks the current line offset based on the existing mapping length\n * 3. For each frame (line) in the mapping:\n * - Preserves null frames as-is (representing empty lines)\n * - Validates that each frame is an array\n * - For each segment in a frame:\n * - Validates the segment structure\n * - Applies the name and source offsets\n * - Adjusts the generated line index by the line offset\n * - Adds the processed frame to the internal mapping array\n *\n * This method is primarily used when combining multiple source maps or\n * importing mapping data from pre-structured arrays rather than VLQ strings.\n * The offsets enable proper indexing when concatenating multiple mappings.\n *\n * @throws Error - When the input format is invalid or segments don't conform to requirements\n *\n * @since 1.0.0\n */\n private decodeMappingArray(encodedMap: MapType, namesOffset: number, sourceOffset: number): void {\n const linesOffset = this.mapping.length;\n if (!Array.isArray(encodedMap))\n throw new Error('Invalid encoded map: expected an array of frames.');\n try {\n encodedMap.forEach((frame, index) => {\n if (!frame) {\n this.mapping.push(frame);\n return;\n }\n if (!Array.isArray(frame))\n throw new Error(`Invalid Mappings array format at frame index ${index}: expected an array, received ${typeof frame}.`);\n const segments: FrameType = frame.map(segment => {\n this.validateSegment(segment);\n return {\n ...segment,\n nameIndex: (typeof segment.nameIndex === 'number') ? segment.nameIndex + namesOffset : null,\n sourceIndex: segment.sourceIndex + sourceOffset,\n generatedLine: segment.generatedLine + linesOffset\n };\n });\n this.mapping.push(segments);\n });\n }\n catch (error: unknown) {\n const errorMessage = (error instanceof Error) ? error.message : 'Unknown error';\n throw new Error(`Error decoding mappings: ${errorMessage}`);\n }\n }\n}\n", "/**\n * Import will remove at compile time\n */\nimport type { PositionInterface, SourceMapInterface, SourceOptionsInterface, PositionWithCodeInterface, PositionWithContentInterface } from '@services/interfaces/source-service.interface';\n/**\n * Imports\n */\nimport { MappingProvider } from '@providers/mapping.provider';\nimport { Bias } from '@providers/interfaces/mapping-provider.interface';\n/**\n * A service for validating and processing source maps that provides functionality for parsing,\n * position mapping, concatenation, and code snippet extraction.\n *\n * @param source - Source map data (SourceService, SourceMapInterface object, or JSON string)\n * @param file - Optional file name for the generated bundle\n * @returns A new SourceService instance\n *\n * @example\n * ```ts\n * const sourceMapJSON = '{\"version\": 3, \"file\": \"bundle.js\", \"sources\": [\"foo.ts\"], \"names\": [], \"mappings\": \"AAAA\"}';\n * const sourceService = new SourceService(sourceMapJSON);\n * console.log(sourceService.file); // 'bundle.js'\n * ```\n *\n * @since 1.0.0\n */\nexport class SourceService {\n /**\n * The name of the generated file this source map applies to.\n *\n * @since 1.0.0\n */\n readonly file: string | null;\n /**\n * Provider for accessing and manipulating the base64 VLQ-encoded mappings.\n *\n * @since 1.0.0\n */\n readonly mappings: MappingProvider;\n /**\n * The root URL for resolving relative paths in the source files.\n * @since 1.0.0\n */\n readonly sourceRoot: string | null;\n /**\n * List of symbol names referenced by the mappings.\n * @since 1.0.0\n */\n readonly names: Array<string>;\n /**\n * Array of source file paths.\n * @since 1.0.0\n */\n readonly sources: Array<string>;\n /**\n * Array of source file contents.\n * @since 1.0.0\n */\n readonly sourcesContent: Array<string>;\n /**\n * Creates a new SourceService instance.\n *\n * @param source - Source map data (SourceService, SourceMapInterface object, or JSON string)\n * @param file - Optional file name for the generated bundle\n *\n * @throws Error - When a source map has an invalid format or missing required properties\n *\n * @since 1.0.0\n */\n constructor(source: SourceService);\n constructor(source: SourceMapInterface | string, file?: string | null);\n constructor(source: SourceService | SourceMapInterface | string, file: string | null = null) {\n if (typeof source === 'string') {\n source = <SourceMapInterface>JSON.parse(source);\n }\n source = <SourceMapInterface>source;\n this.validateSourceMap(source);\n this.file = source.file ?? file;\n this.names = [...source.names ?? []];\n this.sources = [...source.sources ?? []];\n this.sourceRoot = source.sourceRoot ?? null;\n this.sourcesContent = source.sourcesContent ? [...source.sourcesContent] : [];\n ;\n this.mappings = new MappingProvider(source.mappings);\n }\n /**\n * Converts the source map data to a plain object.\n *\n * @returns A SourceMapInterface object representing the current state\n *\n * @example\n * ```ts\n * const mapObject = sourceService.getMapObject();\n * console.log(mapObject.file); // 'bundle.js'\n * ```\n *\n * @since 1.0.0\n */\n getMapObject(): SourceMapInterface {\n const sourceMap: SourceMapInterface = {\n version: 3,\n names: this.names,\n sources: this.sources,\n mappings: this.mappings.encode(),\n sourcesContent: this.sourcesContent\n };\n if (this.file)\n sourceMap.file = this.file;\n if (this.sourceRoot)\n sourceMap.sourceRoot = this.sourceRoot;\n return sourceMap;\n }\n /**\n * Concatenates additional source maps into the current instance.\n *\n * @param maps - Source maps to concatenate with the current map\n *\n * @example\n * ```ts\n * sourceService.concat(anotherSourceMap);\n * console.log(sourceService.sources); // Updated source paths\n * ```\n *\n * @throws Error - When no maps are provided\n *\n * @since 1.0.0\n */\n concat(...maps: Array<SourceMapInterface | SourceService>): void {\n if (maps.length < 1)\n throw new Error('At least one map must be provided for concatenation.');\n for (const map of (maps as Array<SourceMapInterface>)) {\n this.mappings.decode(map.mappings, this.names.length, this.sources.length);\n this.names.push(...map.names);\n this.sources.push(...map.sources);\n this.sourcesContent.push(...map.sourcesContent ?? []);\n }\n }\n /**\n * Creates a new SourceService instance with concatenated source maps.\n *\n * @param maps - Source maps to concatenate with a copy of the current map\n * @returns A new SourceService instance with the combined maps\n *\n * @example\n * ```ts\n * const newService = sourceService.concatNewMap(anotherSourceMap);\n * console.log(newService.sources); // Combined sources array\n * ```\n *\n * @throws Error - When no maps are provided\n *\n * @since 1.0.0\n */\n concatNewMap(...maps: Array<SourceMapInterface | SourceService>): SourceService {\n if (maps.length < 1)\n throw new Error('At least one map must be provided for concatenation.');\n const sourceService = new SourceService(this);\n for (const map of (maps as Array<SourceMapInterface>)) {\n sourceService.mappings.decode(map.mappings, sourceService.names.length, sourceService.sources.length);\n sourceService.names.push(...map.names);\n sourceService.sources.push(...map.sources);\n sourceService.sourcesContent.push(...map.sourcesContent ?? []);\n }\n return sourceService;\n }\n /**\n * Finds position in generated code based on original source position.\n *\n * @param line - Line number in the original source\n * @param column - Column number in the original source\n * @param sourceIndex - Index or file path of the original source\n * @param bias - Position matching strategy (default: Bias.BOUND)\n * @returns Position information or null if not found\n *\n * @example\n * ```ts\n * const position = sourceService.getPositionByOriginal(1, 10, 'foo.ts');\n * console.log(position?.generatedLine); // Line in generated code\n * ```\n *\n * @since 1.0.0\n */\n getPositionByOriginal(line: number, column: number, sourceIndex: number | string, bias: Bias = Bias.BOUND): PositionInterface | null {\n let index = <number>sourceIndex;\n if (typeof sourceIndex === 'string')\n index = this.sources.findIndex(str => str.includes(sourceIndex));\n if (index < 0)\n return null;\n const segment = this.mappings.getOriginalSegment(line, column, index, bias);\n if (!segment)\n return null;\n return {\n name: this.names[segment.nameIndex ?? -1] ?? null,\n line: segment.line,\n column: segment.column,\n source: this.sources[segment.sourceIndex],\n sourceRoot: this.sourceRoot,\n sourceIndex: segment.sourceIndex,\n generatedLine: segment.generatedLine,\n generatedColumn: segment.generatedColumn\n };\n }\n /**\n * Finds position in an original source based on generated code position.\n *\n * @param line - Line number in the generated code\n * @param column - Column number in the generated code\n * @param bias - Position matching strategy (default: Bias.BOUND)\n * @returns Position information or null if not found\n *\n * @example\n * ```ts\n * const position = sourceService.getPosition(2, 15);\n * console.log(position?.source); // Original source file\n * ```\n *\n * @since 1.0.0\n */\n getPosition(line: number, column: number, bias: Bias = Bias.BOUND): PositionInterface | null {\n const segment = this.mappings.getSegment(line, column, bias);\n if (!segment)\n return null;\n return {\n name: this.names[segment.nameIndex ?? -1] ?? null,\n line: segment.line,\n column: segment.column,\n source: this.sources[segment.sourceIndex],\n sourceRoot: this.sourceRoot,\n sourceIndex: segment.sourceIndex,\n generatedLine: segment.generatedLine,\n generatedColumn: segment.generatedColumn\n };\n }\n /**\n * Retrieves position with source content for a location in generated code.\n *\n * @param line - Line number in the generated code\n * @param column - Column number in the generated code\n * @param bias - Position matching strategy (default: Bias.BOUND)\n * @returns Position with content information or null if not found\n *\n * @example\n * ```ts\n * const posWithContent = sourceService.getPositionWithContent(3, 5);\n * console.log(posWithContent?.sourcesContent); // Original source content\n * ```\n *\n * @since 1.0.0\n */\n getPositionWithContent(line: number, column: number, bias: Bias = Bias.BOUND): PositionWithContentInterface | null {\n const position = this.getPosition(line, column, bias);\n if (!position)\n return null;\n return {\n ...position,\n sourcesContent: this.sourcesContent[position.sourceIndex]\n };\n }\n /**\n * Retrieves position with a code snippet from the original source.\n *\n * @param line - Line number in the generated code\n * @param column - Column number in the generated code\n * @param bias - Position matching strategy (default: Bias.BOUND)\n * @param options - Configuration for the amount of surrounding lines\n * @returns Position with code snippet or null if not found\n *\n * @example\n * ```ts\n * const posWithCode = sourceService.getPositionWithCode(4, 8, Bias.BOUND, {\n * linesBefore: 2,\n * linesAfter: 2\n * });\n * console.log(posWithCode?.code); // Code snippet with context\n * ```\n *\n * @since 1.0.0\n */\n getPositionWithCode(line: number, column: number, bias: Bias = Bias.BOUND, options?: SourceOptionsInterface): PositionWithCodeInterface | null {\n const position = this.getPosition(line, column, bias);\n if (!position || !this.sourcesContent[position.sourceIndex])\n return null;\n const settings = Object.assign({\n linesAfter: 4,\n linesBefore: 3\n }, options);\n const code = this.sourcesContent[position.sourceIndex].split('\\n');\n const endLine = Math.min((position.line ?? 1) + settings.linesAfter, code.length);\n const startLine = Math.max((position.line ?? 1) - settings.linesBefore, 0);\n const relevantCode = code.slice(startLine, Math.min(endLine + 1, code.length)).join('\\n');\n return {\n ...position,\n code: relevantCode,\n endLine: endLine,\n startLine: startLine\n };\n }\n /**\n * Serializes the source map to a JSON string.\n *\n * @returns JSON string representation of the source map\n *\n * @example\n * ```ts\n * const jsonString = sourceService.toString();\n * console.log(jsonString); // '{\"version\":3,\"file\":\"bundle.js\",...}'\n * ```\n *\n * @since 1.0.0\n */\n toString(): string {\n return JSON.stringify(this.getMapObject());\n }\n /**\n * Validates a source map object has all required properties.\n *\n * @param input - Source map object to validate\n *\n * @throws Error - When required properties are missing\n *\n * @since 1.0.0\n */\n private validateSourceMap(input: SourceMapInterface): void {\n const requiredKeys: (keyof SourceMapInterface)[] = ['sources', 'mappings', 'names'];\n if (!requiredKeys.every(key => key in input)) {\n throw new Error('Missing required keys in SourceMap.');\n }\n }\n}\n"],
|
|
6
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,cAAAC,EAAA,mBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAN,GCKA,IAAMO,EAEF,CAAC,EAECC,EAAc,mEAAmE,MAAM,EAAE,EAE/FA,EAAY,QAAQ,CAACC,EAAMC,IAAU,CACjCH,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,CAC3B,WAAY,EACZ,YAAa,CACjB,EAAGD,CAAO,EACJE,EAAO,KAAK,eAAeH,EAAS,WAAW,EAAE,MAAM;AAAA,CAAI,EAC3DI,EAAU,KAAK,KAAKJ,EAAS,MAAQ,GAAKE,EAAS,WAAYC,EAAK,MAAM,EAC1EE,EAAY,KAAK,KAAKL,EAAS,MAAQ,GAAKE,EAAS,YAAa,CAAC,EACnEI,EAAeH,EAAK,MAAME,EAAW,KAAK,IAAID,EAAU,EAAGD,EAAK,MAAM,CAAC,EAAE,KAAK;AAAA,CAAI,EACxF,MAAO,CACH,GAAGH,EACH,KAAMM,EACN,QAASF,EACT,UAAWC,CACf,CACJ,CAcA,UAAmB,CACf,OAAO,KAAK,UAAU,KAAK,aAAa,CAAC,CAC7C,CAUQ,kBAAkBE,EAAiC,CAEvD,GAAI,CAD+C,CAAC,UAAW,WAAY,OAAO,EAChE,MAAMC,GAAOA,KAAOD,CAAK,EACvC,MAAM,IAAI,MAAM,qCAAqC,CAE7D,CACJ",
|
|
7
|
+
"names": ["src_exports", "__export", "SourceService", "decodeVLQ", "encodeArrayVLQ", "encodeVLQ", "__toCommonJS", "base64Map", "base64Chars", "char", "index", "encodeVLQ", "value", "isNegative", "encoded", "vlq", "digit", "encodeArrayVLQ", "values", "decodeVLQ", "data", "result", "shift", "i", "continuation", "shifted", "MappingProvider", "_MappingProvider", "mapping", "namesOffset", "sourcesOffset", "generatedLine", "generatedColumn", "bias", "segments", "low", "high", "closestSegment", "mid", "segment", "line", "column", "sourceIndex", "midSegment", "encodedSourceMap", "segmentOffset", "segmentObject", "nameIndex", "adjustedLine", "adjustedColumn", "adjustedGeneratedColumn", "encodeArrayVLQ", "map", "positionOffset", "frame", "decodedSegment", "sourceLine", "sourceColumn", "encodedMap", "sourceOffset", "frames", "linesOffset", "index", "segmentsArray", "decodeVLQ", "error", "errorMessage", "SourceService", "_SourceService", "source", "file", "MappingProvider", "sourceMap", "maps", "map", "sourceService", "line", "column", "sourceIndex", "bias", "index", "str", "segment", "position", "options", "settings", "code", "endLine", "startLine", "relevantCode", "input", "key"]
|
|
8
8
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";var d=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var D=(n,e)=>{for(var t in e)d(n,t,{get:e[t],enumerable:!0})},k=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of g(e))!R.call(n,a)&&a!==t&&d(n,a,{get:()=>e[a],enumerable:!(r=v(e,a))||r.enumerable});return n};var C=n=>k(d({},"__esModule",{value:!0}),n);var T={};D(T,{JSEngines:()=>f,createDefaultFrame:()=>u,detectJSEngine:()=>m,normalizePath:()=>s,parseErrorStack:()=>O,parseJavaScriptCoreStackLine:()=>N,parseSpiderMonkeyStackLine:()=>S,parseStackLine:()=>p,parseV8StackLine:()=>l,safeParseInt:()=>i});module.exports=C(T);var o={V8:{STANDARD:/at\s+(?:([^(]+?)\s+)?\(?(?:(.+?):(\d+):(\d+)|(native))\)?/,EVAL:/^at\s(.+?)\s\(eval\sat\s(.+?)\s?\((.*):(\d+):(\d+)\),\s(.+?):(\d+):(\d+)\)$/},SPIDERMONKEY:{EVAL:/^(.*)@(.+?):(\d+):(\d+),\s(.+?)@(.+?):(\d+):(\d+)$/,STANDARD:/^(.*)@(.*?)(?:(\[native code\])|:(\d+):(\d+))$/},JAVASCRIPT_CORE:{STANDARD:/^(?:(global|eval)\s)?(.*)@(.*?)(?::(\d+)(?::(\d+))?)?$/}},f=(a=>(a[a.V8=0]="V8",a[a.SPIDERMONKEY=1]="SPIDERMONKEY",a[a.JAVASCRIPT_CORE=2]="JAVASCRIPT_CORE",a[a.UNKNOWN=3]="UNKNOWN",a))(f||{});function m(n){return n.startsWith(" at ")||n.startsWith("at ")?0:n.includes("@")?/(?:global|eval) code@/.test(n)?2:1:3}function s(n){return n.startsWith("file://")?n.startsWith("file:///")&&/^file:\/\/\/[A-Za-z]:/.test(n)?n.substring(8):n.substring(7):(n=n.replace(/\\/g,"/"),n)}function u(n){return{source:n,eval:!1,async:!1,native:!1,constructor:!1}}function i(n){return n&&n.trim()!==""?parseInt(n,10):void 0}function l(n){let e=u(n),t=n.match(o.V8.EVAL);if(t)return e.eval=!0,e.functionName=t[1]?t[1]:void 0,e.evalOrigin={line:i(t[4])??void 0,column:i(t[5])??void 0,fileName:t[3]?s(t[3]):void 0,functionName:t[2]||"<anonymous>"},e.line=i(t[7])??void 0,e.column=i(t[8])??void 0,e.fileName=t[6]?s(t[6]):void 0,e.native=(e.fileName??"").startsWith("node")??!1,e;let r=n.match(o.V8.STANDARD);return r&&(e.functionName=r[1]?r[1].trim():void 0,n.toLowerCase().includes("new")&&(e.constructor=!0),n.toLowerCase().includes("async")&&(e.async=!0),r[5]==="native"?(e.native=!0,e.fileName="[native code]"):(e.line=i(r[3])??void 0,e.column=i(r[4])??void 0,e.fileName=r[2]?s(r[2]):void 0,e.native=(e.fileName??"").startsWith("node")??!1)),e}function S(n){let e=u(n),t=n.match(o.SPIDERMONKEY.EVAL);if(t)return e.eval=!0,e.functionName=t[1]?t[1]:void 0,n.toLowerCase().includes("constructor")&&(e.constructor=!0),n.toLowerCase().includes("async")&&(e.async=!0),e.evalOrigin={line:i(t[7])??void 0,column:i(t[8])??void 0,fileName:s(t[6]),functionName:t[5]?t[5]:void 0},e.line=i(t[3])??void 0,e.column=i(t[4])??void 0,e;let r=n.match(o.SPIDERMONKEY.STANDARD);return r&&(e.functionName=r[1]?r[1]:void 0,e.fileName=s(r[2]),r[3]==="[native code]"?e.fileName="[native code]":(e.line=i(r[4])??void 0,e.column=i(r[5])??void 0)),e}function N(n){let e=u(n),t=n.match(o.JAVASCRIPT_CORE.STANDARD);return t&&(e.functionName=t[2],e.eval=t[1]==="eval"||t[3]==="eval",n.toLowerCase().includes("constructor")&&(e.constructor=!0),n.toLowerCase().includes("async")&&(e.async=!0),t[3]==="[native code]"?(e.native=!0,e.fileName="[native code]"):(e.line=i(t[4])??void 0,e.column=i(t[5])??void 0,e.fileName=s(t[3]))),e}function p(n,e){switch(e){case 1:return S(n);case 2:return N(n);case 0:default:return l(n)}}function O(n){let e=typeof n=="string"?new Error(n):n,t=e.stack||"",r=e.message||"",a=e.name||"Error",A=m(t),E=t.split(`
|
|
2
|
+
`).map(c=>c.trim()).filter(c=>c.trim()!=="").slice(1);return{name:a,message:r,stack:E.map(c=>p(c,A)),rawStack:t}}0&&(module.exports={JSEngines,createDefaultFrame,detectJSEngine,normalizePath,parseErrorStack,parseJavaScriptCoreStackLine,parseSpiderMonkeyStackLine,parseStackLine,parseV8StackLine,safeParseInt});
|
|
3
|
+
//# sourceMappingURL=parser.component.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/parser.component.ts"],
|
|
4
|
+
"sourceRoot": "https://github.com/remotex-lab/xmap/tree/v3.0.0/",
|
|
5
|
+
"sourcesContent": ["/**\n * Export interfaces\n */\nexport { ParsedStackTrace, StackFrame } from '@components/interfaces/parse-component.interface';\n/**\n * Import will remove at compile time\n */\nimport type { ParsedStackTrace, StackFrame } from '@components/interfaces/parse-component.interface';\n/**\n * Regular expression patterns for different JavaScript engines' stack traces\n *\n * @since 2.1.0\n */\nconst PATTERNS = {\n V8: {\n STANDARD: /at\\s+(?:([^(]+?)\\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 * Enumeration of JavaScript engines that can be detected from stack traces\n *\n * @since 2.1.0\n */\nexport const enum JSEngines {\n V8,\n SPIDERMONKEY,\n JAVASCRIPT_CORE,\n UNKNOWN\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 */\nexport function detectJSEngine(stack: string): JSEngines {\n if (stack.startsWith(' at ') || stack.startsWith('at '))\n return JSEngines.V8;\n if (stack.includes('@'))\n return /(?:global|eval) code@/.test(stack)\n ? JSEngines.JAVASCRIPT_CORE : JSEngines.SPIDERMONKEY;\n return JSEngines.UNKNOWN;\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 */\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 // Handle *nix file:// format\n return filePath.substring(7);\n }\n // Handle Windows-style paths with backward slashes\n filePath = filePath.replace(/\\\\/g, '/');\n return filePath;\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 */\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 * 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 */\nexport function safeParseInt(value: string | undefined | null): number | undefined {\n return value && value.trim() !== '' ? parseInt(value, 10) : undefined;\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 */\nexport function parseV8StackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\n // Check for eval format first\n const evalMatch = line.match(PATTERNS.V8.EVAL);\n if (evalMatch) {\n frame.eval = true;\n frame.functionName = evalMatch[1] ? evalMatch[1] : undefined;\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 // 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 frame.native = (frame.fileName ?? '').startsWith('node') ?? false;\n return frame;\n }\n // Standard V8 format\n const match = line.match(PATTERNS.V8.STANDARD);\n if (match) {\n frame.functionName = match[1] ? match[1].trim() : undefined;\n if (line.toLowerCase().includes('new'))\n frame.constructor = true;\n if (line.toLowerCase().includes('async'))\n frame.async = true;\n if (match[5] === 'native') {\n frame.native = true;\n frame.fileName = '[native code]';\n }\n else {\n frame.line = safeParseInt(match[3]) ?? undefined;\n frame.column = safeParseInt(match[4]) ?? undefined;\n frame.fileName = match[2] ? normalizePath(match[2]) : undefined;\n frame.native = (frame.fileName ?? '').startsWith('node') ?? false;\n }\n }\n return frame;\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 */\nexport function parseSpiderMonkeyStackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\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 if (line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n if (line.toLowerCase().includes('async'))\n frame.async = true;\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 // Position inside evaluated code\n frame.line = safeParseInt(evalMatch[3]) ?? undefined;\n frame.column = safeParseInt(evalMatch[4]) ?? undefined;\n return frame;\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 if (match[3] === '[native code]') {\n frame.fileName = '[native code]';\n }\n else {\n frame.line = safeParseInt(match[4]) ?? undefined;\n frame.column = safeParseInt(match[5]) ?? undefined;\n }\n }\n return frame;\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 */\nexport function parseJavaScriptCoreStackLine(line: string): StackFrame {\n const frame = createDefaultFrame(line);\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 if (line.toLowerCase().includes('constructor'))\n frame.constructor = true;\n if (line.toLowerCase().includes('async'))\n frame.async = true;\n if (match[3] === '[native code]') {\n frame.native = true;\n frame.fileName = '[native code]';\n }\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 return frame;\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 */\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 * 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 */\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 const engine = detectJSEngine(stack);\n const stackLines = stack.split('\\n')\n .map(line => line.trim())\n .filter(line => line.trim() !== '')\n .slice(1);\n return {\n name,\n message,\n stack: stackLines.map(line => parseStackLine(line, engine)),\n rawStack: stack\n };\n}\n"],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EAAaM,EAAM,CAAC,CAAC,GAAK,OACzCF,EAAM,SAAWR,EAAcU,EAAM,CAAC,CAAC,IAGxCF,CACX,CAyBO,SAASK,EAAeN,EAAcO,EAA+B,CACxE,OAAQA,EAAQ,CACZ,IAAK,GACD,OAAOH,EAA2BJ,CAAI,EAC1C,IAAK,GACD,OAAOK,EAA6BL,CAAI,EAC5C,IAAK,GACL,QACI,OAAOD,EAAiBC,CAAI,CACpC,CACJ,CA+BO,SAASQ,EAAgBC,EAAyC,CACrE,IAAMC,EAAW,OAAOD,GAAU,SAAW,IAAI,MAAMA,CAAK,EAAIA,EAC1DjB,EAAQkB,EAAS,OAAS,GAC1BC,EAAUD,EAAS,SAAW,GAC9BE,EAAOF,EAAS,MAAQ,QACxBH,EAAShB,EAAeC,CAAK,EAC7BqB,EAAarB,EAAM,MAAM;AAAA,CAAI,EAC9B,IAAIQ,GAAQA,EAAK,KAAK,CAAC,EACvB,OAAOA,GAAQA,EAAK,KAAK,IAAM,EAAE,EACjC,MAAM,CAAC,EACZ,MAAO,CACH,KAAAY,EACA,QAAAD,EACA,MAAOE,EAAW,IAAIb,GAAQM,EAAeN,EAAMO,CAAM,CAAC,EAC1D,SAAUf,CACd,CACJ",
|
|
7
|
+
"names": ["parser_component_exports", "__export", "JSEngines", "createDefaultFrame", "detectJSEngine", "normalizePath", "parseErrorStack", "parseJavaScriptCoreStackLine", "parseSpiderMonkeyStackLine", "parseStackLine", "parseV8StackLine", "safeParseInt", "__toCommonJS", "PATTERNS", "JSEngines", "detectJSEngine", "stack", "normalizePath", "filePath", "createDefaultFrame", "source", "safeParseInt", "value", "parseV8StackLine", "line", "frame", "evalMatch", "match", "parseSpiderMonkeyStackLine", "parseJavaScriptCoreStackLine", "parseStackLine", "engine", "parseErrorStack", "error", "errorObj", "message", "name", "stackLines"]
|
|
8
|
+
}
|
|
@@ -1,26 +1,70 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Encodes a given number using Variable-Length Quantity (VLQ) encoding.
|
|
3
|
-
*
|
|
4
|
-
* The continuation bit is used to indicate if more bytes follow.
|
|
2
|
+
* Encodes a given number using Variable-Length Quantity (VLQ) encoding. Negative numbers are encoded by
|
|
3
|
+
* converting to a non-negative representation and the continuation bit is used to indicate if more bytes follow.
|
|
5
4
|
*
|
|
6
|
-
* @param value - The number to be encoded
|
|
7
|
-
* @returns The VLQ encoded string
|
|
5
|
+
* @param value - The number to be encoded
|
|
6
|
+
* @returns The VLQ encoded string represented as Base64 characters
|
|
7
|
+
*
|
|
8
|
+
* @throws Error - If the value cannot be properly encoded
|
|
9
|
+
*
|
|
10
|
+
* @remarks The encoding process shifts the value left by 1 bit to accommodate a sign bit in the least significant position.
|
|
11
|
+
* Negative values have their sign bit set to 1, while positive values have it set to 0.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Encoding a positive number
|
|
16
|
+
* const encoded = encodeVLQ(25); // Returns "Y"
|
|
17
|
+
*
|
|
18
|
+
* // Encoding a negative number
|
|
19
|
+
* const encodedNegative = encodeVLQ(-25); // Returns "Z"
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @see decodeVLQ - For the corresponding decode function
|
|
23
|
+
*
|
|
24
|
+
* @since 1.0.0
|
|
8
25
|
*/
|
|
9
26
|
export declare function encodeVLQ(value: number): string;
|
|
10
27
|
/**
|
|
11
|
-
* Encodes an array of numbers using VLQ encoding.
|
|
12
|
-
*
|
|
28
|
+
* Encodes an array of numbers using VLQ encoding by individually encoding each number and concatenating the results.
|
|
29
|
+
*
|
|
30
|
+
* @param values - The array of numbers to be encoded
|
|
31
|
+
* @returns The concatenated VLQ encoded string
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* // Encoding multiple values
|
|
36
|
+
* const encoded = encodeArrayVLQ([1, 0, -5]); // Returns "CAAK"
|
|
37
|
+
* ```
|
|
13
38
|
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
39
|
+
* @see encodeVLQ - The underlying function used to encode each number
|
|
40
|
+
*
|
|
41
|
+
* @since 1.0.0
|
|
16
42
|
*/
|
|
17
43
|
export declare function encodeArrayVLQ(values: number[]): string;
|
|
18
44
|
/**
|
|
19
|
-
* Decodes a VLQ encoded string back into an array of numbers.
|
|
20
|
-
*
|
|
45
|
+
* Decodes a VLQ encoded string back into an array of numbers by processing Base64 characters and continuation bits.
|
|
46
|
+
*
|
|
47
|
+
* @param data - The VLQ encoded string
|
|
48
|
+
* @returns The array of decoded numbers
|
|
49
|
+
*
|
|
50
|
+
* @throws Error - If the string contains invalid Base64 characters
|
|
51
|
+
*
|
|
52
|
+
* @remarks The decoding process examines each Base64 character,
|
|
53
|
+
* checking for continuation bits and progressively building up numeric values.
|
|
54
|
+
* The sign bit is extracted from the least significant position
|
|
55
|
+
* to determine if the original number was negative.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* // Decoding a simple VLQ string
|
|
60
|
+
* const decoded = decodeVLQ("Y"); // Returns [25]
|
|
61
|
+
*
|
|
62
|
+
* // Decoding multiple values
|
|
63
|
+
* const multiDecoded = decodeVLQ("CAAK"); // Returns [1, 0, -5]
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @see encodeVLQ - For the corresponding encode function
|
|
21
67
|
*
|
|
22
|
-
* @
|
|
23
|
-
* @returns The array of decoded numbers.
|
|
24
|
-
* @throws Error If the string contains invalid Base64 characters.
|
|
68
|
+
* @since 1.0.0
|
|
25
69
|
*/
|
|
26
70
|
export declare function decodeVLQ(data: string): number[];
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Export interfaces
|
|
3
|
+
*/
|
|
4
|
+
export type { AnsiOptionInterface, FormatCodeInterface } from "./interfaces/formatter-component.interface";
|
|
1
5
|
/**
|
|
2
6
|
* Import will remove at compile time
|
|
3
7
|
*/
|
|
4
|
-
import type { PositionWithCodeInterface } from "../services/interfaces/source.interface";
|
|
5
|
-
import type { AnsiOptionInterface, FormatCodeInterface } from "./interfaces/formatter.interface";
|
|
8
|
+
import type { PositionWithCodeInterface } from "../services/interfaces/source-service.interface";
|
|
9
|
+
import type { AnsiOptionInterface, FormatCodeInterface } from "./interfaces/formatter-component.interface";
|
|
6
10
|
/**
|
|
7
|
-
* Formats a code snippet with optional line padding and custom actions
|
|
11
|
+
* Formats a code snippet with optional line padding and custom actions
|
|
12
|
+
*
|
|
13
|
+
* @param code - The source code | stack to be formatted
|
|
14
|
+
* @param options - Configuration options for formatting the code
|
|
15
|
+
* @returns A formatted string of the code snippet with applied padding and custom actions
|
|
8
16
|
*
|
|
17
|
+
* @remarks
|
|
9
18
|
* This function takes a code string and an options object to format the code snippet.
|
|
10
19
|
* It applies padding to line numbers and can trigger custom actions for specific lines.
|
|
11
|
-
*
|
|
12
|
-
* @param code - The source code | stack to be formatted.
|
|
13
|
-
* @param options - Configuration options for formatting the code.
|
|
14
|
-
* - `padding` (number, optional): Number of characters for line number padding. Defaults to 10.
|
|
15
|
-
* - `startLine` (number, optional): The starting line number for formatting. Defaults to 1.
|
|
16
|
-
* - `action` (object, optional): Custom actions to apply to specific lines.
|
|
17
|
-
* - `triggerLine` (number): The line number where the action should be triggered.
|
|
18
|
-
* - `callback` (function): A callback function to format the line string when `triggerLine` is matched.
|
|
19
|
-
* The callback receives the formatted line string, the padding value, and the current line number as arguments.
|
|
20
|
-
*
|
|
21
|
-
* @returns A formatted string of the code snippet with applied padding and custom actions.
|
|
20
|
+
* Options include padding (default 10), startLine (default 0), and custom actions for specific lines.
|
|
22
21
|
*
|
|
23
22
|
* @example
|
|
24
|
-
* ```
|
|
23
|
+
* ```ts
|
|
25
24
|
* const formattedCode = formatCode(code, {
|
|
26
25
|
* padding: 8,
|
|
27
26
|
* startLine: 5,
|
|
@@ -32,35 +31,38 @@ import type { AnsiOptionInterface, FormatCodeInterface } from "./interfaces/form
|
|
|
32
31
|
* }
|
|
33
32
|
* }
|
|
34
33
|
* });
|
|
35
|
-
* console.log(formattedCode);
|
|
36
34
|
* ```
|
|
35
|
+
*
|
|
36
|
+
* @since 1.0.0
|
|
37
37
|
*/
|
|
38
38
|
export declare function formatCode(code: string, options?: FormatCodeInterface): string;
|
|
39
39
|
/**
|
|
40
|
-
* Formats a code snippet around an error location with special highlighting
|
|
41
|
-
*
|
|
42
|
-
* This function takes a `sourcePosition` object containing information about the source code
|
|
43
|
-
* and error location, then uses `formatCode` to format and highlight the relevant code snippet.
|
|
40
|
+
* Formats a code snippet around an error location with special highlighting
|
|
44
41
|
*
|
|
45
|
-
* @param sourcePosition - An object containing information about the source code and error location
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* - `column` (number): The column number within the line where the error occurred (1-based indexing).
|
|
49
|
-
* - `startLine` (number, optional): The starting line number of the code snippet (defaults to 1).
|
|
50
|
-
* @param ansiOption - Optional configuration for ANSI color codes.
|
|
51
|
-
* - `color` (string): The ANSI escape sequence to colorize the error marker and prefix (e.g., `'\x1b[38;5;160m'`).
|
|
52
|
-
* - `reset` (string): The ANSI escape sequence to reset the color (e.g., `'\x1b[0m'`).
|
|
42
|
+
* @param sourcePosition - An object containing information about the source code and error location
|
|
43
|
+
* @param ansiOption - Optional configuration for ANSI color codes
|
|
44
|
+
* @returns A formatted string representing the relevant code snippet with error highlighting
|
|
53
45
|
*
|
|
54
|
-
* @throws Error - If the provided
|
|
55
|
-
* or if the error line is outside the boundaries of the provided code content.
|
|
46
|
+
* @throws Error - If the provided sourcePosition object has invalid line or column numbers
|
|
56
47
|
*
|
|
57
|
-
* @
|
|
58
|
-
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* This function takes a sourcePosition object with code content and error location information,
|
|
50
|
+
* then uses formatCode to format and highlight the relevant code snippet around the error.
|
|
51
|
+
* The sourcePosition object should contain code (string), line (number), column (number),
|
|
52
|
+
* and optional startLine (number, defaults to 1).
|
|
59
53
|
*
|
|
60
54
|
* @example
|
|
61
|
-
* ```
|
|
62
|
-
* const formattedErrorCode = formatErrorCode(
|
|
63
|
-
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* const formattedErrorCode = formatErrorCode({
|
|
57
|
+
* code: "const x = 1;\nconst y = x.undefined;\n",
|
|
58
|
+
* line: 2,
|
|
59
|
+
* column: 15,
|
|
60
|
+
* startLine: 1
|
|
61
|
+
* });
|
|
64
62
|
* ```
|
|
63
|
+
*
|
|
64
|
+
* @see formatCode - The underlying function used for basic code formatting
|
|
65
|
+
*
|
|
66
|
+
* @since 1.0.0
|
|
65
67
|
*/
|
|
66
68
|
export declare function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string;
|