fix(parser): retain enclosing context for calls in anonymous callbacks (JS/TS) (#1570) - #1629
Open
Shriraj888 wants to merge 1 commit into
Open
Conversation
|
@Shriraj888 is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
@Shashankss1205 could you please review my PR when you get a chance? |
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.
Description
Fixes #1570
When a function call is located inside an anonymous callback (such as arrow functions or function expressions passed to
setTimeout,.then,app.use, event listeners, array methods, etc.),_get_parent_contextin the TypeScript and JavaScript parsers previously stopped its AST traversal at the anonymous function node. Because anonymous functions lack an identifier name,name_noderesolved toNone, causing_get_parent_contextto immediately return(None, curr.type, line).Consequently, the call was attributed to a nameless caller, dropping the
(Function)-[:CALLS]->(...)edge from the call graph and causingfind_callersto miss the enclosing function.Changes Made
typescript.py,javascript.py):_get_parent_contextto continue ascending parent AST nodes until a named enclosing scope (function_declaration,class_declaration,method_definition, or named/assignedarrow_function/function_expression) is found.obj.fn = ...), object pairs ({ fn: ... }), and class field definitions (field_definition,public_field_definition,property_definition).typescriptjsx.py) automatically inherits the fix.cpp.py,csharp.py,go.py,lua.py):_get_parent_contextonly returns when a name is resolved and continues walking up otherwise.tests/unit/parsers/test_typescript_parser.py: Unit tests for single- and multi-level nested callbacks and top-level anonymous IIFEs.tests/unit/parsers/test_javascript_parser.py: Unit tests for callback functions and class method callbacks in JS.tests/unit/tools/test_cross_lang_call_resolution_patterns.py: End-to-end call graph resolution tests verifying thatbuild_function_call_groupsoutputsCALLSedges from the enclosing named caller function in TS, TSX, and JS.Verification