1) The document proposes a method called "context-aware output escaping" to defend against XSS attacks in JavaScript template engines. It uses contextual analysis of the template and applies appropriate filtering rules.
2) It presents an architecture that parses templates to build an AST, then uses context parsers like HTML, CSS, and URI parsers to analyze output contexts. Context-sensitive XSS filters are applied based on the analysis.
3) Key aspects of the design include the template parser and walker, handling of branching logic and sub-templates, and dealing with ambiguous contexts. Contextual parsing of HTML is also discussed.