From 4b3d13519399f8db5ead50ab24ee6e5a64acbe43 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 12 Dec 2016 19:10:20 -0800 Subject: [PATCH] fix(compiler): xmb `` tags should not self close (#13413) --- modules/@angular/compiler/src/i18n/serializers/xmb.ts | 4 ++-- .../@angular/compiler/src/i18n/serializers/xml_helper.ts | 7 ++++--- modules/@angular/compiler/test/i18n/integration_spec.ts | 6 +++--- .../@angular/compiler/test/i18n/serializers/xmb_spec.ts | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/@angular/compiler/src/i18n/serializers/xmb.ts b/modules/@angular/compiler/src/i18n/serializers/xmb.ts index 3834ee3938..1df69b7ad1 100644 --- a/modules/@angular/compiler/src/i18n/serializers/xmb.ts +++ b/modules/@angular/compiler/src/i18n/serializers/xmb.ts @@ -119,11 +119,11 @@ class _Visitor implements i18n.Visitor { } visitPlaceholder(ph: i18n.Placeholder, context?: any): xml.Node[] { - return [new xml.Tag(_PLACEHOLDER_TAG, {name: ph.name})]; + return [new xml.Tag(_PLACEHOLDER_TAG, {name: ph.name}, [], false)]; } visitIcuPlaceholder(ph: i18n.IcuPlaceholder, context?: any): xml.Node[] { - return [new xml.Tag(_PLACEHOLDER_TAG, {name: ph.name})]; + return [new xml.Tag(_PLACEHOLDER_TAG, {name: ph.name}, [], false)]; } serialize(nodes: i18n.Node[]): xml.Node[] { diff --git a/modules/@angular/compiler/src/i18n/serializers/xml_helper.ts b/modules/@angular/compiler/src/i18n/serializers/xml_helper.ts index e7cbc8bbcb..cf01674b5e 100644 --- a/modules/@angular/compiler/src/i18n/serializers/xml_helper.ts +++ b/modules/@angular/compiler/src/i18n/serializers/xml_helper.ts @@ -18,7 +18,8 @@ class _Visitor implements IVisitor { const strAttrs = this._serializeAttributes(tag.attrs); if (tag.children.length == 0) { - return `<${tag.name}${strAttrs}/>`; + return tag.canSelfClose ? `<${tag.name}${strAttrs}/>` : + `<${tag.name}${strAttrs}>`; } const strChildren = tag.children.map(node => node.visit(this)); @@ -71,8 +72,8 @@ export class Tag implements Node { public attrs: {[k: string]: string} = {}; constructor( - public name: string, unescapedAttrs: {[k: string]: string} = {}, - public children: Node[] = []) { + public name: string, unescapedAttrs: {[k: string]: string} = {}, public children: Node[] = [], + public canSelfClose: boolean = true) { Object.keys(unescapedAttrs).forEach((k: string) => { this.attrs[k] = _escapeXml(unescapedAttrs[k]); }); diff --git a/modules/@angular/compiler/test/i18n/integration_spec.ts b/modules/@angular/compiler/test/i18n/integration_spec.ts index 7823c42634..f9b4d3a8ba 100644 --- a/modules/@angular/compiler/test/i18n/integration_spec.ts +++ b/modules/@angular/compiler/test/i18n/integration_spec.ts @@ -208,9 +208,9 @@ const XMB = ` {VAR_SELECT, select, m {male} f {female} } - - sex = - + + sex = > + in a translatable section <h1>Markers in html comments</h1> diff --git a/modules/@angular/compiler/test/i18n/serializers/xmb_spec.ts b/modules/@angular/compiler/test/i18n/serializers/xmb_spec.ts index ecfe0b1519..e71c8c49d6 100644 --- a/modules/@angular/compiler/test/i18n/serializers/xmb_spec.ts +++ b/modules/@angular/compiler/test/i18n/serializers/xmb_spec.ts @@ -46,7 +46,7 @@ export function main(): void { ]> - translatable element <b>with placeholders</b> + translatable element <b>with placeholders</b> {VAR_PLURAL, plural, =0 {<p>test</p>} } foo foo