diff options
-rw-r--r-- | packages/bun-debug-adapter-protocol/debugger/adapter.ts | 4 | ||||
-rw-r--r-- | packages/bun-debug-adapter-protocol/debugger/sourcemap.ts | 56 |
2 files changed, 39 insertions, 21 deletions
diff --git a/packages/bun-debug-adapter-protocol/debugger/adapter.ts b/packages/bun-debug-adapter-protocol/debugger/adapter.ts index 637edcafa..c86fb2d85 100644 --- a/packages/bun-debug-adapter-protocol/debugger/adapter.ts +++ b/packages/bun-debug-adapter-protocol/debugger/adapter.ts @@ -833,8 +833,10 @@ export class DebugAdapter implements IDebugAdapter, InspectorListener { async ["Debugger.scriptParsed"](event: JSC.Debugger.ScriptParsedEvent): Promise<void> { // HACK: remove once Bun starts sending correct source map urls - if (event.url && event.url.startsWith("/")) { + if (event.url && event.url.startsWith("/") && event.url.endsWith(".ts")) { event.sourceMapURL = generateSourceMapUrl(event.url); + } else { + event.sourceMapURL = undefined; } const { url, scriptId, sourceMapURL } = event; diff --git a/packages/bun-debug-adapter-protocol/debugger/sourcemap.ts b/packages/bun-debug-adapter-protocol/debugger/sourcemap.ts index df0fdc215..1e04e56f4 100644 --- a/packages/bun-debug-adapter-protocol/debugger/sourcemap.ts +++ b/packages/bun-debug-adapter-protocol/debugger/sourcemap.ts @@ -37,29 +37,45 @@ class ActualSourceMap implements SourceMap { } generatedPosition(line?: number, column?: number, url?: string): Position { - const source = this.#getSource(url); - const { line: gline, column: gcolumn } = this.#sourceMap.generatedPositionFor({ - line: line ?? 0, - column: column ?? 0, - source, - }); - console.log(`[sourcemap] -->`, { source, url, line, column }, { gline, gcolumn }); - return { - line: gline || 0, - column: gcolumn || 0, - }; + try { + const source = this.#getSource(url); + const { line: gline, column: gcolumn } = this.#sourceMap.generatedPositionFor({ + line: line ?? 0, + column: column ?? 0, + source, + }); + console.log(`[sourcemap] -->`, { source, url, line, column }, { gline, gcolumn }); + return { + line: gline || 0, + column: gcolumn || 0, + }; + } catch (error) { + console.error(error); + return { + line: line || 0, + column: column || 0, + }; + } } originalPosition(line?: number, column?: number): Position { - const { line: oline, column: ocolumn } = this.#sourceMap.originalPositionFor({ - line: line ?? 0, - column: column ?? 0, - }); - console.log(`[sourcemap] <--`, { line, column }, { oline, ocolumn }); - return { - line: oline || 0, - column: ocolumn || 0, - }; + try { + const { line: oline, column: ocolumn } = this.#sourceMap.originalPositionFor({ + line: line ?? 0, + column: column ?? 0, + }); + console.log(`[sourcemap] <--`, { line, column }, { oline, ocolumn }); + return { + line: oline || 0, + column: ocolumn || 0, + }; + } catch (error) { + console.error(error); + return { + line: line || 0, + column: column || 0, + }; + } } } |