Commit 26b354a8 authored by aniket-engg's avatar aniket-engg Committed by Aniket

check if ast is available

parent 61486a77
...@@ -21,10 +21,11 @@ AstWalker.prototype.walk = function (ast, callback) { ...@@ -21,10 +21,11 @@ AstWalker.prototype.walk = function (ast, callback) {
if (!('*' in callback)) { if (!('*' in callback)) {
callback['*'] = function () { return true } callback['*'] = function () { return true }
} }
if(ast) { if (ast) {
const nodes = ast.nodes || (ast.body && ast.body.statements) || ast.declarations || [] const nodes = ast.nodes || (ast.body && ast.body.statements) || ast.declarations || []
if(ast.body && ast.initializationExpression) // 'for' loop handling if (ast.body && ast.initializationExpression) { // 'for' loop handling
nodes.push(ast.initializationExpression) nodes.push(ast.initializationExpression)
}
if (manageCallBack(ast, callback) && nodes && nodes.length > 0) { if (manageCallBack(ast, callback) && nodes && nodes.length > 0) {
for (let k in nodes) { for (let k in nodes) {
const child = nodes[k] const child = nodes[k]
......
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