How to use the meriyah.parseScript function in meriyah

To help you get started, we’ve selected a few meriyah examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ES-Community / nsecure / src / ast / index.js View on Github external
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;
                        }
                    }

meriyah

A 100% compliant, self-hosted javascript parser with high focus on both performance and stability

ISC
Latest version published 1 month ago

Package Health Score

84 / 100
Full package analysis