From e484c62a8d369c28ab1f4e8a256257620bf53a8b Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 15 Jun 2016 09:45:19 -0700 Subject: [PATCH] fix(HtmlParser): do not add required parents to template root elements fixes #5967 --- modules/@angular/compiler/src/html_parser.ts | 2 +- modules/@angular/compiler/test/html_parser_spec.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/@angular/compiler/src/html_parser.ts b/modules/@angular/compiler/src/html_parser.ts index 092232c1e0..2240ace0b8 100644 --- a/modules/@angular/compiler/src/html_parser.ts +++ b/modules/@angular/compiler/src/html_parser.ts @@ -266,7 +266,7 @@ class TreeBuilder { const tagDef = getHtmlTagDefinition(el.name); const {parent, container} = this._getParentElementSkippingContainers(); - if (tagDef.requireExtraParent(isPresent(parent) ? parent.name : null)) { + if (isPresent(parent) && tagDef.requireExtraParent(parent.name)) { var newParent = new HtmlElementAst( tagDef.parentToAdd, [], [], el.sourceSpan, el.startSourceSpan, el.endSourceSpan); this._insertBeforeContainer(parent, container, newParent); diff --git a/modules/@angular/compiler/test/html_parser_spec.ts b/modules/@angular/compiler/test/html_parser_spec.ts index e2ca0d6987..3e4dc1ceb8 100644 --- a/modules/@angular/compiler/test/html_parser_spec.ts +++ b/modules/@angular/compiler/test/html_parser_spec.ts @@ -36,7 +36,6 @@ export function main() { }); }); - describe('elements', () => { it('should parse root level elements', () => { expect(humanizeDom(parser.parse('
', 'TestComp'))).toEqual([ @@ -158,6 +157,13 @@ export function main() { ]); }); + // https://github.com/angular/angular/issues/5967 + it('should not add the requiredParent to a template root element', () => { + expect(humanizeDom(parser.parse('', 'TestComp'))).toEqual([ + [HtmlElementAst, 'tr', 0], + ]); + }); + it('should support explicit mamespace', () => { expect(humanizeDom(parser.parse('', 'TestComp'))).toEqual([ [HtmlElementAst, ':myns:div', 0]