Third pass at supporting namespaces, SVG

![](https://api.monosnap.com/image/download?id=HRJXiL0SlHr7On6U8TFJpAgSHJr0Gy)

This namespace implementation involved several steps.

  1. As the parser (token-handlers) sees elements, it flags them with namespaces, or as being HTML integration points.
  2. As the ast walker handles these elements, it emits opcodes to open and close dom helper contexts.
  3. As the template compiler runs, it manages a stack of dom helpers, a list of variable names, and emits opcodes for picking a dom helper to the fragment and hydration compilers.
  4. At completion, the template compiler puts all dom helper variables into the shared scope of the template. The build and hydration steps share access to this scope.
  5. At runtime, the initial dom helper instance is passed to the template (or defaulted) as `dom` in scope.
  6. The fragment and hydration sections use the proper dom helper object as signalled by their compiler.

Templates can now be passed a custom dom helper at runtime:

    var template = compile("<svg></svg>");
    template({}, {dom: new DOMHelper(document)});

This allows hooks or helpers the change to change the DOM namespace or root document for their inner content, and possibly inject their own custom helpers. This is with the caveat (due to caching the dom) that this passed-in dom helper is only respected on the *first* call of the template.

TODO:

  * [x] Update the simple-html-tokenizer to gain de-normalized tag and attribute strings (https://github.com/tildeio/simple-html-tokenizer/pull/10) (merged).
  * [ ] ~~Better way of detecting namespace change in ast walker? I worry accessing the parent element as `this.program` will not always be an option, and would like to know the last parent namespace explicitly.~~ Cleaned this up a bit based on looking at the AST in different situations, but please take note of it and review before merge.
  * [x] Add tests for the dom helper stack around `<svg></svg><svg></svg><div></div>` where div is properly xhtml.
  * [ ] Confirm moving all the dom scopes to the template shared scope is good (@krisselden).
  * [x] Test token parser changes directly
  * [x] Document `DOMHelper`
  * [x] Work-around or fix for root level SVG elements having the namespace opcodes pulled off from hydration instead of `consumeParent` and `popParent`. (root level SVG is broken until this is fixed)
  * [x] Split tokenizer changes into their own commit.
  * [x] Add other elements besides `foreignObject` to the HTML integration point list.
  * [x] Define `dom0` inside the `cachedFragment` `if` statement.
  * [x] Flush the built fragment cache when `dom0` changes.

Possible, or next step:

  * [x] Better work-around or refactor for `openRootElement`. Kind of stacking bad on top of bad there.
  * [ ] Test with a non-svg namespace. MathML or such.
  * [ ] Conserve the number of dom helpers created for nested or sibling helpers

Ready to merge.

/cc @mmun @krisselden