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.4.1 to 0.4.2

69

lib/path-visitor.js

@@ -15,2 +15,3 @@ var assert = require("assert");

this._methodNameTable = computeMethodNameTable(this);
this.Context = makeContextConstructor(this);
}

@@ -42,3 +43,3 @@

PathVisitor.fromMethodsObject = function(methods) {
PathVisitor.fromMethodsObject = function fromMethodsObject(methods) {
if (methods instanceof PathVisitor) {

@@ -64,3 +65,4 @@ return methods;

isFunction.assert(Visitor.Context);
isFunction.assert(Visitor.fromMethodsObject);
isFunction.assert(Visitor.visit);

@@ -96,2 +98,8 @@ return new Visitor;

PVp.visit = function(path) {
if (this instanceof this.Context) {
// If we somehow end up calling context.visit, then we need to
// re-invoke the .visit method against context.visitor.
return this.visitor.visit(path);
}
assert.ok(path instanceof NodePath);

@@ -139,3 +147,3 @@ var value = path.value;

if (this._reusableContextStack.length === 0) {
return new this.constructor.Context(this).reset(path);
return new this.Context(path);
}

@@ -146,2 +154,3 @@ return this._reusableContextStack.pop().reset(path);

PVp.releaseContext = function(context) {
assert.ok(context instanceof this.Context);
this._reusableContextStack.push(context);

@@ -151,20 +160,45 @@ context.currentPath = null;

PathVisitor.Context = function Context(visitor) {
assert.ok(this instanceof Context);
function makeContextConstructor(visitor) {
function Context(path) {
assert.ok(this instanceof Context);
assert.ok(this instanceof PathVisitor);
assert.ok(path instanceof NodePath);
Object.defineProperty(this, "visitor", {
value: visitor,
writable: false,
enumerable: true,
configurable: false
});
this.currentPath = path;
this.needToCallTraverse = true;
}
assert.ok(visitor instanceof PathVisitor);
Object.defineProperty(this, "visitor", { value: visitor });
this.currentPath = null;
this.needToCallTraverse = true;
};
var Cp = PathVisitor.Context.prototype;
// Note that the visitor object is the prototype of Context.prototype,
// so all visitor methods are inherited by context objects.
var Cp = Context.prototype = Object.create(visitor);
Cp.reset = function(path) {
Cp.constructor = Context;
Cp.reset = sharedReset;
Cp.invokeVisitorMethod = sharedInvokeVisitorMethod;
Cp.traverse = sharedTraverse;
return Context;
}
function sharedReset(path) {
assert.ok(this instanceof this.Context);
assert.ok(path instanceof NodePath);
this.currentPath = path;
this.needToCallTraverse = true;
return this;
};
}
Cp.invokeVisitorMethod = function(methodName) {
function sharedInvokeVisitorMethod(methodName) {
assert.ok(this instanceof this.Context);
assert.ok(this.currentPath instanceof NodePath);

@@ -196,13 +230,16 @@

);
};
}
Cp.traverse = function(path, newVisitor) {
function sharedTraverse(path, newVisitor) {
assert.ok(this instanceof this.Context);
assert.ok(path instanceof NodePath);
assert.ok(this.currentPath instanceof NodePath);
this.needToCallTraverse = false;
visitChildren(path, PathVisitor.fromMethodsObject(
newVisitor || this.visitor
));
};
}
module.exports = PathVisitor;

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

],
"version": "0.4.1",
"version": "0.4.2",
"homepage": "http://github.com/benjamn/ast-types",

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

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