Skip to content

Instantly share code, notes, and snippets.

@ibreathebsb
Last active July 26, 2021 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibreathebsb/78db2a5619571f6eed10c3f0996c5f5b to your computer and use it in GitHub Desktop.
Save ibreathebsb/78db2a5619571f6eed10c3f0996c5f5b to your computer and use it in GitHub Desktop.
const path = require('path')
const fs = require('fs')
const parser = require('@babel/parser')
const traverse = require('@babel/traverse').default
const root = path.resolve(__dirname, 'src')
const res = []
const impl = (asbPath, fn) => {
const stats = fs.statSync(asbPath)
if (stats.isDirectory()) {
const children = fs.readdirSync(asbPath)
children.forEach((child) => {
impl(path.resolve(asbPath, child), fn)
})
} else {
const filename = path.basename(asbPath)
if (
filename.endsWith('.jsx') ||
filename.endsWith('.js') ||
filename.endsWith('.page')
) {
fn(asbPath)
}
}
}
impl(root, (asbPath) => {
const content = fs.readFileSync(asbPath, {encoding: 'utf8'})
const ast = parser.parse(content, {
sourceType: 'module', // enable jsx syntax
plugins: ['jsx']
})
const visitor = {
CallExpression: function (path) {
try {
const property = path.node.callee.property
if (property) {
if (['funcA', 'funcB'].includes(property.name)) {
console.log(path.toString())
res.push(path.toString())
}
}
} catch (e) {
console.log(e)
}
}
}
traverse(ast, visitor)
})
console.log(res.length)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment