Bug 911373 - Improve shared/js/template.js's escaping logic

`make lint` passes.
Waiting to see if other tests will pass.