Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function searchRuntimeDependencies(str, module = false) {
const identifiers = new Map();
const dependencies = new Set();
let isSuspect = false;
if (str.charAt(0) === "#") {
// eslint-disable-next-line
str = str.slice(str.indexOf("\n"));
}
const { body } = meriyah.parseScript(str, { next: true, module });
walk(body, {
enter(node) {
// console.log(JSON.stringify(node, null, 2));
// console.log("-------------------------");
try {
if (!module && (helpers.isRequireStatment(node) || helpers.isRequireResolve(node))) {
const arg = node.arguments[0];
if (arg.type === "Identifier") {
if (identifiers.has(arg.name)) {
dependencies.add(identifiers.get(arg.name));
}
else {
isSuspect = true;
}
}