Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
merge-estraverse-visitors
Advanced tools
Merge multiple visitors for estraverse into one
const mergedVisitor = mergeVisitors(arrayOfVisitors)
npm install merge-estraverse-visitors
For given code,
function tenTimes (cb) {
for (var i = 0; i < 10; i += 1) {
cb();
}
}
Merge multiple estraverse visitors into one then run against target AST.
const visitor1 = {
enter: function (currentNode, parentNode) {
switch(currentNode.type) {
case 'ForStatement':
console.log('v1: going to skip ' + currentNode.type);
this.skip();
break;
case 'CallExpression':
case 'FunctionDeclaration':
console.log('v1: entering ' + currentNode.type);
break;
}
return undefined;
},
leave: function (currentNode, parentNode) {
switch(currentNode.type) {
case 'ForStatement':
case 'CallExpression':
case 'FunctionDeclaration':
console.log('v1: leaving ' + currentNode.type);
break;
}
}
};
const visitor2 = {
enter: function (currentNode, parentNode) {
switch(currentNode.type) {
case 'ForStatement':
case 'CallExpression':
case 'FunctionDeclaration':
console.log('v2: entering ' + currentNode.type);
break;
}
},
leave: function (currentNode, parentNode) {
switch(currentNode.type) {
case 'ForStatement':
case 'CallExpression':
case 'FunctionDeclaration':
console.log('v2: leaving ' + currentNode.type);
break;
}
}
};
const mergeVisitors = require('merge-estraverse-visitors');
const estraverse = require('estraverse');
const { parse } = require('acorn');
const ast = parse(code);
const mergedVisitor = mergeVisitors([ visitor1, visitor2 ])
estraverse.traverse(ast, mergedVisitor);
Results in:
v1: entering FunctionDeclaration
v2: entering FunctionDeclaration
v1: going to skip ForStatement
v2: entering ForStatement
v2: entering CallExpression
v2: leaving CallExpression
v2: leaving ForStatement
v1: leaving ForStatement
v2: leaving FunctionDeclaration
v1: leaving FunctionDeclaration
Supports Node under maintenance. In other words, we stop supporting old Node versions when their maintenance ends. Any other environments are not supported officially (means that we do not test against them on CI service).
Licensed under the MIT license.
2.0.0 (2020-05-19)
merge-estraverse-visitors@1.x
FAQs
merge multiple estraverse visitors into one
We found that merge-estraverse-visitors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.