Repository navigation
fix(extractor): attribute file-scope calls to synthetic <file> caller (TS/JS, Python) - #722
Open
lalith0407 wants to merge 1 commit into
Open
lalith0407 wants to merge 1 commit into
lalith0407 wants to merge 1 commit into
Conversation
… (TS/JS, Python) extractCallGraph in the TypeScript and Python extractors only recorded a call when functionStack was non-empty, so module-level calls, __main__ guards, IIFEs and anonymous callbacks at file scope were dropped. Attribute them to the synthetic "<file>" caller (same convention as Egonex-AI#400 for PHP), export FILE_SCOPE_CALLER from core, and instruct the file-analyzer to map "<file>" to the file node rather than a function node.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #721 · Refs #367 · Follows the convention introduced in #400 (PHP)
extractCallGraph()in the TypeScript/JavaScript and Python extractors only recorded a call whenfunctionStack.length > 0. Any call outside a named function was silently dropped: module-level wiring (app.use(router),app = Flask(__name__)),if __name__ == "__main__":blocks, top-levelmain()invocations, IIFEs, and anonymous callbacks at file scope (items.forEach(x => register(x))). Entry-point, bootstrap, and config modules therefore ended up with an empty or near-empty call graph.Changes
<file>caller convention. When no enclosing named function exists, the call is now attributed to the synthetic caller"<file>", the same stable, language-neutral identifier fix(php-extractor): capture file-scope calls + map include/require as imports (#367) #400 uses for PHP. Calls inside named functions are unchanged.FILE_SCOPE_CALLERconstant. Addedexport const FILE_SCOPE_CALLER = "<file>"inplugins/extractors/types.tsand re-exported it from@understand-anything/core, so every extractor (and fix(php-extractor): capture file-scope calls + map include/require as imports (#367) #400's PHP fix, once merged) can share one definition instead of repeating the string.<file>to the file node. Edges are built by thefile-analyzeragent rather than a code-level merge step, so I added a note toagents/file-analyzer.md: acallerof"<file>"means file-scope code; never create a function node named<file>, use the file node (file:<path>) as the edge source.Question for maintainers: would you prefer this enforced in code instead (e.g. rewriting
<file>callers to the file node id inextract-structure-result.mjs/ the merge script) rather than relying on the prompt? Happy to add that in this PR or a follow-up.Tests
main();express()/app.use(router)at module scope; calls inside a top-level IIFE; anonymousitems.forEachcallback; a regression test that calls inside a named function (including nested anonymous callbacks) stay attributed to that function with no<file>entries.main(); calls under anif __name__ == "__main__":guard; module-levelFlask(...)/app.register_blueprint(...); a regression test that a file whose calls are all inside functions emits no<file>entries.ignores top-level calls (no caller)encoded the old dropping behaviour. It's renamed toattributes top-level calls to the synthetic <file> callerand now expects two<file>entries (print,main).Test results (Node 22.23.3, pnpm 10)
pnpm --filter @understand-anything/core build: ✅pnpm --filter @understand-anything/core test: ✅ 47 files, 1022 tests passedpnpm test: ✅ 38 files passed, 1 skipped; 786 tests passed, 12 skipped (the skips are pre-existing)pnpm lint: ✅ cleanNotes
functionStack.length > 0check exists in the Go, Rust, Java, C#, C++, Kotlin, Ruby, Scala and Dart extractors; I can follow up per language.typescript-extractor.ts, so there may be a trivial conflict.