Socket
Socket
Sign inDemoInstall

ast-types

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ast-types - npm Package Compare versions

Comparing version 0.2.24 to 0.2.25

lib/node-path.js

53

lib/traverse.js

@@ -1,45 +0,13 @@

var assert = require("assert");
var types = require("./types");
var namedTypes = types.namedTypes;
var Node = namedTypes.Node;
var Node = types.namedTypes.Node;
var isArray = types.builtInTypes.array;
var Scope = require("./scope");
var NodePath = require("./node-path");
function Path(node, parentPath) {
assert.ok(this instanceof Path);
Node.assert(node);
if (parentPath) {
assert.ok(parentPath instanceof Path);
} else {
parentPath = null;
}
var parentScope = parentPath && parentPath.scope;
var scope = null;
if (Scope.isEstablishedBy(node)) {
scope = new Scope(node, parentScope);
} else if (parentScope) {
scope = parentScope;
}
Object.defineProperties(this, {
node: { value: node },
parent: { value: parentPath },
scope: { value: scope }
});
}
module.exports = function(node, callback) {
function traverse(node, parentPath) {
if (isArray.check(node)) {
node.map(function(child) {
traverse(child, parentPath);
});
function traverse(path) {
if (isArray.check(path.value)) {
path.each(traverse);
} else if (Node.check(path.value)) {
var node = path.value;
} else if (Node.check(node)) {
var path = new Path(node, parentPath);
if (callback.call(path, node) === false) {

@@ -50,3 +18,6 @@ return;

types.eachField(node, function(name, child) {
traverse(child, path);
// Need to create the child path manually because child
// might not actually be identical to path.value[name],
// if for instance a default field value was substituted.
traverse(new NodePath(child, path, name));
});

@@ -56,3 +27,3 @@ }

traverse(node);
traverse(new NodePath(node));
};

@@ -535,2 +535,26 @@ var assert = require("assert");

// Similar to eachField, except that iteration stops as soon as the
// callback returns a truthy value. Like Array.prototype.some, the final
// result is either true or false to indicates whether the callback
// returned true for any element or not.
Object.defineProperty(exports, "someField", {
value: function(object, callback, context) {
var d = Def.fromValue(object);
if (d) {
var all = d.allFields;
return Object.keys(all).some(function(name) {
var field = all[name];
if (!field.hidden) {
var value = field.getValue(object);
return callback.call(this, name, value);
}
}, context);
}
// If the object has no fields, then of course no field satisified
// the predicate.
return false;
}
});
// This property will be overridden as true by individual Def instances

@@ -537,0 +561,0 @@ // when they are finalized.

@@ -21,3 +21,3 @@ {

],
"version": "0.2.24",
"version": "0.2.25",
"homepage": "http://github.com/benjamn/ast-types",

@@ -32,3 +32,5 @@ "repository": {

},
"dependencies": {},
"dependencies": {
"ast-path": "~0.1.0"
},
"devDependencies": {},

@@ -35,0 +37,0 @@ "optionalDependencies": {

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