UNPKG

@ai-capabilities-suite/mcp-debugger-core

Version:

Core debugging engine for Node.js and TypeScript applications. Provides Inspector Protocol integration, breakpoint management, variable inspection, execution control, profiling, hang detection, and source map support.

109 lines (108 loc) 4.02 kB
import { SourceMapConsumer } from "source-map"; /** * Source location in original source code (TypeScript) */ export interface SourceLocation { file: string; line: number; column: number; } /** * Source location in compiled code (JavaScript) */ export interface CompiledLocation { file: string; line: number; column: number; } /** * Manages source maps for a debug session * Handles loading, parsing, and caching of source maps * Requirements: 7.1 */ export declare class SourceMapManager { private sourceMapCache; private sourceMapPromises; /** * Load and parse a source map for a JavaScript file * Detects .map files alongside JavaScript files * Caches loaded source maps per session * @param jsFile Path to the JavaScript file * @returns SourceMapConsumer or null if no source map found */ loadSourceMap(jsFile: string): Promise<SourceMapConsumer | null>; /** * Internal method to load and parse a source map */ private loadSourceMapInternal; /** * Check if a source map exists for a JavaScript file * @param jsFile Path to the JavaScript file * @returns True if a source map exists */ hasSourceMap(jsFile: string): boolean; /** * Get a cached source map consumer * @param jsFile Path to the JavaScript file * @returns SourceMapConsumer or undefined if not cached */ getCachedSourceMap(jsFile: string): SourceMapConsumer | undefined; /** * Clear all cached source maps * Should be called when the session ends */ clearCache(): void; /** * Get the number of cached source maps */ getCacheSize(): number; /** * Map a TypeScript source location to JavaScript compiled location * Used when setting breakpoints in TypeScript files * Requirements: 7.2 * @param sourceLocation Original TypeScript location * @returns Compiled JavaScript location or null if mapping fails */ mapSourceToCompiled(sourceLocation: SourceLocation): Promise<CompiledLocation | null>; /** * Map a JavaScript compiled location back to TypeScript source location * Used when the debugger pauses to show the original source location * Requirements: 7.3 * @param compiledLocation Compiled JavaScript location * @returns Original TypeScript location or null if mapping fails */ mapCompiledToSource(compiledLocation: CompiledLocation): Promise<SourceLocation | null>; /** * Find the compiled JavaScript file for a TypeScript source file * @param sourceFile Path to the TypeScript file * @returns Path to the JavaScript file or null if not found */ private findCompiledFile; /** * Resolve the source file path from the source map * @param jsFile Path to the JavaScript file * @param sourcePath Source path from the source map (usually relative) * @returns Absolute path to the source file */ private resolveSourcePath; /** * Map a JavaScript variable name to its TypeScript source name * Uses the source map's names section for variable mapping * Requirements: 7.4 * @param jsFile Path to the JavaScript file * @param jsVariableName Variable name in the compiled JavaScript * @param line Line number where the variable is used * @param column Column number where the variable is used * @returns Original TypeScript variable name or null if mapping unavailable */ mapVariableName(jsFile: string, jsVariableName: string, line: number, column: number): Promise<string | null>; /** * Get all variable names at a specific location * This can be used to map all variables in a scope * @param jsFile Path to the JavaScript file * @param line Line number * @param column Column number * @returns Array of variable names from the source map */ getVariableNamesAtLocation(jsFile: string, line: number, column: number): Promise<string[]>; }