perf(ivy): avoid unnecessary i18n pass while processing a template (#33284)
Prior to this commit, we always invoked second i18n pass (in case whitespace removal is on, which is a default), even if a given template doesn't contain i18n information. Now we store a flag (that indicates presence of i18n information in a template) during first i18n pass and use it to check whether second pass is needed. PR Close #33284
This commit is contained in:

committed by
Matias Niemelä

parent
5d86e4a9b1
commit
7f7dc7c294
@ -1965,19 +1965,21 @@ export function parseTemplate(
|
||||
// before we run whitespace removal process, because existing i18n
|
||||
// extraction process (ng xi18n) relies on a raw content to generate
|
||||
// message ids
|
||||
rootNodes = html.visitAll(
|
||||
new I18nMetaVisitor(interpolationConfig, !preserveWhitespaces, i18nLegacyMessageIdFormat),
|
||||
rootNodes);
|
||||
const i18nMetaVisitor = new I18nMetaVisitor(
|
||||
interpolationConfig, /* keepI18nAttrs */ !preserveWhitespaces, i18nLegacyMessageIdFormat);
|
||||
rootNodes = html.visitAll(i18nMetaVisitor, rootNodes);
|
||||
|
||||
if (!preserveWhitespaces) {
|
||||
rootNodes = html.visitAll(new WhitespaceVisitor(), rootNodes);
|
||||
|
||||
// run i18n meta visitor again in case we remove whitespaces, because
|
||||
// that might affect generated i18n message content. During this pass
|
||||
// i18n IDs generated at the first pass will be preserved, so we can mimic
|
||||
// existing extraction process (ng xi18n)
|
||||
rootNodes = html.visitAll(
|
||||
new I18nMetaVisitor(interpolationConfig, /* keepI18nAttrs */ false), rootNodes);
|
||||
// run i18n meta visitor again in case whitespaces are removed (because that might affect
|
||||
// generated i18n message content) and first pass indicated that i18n content is present in a
|
||||
// template. During this pass i18n IDs generated at the first pass will be preserved, so we can
|
||||
// mimic existing extraction process (ng xi18n)
|
||||
if (i18nMetaVisitor.hasI18nMeta) {
|
||||
rootNodes = html.visitAll(
|
||||
new I18nMetaVisitor(interpolationConfig, /* keepI18nAttrs */ false), rootNodes);
|
||||
}
|
||||
}
|
||||
|
||||
const {nodes, errors, styleUrls, styles} = htmlAstToRender3Ast(rootNodes, bindingParser);
|
||||
|
Reference in New Issue
Block a user