How to use the acorn-node.parseExpressionAt 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 (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 {
                args.push(token);
            }
        } else if (REQUIRE_REDEF_PATTERN[0](token)) {
            state = ST_REDEF_PATTERN;
            redefIndex = 1;
        } else {
            state = ST_NONE;
        }
    }
    return modules;

acorn-node

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

Apache-2.0
Latest version published 5 years ago

Package Health Score

68 / 100
Full package analysis