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
50 lines (41 loc) · 1.41 KB
/
ast.js
File metadata and controls
50 lines (41 loc) · 1.41 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
/* 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 { without, range } from "lodash";
import type { Source, Position } from "../types";
import type { PausePoint, SymbolDeclarations } from "../workers/parser";
export function findBestMatchExpression(
symbols: SymbolDeclarations,
tokenPos: Position
) {
const { memberExpressions, identifiers } = symbols;
const { line, column } = tokenPos;
return identifiers.concat(memberExpressions).reduce((found, expression) => {
const overlaps =
expression.location.start.line == line &&
expression.location.start.column <= column &&
expression.location.end.column >= column &&
!expression.computed;
if (overlaps) {
return expression;
}
return found;
}, null);
}
export function findEmptyLines(
selectedSource: Source,
pausePoints: PausePoint[]
) {
if (!pausePoints || !selectedSource) {
return [];
}
const breakpoints = pausePoints.filter(point => point.types.breakpoint);
const breakpointLines = breakpoints.map(point => point.location.line);
if (!selectedSource.text) {
return [];
}
const lineCount = selectedSource.text.split("\n").length;
const sourceLines = range(1, lineCount + 1);
return without(sourceLines, ...breakpointLines);
}