Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-source-walk

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-source-walk - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

.travis.yml

32

index.js

@@ -16,4 +16,15 @@ var acorn = require('acorn');

// Adapted from substack/node-detective
// Executes cb on a non-array AST node
/**
* @param {String} src
* @param {Object} [options] - Parser options
* @return {Object} The AST of the given src
*/
module.exports.prototype.parse = function(src, options) {
return acorn.parse(src, options);
};
/**
* Adapted from substack/node-detective
* Executes cb on a non-array AST node
*/
module.exports.prototype.traverse = function (node, cb) {

@@ -46,8 +57,15 @@ var that = this;

// Executes the passed callback for every traversed node of
// the passed in src's ast
/**
* Executes the passed callback for every traversed node of
* the passed in src's ast
*
* @param {String|Object} src - The source code or AST to traverse
* @param {Function} cb - Called for every node
*/
module.exports.prototype.walk = function (src, cb) {
this.shouldStop = false;
var ast = acorn.parse(src, this.options);
var ast = typeof src === 'object' ?
src :
this.parse(src, this.options);

@@ -57,5 +75,7 @@ this.traverse(ast, cb);

// Halts further traversal of the AST
/**
* Halts further traversal of the AST
*/
module.exports.prototype.stopWalking = function () {
this.shouldStop = true;
};

8

package.json
{
"name": "node-source-walk",
"version": "1.3.0",
"version": "1.4.0",
"description": "Execute a callback on every node of a source code's AST and stop walking when you see fit",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha test/test.js"
},

@@ -27,3 +27,7 @@ "repository": {

"acorn": "~0.10.0"
},
"devDependencies": {
"mocha": "~2.0.1",
"sinon": "~1.12.2"
}
}

@@ -1,2 +0,2 @@

Execute a callback on every node of a source code's AST and stop walking whenever you see fit.
Execute a callback on every node of a file's AST and stop walking whenever you see fit.

@@ -16,17 +16,9 @@ *A variation of [substack/node-detective](https://github.com/substack/node-detective)

// Assume src is the string contents of myfile.js
// or the AST of an outside parse of myfile.js
walker.walk(src, function (node) {
// Example: looking for the use of define()
var callee = node.callee;
if (callee &&
node.type === 'CallExpression' &&
callee.type === 'Identifier' &&
callee.name === 'define') {
console.log('AMD syntax');
// No need to keep traversing since we found
// what we wanted
walker.stopWalking();
}
if (/* some condition */) {
// No need to keep traversing since we found what we wanted
walker.stopWalking();
}
});

@@ -51,4 +43,4 @@

* Generates and recursively walks through the AST for `src` and executes `cb`
on every node.
* src: the contents of a file OR its AST (via Esprima or Acorn)
* cb: a function that is called for every visited node

@@ -55,0 +47,0 @@ `stopWalking()`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc