estree-variable-scopes
An NPM package that shows the top scope of defined variables and what variable can access to another specific variable
Usage
Getting all of the variables and it's grandparents
import { getVariables } from "estree-variable-scopes";
const code = `
let a = "Hello!"
let b = "Hi!"
const goodMorning = () => {
const str = "Good morning!"
}
`
console.log(getVariables(code))
Checking a variable can access to a specific variable
import { getVariables, canAccess } from "estree-variable-scopes";
const code = `
let a = "Hello!"
let b = "Hi!"
const goodMorning = () => {
const str = "Good morning!"
}
`
const scopes = getVariables(code)
const a_value = scopes[0].vars[0]
const str_value = scopes[1].vars[0]
console.log(canAccess(str_value, a_value, scopes))