Comparing version 1.0.1 to 1.1.0
@@ -55,2 +55,6 @@ /* | ||
function isProperty(nodeType, key) { | ||
return (nodeType === estraverse.Syntax.ObjectExpression || nodeType === estraverse.Syntax.ObjectPattern) && 'properties' === key; | ||
} | ||
function Visitor(visitor) { | ||
@@ -60,11 +64,15 @@ this.__visitor = visitor; | ||
Visitor.prototype.visit = function (node) { | ||
/* Default method for visiting children. | ||
* When you need to call default visiting operation inside custom visiting | ||
* operation, you can use it with `this.visitChildren(node)`. | ||
*/ | ||
Visitor.prototype.visitChildren = function (node) { | ||
var type, children, i, iz, j, jz, child; | ||
type = node.type || estraverse.Syntax.Property; | ||
if (this.__visitor[type]) { | ||
this.__visitor[type].call(this, node); | ||
if (node == null) { | ||
return; | ||
} | ||
type = node.type || estraverse.Syntax.Property; | ||
children = estraverse.VisitorKeys[type]; | ||
@@ -80,4 +88,6 @@ if (!children) { | ||
for (j = 0, jz = child.length; j < jz; ++j) { | ||
if (child[j] && isNode(child[j])) { | ||
this.visit(child[j]); | ||
if (child[j]) { | ||
if (isNode(child[j]) || isProperty(type, children[i])) { | ||
this.visit(child[j]); | ||
} | ||
} | ||
@@ -92,2 +102,18 @@ } | ||
/* Dispatching node. */ | ||
Visitor.prototype.visit = function (node) { | ||
var type; | ||
if (node == null) { | ||
return; | ||
} | ||
type = node.type || estraverse.Syntax.Property; | ||
if (this.__visitor[type]) { | ||
this.__visitor[type].call(this, node); | ||
return; | ||
} | ||
this.visitChildren(node); | ||
}; | ||
exports.version = require('./package.json').version; | ||
@@ -94,0 +120,0 @@ exports.Visitor = Visitor; |
@@ -6,3 +6,3 @@ { | ||
"main": "esrecurse.js", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"engines": { | ||
@@ -9,0 +9,0 @@ "node": ">=0.10.0" |
@@ -41,12 +41,23 @@ ### Esrecurse [![Build Status](https://secure.travis-ci.org/estools/esrecurse.png)](http://travis-ci.org/estools/esrecurse) | ||
} | ||
DerivedVisitor.prototype = { | ||
constructor: DerivedVisitor, | ||
XXXStatement: function (node) { | ||
this.visit(node.left); | ||
// do something... | ||
this.visit(node.right); | ||
} | ||
util.inherits(DerivedVisitor, esrecurse.Visitor); | ||
DerivedVisitor.prototype.XXXStatement = function (node) { | ||
this.visit(node.left); | ||
// do something... | ||
this.visit(node.right); | ||
}; | ||
``` | ||
And you can invoke default visiting operation inside custom visit operation. | ||
```javascript | ||
function DerivedVisitor() { | ||
esrecurse.Visitor.call(/* this for constructor */ this, /* visitor object. */ this); | ||
} | ||
util.inherits(DerivedVisitor, esrecurse.Visitor); | ||
DerivedVisitor.prototype.XXXStatement = function (node) { | ||
// do something... | ||
this.visitChildren(node); | ||
}; | ||
``` | ||
### License | ||
@@ -53,0 +64,0 @@ |
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
10260
103
87