Fix infinite loop detection

Also debounce it with the ram calc to improve performance
This commit is contained in:
omuretsu
2023-05-16 11:27:11 -04:00
parent b44050cfec
commit 00522fb8f3
2 changed files with 34 additions and 37 deletions
+8 -3
View File
@@ -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 {