refactor($parse): refactor repeated code

declare promise in correct scope