summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/utils/selected-location.js
blob: a07877449fb90ebfbc51f9099b2916839eeb8027 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* 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/>. */

// @flow

import { isOriginalId } from "devtools-source-map";
import type { SourceLocation, MappedLocation, Source } from "../types";

export function getSelectedLocation(
  mappedLocation: MappedLocation,
  context: ?(Source | SourceLocation)
): SourceLocation {
  if (!context) {
    return mappedLocation.location;
  }

  // $FlowIgnore
  const sourceId = context.sourceId || context.id;
  return isOriginalId(sourceId)
    ? mappedLocation.location
    : mappedLocation.generatedLocation;
}