fix(compiler): fix build error in xliff2

This commit is contained in:
Victor Berchet 2017-04-14 09:41:41 -07:00 committed by Tobias Bosch
parent ea4afebeb9
commit bd704c90dd
2 changed files with 14 additions and 9 deletions

View File

@ -98,9 +98,10 @@ const EXPECTED_XLIFF2 = `<?xml version="1.0" encoding="UTF-8" ?>
<source>Welcome</source> <source>Welcome</source>
</segment> </segment>
</unit> </unit>
<unit id="3772663375917578720"> <unit id="126808141597411718">
<segment> <segment>
<source>other-3rdP-component</source> <source>other-3rdP-component
multi-lines</source>
</segment> </segment>
</unit> </unit>
</file> </file>

View File

@ -97,7 +97,7 @@ export class Xliff2 extends Serializer {
throw new Error(`xliff2 parse errors:\n${errors.join('\n')}`); 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); } 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 // Extract messages as xml nodes from the xliff file
class Xliff2Parser implements ml.Visitor { class Xliff2Parser implements ml.Visitor {
private _unitMlString: string; private _unitMlString: string|null;
private _errors: I18nError[]; private _errors: I18nError[];
private _msgIdToHtml: {[msgId: string]: string}; private _msgIdToHtml: {[msgId: string]: string};
private _locale: string|null = null; private _locale: string|null = null;
@ -225,9 +225,9 @@ class Xliff2Parser implements ml.Visitor {
break; break;
case _TARGET_TAG: case _TARGET_TAG:
const innerTextStart = element.startSourceSpan.end.offset; const innerTextStart = element.startSourceSpan !.end.offset;
const innerTextEnd = element.endSourceSpan.start.offset; const innerTextEnd = element.endSourceSpan !.start.offset;
const content = element.startSourceSpan.start.file.content; const content = element.startSourceSpan !.start.file.content;
const innerText = content.slice(innerTextStart, innerTextEnd); const innerText = content.slice(innerTextStart, innerTextEnd);
this._unitMlString = innerText; this._unitMlString = innerText;
break; break;
@ -290,7 +290,7 @@ class XmlToI18n implements ml.Visitor {
visitText(text: ml.Text, context: any) { return new i18n.Text(text.value, text.sourceSpan); } 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) { switch (el.name) {
case _PLACEHOLDER_TAG: case _PLACEHOLDER_TAG:
const nameAttr = el.attrs.find((attr) => attr.name === 'equiv'); const nameAttr = el.attrs.find((attr) => attr.name === 'equiv');
@ -312,7 +312,9 @@ class XmlToI18n implements ml.Visitor {
const startId = startAttr.value; const startId = startAttr.value;
const endId = endAttr.value; const endId = endAttr.value;
return [].concat( const nodes: i18n.Node[] = [];
return nodes.concat(
new i18n.Placeholder('', startId, el.sourceSpan), new i18n.Placeholder('', startId, el.sourceSpan),
...el.children.map(node => node.visit(this, null)), ...el.children.map(node => node.visit(this, null)),
new i18n.Placeholder('', endId, el.sourceSpan)); new i18n.Placeholder('', endId, el.sourceSpan));
@ -321,6 +323,8 @@ class XmlToI18n implements ml.Visitor {
default: default:
this._addError(el, `Unexpected tag`); this._addError(el, `Unexpected tag`);
} }
return null;
} }
visitExpansion(icu: ml.Expansion, context: any) { visitExpansion(icu: ml.Expansion, context: any) {