Last active
July 26, 2021 12:38
-
-
Save ibreathebsb/78db2a5619571f6eed10c3f0996c5f5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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