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
44 lines (36 loc) · 1.4 KB
/
steps.js
File metadata and controls
44 lines (36 loc) · 1.4 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
/* 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/>. */
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;
}