guard parentNode being null when walking DOM

While walking the DOM it is possible that parentNode can become null. As a result, the not null check at line 53 may not guard against all null cases. This can be fixed by moving the check into the while loop conditions.

@tylermercier @celsodantas @nsimmons @patrickdonovan @kurtfunai @qq99 
`!==` some has been doing some JS recently :smile: