How to use the acorn-walk.base function in acorn-walk

To help you get started, we’ve selected a few acorn-walk 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 sverweij / dependency-cruiser / src / extract / ast-extractors / extract-ES6-deps.js View on Github external
dynamic: false,
        exoticallyRequired: false
      });
    }
  }

  walk.simple(
    pAST,
    {
      ImportDeclaration: pushSourceValue,
      ImportExpression: pushImportNodeValue(pDependencies),
      ExportAllDeclaration: pushSourceValue,
      ExportNamedDeclaration: pushSourceValue
    },
    // see https://github.com/acornjs/acorn/issues/746
    walk.base
  );
};
github webhintio / hint / packages / parser-javascript / src / walk.ts View on Github external
import * as acornWalk from 'acorn-walk';
import { Node } from 'estree-jsx';
import { NodeVisitor, Walk, WalkMethods, WalkCompleteListener } from './types';

const { extend } = require('acorn-jsx-walk');

extend(acornWalk.base); // Add `walk` support for JSXElement, etc.

type Key = {
    node: Node;
    base?: NodeVisitor;
    state?: any;
};

export const base = acornWalk.base;

const getCurrentVisitorsOrCallback = (walkArray: WalkArray, node: Node, base?: NodeVisitor, state?: any) => {
    const item = walkArray.find(([key]) => {
        return key.node === node && key.base === base && key.state === state;
    });

    return item ? item[1] : null;
};

/**
 * A WalkArray is a pair of Key and a Map with
 * all the callbacks (for methods full and fullAncestor)
 * or all the NodeVisitor (for methods simple and ancestor) for that Key.
 *
 * The key is the same if the root node, the base and the state
 * you call walk.(simple|ancestor|full|fullAncestor) is the same.
github stdlib-js / stdlib / lib / node_modules / @stdlib / repl / lib / process_top_level_await.js View on Github external
function ForOfStatement( node, state, clbk ) {
	if ( node.await === true ) {
		state.hasAwait = true;
	}
	walk.base.ForOfStatement( node, state, clbk ); // eslint-disable-line new-cap
}
github mkmarek / unity-react-uielements / packages / babel-transform / src / jsx-visitor.js View on Github external
throw new Error(`Unknown ${ancestor.type} element in replaceWith`)
					}
				}
			}

			const options =  {
				opts: {},
				get: (key) => state[key],
				set: (key, value) => state[key] = value
			};

			if (visitor[key].enter) {
				visitor[key].enter(path, options);
			}

			walk.base[key](node,state,c);

			if (visitor[key].exit) {
				visitor[key].exit(path, options);
			}
		}
	}
github thx / magix-combine / plugins / js-acorn.js View on Github external
walk(ast, visitors) {
        walker.simple(ast, visitors, walker.base);
    }
};
github nodejs / repl / src / await.js View on Github external
ClassDeclaration(node, state, c) {
    if (state.ancestors[state.ancestors.length - 2] === state.body) {
      state.prepend(node, `${node.id.name}=`);
    }
    walk.base.ClassDeclaration(node, state, c);
  },
  ForOfStatement(node, state, c) {
github stdlib-js / stdlib / lib / node_modules / @stdlib / repl / lib / process_top_level_await.js View on Github external
function createVisitors( visitors ) {
	var clbk;
	var type;
	var keys;
	var out;
	var i;

	keys = objectKeys( walk.base );
	out = {};
	for ( i = 0; i < keys.length; i++ ) {
		type = keys[ i ];
		clbk = visitors[ type ] || walk.base[ type ];
		out[ type ] = wrapVisitor( clbk );
	}
	return out;

	/**
	* Returns a visitor callback which tracks ancestor nodes.
	*
	* @private
	* @param {Function} clbk - callback function
	* @returns {Function} visitor callback
	*/
	function wrapVisitor( clbk ) {
github nodejs / repl / src / await.js View on Github external
ForOfStatement(node, state, c) {
    if (node.await === true) {
      state.containsAwait = true;
    }
    walk.base.ForOfStatement(node, state, c);
  },
  FunctionDeclaration(node, state) {
github stdlib-js / stdlib / lib / node_modules / @stdlib / _tools / modules / import-require / lib / walk.js View on Github external
function callExpression( node, state, clbk ) {
		var expression;
		var arg;
		walk.base[ node.type ]( node, state, clbk );
		if ( isRequire( node ) === false ) {
			return;
		}
		debug( 'Found a `require` statement.' );
		if ( node.arguments.length ) {
			arg = node.arguments[ 0 ];
			if ( arg.type === 'Literal' ) {
				debug( '`require` literal: %s', arg.value );
				results.literals.push( arg.value );
			} else {
				expression = src.slice( arg.start, arg.end );
				debug( '`require` expression: %s', expression );
				results.expressions.push( expression );
			}
		}
	}
github peterqliu / threebox / node_modules / acorn-node / walk.js View on Github external
var xtend = require('xtend')
var walk = require('acorn-walk')
var dynamicImportKey = require('acorn-dynamic-import').DynamicImportKey

var base = xtend(walk.base)
base[dynamicImportKey] = 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) {
  return walk.full(node, callback, baseVisitor || base, state, override)