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.

Closes #6794