Open comments for this post
NEW DEVLOG. Okay so:
I finished my symbol extraction and I have moved on to extracting exports :0 Unfortunately, all i have to show for it is STILL console output, but we’re getting there :>
-
For the symbol extraction, i did a MAJOR refactoring of my code to use generator functions, and I’m much happier with the output now :D I also added extraction of some other symbols, and change the object extraction strategy to use a recursive approach (if i hit a property that contains an object, i recurse).
-
For export extraction, I go over all export symbols that I found inside of the source file and then I handle their initializers. Basically: see what is being exported, and make an edge from the file to the export :>
Some hard cases that I have to handle include default exports and export specifiers. These aren’t exactly the same as other types of exports in the parsed AST, so I need to make sure some weird cases are working as well.
Next step is finishing my export extraction, writing a buncha tests, and then moving on to call extraction.
Open comments for this post
Okay devlog time :>
So far I’ve been really focused on accurate symbol extraction from the AST, I need to have enough information extraction about what functions are actually useful enough to qualify as a symbol, because I don’t want a symbol for some random .map() callback function!
Anyways, the image i’ve attached below is a dual view of the symbols im extracting. On the left, I’ve only got ids (for a quicker glance) and on the right I’ve got the full symbols for each id!
Also, after the first devlog, I realized the complexity of the project and instantly decided to write tests, so I’ve been doing that as well :> I don’t want to break something accidentally in the future without even knowing smh
So far, im creating a symbol for:
- non-exported variables that contain a function
- exported variables
- named classes
- named class’s methods
- named function declarations and arrow functions
- nested function declarations and arrow functions
- an object’s properties that are arrow functions/function expressions
- intermediate objects of a parent object that contains at least one callable descendant, that act as namespaces
- a function’s methods
Right now, I still need to collect a symbol for:
- default exports, whether named or not
- types
- enums
- interfaces
- Anonymous classes stored in a variable
After that, I need to write a couple of more tests, refactor my code a little (it’s pretty messy right now), and then move on to the call graph, where I’ll have to extract CallFacts (basically whenever a symbol is being called/referred to)
Open comments for this post
Okay! This is supposed to be a local tool that takes in a repository, creates a huge graph out of the entire thing (with relationships between imports, exports, function calls, etc), and then based on the graph, I’ll be able to answer questions like “what is this function for?”, or “What functions depend on this?”
The first step is scanning the repo (the easy part). Doing this was quite easy, since I just needed to use node’s fs module.
The next step is significantly more challenging: creating the graph. First, I’ll have to parse each file and get an AST out of it, then i’ll have to traverse it in order to collect all the information i need, along with all of the relationships.
Currently, this is the only output i can screenshot since im just trying to correctly parse and collect the AST nodes x-x but yes, i think its going to turn out well in the future :>