Skip to content

Commit 3a43861

Browse files
committed
fix(HtmlParser): Do not add parent element for template children
fixes angular#5638
1 parent 9850e68 commit 3a43861

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

modules/angular2/src/compiler/html_tags.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,16 @@ export class HtmlTagDefinition {
304304
}
305305

306306
requireExtraParent(currentParent: string): boolean {
307-
return isPresent(this.requiredParents) &&
308-
(isBlank(currentParent) || this.requiredParents[currentParent.toLowerCase()] != true);
307+
if (isBlank(this.requiredParents)) {
308+
return false;
309+
}
310+
311+
if (isBlank(currentParent)) {
312+
return true;
313+
}
314+
315+
let lcParent = currentParent.toLowerCase();
316+
return this.requiredParents[lcParent] != true && lcParent != 'template';
309317
}
310318

311319
isClosedByChild(name: string): boolean {

modules/angular2/test/compiler/html_parser_spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ export function main() {
141141
]);
142142
});
143143

144+
it('should not add the requiredParent when the parent is a template', () => {
145+
expect(humanizeDom(parser.parse('<template><tr></tr></template>', 'TestComp')))
146+
.toEqual([
147+
[HtmlElementAst, 'template', 0],
148+
[HtmlElementAst, 'tr', 1],
149+
]);
150+
});
151+
144152
it('should support explicit mamespace', () => {
145153
expect(humanizeDom(parser.parse('<myns:div></myns:div>', 'TestComp')))
146154
.toEqual([[HtmlElementAst, '@myns:div', 0]]);

0 commit comments

Comments
 (0)