aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-debug-adapter-protocol/debugger/sourcemap.test.ts
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-08-24 22:53:34 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-24 22:53:34 -0700
commit1480889205d49cf7221a36608a8896b452967cea (patch)
treee1427e4041cf19ef1e8e8e0f58cfbbceb4cbbf74 /packages/bun-debug-adapter-protocol/debugger/sourcemap.test.ts
parentf269432d90826ad3e5b66c7685a6e826e0fb05e2 (diff)
downloadbun-1480889205d49cf7221a36608a8896b452967cea.tar.gz
bun-1480889205d49cf7221a36608a8896b452967cea.tar.zst
bun-1480889205d49cf7221a36608a8896b452967cea.zip
Improved support for `debug-adapter-protocol` (#4186)
* Improve support for \`debug-adapter-protocol\` * More improvements, fix formatting in debug console * Fix attaching * Prepare for source maps * Start of source map support, breakpoints work * Source map support * add some package.jsons * wip * Update package.json * More fixes * Make source maps safer if exception occurs * Check bun version if it fails * Fix console.log formatting * Fix source maps partly * More source map fixes * Prepare for extension * watch mode with dap * Improve preview code * Prepare for extension 2 --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'packages/bun-debug-adapter-protocol/debugger/sourcemap.test.ts')
-rw-r--r--packages/bun-debug-adapter-protocol/debugger/sourcemap.test.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/bun-debug-adapter-protocol/debugger/sourcemap.test.ts b/packages/bun-debug-adapter-protocol/debugger/sourcemap.test.ts
new file mode 100644
index 000000000..44d9ca362
--- /dev/null
+++ b/packages/bun-debug-adapter-protocol/debugger/sourcemap.test.ts
@@ -0,0 +1,31 @@
+import { test, expect } from "bun:test";
+import { readFileSync } from "node:fs";
+import { SourceMap } from "./sourcemap";
+
+test("works without source map", () => {
+ const sourceMap = getSourceMap("without-sourcemap.js");
+ expect(sourceMap.generatedLocation({ line: 7 })).toEqual({ line: 7, column: 0, verified: true });
+ expect(sourceMap.generatedLocation({ line: 7, column: 2 })).toEqual({ line: 7, column: 2, verified: true });
+ expect(sourceMap.originalLocation({ line: 11 })).toEqual({ line: 11, column: 0, verified: true });
+ expect(sourceMap.originalLocation({ line: 11, column: 2 })).toEqual({ line: 11, column: 2, verified: true });
+});
+
+test("works with source map", () => {
+ const sourceMap = getSourceMap("with-sourcemap.js");
+ // FIXME: Columns don't appear to be accurate for `generatedLocation`
+ expect(sourceMap.generatedLocation({ line: 3 })).toMatchObject({ line: 4, verified: true });
+ expect(sourceMap.generatedLocation({ line: 27 })).toMatchObject({ line: 20, verified: true });
+ expect(sourceMap.originalLocation({ line: 32 })).toEqual({ line: 43, column: 4, verified: true });
+ expect(sourceMap.originalLocation({ line: 13 })).toEqual({ line: 13, column: 6, verified: true });
+});
+
+function getSourceMap(filename: string): SourceMap {
+ const { pathname } = new URL(`./fixtures/${filename}`, import.meta.url);
+ const source = readFileSync(pathname, "utf-8");
+ const match = source.match(/\/\/# sourceMappingURL=(.*)$/m);
+ if (match) {
+ const [, url] = match;
+ return SourceMap(url);
+ }
+ return SourceMap();
+}