Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
);
};
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.
function ForOfStatement( node, state, clbk ) {
if ( node.await === true ) {
state.hasAwait = true;
}
walk.base.ForOfStatement( node, state, clbk ); // eslint-disable-line new-cap
}
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);
}
}
}
walk(ast, visitors) {
walker.simple(ast, visitors, walker.base);
}
};
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) {
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 ) {
ForOfStatement(node, state, c) {
if (node.await === true) {
state.containsAwait = true;
}
walk.base.ForOfStatement(node, state, c);
},
FunctionDeclaration(node, state) {
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 );
}
}
}
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)