Commit b8df4da0 authored by yann300's avatar yann300

small changes

parent e8786f49
...@@ -9,18 +9,16 @@ function AstWalker () { ...@@ -9,18 +9,16 @@ function AstWalker () {
* *
* @param {Object} ast - AST node * @param {Object} ast - AST node
* @param {Object or Function} callback - if (Function) the function will be called for every node. * @param {Object or Function} callback - if (Function) the function will be called for every node.
* - if (Object) callback[<Node Type>] will be called for every node of type <Node Type>. callback["*"] will be called fo all other nodes. * - if (Object) callback[<Node Type>] will be called for
* in each case, if the callback returns false it does not descend into children. If no callback for the current type, children are visited. * every node of type <Node Type>. callback["*"] will be called fo all other nodes.
* in each case, if the callback returns false it does not descend into children.
* If no callback for the current type, children are visited.
*/ */
AstWalker.prototype.walk = function (ast, callback) { AstWalker.prototype.walk = function (ast, callback) {
crawlNode(ast, callback) if (manageCallBack(ast, callback) && ast.children && ast.children.length > 0) {
} for (var k in ast.children) {
var child = ast.children[k]
function crawlNode (node, callback) { this.walk(child, callback)
if (manageCallBack(node, callback) && node.children && node.children.length > 0) {
for (var k in node.children) {
var child = node.children[k]
crawlNode(child, callback)
} }
} }
} }
...@@ -29,8 +27,8 @@ function manageCallBack (node, callback) { ...@@ -29,8 +27,8 @@ function manageCallBack (node, callback) {
if (callback instanceof Function) { if (callback instanceof Function) {
return callback(null, node) return callback(null, node)
} else if (callback instanceof Object) { } else if (callback instanceof Object) {
if (callback[node.name] instanceof 'Function') { if (callback[node.name] instanceof Function) {
return callback[node.name](null, node) return callback[node.name](null, Function)
} else if (callback['*'] instanceof 'Function') { } else if (callback['*'] instanceof 'Function') {
return callback['*'](null, node) return callback['*'](null, node)
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment