summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/utils/source-maps.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /devtools/client/debugger/src/utils/source-maps.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/debugger/src/utils/source-maps.js')
-rw-r--r--devtools/client/debugger/src/utils/source-maps.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/utils/source-maps.js b/devtools/client/debugger/src/utils/source-maps.js
new file mode 100644
index 0000000000..fb8dd005ee
--- /dev/null
+++ b/devtools/client/debugger/src/utils/source-maps.js
@@ -0,0 +1,88 @@
+/* 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 { isOriginalId } from "devtools/client/shared/source-map-loader/index";
+import { getSource, getLocationSource } from "../selectors";
+
+export async function getGeneratedLocation(
+ state,
+ source,
+ location,
+ sourceMapLoader
+) {
+ if (!isOriginalId(location.sourceId)) {
+ return location;
+ }
+
+ const { line, sourceId, column } = await sourceMapLoader.getGeneratedLocation(
+ location
+ );
+
+ const generatedSource = getSource(state, sourceId);
+ if (!generatedSource) {
+ throw new Error(`Could not find generated source ${sourceId}`);
+ }
+
+ return {
+ line,
+ sourceId,
+ column: column === 0 ? undefined : column,
+ sourceUrl: generatedSource.url,
+ };
+}
+
+export async function getOriginalLocation(generatedLocation, sourceMapLoader) {
+ if (isOriginalId(generatedLocation.sourceId)) {
+ return location;
+ }
+
+ return sourceMapLoader.getOriginalLocation(generatedLocation);
+}
+
+export async function getMappedLocation(state, sourceMapLoader, location) {
+ const source = getLocationSource(state, location);
+
+ if (!source) {
+ throw new Error(`no source ${location.sourceId}`);
+ }
+
+ if (isOriginalId(location.sourceId)) {
+ const generatedLocation = await getGeneratedLocation(
+ state,
+ source,
+ location,
+ sourceMapLoader
+ );
+ return { location, generatedLocation };
+ }
+
+ const generatedLocation = location;
+ const originalLocation = await sourceMapLoader.getOriginalLocation(
+ generatedLocation
+ );
+
+ return { location: originalLocation, generatedLocation };
+}
+
+/**
+ * Gets the "mapped location".
+ *
+ * If the passed location is on a generated source, it gets the
+ * related location in the original source.
+ * If the passed location is on an original source, it gets the
+ * related location in the generated source.
+ */
+export async function getRelatedMapLocation(state, sourceMapLoader, location) {
+ const source = getLocationSource(state, location);
+
+ if (!source) {
+ return location;
+ }
+
+ if (isOriginalId(location.sourceId)) {
+ return getGeneratedLocation(state, source, location, sourceMapLoader);
+ }
+
+ return sourceMapLoader.getOriginalLocation(location);
+}