refactor(ivy): generate vars in component defs (#25562)
PR Close #25562
This commit is contained in:

committed by
Jason Aden

parent
d2be3d5775
commit
21a14407f6
@ -197,7 +197,10 @@ export function compileComponentFromMetadata(
|
||||
template.nodes, [], template.hasNgContent, template.ngContentSelectors);
|
||||
|
||||
// e.g. `consts: 2`
|
||||
definitionMap.set('consts', o.literal(templateBuilder.getSlotCount()));
|
||||
definitionMap.set('consts', o.literal(templateBuilder.getConstCount()));
|
||||
|
||||
// e.g. `vars: 2`
|
||||
definitionMap.set('vars', o.literal(templateBuilder.getVarCount()));
|
||||
|
||||
definitionMap.set('template', templateFunctionExpression);
|
||||
|
||||
|
@ -93,6 +93,9 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
|
||||
// Number of slots to reserve for pureFunctions
|
||||
private _pureFunctionSlots = 0;
|
||||
|
||||
// Number of binding slots
|
||||
private _bindingSlots = 0;
|
||||
|
||||
constructor(
|
||||
private constantPool: ConstantPool, parentBindingScope: BindingScope, private level = 0,
|
||||
private contextName: string|null, private templateName: string|null,
|
||||
@ -175,12 +178,12 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
|
||||
// instructions can be generated with the correct internal const count.
|
||||
this._nestedTemplateFns.forEach(buildTemplateFn => buildTemplateFn());
|
||||
|
||||
// Generate all the creation mode instructions (e.g. resolve bindings in listeners)
|
||||
const creationStatements = this._creationCodeFns.map((fn: () => o.Statement) => fn());
|
||||
|
||||
// Generate all the update mode instructions (e.g. resolve property or text bindings)
|
||||
const updateStatements = this._updateCodeFns.map((fn: () => o.Statement) => fn());
|
||||
|
||||
// Generate all the creation mode instructions (e.g. resolve bindings in listeners)
|
||||
const creationStatements = this._creationCodeFns.map((fn: () => o.Statement) => fn());
|
||||
|
||||
// To count slots for the reserveSlots() instruction, all bindings must have been visited.
|
||||
if (this._pureFunctionSlots > 0) {
|
||||
creationStatements.push(
|
||||
@ -758,7 +761,9 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
|
||||
|
||||
// e.g. template(1, MyComp_Template_1)
|
||||
this.creationInstruction(template.sourceSpan, R3.templateCreate, () => {
|
||||
parameters.splice(2, 0, o.literal(templateVisitor.getSlotCount()));
|
||||
parameters.splice(
|
||||
2, 0, o.literal(templateVisitor.getConstCount()),
|
||||
o.literal(templateVisitor.getVarCount()));
|
||||
return trimTrailingNulls(parameters);
|
||||
});
|
||||
}
|
||||
@ -807,7 +812,9 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
|
||||
|
||||
private allocateDataSlot() { return this._dataIndex++; }
|
||||
|
||||
getSlotCount() { return this._dataIndex; }
|
||||
getConstCount() { return this._dataIndex; }
|
||||
|
||||
getVarCount() { return this._bindingSlots + this._pureFunctionSlots; }
|
||||
|
||||
private bindingContext() { return `${this._bindingContext++}`; }
|
||||
|
||||
@ -838,6 +845,8 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
|
||||
|
||||
private convertPropertyBinding(implicit: o.Expression, value: AST, skipBindFn?: boolean):
|
||||
o.Expression {
|
||||
if (!skipBindFn) this._bindingSlots++;
|
||||
|
||||
const interpolationFn =
|
||||
value instanceof Interpolation ? interpolate : () => error('Unexpected interpolation');
|
||||
|
||||
|
Reference in New Issue
Block a user