refactor(ivy): add new attribute interpolation instructions (#30503)

PR Close #30503
This commit is contained in:
Ben Lesh
2019-05-15 19:53:13 -07:00
committed by Jason Aden
parent 38d7acee4d
commit 7555a46e23
8 changed files with 939 additions and 6 deletions

View File

@ -43,6 +43,27 @@ export class Identifiers {
static attribute: o.ExternalReference = {name: 'ɵɵattribute', moduleName: CORE};
static attributeInterpolate:
o.ExternalReference = {name: 'ɵɵattributeInterpolate', moduleName: CORE};
static attributeInterpolate1:
o.ExternalReference = {name: 'ɵɵattributeInterpolate1', moduleName: CORE};
static attributeInterpolate2:
o.ExternalReference = {name: 'ɵɵattributeInterpolate2', moduleName: CORE};
static attributeInterpolate3:
o.ExternalReference = {name: 'ɵɵattributeInterpolate3', moduleName: CORE};
static attributeInterpolate4:
o.ExternalReference = {name: 'ɵɵattributeInterpolate4', moduleName: CORE};
static attributeInterpolate5:
o.ExternalReference = {name: 'ɵɵattributeInterpolate5', moduleName: CORE};
static attributeInterpolate6:
o.ExternalReference = {name: 'ɵɵattributeInterpolate6', moduleName: CORE};
static attributeInterpolate7:
o.ExternalReference = {name: 'ɵɵattributeInterpolate7', moduleName: CORE};
static attributeInterpolate8:
o.ExternalReference = {name: 'ɵɵattributeInterpolate8', moduleName: CORE};
static attributeInterpolateV:
o.ExternalReference = {name: 'ɵɵattributeInterpolateV', moduleName: CORE};
static classProp: o.ExternalReference = {name: 'ɵɵclassProp', moduleName: CORE};
static elementContainerStart:

View File

@ -772,12 +772,12 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
} else if (inputType === BindingType.Attribute) {
if (value instanceof Interpolation) {
// attr.name="{{value}}" and friends
this.updateInstruction(elementIndex, input.sourceSpan, R3.elementAttribute, () => {
return [
o.literal(elementIndex), o.literal(attrName),
this.convertPropertyBinding(implicit, value), ...params
];
});
this.updateInstruction(
elementIndex, input.sourceSpan, getAttributeInterpolationExpression(value),
() =>
[o.literal(attrName),
...this.getUpdateInstructionArguments(o.variable(CONTEXT_NAME), value),
...params]);
} else {
// [attr.name]="value"
this.updateInstruction(elementIndex, input.sourceSpan, R3.attribute, () => {
@ -1695,6 +1695,35 @@ function getPropertyInterpolationExpression(interpolation: Interpolation) {
}
}
/**
* Gets the instruction to generate for an interpolated attribute
* @param interpolation An Interpolation AST
*/
function getAttributeInterpolationExpression(interpolation: Interpolation) {
switch (getInterpolationArgsLength(interpolation)) {
case 1:
return R3.attributeInterpolate;
case 3:
return R3.attributeInterpolate1;
case 5:
return R3.attributeInterpolate2;
case 7:
return R3.attributeInterpolate3;
case 9:
return R3.attributeInterpolate4;
case 11:
return R3.attributeInterpolate5;
case 13:
return R3.attributeInterpolate6;
case 15:
return R3.attributeInterpolate7;
case 17:
return R3.attributeInterpolate8;
default:
return R3.attributeInterpolateV;
}
}
/**
* Gets the number of arguments expected to be passed to a generated instruction in the case of
* interpolation instructions.