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]