fix($compile): fix memory leak

For functions that have a '&' binding on the scope, change the function
from an inline definition to an external definition so the function
closure has no access to the parent scope.
Backport of fix on 1.3.x

Closes #6794