Added namespace tracking to $compile

This is in relation to #8494

### Things to note:

1. This is a work in progress.
2. This needs cleaned up badly.
3. The commits need flattened.
4. etc.

### Basic Idea

Added namespace tracking to the compile process.

When a namespace change is detected, it updates a namespace context object that contains methods to wrap and clone elements appropriately. There is some ugliness where the namespace context had to be ferried around via some monkey-patches to get them into the appropriate closures.