INNER CODE UNIT · JavaScript
analyzeWithBabel
Fausto-404/js-reverse-automation--skill · js-reverse-automation/scripts/ast_candidate_analyzer.js:83
function analyzeWithBabel(code, map) {
const ast = babelParser.parse(code, {
sourceType: "unambiguous",
errorRecovery: true,
plugins: ["jsx", "typescript", "classProperties", "optionalChaining", "dynamicImport", "decorators-legacy"]
});
walk(ast, null, (node, parent) => {
if (!["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression",
"ObjectMethod", "ClassMethod"].includes(node.type)) return;
addCandidate(map, code, nameOf(node, parent), node.start, node.end, "babel");
});
}
function analyzeFallback(code, map) {
const patterns = [
/function\s+([A-Za-z_$][\w$]*)\s*\([^)]*\)\s*\{/g,
/(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s*)?(?:function\s*)?\([^)]*\)\s*=>?\s*\{/g,
/([A-Za-z_$][\w$]*)\s*:\s*(?:async\s*)?function\s*\([^)]*\)\s*\{/g