From bd704c90dd205f278769467262f383722d6e6a9f Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 14 Apr 2017 09:41:41 -0700 Subject: [PATCH] fix(compiler): fix build error in xliff2 --- .../integrationtest/test/i18n_spec.ts | 5 +++-- .../compiler/src/i18n/serializers/xliff2.ts | 18 +++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/compiler-cli/integrationtest/test/i18n_spec.ts b/packages/compiler-cli/integrationtest/test/i18n_spec.ts index eb80b5f70b..787def3142 100644 --- a/packages/compiler-cli/integrationtest/test/i18n_spec.ts +++ b/packages/compiler-cli/integrationtest/test/i18n_spec.ts @@ -98,9 +98,10 @@ const EXPECTED_XLIFF2 = ` Welcome - + - other-3rdP-component + other-3rdP-component +multi-lines diff --git a/packages/compiler/src/i18n/serializers/xliff2.ts b/packages/compiler/src/i18n/serializers/xliff2.ts index cb7fd960c8..e2940491ef 100644 --- a/packages/compiler/src/i18n/serializers/xliff2.ts +++ b/packages/compiler/src/i18n/serializers/xliff2.ts @@ -97,7 +97,7 @@ export class Xliff2 extends Serializer { throw new Error(`xliff2 parse errors:\n${errors.join('\n')}`); } - return {locale, i18nNodesByMsgId}; + return {locale: locale !, i18nNodesByMsgId}; } digest(message: i18n.Message): string { return decimalDigest(message); } @@ -177,7 +177,7 @@ class _WriteVisitor implements i18n.Visitor { // Extract messages as xml nodes from the xliff file class Xliff2Parser implements ml.Visitor { - private _unitMlString: string; + private _unitMlString: string|null; private _errors: I18nError[]; private _msgIdToHtml: {[msgId: string]: string}; private _locale: string|null = null; @@ -225,9 +225,9 @@ class Xliff2Parser implements ml.Visitor { break; case _TARGET_TAG: - const innerTextStart = element.startSourceSpan.end.offset; - const innerTextEnd = element.endSourceSpan.start.offset; - const content = element.startSourceSpan.start.file.content; + const innerTextStart = element.startSourceSpan !.end.offset; + const innerTextEnd = element.endSourceSpan !.start.offset; + const content = element.startSourceSpan !.start.file.content; const innerText = content.slice(innerTextStart, innerTextEnd); this._unitMlString = innerText; break; @@ -290,7 +290,7 @@ class XmlToI18n implements ml.Visitor { visitText(text: ml.Text, context: any) { return new i18n.Text(text.value, text.sourceSpan); } - visitElement(el: ml.Element, context: any): i18n.Node[] { + visitElement(el: ml.Element, context: any): i18n.Node[]|null { switch (el.name) { case _PLACEHOLDER_TAG: const nameAttr = el.attrs.find((attr) => attr.name === 'equiv'); @@ -312,7 +312,9 @@ class XmlToI18n implements ml.Visitor { const startId = startAttr.value; const endId = endAttr.value; - return [].concat( + const nodes: i18n.Node[] = []; + + return nodes.concat( new i18n.Placeholder('', startId, el.sourceSpan), ...el.children.map(node => node.visit(this, null)), new i18n.Placeholder('', endId, el.sourceSpan)); @@ -321,6 +323,8 @@ class XmlToI18n implements ml.Visitor { default: this._addError(el, `Unexpected tag`); } + + return null; } visitExpansion(icu: ml.Expansion, context: any) {