refactor(compiler): rename i18n AST
to i18nMeta
(#33318)
This better reflects what this type represents and what it is used for. PR Close #33318
This commit is contained in:

committed by
Matias Niemelä

parent
447e251736
commit
03103d2d59
@ -51,7 +51,8 @@ export class I18nContext {
|
||||
|
||||
constructor(
|
||||
readonly index: number, readonly ref: o.ReadVarExpr, readonly level: number = 0,
|
||||
readonly templateIndex: number|null = null, readonly meta: i18n.AST, private registry?: any) {
|
||||
readonly templateIndex: number|null = null, readonly meta: i18n.I18nMeta,
|
||||
private registry?: any) {
|
||||
this._registry = registry || setupRegistry();
|
||||
this.id = this._registry.getUniqueId();
|
||||
}
|
||||
@ -81,21 +82,21 @@ export class I18nContext {
|
||||
appendIcu(name: string, ref: o.Expression) {
|
||||
updatePlaceholderMap(this._registry.icus, name, ref);
|
||||
}
|
||||
appendBoundText(node: i18n.AST) {
|
||||
appendBoundText(node: i18n.I18nMeta) {
|
||||
const phs = assembleBoundTextPlaceholders(node, this.bindings.size, this.id);
|
||||
phs.forEach((values, key) => updatePlaceholderMap(this.placeholders, key, ...values));
|
||||
}
|
||||
appendTemplate(node: i18n.AST, index: number) {
|
||||
appendTemplate(node: i18n.I18nMeta, index: number) {
|
||||
// add open and close tags at the same time,
|
||||
// since we process nested templates separately
|
||||
this.appendTag(TagType.TEMPLATE, node as i18n.TagPlaceholder, index, false);
|
||||
this.appendTag(TagType.TEMPLATE, node as i18n.TagPlaceholder, index, true);
|
||||
this._unresolvedCtxCount++;
|
||||
}
|
||||
appendElement(node: i18n.AST, index: number, closed?: boolean) {
|
||||
appendElement(node: i18n.I18nMeta, index: number, closed?: boolean) {
|
||||
this.appendTag(TagType.ELEMENT, node as i18n.TagPlaceholder, index, closed);
|
||||
}
|
||||
appendProjection(node: i18n.AST, index: number) {
|
||||
appendProjection(node: i18n.I18nMeta, index: number) {
|
||||
// add open and close tags at the same time,
|
||||
// since we process projected content separately
|
||||
this.appendTag(TagType.PROJECTION, node as i18n.TagPlaceholder, index, false);
|
||||
@ -112,7 +113,7 @@ export class I18nContext {
|
||||
*
|
||||
* @returns I18nContext instance
|
||||
*/
|
||||
forkChildContext(index: number, templateIndex: number, meta: i18n.AST) {
|
||||
forkChildContext(index: number, templateIndex: number, meta: i18n.I18nMeta) {
|
||||
return new I18nContext(index, this.ref, this.level + 1, templateIndex, meta, this._registry);
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ export type I18nMeta = {
|
||||
meaning?: string
|
||||
};
|
||||
|
||||
function setI18nRefs(html: html.Node & {i18n?: i18n.AST}, i18n: i18n.Node): i18n.Node {
|
||||
function setI18nRefs(html: html.Node & {i18n?: i18n.I18nMeta}, i18n: i18n.Node): i18n.Node {
|
||||
html.i18n = i18n;
|
||||
return i18n;
|
||||
}
|
||||
@ -42,7 +42,8 @@ export class I18nMetaVisitor implements html.Visitor {
|
||||
private keepI18nAttrs: boolean = false, private i18nLegacyMessageIdFormat: string = '') {}
|
||||
|
||||
private _generateI18nMessage(
|
||||
nodes: html.Node[], meta: string|i18n.AST = '', visitNodeFn?: VisitNodeFn): i18n.Message {
|
||||
nodes: html.Node[], meta: string|i18n.I18nMeta = '',
|
||||
visitNodeFn?: VisitNodeFn): i18n.Message {
|
||||
const parsed: I18nMeta =
|
||||
typeof meta === 'string' ? parseI18nMeta(meta) : metaFromI18nMessage(meta as i18n.Message);
|
||||
const message = this._createI18nMessage(
|
||||
|
@ -33,11 +33,11 @@ export function isI18nAttribute(name: string): boolean {
|
||||
return name === I18N_ATTR || name.startsWith(I18N_ATTR_PREFIX);
|
||||
}
|
||||
|
||||
export function isI18nRootNode(meta?: i18n.AST): meta is i18n.Message {
|
||||
export function isI18nRootNode(meta?: i18n.I18nMeta): meta is i18n.Message {
|
||||
return meta instanceof i18n.Message;
|
||||
}
|
||||
|
||||
export function isSingleI18nIcu(meta?: i18n.AST): boolean {
|
||||
export function isSingleI18nIcu(meta?: i18n.I18nMeta): boolean {
|
||||
return isI18nRootNode(meta) && meta.nodes.length === 1 && meta.nodes[0] instanceof i18n.Icu;
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ export function updatePlaceholderMap(map: Map<string, any[]>, name: string, ...v
|
||||
}
|
||||
|
||||
export function assembleBoundTextPlaceholders(
|
||||
meta: i18n.AST, bindingStartIndex: number = 0, contextId: number = 0): Map<string, any[]> {
|
||||
meta: i18n.I18nMeta, bindingStartIndex: number = 0, contextId: number = 0): Map<string, any[]> {
|
||||
const startIdx = bindingStartIndex;
|
||||
const placeholders = new Map<string, any>();
|
||||
const node =
|
||||
|
@ -188,7 +188,7 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
|
||||
|
||||
buildTemplateFunction(
|
||||
nodes: t.Node[], variables: t.Variable[], ngContentSelectorsOffset: number = 0,
|
||||
i18n?: i18n.AST): o.FunctionExpr {
|
||||
i18n?: i18n.I18nMeta): o.FunctionExpr {
|
||||
this._ngContentSelectorsOffset = ngContentSelectorsOffset;
|
||||
|
||||
if (this._namespace !== R3.namespaceHTML) {
|
||||
@ -415,7 +415,7 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
|
||||
}
|
||||
}
|
||||
|
||||
private i18nStart(span: ParseSourceSpan|null = null, meta: i18n.AST, selfClosing?: boolean):
|
||||
private i18nStart(span: ParseSourceSpan|null = null, meta: i18n.I18nMeta, selfClosing?: boolean):
|
||||
void {
|
||||
const index = this.allocateDataSlot();
|
||||
if (this.i18nContext) {
|
||||
|
Reference in New Issue
Block a user