diff --git a/src/dataflow.js b/src/dataflow.js index f6a81606..ad6f156f 100644 --- a/src/dataflow.js +++ b/src/dataflow.js @@ -911,7 +911,7 @@ export function extractDataflow(tree, _filePath, _definitions, langId = 'javascr if (scope?.funcName) { const expr = node.namedChildren[0]; const referencedNames = []; - if (expr) collectIdentifiers(expr, referencedNames); + if (expr) collectIdentifiers(expr, referencedNames, rules); returns.push({ funcName: scope.funcName, expression: truncate(expr ? expr.text : ''), @@ -977,14 +977,17 @@ export function extractDataflow(tree, _filePath, _definitions, langId = 'javascr /** * Collect all identifier names referenced within a node. + * Uses isIdent() to support language-specific identifier node types + * (e.g. PHP's `variable_name`). */ -function collectIdentifiers(node, out) { - if (node.type === 'identifier') { +function collectIdentifiers(node, out, rules) { + if (!node) return; + if (isIdent(node.type, rules)) { out.push(node.text); return; } for (const child of node.namedChildren) { - collectIdentifiers(child, out); + collectIdentifiers(child, out, rules); } } diff --git a/tests/parsers/dataflow-php.test.js b/tests/parsers/dataflow-php.test.js index bc35123a..8d1d4cb3 100644 --- a/tests/parsers/dataflow-php.test.js +++ b/tests/parsers/dataflow-php.test.js @@ -32,12 +32,25 @@ describe('extractDataflow — PHP', () => { }); describe('returns', () => { - it('captures return expressions', () => { + it('captures return expressions with referencedNames', () => { const data = parseAndExtract(' { + const data = parseAndExtract(' r.funcName === 'add'); + expect(ret).toBeDefined(); + expect(ret.referencedNames).toContain('$a'); + expect(ret.referencedNames).toContain('$b'); + }); }); describe('assignments', () => {