test(AstSerializer): fix serializing void tags

This commit is contained in:
Victor Berchet 2016-09-30 15:50:59 -07:00 committed by Chuck Jazdzewski
parent 040bf57966
commit af520947aa
2 changed files with 9 additions and 5 deletions

View File

@ -116,7 +116,7 @@ export function main(): void {
'ec1d033f2436133c14ab038286c4f5df4697484a': 'ec1d033f2436133c14ab038286c4f5df4697484a':
'{{ interpolation}} footnemele elbatalsnart <b>sredlohecalp htiw</b>', '{{ interpolation}} footnemele elbatalsnart <b>sredlohecalp htiw</b>',
'db3e0a6a5a96481f60aec61d98c3eecddef5ac23': 'oof', 'db3e0a6a5a96481f60aec61d98c3eecddef5ac23': 'oof',
'd7fa2d59aaedcaa5309f13028c59af8c85b8c49d': '<div></div><img></img><br></br>', 'd7fa2d59aaedcaa5309f13028c59af8c85b8c49d': '<div></div><img/><br/>',
}); });
}); });
}); });

View File

@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {beforeEach, describe, expect, it} from '../../../core/testing/testing_internal'; import * as html from '@angular/compiler/src/ml_parser/ast';
import * as html from '../../src/ml_parser/ast'; import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
import {HtmlParser} from '../../src/ml_parser/html_parser'; import {getHtmlTagDefinition} from '@angular/compiler/src/ml_parser/html_tags';
export function main() { export function main() {
describe('Node serializer', () => { describe('Node serializer', () => {
@ -62,6 +62,10 @@ export function main() {
class _SerializerVisitor implements html.Visitor { class _SerializerVisitor implements html.Visitor {
visitElement(element: html.Element, context: any): any { visitElement(element: html.Element, context: any): any {
if (getHtmlTagDefinition(element.name).isVoid) {
return `<${element.name}${this._visitAll(element.attrs, ' ')}/>`;
}
return `<${element.name}${this._visitAll(element.attrs, ' ')}>${this._visitAll(element.children)}</${element.name}>`; return `<${element.name}${this._visitAll(element.attrs, ' ')}>${this._visitAll(element.children)}</${element.name}>`;
} }