mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-20 16:22:56 +02:00
Fix infinite loop detection
Also debounce it with the ram calc to improve performance
This commit is contained in:
@@ -192,10 +192,15 @@ function parseOnlyRamCalculate(otherScripts: Map<ScriptFilePath, Script>, code:
|
||||
}
|
||||
|
||||
export function checkInfiniteLoop(code: string): number {
|
||||
const ast = parse(code, { sourceType: "module", ecmaVersion: "latest" });
|
||||
|
||||
let ast: acorn.Node;
|
||||
try {
|
||||
ast = parse(code, { sourceType: "module", ecmaVersion: "latest" });
|
||||
} catch (e) {
|
||||
// If code cannot be parsed, do not provide infinite loop detection warning
|
||||
return -1;
|
||||
}
|
||||
function nodeHasTrueTest(node: acorn.Node): boolean {
|
||||
return node.type === "Literal" && (node as any).raw === "true";
|
||||
return node.type === "Literal" && "raw" in node && node.raw === "true";
|
||||
}
|
||||
|
||||
function hasAwait(ast: acorn.Node): boolean {
|
||||
|
||||
Reference in New Issue
Block a user