forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.js
More file actions
142 lines (117 loc) · 3.37 KB
/
ast.js
File metadata and controls
142 lines (117 loc) · 3.37 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* 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 {
getSource,
getSourceFromId,
hasSymbols,
getSelectedLocation,
isPaused
} from "../selectors";
import { mapFrames, fetchExtra } from "./pause";
import { setInScopeLines } from "./ast/setInScopeLines";
import {
getSymbols,
findOutOfScopeLocations,
getFramework,
getPausePoints
} from "../workers/parser";
import { PROMISE } from "./utils/middleware/promise";
import { isGeneratedId } from "devtools-source-map";
import { features } from "../utils/prefs";
import { isLoaded } from "../utils/source";
import type { SourceId } from "../types";
import type { ThunkArgs, Action } from "./types";
export function setSourceMetaData(sourceId: SourceId) {
return async ({ dispatch, getState }: ThunkArgs) => {
const source = getSource(getState(), sourceId);
if (!source || !isLoaded(source) || source.isWasm) {
return;
}
const framework = await getFramework(source.id);
dispatch(
({
type: "SET_SOURCE_METADATA",
sourceId: source.id,
sourceMetaData: {
framework
}
}: Action)
);
};
}
export function setSymbols(sourceId: SourceId) {
return async ({ dispatch, getState }: ThunkArgs) => {
const source = getSourceFromId(getState(), sourceId);
if (source.isWasm || hasSymbols(getState(), source)) {
return;
}
await dispatch({
type: "SET_SYMBOLS",
sourceId,
[PROMISE]: getSymbols(sourceId)
});
if (isPaused(getState())) {
await dispatch(fetchExtra());
await dispatch(mapFrames());
}
await dispatch(setPausePoints(sourceId));
await dispatch(setSourceMetaData(sourceId));
};
}
export function setOutOfScopeLocations() {
return async ({ dispatch, getState }: ThunkArgs) => {
const location = getSelectedLocation(getState());
if (!location) {
return;
}
const source = getSourceFromId(getState(), location.sourceId);
let locations = null;
if (location.line && source && isPaused(getState())) {
locations = await findOutOfScopeLocations(source.id, location);
}
dispatch(
({
type: "OUT_OF_SCOPE_LOCATIONS",
locations
}: Action)
);
dispatch(setInScopeLines());
};
}
function compressPausePoints(pausePoints) {
const compressed = {};
for (const line in pausePoints) {
compressed[line] = {};
for (const col in pausePoints[line]) {
const point = pausePoints[line][col];
compressed[line][col] = (point.break && 1) | (point.step && 2);
}
}
return compressed;
}
export function setPausePoints(sourceId: SourceId) {
return async ({ dispatch, getState, client }: ThunkArgs) => {
const source = getSourceFromId(getState(), sourceId);
if (!features.pausePoints || !source || !source.text) {
return;
}
if (source.isWasm) {
return;
}
const pausePoints = await getPausePoints(sourceId);
const compressed = compressPausePoints(pausePoints);
if (isGeneratedId(sourceId)) {
await client.setPausePoints(sourceId, compressed);
}
dispatch(
({
type: "SET_PAUSE_POINTS",
sourceText: source.text || "",
sourceId,
pausePoints
}: Action)
);
};
}