Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function readFromPattern(node, scope) {
walk.recursive(node, null, {
Expression: function() {},
VariablePattern: function(node) { readVariable(node, scope); }
}, null, "Pattern");
}
function assignToPattern(node, scope) {
walk.recursive(node, null, {
Expression: function(node) {
check(node, scope);
},
VariablePattern: function(node) {
var found = searchScope(node.name, scope);
if (found) {
found.written = true;
} else if (!(node.name in ignoredGlobals)) {
ignoredGlobals[node.name] = true;
fail("Assignment to global variable " + node.name, node.loc);
}
}
}, null, "Pattern");
}
function recursive (node, state, funcs, baseVisitor, override) {
return walk.recursive(node, state, funcs, baseVisitor || base, override)
}
export function walkRecursive(node: Ast.Node, state?: T, funcs?: AstVisitors, baseVisitor = base, override?: string): void {
acornWalk.recursive(node, state, funcs, baseVisitor, override);
}
exports.checkReusedIndex = function(node, fail) {
if (!node.init || node.init.type != "VariableDeclaration") return;
var name = node.init.declarations[0].id.name;
walk.recursive(node.body, null, {
Function: function() {},
VariableDeclaration: function(node, st, c) {
for (var i = 0; i < node.declarations.length; i++)
if (node.declarations[i].id.name == name)
fail("Redefined loop variable", node.declarations[i].id.loc);
walk.base.VariableDeclaration(node, st, c);
}
});
};
function walker( src, ast ) {
var results;
var opts;
opts = {
'CallExpression': callExpression,
'ImportDeclaration': importDeclaration
};
results = {
'literals': [],
'expressions': []
};
walk.recursive( ast, null, opts );
return results;
/**
* Callback invoked upon visiting a `CallExpression` AST node.
*
* @private
* @param {Node} node - AST node
* @param {*} state - start state
* @param {Callback} clbk - callback to continue walking a sub-node
*/
function callExpression( node, state, clbk ) {
var expression;
var arg;
walk.base[ node.type ]( node, state, clbk );
if ( isRequire( node ) === false ) {
return;
function recursive (node, state, funcs, baseVisitor, override) {
return walk.recursive(node, state, funcs, baseVisitor || base, override)
}
fail("Duplicate definition of " + name, node.loc);
scope.vars[name] = {type: type, node: node, deadZone: deadZone && scope,
written: written, read: false};
}
function makeCx(scope, binding) {
return {scope: scope, binding: binding};
}
function isBlockScopedDecl(node) {
return node.type == "VariableDeclaration" && node.kind != "var";
}
var topScope = makeScope(null, "fn");
walk.recursive(ast, makeCx(topScope), {
Function: function(node, cx, c) {
var inner = node.scope = node.body.scope = makeScope(cx.scope, "fn");
var innerCx = makeCx(inner, {scope: inner, type: "argument", deadZone: true, written: true});
for (var i = 0; i < node.params.length; ++i)
c(node.params[i], innerCx, "Pattern");
if (node.id) {
var decl = node.type == "FunctionDeclaration";
addVar(decl ? cx.scope : inner, node.id.name,
decl ? "function" : "function name", node.id, false, true);
}
c(node.body, innerCx, node.expression ? "Expression" : "Statement")
},
TryStatement: function(node, cx, c) {
c(node.block, cx, "Statement");
if (node.handler) {