feat(js): implement JS definitions
NOTE: This is a slimmed down continuation of my original MR, now closed. Down from 10KLOC's to ~500 lines, excluding test code snippets (no longer pointing to main).
What does this MR do?
This MR implements definition extraction for Javascript. It builds off the analyzer pattern established by the Ruby definitions MR. It also provides an integration test of the JS Definition parsing in javascript/analyzer.rs, against javascript/fixtures/sample.js. There is one change that I made to the source (not JS-specific) FQN file, mainly adding a few helper functions (entirely optional), and a generic NodeFqnMap type.
Given a JS file, the parser will return a list of DefinitionInfo objects. Each will contain the following:
- The definition type (class, class method, function, named arrow function, getter/setter functions)
- Name of the function
- Fully qualified name (FQN) of the definition, with metadata, according to the new schema
- Match information from the ast-grep rule engine
- All captured ast-grep variables
Notably, there are a few limitations:
- We have not tested JSX, nor have we tested TS/TSX.
ast-greptreats JS and TS as separate languages, as they technically share differenttree-sitterparsers. We can leave it to the reviewers to decide if that's best tested in this MR, or a future iteration. - We should compute aliases for each iteration, as described here
- Saving for a future iteration
- Anonymous functions (i.e. arrow functions used as arguments) are intentionally not handled here, as they are not callable
- We do not capture nested lambda definitions (e.g.
foo = { bar: () => {} }) even though they are technically named- Saving for a future iteration
Related issues
- #9 (closed), #10 (closed) (Not closed yet, that is dependent on JSX, TS/TSX support)
- Proposal: 5+ phases of work for the knowledge g... (knowledge-graph#1 - closed)
Follow-up work
I will open an MR with unit tests, expand the scope of javascript/fixtures to test more parsing edge cases, and add support (plus E2E tests) for JSX, and TS/TSX.