How to use the acorn-node.parse 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 peterqliu / threebox / node_modules / undeclared-identifiers / index.js View on Github external
properties: true,
    wildcard: false
  }, opts)

  var state = {
    undeclared: {},
    undeclaredProps: {},
    identifiers: opts.identifiers,
    properties: opts.properties,
    wildcard: opts.wildcard
  }

  // Parse if `src` is not already an AST.
  var ast = typeof src === 'object' && src !== null && typeof src.type === 'string'
    ? src
    : acorn.parse(src)

  var parents = []
  dash(ast, {
    enter: function (node, parent) {
      if (parent) parents.push(parent)
      var visit = scopeVisitor[node.type]
      if (visit) visit(node, state, parents)
    },
    leave: function (node, parent) {
      var visit = bindingVisitor[node.type]
      if (visit) visit(node, state, parents)
      if (parent) parents.pop()
    }
  })

  return {
github browserify / detective / index.js View on Github external
function parse (src, opts) {
    if (!opts) opts = {};
    var acornOpts = {
        ranges: defined(opts.ranges, opts.range),
        locations: defined(opts.locations, opts.loc),
        allowReserved: defined(opts.allowReserved, true),
        allowImportExportEverywhere: defined(opts.allowImportExportEverywhere, false)
    };

    // Use acorn-node's defaults for the rest.
    if (opts.ecmaVersion != null) acornOpts.ecmaVersion = opts.ecmaVersion;
    if (opts.sourceType != null) acornOpts.sourceType = opts.sourceType;
    if (opts.allowHashBang != null) acornOpts.allowHashBang = opts.allowHashBang;
    if (opts.allowReturnOutsideFunction != null) acornOpts.allowReturnOutsideFunction = opts.allowReturnOutsideFunction;

    return acorn.parse(src, acornOpts);
}
github goto-bus-stop / split-require / plugin.js View on Github external
function onwrite (row, enc, cb) {
    if (mayContainSplitRequire(row.source)) {
      var ast = acorn.parse(row.source)
      row.transformable = transformAst(row.source, { ast: ast })
      detectSplitRequireCalls(ast, function (node) {
        if (node.parent.type === 'CallExpression' && node.parent.callee === node) {
          processSplitRequire(row, node.parent)
        }
      }, function (node) {
        // Mark the thing we imported as the runtime row.
        var importPath = getStringValue(node.arguments[0])
        runtimeId = row.deps[importPath]
        if (rowsById[runtimeId]) {
          runtimeRow = rowsById[runtimeId]
        }
      })
    }

    if (runtimeId && String(row.id) === String(runtimeId)) {
github browserify / browser-unpack / index.js View on Github external
module.exports = function (src) {
    // If src is a Buffer, esprima will just stringify it, so we beat them to
    // the punch. This avoids the problem where we're using esprima's range
    // indexes -- which are meant for a UTF-16 string -- in a buffer that
    // contains UTF-8 encoded text.
    if (typeof src !== 'string') {
        src = String(src);
    }

    var ast = parse(src, { range: true });

    ast.body = ast.body.filter(function(node) {
        return node.type !== 'EmptyStatement';
    });

    if (ast.body.length !== 1) return;
    if (ast.body[0].type !== 'ExpressionStatement') return;
    if (ast.body[0].expression.type === 'UnaryExpression') {
        var body = ast.body[0].expression.argument;
    } else if (ast.body[0].expression.type === 'AssignmentExpression') {
        var body = ast.body[0].expression.right;
    } else {
        var body = ast.body[0].expression;
    }

    if (body.type !== 'CallExpression') return;
github goto-bus-stop / split-require / plugin.js View on Github external
function onend (cb) {
    if (!mayContainSplitRequire(source)) {
      cb()
      return
    }

    if (this.listenerCount('dep') === 0) {
      throw new Error('split-require requires browserify v16 or up')
    }

    var self = this
    var ast = acorn.parse(source)
    detectSplitRequireCalls(ast, function (node) {
      if (node.parent.type === 'CallExpression') {
        var arg = node.parent.arguments[0]
        self.emit('dep', arg.value)
      }
    })

    cb()
  }
}
github browserify / syntax-error / index.js View on Github external
function parse (src, opts) {
    if (!opts) opts = {}
    return aparse(src, opts);
}
github splunk / splunk-sdk-javascript / node_modules / detective / index.js View on Github external
function parse (src, opts) {
    if (!opts) opts = {};
    return acorn.parse(src, {
        ecmaVersion: defined(opts.ecmaVersion, 9),
        sourceType: defined(opts.sourceType, 'script'),
        ranges: defined(opts.ranges, opts.range),
        locations: defined(opts.locations, opts.loc),
        allowReserved: defined(opts.allowReserved, true),
        allowReturnOutsideFunction: defined(
            opts.allowReturnOutsideFunction, true
        ),
        allowImportExportEverywhere: defined(
            opts.allowImportExportEverywhere, true
        ),
        allowHashBang: defined(opts.allowHashBang, true)
    });
}

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