fix(ExtractorMerger): returns errors together with nodes (as a ParseTreeResult)

This commit is contained in:
Victor Berchet 2016-08-11 15:31:36 -07:00 committed by Vikram Subramanian
parent e60c765280
commit 39c0f9ebb3
3 changed files with 10 additions and 11 deletions

View File

@ -8,6 +8,7 @@
import * as html from '../ml_parser/ast';
import {InterpolationConfig} from '../ml_parser/interpolation_config';
import {ParseTreeResult} from '../ml_parser/parser';
import {digestMessage} from './digest';
import * as i18n from './i18n_ast';
@ -31,7 +32,7 @@ export function extractMessages(
export function mergeTranslations(
nodes: html.Node[], translations: TranslationBundle, interpolationConfig: InterpolationConfig,
implicitTags: string[], implicitAttrs: {[k: string]: string[]}): html.Node[] {
implicitTags: string[], implicitAttrs: {[k: string]: string[]}): ParseTreeResult {
const visitor = new _Visitor(implicitTags, implicitAttrs);
return visitor.merge(nodes, translations, interpolationConfig);
}
@ -102,7 +103,7 @@ class _Visitor implements html.Visitor {
*/
merge(
nodes: html.Node[], translations: TranslationBundle,
interpolationConfig: InterpolationConfig): html.Node[] {
interpolationConfig: InterpolationConfig): ParseTreeResult {
this._init(_VisitorMode.Merge, interpolationConfig);
this._translations = translations;
@ -111,12 +112,11 @@ class _Visitor implements html.Visitor {
const translatedNode = wrapper.visit(this, null);
// TODO(vicb): return MergeResult with errors
if (this._inI18nBlock) {
this._reportError(nodes[nodes.length - 1], 'Unclosed block');
}
return translatedNode.children;
return new ParseTreeResult(translatedNode.children, this._errors);
}
visitExpansionCase(icuCase: html.ExpansionCase, context: any): any {

View File

@ -46,9 +46,6 @@ export class HtmlParser implements BaseHtmlParser {
const xtb = new Xtb(this._htmlParser, interpolationConfig);
const translationBundle = TranslationBundle.load(this._translations, url, messageBundle, xtb);
const translatedNodes =
mergeTranslations(parseResult.rootNodes, translationBundle, interpolationConfig, [], {});
return new ParseTreeResult(translatedNodes, []);
return mergeTranslations(parseResult.rootNodes, translationBundle, interpolationConfig, [], {});
}
}

View File

@ -410,10 +410,12 @@ function fakeTranslate(
const translations = new TranslationBundle(i18nMsgMap);
const translateNodes = mergeTranslations(
htmlNodes, translations, DEFAULT_INTERPOLATION_CONFIG, implicitTags, implicitAttrs);
const translatedNodes =
mergeTranslations(
htmlNodes, translations, DEFAULT_INTERPOLATION_CONFIG, implicitTags, implicitAttrs)
.rootNodes;
return serializeHtmlNodes(translateNodes).join('');
return serializeHtmlNodes(translatedNodes).join('');
}
function extract(