ast-types
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -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": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
90526
2293
0