forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteps.js
More file actions
40 lines (33 loc) · 1.2 KB
/
steps.js
File metadata and controls
40 lines (33 loc) · 1.2 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
import type { Source } from "debugger-html";
import { AstPosition } from "./types";
import { getClosestPath } from "./utils/closest";
import { isAwaitExpression, isYieldExpression } from "./utils/helpers";
import type { NodePath } from "babel-traverse";
export function getNextStep(source: Source, pausedPosition: AstPosition) {
const currentExpression = getSteppableExpression(source, pausedPosition);
if (!currentExpression) {
return null;
}
const currentStatement = currentExpression.getStatementParent();
return _getNextStep(currentStatement, pausedPosition);
}
function getSteppableExpression(source: Source, pausedPosition: AstPosition) {
const closestPath = getClosestPath(source, pausedPosition);
if (!closestPath) {
return null;
}
if (isAwaitExpression(closestPath) || isYieldExpression(closestPath)) {
return closestPath;
}
return closestPath.find(p => p.isAwaitExpression() || p.isYieldExpression());
}
function _getNextStep(statement: NodePath, position: AstPosition) {
const nextStatement = statement.getSibling(statement.key + 1);
if (nextStatement.node) {
return {
...nextStatement.node.loc.start,
sourceId: position.sourceId
};
}
return null;
}