forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource-maps.js
More file actions
66 lines (54 loc) · 1.6 KB
/
source-maps.js
File metadata and controls
66 lines (54 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* 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 { getSource } from "../selectors";
import type { SourceLocation, MappedLocation, Source } from "../types";
import { isGenerated } from "../utils/source";
export async function getGeneratedLocation(
state: Object,
source: Source,
location: SourceLocation,
sourceMaps: Object
): Promise<SourceLocation> {
if (!isOriginalId(location.sourceId)) {
return location;
}
const { line, sourceId, column } = await sourceMaps.getGeneratedLocation(
location,
source
);
const generatedSource = getSource(state, sourceId);
if (!generatedSource) {
return location;
}
return {
line,
sourceId,
column: column === 0 ? undefined : column,
sourceUrl: generatedSource.url
};
}
export async function getMappedLocation(
state: Object,
sourceMaps: Object,
location: SourceLocation
): Promise<SourceLocation> {
const source = getSource(state, location.sourceId);
if (!source) {
return location;
}
if (isOriginalId(location.sourceId)) {
return getGeneratedLocation(state, source, location, sourceMaps);
}
return sourceMaps.getOriginalLocation(location, source);
}
export function getSelectedLocation(
mappedLocation: MappedLocation,
selectedSource: ?Source
) {
return selectedSource && isGenerated(selectedSource)
? mappedLocation.generatedLocation
: mappedLocation.location;
}