summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/workers/pretty-print
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/debugger/src/workers/pretty-print')
-rw-r--r--devtools/client/debugger/src/workers/pretty-print/index.js25
-rw-r--r--devtools/client/debugger/src/workers/pretty-print/moz.build10
-rw-r--r--devtools/client/debugger/src/workers/pretty-print/worker.js41
3 files changed, 76 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/workers/pretty-print/index.js b/devtools/client/debugger/src/workers/pretty-print/index.js
new file mode 100644
index 0000000000..78ed2ab4fc
--- /dev/null
+++ b/devtools/client/debugger/src/workers/pretty-print/index.js
@@ -0,0 +1,25 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+import { prefs } from "../../utils/prefs";
+import { WorkerDispatcher } from "devtools/client/shared/worker-utils";
+
+const WORKER_URL =
+ "resource://devtools/client/debugger/dist/pretty-print-worker.js";
+
+export class PrettyPrintDispatcher extends WorkerDispatcher {
+ constructor(jestUrl) {
+ super(jestUrl || WORKER_URL);
+ }
+
+ #prettyPrintTask = this.task("prettyPrint");
+
+ prettyPrint({ url, text }) {
+ return this.#prettyPrintTask({
+ url,
+ indent: prefs.indentSize,
+ sourceText: text,
+ });
+ }
+}
diff --git a/devtools/client/debugger/src/workers/pretty-print/moz.build b/devtools/client/debugger/src/workers/pretty-print/moz.build
new file mode 100644
index 0000000000..b7223ac81a
--- /dev/null
+++ b/devtools/client/debugger/src/workers/pretty-print/moz.build
@@ -0,0 +1,10 @@
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DIRS += []
+
+CompiledModules(
+ "index.js",
+)
diff --git a/devtools/client/debugger/src/workers/pretty-print/worker.js b/devtools/client/debugger/src/workers/pretty-print/worker.js
new file mode 100644
index 0000000000..299da0b1c4
--- /dev/null
+++ b/devtools/client/debugger/src/workers/pretty-print/worker.js
@@ -0,0 +1,41 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+import prettyFast from "pretty-fast";
+
+import { workerHandler } from "devtools/client/shared/worker-utils";
+
+function prettyPrint({ url, indent, sourceText }) {
+ const prettified = prettyFast(sourceText, {
+ url,
+ indent: " ".repeat(indent),
+ });
+
+ return {
+ code: prettified.code,
+ mappings: invertMappings(prettified.map._mappings),
+ };
+}
+
+function invertMappings(mappings) {
+ return mappings._array.map(m => {
+ const mapping = {
+ generated: {
+ line: m.originalLine,
+ column: m.originalColumn,
+ },
+ };
+ if (m.source) {
+ mapping.source = m.source;
+ mapping.original = {
+ line: m.generatedLine,
+ column: m.generatedColumn,
+ };
+ mapping.name = m.name;
+ }
+ return mapping;
+ });
+}
+
+self.onmessage = workerHandler({ prettyPrint });