'use strict'


function walk( ast, fn ) {

	var stack = [ ast ], i, j, key, len, node, child

	for ( i = 0; i < stack.length; i += 1 ) {

		node = stack[ i ]

		fn( node )

		for ( key in node ) {

			child = node[ key ]

			if ( child instanceof Array ) {

				for ( j = 0, len = child.length; j < len; j += 1 ) {
					stack.push( child[ j ] )
				}

			} else if ( child != void 0 && typeof child.type === 'string' ) {

				stack.push( child )

			}

		}

	}

}

walk.walk = walk

walk.walkAddParent = function ( ast, fn ) {

	var stack = [ ast ], i, j, key, len, node, child, subchild

	for ( i = 0; i < stack.length; i += 1 ) {

		node = stack[ i ]

		fn( node )

		for ( key in node ) {

			child = node[ key ]

			if ( child instanceof Array ) {

				for ( j = 0, len = child.length; j < len; j += 1 ) {

					subchild = child[ j ]

					subchild.parent = node

					stack.push( subchild )

				}

			} else if ( child != void 0 && typeof child.type === 'string' ) {

				child.parent = node

				stack.push( child )

			}

		}

	}

}


exports = module.exports = walk

@@ -678,32 +678,67 @@
 ey in node ) %7B%0A%0A
+%09%09%09if ( key !== 'parent' ) %7B%0A%09%09%09%09%0A%09
 %09%09%09child = node%5B
@@ -737,32 +737,33 @@
  = node%5B key %5D%0A%0A
+%09
 %09%09%09if ( child in
@@ -778,32 +778,33 @@
  Array ) %7B%0A%0A%09%09%09%09
+%09
 for ( j = 0, len
@@ -842,24 +842,25 @@
 1 ) %7B%0A%0A%09%09%09%09%09
+%09
 subchild = c
@@ -866,24 +866,25 @@
 child%5B j %5D%0A%0A
+%09
 %09%09%09%09%09subchil
@@ -901,24 +901,25 @@
  node%0A%0A%09%09%09%09%09
+%09
 stack.push( 
@@ -930,27 +930,29 @@
 hild )%0A%0A%09%09%09%09
+%09
 %7D%0A%0A
+%09
 %09%09%09%7D else if
@@ -1009,24 +1009,25 @@
 g' ) %7B%0A%0A%09%09%09%09
+%09
 child.parent
@@ -1035,24 +1035,25 @@
 = node%0A%0A%09%09%09%09
+%09
 stack.push( 
@@ -1053,32 +1053,39 @@
 .push( child )%0A%0A
+%09%09%09%09%7D%0A%0A
 %09%09%09%7D%0A%0A%09%09%7D%0A%0A%09%7D%0A%0A%7D

Fix walkAddParent, check for parent key