How to use the acorn/dist/walk.base function in acorn

To help you get started, we’ve selected a few acorn 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 dortaldt / notyet / node_modules / with / index.js View on Github external
'use strict';

var detect = require('acorn-globals');
var acorn = require('acorn');
var walk = require('acorn/dist/walk');

// polyfill for https://github.com/marijnh/acorn/pull/231
walk.base.ExportNamedDeclaration = walk.base.ExportDefaultDeclaration = function (node, st, c) {
  return c(node.declaration, st);
};
walk.base.ImportDefaultSpecifier = walk.base.ImportNamespaceSpecifier = function () {};

// hacky fix for https://github.com/marijnh/acorn/issues/227
function reallyParse(source) {
  try {
    return acorn.parse(source, {
      ecmaVersion: 5,
      allowReturnOutsideFunction: true
    });
  } catch (ex) {
    if (ex.name !== 'SyntaxError') {
      throw ex;
    }
    return acorn.parse(source, {
github Nols1000 / hltv-scorebot / node_modules / jsdom / node_modules / acorn-globals / index.js View on Github external
'use strict';

var acorn = require('acorn');
var walk = require('acorn/dist/walk');

// polyfill for https://github.com/marijnh/acorn/pull/231
walk.base.ExportNamedDeclaration = walk.base.ExportDefaultDeclaration = function (node, st, c) {
  return c(node.declaration, st);
};
walk.base.ImportDefaultSpecifier = walk.base.ImportNamespaceSpecifier = function () {};

function isScope(node) {
  return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'Program';
}
function isBlockScope(node) {
  return node.type === 'BlockStatement' || isScope(node);
}

function declaresArguments(node) {
  return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ArrowFunction';
}
function declaresThis(node) {
  return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
}

function reallyParse(source) {
github dortaldt / notyet / node_modules / with / index.js View on Github external
'use strict';

var detect = require('acorn-globals');
var acorn = require('acorn');
var walk = require('acorn/dist/walk');

// polyfill for https://github.com/marijnh/acorn/pull/231
walk.base.ExportNamedDeclaration = walk.base.ExportDefaultDeclaration = function (node, st, c) {
  return c(node.declaration, st);
};
walk.base.ImportDefaultSpecifier = walk.base.ImportNamespaceSpecifier = function () {};

// hacky fix for https://github.com/marijnh/acorn/issues/227
function reallyParse(source) {
  try {
    return acorn.parse(source, {
      ecmaVersion: 5,
      allowReturnOutsideFunction: true
    });
  } catch (ex) {
    if (ex.name !== 'SyntaxError') {
      throw ex;
    }
    return acorn.parse(source, {
      ecmaVersion: 6,
      allowReturnOutsideFunction: true
    });
github phenomejs / phenome / test-acorn / compile.js View on Github external
);
    },
  },
};
`;
const base = {
  JSXElement(node, st, c) {
    node.children.forEach((n) => {
      c(n, st);
    });
  },
  JSXExpressionContainer(node, st, c) {
    c(node.expression, st);
  },
  JSXText() {},
  ...walk.base,
};

function transformReactJSX() {
  const helpers = {
    slots: false,
    transformJSXProps: false,
  };
  const ast = acorn.parse(content, {
    sourceType: 'module',
    ecmaVersion: '9',
    plugins: { jsx: true },
  });
  function transformJSXText(node) {
    const textValue = node.value.trim().split('\n').map(line => line.trim()).join(' ');

    if (!textValue) {
github jamesshore / automatopia / node_modules / browserify / node_modules / module-deps / node_modules / detective / index.js View on Github external
function visit(node, st, c) {
        var hasRequire = wordRe.test(src.slice(node.start, node.end));
        if (!hasRequire) return;
        walk.base[node.type](node, st, c);
        if (node.type !== 'CallExpression') return;
        if (isRequire(node)) {
            if (node.arguments.length) {
                var arg = node.arguments[0];
                if (arg.type === 'Literal') {
                    modules.strings.push(arg.value);
                }
                else {
                    modules.expressions.push(src.slice(arg.start, arg.end));
                }
            }
            if (opts.nodes) modules.nodes.push(node);
        }
    }
github marijnh / getdocs / src / doccomments.js View on Github external
function c(node, _, override) {
    if (node.end < pos) return
    if (node.start >= pos && types[node.type]) {
      stack.push(node)
      throw new Found
    }
    if (!override) stack.push(node)
    walk.base[override || node.type](node, null, c)
    if (!override) stack.pop()
  }
  try {
github maierfelix / Iroh / dist / iroh-node.js View on Github external
Patcher.prototype.walk = function(ast, state, visitors) {
  return acorn_dist_walk.recursive(ast, state, visitors, acorn_dist_walk.base);
};
github auth0 / webtask-runtime / lib / compiler.js View on Github external
CallExpression: (node, state, recurse) => {
                Walk.base[node.type](node, state, recurse);

                if (node.callee.type === 'Identifier'
                    && node.callee.name === 'require'
                    && node.arguments.length
                    && node.arguments[0].type === 'Literal'
                ) {
                    const arg = node.arguments[0];
                    const spec = arg.value;

                    if (spec[0] === '.' || spec[0] === '/') return;

                    try {
                        require(spec);
                    } catch (__) {
                        missing.push(spec);
github oceanofthelost / InteractiveBOM / GUI / node_modules / acorn-node / walk.js View on Github external
var xtend = require('xtend')
var walk = require('acorn/dist/walk')

var base = xtend(walk.base, {
  Import: function () {}
})

function simple (node, visitors, baseVisitor, state, override) {
  return walk.simple(node, visitors, baseVisitor || base, state, override)
}

function ancestor (node, visitors, baseVisitor, state) {
  return walk.ancestor(node, visitors, baseVisitor || base, state)
}

function recursive (node, state, funcs, baseVisitor, override) {
  return walk.recursive(node, state, funcs, baseVisitor || base, override)
}

function full (node, callback, baseVisitor, state, override) {