How to grab identifiers used in a particular function?
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 194
- Avg merge
- 22h 43m
- Merged PRs (30d)
- 10
Description
Let us say we are visiting function declarations and would like to see for each function all variables that are NOT in local scope.
``` js
var two = 2;
function add2(a) {
return a + two;
}
```
Function `add2` declares `a` in the local scope, easy to find
``` js
types.visit(ast, {
visitFunctionDeclaration: function (path) {
console.log(path.scope.getBindings()); // prints ['a']
this.traverse(path);
}
});
```
How do we find the identifiers `a` and `two` inside function `add2` though?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the visitFunctionDeclaration entry point and the path.scope.getBindings() API shown in the issue. Determine how ast-types exposes identifiers referenced from the function, then document or demonstrate the answer with the add2 example so the expected result is clear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100