How to use the acorn-node.tokTypes function in acorn-node

To help you get started, we’ve selected a few acorn-node 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 browserify / detective / find-fast.js View on Github external
if (state !== ST_INSIDE_CALL && token.type === acorn.tokTypes.dot) {
            state = ST_MEMBER_EXPRESSION;
        } else if (state === ST_NONE && token.type === acorn.tokTypes.name && mayBeRequire(token)) {
            state = ST_SAW_NAME;
            opener = token;
        } else if (state === ST_SAW_NAME && token.type === acorn.tokTypes.parenL) {
            state = ST_INSIDE_CALL;
            args = [];
        } else if (state === ST_INSIDE_CALL) {
            if (token.type === acorn.tokTypes.parenR) { // End of fn() call
                if (args.length === 1 && args[0].type === acorn.tokTypes.string) {
                    modules.strings.push(args[0].value);
                } else if (args.length === 3 // A template string without any expressions
                          && args[0].type === acorn.tokTypes.backQuote
                          && args[1].type === acorn.tokTypes.template
                          && args[2].type === acorn.tokTypes.backQuote) {
                    modules.strings.push(args[1].value);
                } else if (args.length > 0) {
                    modules.expressions.push(src.slice(args[0].start, args[args.length - 1].end));
                }

                if (opts.nodes) {
                    // Cut `src` at the end of this call, so that parseExpressionAt doesn't consider the `.abc` in
                    // `require('xyz').abc`
                    var chunk = src.slice(0, token.end);
                    var node = acorn.parseExpressionAt(chunk, opener.start, opts.parse);
                    modules.nodes.push(node);
                }

                state = ST_NONE;
            } else {
github browserify / detective / find-fast.js View on Github external
    function (token) { return token.type === acorn.tokTypes.num || token.type === acorn.tokTypes.string; }, // 0
    function (token) { return token.type === acorn.tokTypes.colon; }, // :
github browserify / detective / find-fast.js View on Github external
function mayBeRequire(token) {
        return token.type === acorn.tokTypes.name &&
            token.value === opts.word;
    }
}

acorn-node

the acorn javascript parser, preloaded with plugins for syntax parity with recent node versions

Apache-2.0
Latest version published 4 years ago

Package Health Score

68 / 100
Full package analysis