Socket
Socket
Sign inDemoInstall

ast-types

Package Overview
Dependencies
27
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.12 to 0.3.13

100

lib/node-path.js

@@ -12,23 +12,65 @@ var assert = require("assert");

Path.call(this, value, parentPath, name);
}
// Conservatively update parameters to reflect any alterations made by
// the Path constructor.
value = this.value;
parentPath = this.parentPath;
name = this.name;
require("util").inherits(NodePath, Path);
var NPp = NodePath.prototype;
var node = null;
var pp = parentPath;
var scope = pp && pp.scope;
Object.defineProperties(NPp, {
node: {
get: function() {
Object.defineProperty(this, "node", {
value: this._computeNode()
});
return this.node;
}
},
parent: {
get: function() {
Object.defineProperty(this, "parent", {
value: this._computeParent()
});
return this.parent;
}
},
scope: {
get: function() {
Object.defineProperty(this, "scope", {
value: this._computeScope()
});
return this.scope;
}
}
});
// The value of the first ancestor Path whose value is a Node.
NPp._computeNode = function() {
var value = this.value;
if (n.Node.check(value)) {
node = value;
return value;
}
if (Scope.isEstablishedBy(node)) {
scope = new Scope(this, scope);
var pp = this.parentPath;
for (var pp = this.parentPath; pp; pp = pp.parentPath) {
if (n.Node.check(value = pp.value)) {
return value;
}
}
} else {
return null;
};
// The first ancestor Path whose value is a Node distinct from this.node.
NPp._computeParent = function() {
var value = this.value;
var pp = this.parentPath;
if (!n.Node.check(value)) {
while (pp && !n.Node.check(pp.value)) {
assert.strictEqual(pp.scope, scope);
pp = pp.parentPath;

@@ -38,4 +80,2 @@ }

if (pp) {
assert.strictEqual(pp.scope, scope);
node = pp.value || null;
pp = pp.parentPath;

@@ -49,23 +89,19 @@ }

if (pp && node) {
assert.notStrictEqual(pp.value, node);
assert.notStrictEqual(pp.node, node);
}
return pp || null;
};
Object.defineProperties(this, {
// The value of the first ancestor Path whose value is a Node.
node: { value: node || null },
// The closest enclosing scope that governs this node.
NPp._computeScope = function() {
var value = this.value;
var pp = this.parentPath;
var scope = pp && pp.scope;
// The first ancestor Path whose value is a Node distinct from
// this.node.
parent: { value: pp || null },
if (n.Node.check(value) &&
Scope.isEstablishedBy(value)) {
scope = new Scope(this, scope);
}
// The closest enclosing scope that governs this node.
scope: { value: scope || null }
});
}
return scope || null;
};
require("util").inherits(NodePath, Path);
var NPp = NodePath.prototype;
NPp.getValueProperty = function(name) {

@@ -72,0 +108,0 @@ return types.getFieldValue(this.value, name);

@@ -6,2 +6,4 @@ var assert = require("assert");

var NodePath = require("./node-path");
var funToStr = Function.prototype.toString;
var thisPattern = /\bthis\b/;

@@ -12,2 +14,10 @@ // Good for traversals that need to modify the syntax tree or to access

function traverseWithFullPathInfo(node, callback) {
if (!thisPattern.test(funToStr.call(callback))) {
// If the callback function contains no references to `this`, then
// it will have no way of using any of the NodePath information
// that traverseWithFullPathInfo provides, so we can skip that
// bookkeeping altogether.
return traverseWithNoPathInfo(node, callback);
}
function traverse(path) {

@@ -69,2 +79,4 @@ assert.ok(path instanceof NodePath);

traverse(node);
return node;
}

@@ -71,0 +83,0 @@

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

],
"version": "0.3.12",
"version": "0.3.13",
"homepage": "http://github.com/benjamn/ast-types",

@@ -24,0 +24,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc