From 3a438615c3ba5d06ea7ec96c118f6beba2e77131 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 7 Dec 2015 09:41:01 -0800 Subject: [PATCH] fix(HtmlParser): Do not add parent element for template children fixes #5638 --- modules/angular2/src/compiler/html_tags.ts | 12 ++++++++++-- modules/angular2/test/compiler/html_parser_spec.ts | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/angular2/src/compiler/html_tags.ts b/modules/angular2/src/compiler/html_tags.ts index a2b77fef3d..e45ff34d16 100644 --- a/modules/angular2/src/compiler/html_tags.ts +++ b/modules/angular2/src/compiler/html_tags.ts @@ -304,8 +304,16 @@ export class HtmlTagDefinition { } requireExtraParent(currentParent: string): boolean { - return isPresent(this.requiredParents) && - (isBlank(currentParent) || this.requiredParents[currentParent.toLowerCase()] != true); + if (isBlank(this.requiredParents)) { + return false; + } + + if (isBlank(currentParent)) { + return true; + } + + let lcParent = currentParent.toLowerCase(); + return this.requiredParents[lcParent] != true && lcParent != 'template'; } isClosedByChild(name: string): boolean { diff --git a/modules/angular2/test/compiler/html_parser_spec.ts b/modules/angular2/test/compiler/html_parser_spec.ts index eb709c6113..a9217414f8 100644 --- a/modules/angular2/test/compiler/html_parser_spec.ts +++ b/modules/angular2/test/compiler/html_parser_spec.ts @@ -141,6 +141,14 @@ export function main() { ]); }); + it('should not add the requiredParent when the parent is a template', () => { + expect(humanizeDom(parser.parse('', 'TestComp'))) + .toEqual([ + [HtmlElementAst, 'template', 0], + [HtmlElementAst, 'tr', 1], + ]); + }); + it('should support explicit mamespace', () => { expect(humanizeDom(parser.parse('', 'TestComp'))) .toEqual([[HtmlElementAst, '@myns:div', 0]]);