refactor(ivy): generate new ɵɵattribute instruction in host bindings (#30503)

PR Close #30503
This commit is contained in:
Ben Lesh 2019-05-15 20:21:24 -07:00 committed by Jason Aden
parent 1537aec1f9
commit 988afad2af
4 changed files with 37 additions and 37 deletions

View File

@ -3253,7 +3253,7 @@ describe('compiler compliance', () => {
$r3$.ɵɵallocHostVars(1); $r3$.ɵɵallocHostVars(1);
} }
if (rf & 2) { if (rf & 2) {
$r3$.ɵɵelementAttribute(elIndex, "tabindex", $r3$.ɵɵbind(ctx.tabindex)); $r3$.ɵɵattribute("tabindex", ctx.tabindex);
} }
} }
}); });

View File

@ -308,7 +308,7 @@ describe('compiler compliance: bindings', () => {
$r3$.ɵɵallocHostVars(1); $r3$.ɵɵallocHostVars(1);
} }
if (rf & 2) { if (rf & 2) {
$r3$.ɵɵelementAttribute(elIndex, "required", $r3$.ɵɵbind(ctx.required)); $r3$.ɵɵattribute("required", ctx.required);
} }
} }
}); });
@ -514,26 +514,26 @@ describe('compiler compliance: bindings', () => {
const template = ` const template = `
if (rf & 2) { if (rf & 2) {
i0.Δselect(0); i0.ɵɵselect(0);
i0.ΔattributeInterpolateV("title", ["a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i", ctx.nine, "j"]); i0.ɵɵattributeInterpolateV("title", ["a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i", ctx.nine, "j"]);
i0.Δselect(1); i0.ɵɵselect(1);
i0.ΔattributeInterpolate8("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i"); i0.ɵɵattributeInterpolate8("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h", ctx.eight, "i");
i0.Δselect(2); i0.ɵɵselect(2);
i0.ΔattributeInterpolate7("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h"); i0.ɵɵattributeInterpolate7("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g", ctx.seven, "h");
i0.Δselect(3); i0.ɵɵselect(3);
i0.ΔattributeInterpolate6("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g"); i0.ɵɵattributeInterpolate6("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f", ctx.six, "g");
i0.Δselect(4); i0.ɵɵselect(4);
i0.ΔattributeInterpolate5("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f"); i0.ɵɵattributeInterpolate5("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e", ctx.five, "f");
i0.Δselect(5); i0.ɵɵselect(5);
i0.ΔattributeInterpolate4("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e"); i0.ɵɵattributeInterpolate4("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d", ctx.four, "e");
i0.Δselect(6); i0.ɵɵselect(6);
i0.ΔattributeInterpolate3("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d"); i0.ɵɵattributeInterpolate3("title", "a", ctx.one, "b", ctx.two, "c", ctx.three, "d");
i0.Δselect(7); i0.ɵɵselect(7);
i0.ΔattributeInterpolate2("title", "a", ctx.one, "b", ctx.two, "c"); i0.ɵɵattributeInterpolate2("title", "a", ctx.one, "b", ctx.two, "c");
i0.Δselect(8); i0.ɵɵselect(8);
i0.ΔattributeInterpolate1("title", "a", ctx.one, "b"); i0.ɵɵattributeInterpolate1("title", "a", ctx.one, "b");
i0.Δselect(9); i0.ɵɵselect(9);
i0.ΔattributeInterpolate("title", ctx.one); i0.ɵɵattributeInterpolate("title", ctx.one);
} }
`; `;

View File

@ -1769,7 +1769,7 @@ describe('ngtsc behavioral tests', () => {
i0.ɵɵstyling(_c0); i0.ɵɵstyling(_c0);
} }
if (rf & 2) { if (rf & 2) {
i0.ɵɵelementAttribute(elIndex, "hello", i0.ɵɵbind(ctx.foo)); i0.ɵɵattribute("hello", ctx.foo);
i0.ɵɵproperty("prop", ctx.bar, null, true); i0.ɵɵproperty("prop", ctx.bar, null, true);
i0.ɵɵclassProp(0, ctx.someClass); i0.ɵɵclassProp(0, ctx.someClass);
i0.ɵɵstylingApply(); i0.ɵɵstylingApply();
@ -1826,7 +1826,7 @@ describe('ngtsc behavioral tests', () => {
`); `);
env.driveMain(); env.driveMain();
expect(env.getContents('test.js')).toContain('"hello", i0.ɵɵbind(ctx.foo)'); expect(env.getContents('test.js')).toContain('i0.ɵɵattribute("hello", ctx.foo)');
}); });
it('should generate host listeners for directives within hostBindings section', () => { it('should generate host listeners for directives within hostBindings section', () => {
@ -3216,12 +3216,12 @@ describe('ngtsc behavioral tests', () => {
i0.ɵɵallocHostVars(6); i0.ɵɵallocHostVars(6);
} }
if (rf & 2) { if (rf & 2) {
i0.ɵɵelementAttribute(elIndex, "href", i0.ɵɵbind(ctx.attrHref), i0.ɵɵsanitizeUrlOrResourceUrl); i0.ɵɵattribute("href", ctx.attrHref, i0.ɵɵsanitizeUrlOrResourceUrl);
i0.ɵɵelementAttribute(elIndex, "src", i0.ɵɵbind(ctx.attrSrc), i0.ɵɵsanitizeUrlOrResourceUrl); i0.ɵɵattribute("src", ctx.attrSrc, i0.ɵɵsanitizeUrlOrResourceUrl);
i0.ɵɵelementAttribute(elIndex, "action", i0.ɵɵbind(ctx.attrAction), i0.ɵɵsanitizeUrl); i0.ɵɵattribute("action", ctx.attrAction, i0.ɵɵsanitizeUrl);
i0.ɵɵelementAttribute(elIndex, "profile", i0.ɵɵbind(ctx.attrProfile), i0.ɵɵsanitizeResourceUrl); i0.ɵɵattribute("profile", ctx.attrProfile, i0.ɵɵsanitizeResourceUrl);
i0.ɵɵelementAttribute(elIndex, "innerHTML", i0.ɵɵbind(ctx.attrInnerHTML), i0.ɵɵsanitizeHtml); i0.ɵɵattribute("innerHTML", ctx.attrInnerHTML, i0.ɵɵsanitizeHtml);
i0.ɵɵelementAttribute(elIndex, "title", i0.ɵɵbind(ctx.attrSafeTitle)); i0.ɵɵattribute("title", ctx.attrSafeTitle);
} }
} }
`; `;
@ -3314,9 +3314,9 @@ describe('ngtsc behavioral tests', () => {
i0.ɵɵproperty("src", ctx.srcProp, null, true); i0.ɵɵproperty("src", ctx.srcProp, null, true);
i0.ɵɵproperty("href", ctx.hrefProp, null, true); i0.ɵɵproperty("href", ctx.hrefProp, null, true);
i0.ɵɵproperty("title", ctx.titleProp, null, true); i0.ɵɵproperty("title", ctx.titleProp, null, true);
i0.ɵɵelementAttribute(elIndex, "src", i0.ɵɵbind(ctx.srcAttr)); i0.ɵɵattribute("src", ctx.srcAttr);
i0.ɵɵelementAttribute(elIndex, "href", i0.ɵɵbind(ctx.hrefAttr)); i0.ɵɵattribute("href", ctx.hrefAttr);
i0.ɵɵelementAttribute(elIndex, "title", i0.ɵɵbind(ctx.titleAttr)); i0.ɵɵattribute("title", ctx.titleAttr);
} }
} }
`; `;

View File

@ -667,9 +667,9 @@ function createHostBindingsFunction(
sanitizerFn = resolveSanitizationFn(securityContexts[0], isAttribute); sanitizerFn = resolveSanitizationFn(securityContexts[0], isAttribute);
} }
} }
const isInstructionWithoutElementIndex =
const isPropertyInstruction = instruction === R3.property; instruction === R3.property || instruction === R3.attribute;
const instructionParams: o.Expression[] = isPropertyInstruction ? const instructionParams: o.Expression[] = isInstructionWithoutElementIndex ?
[ [
o.literal(bindingName), o.literal(bindingName),
bindingExpr.currValExpr, bindingExpr.currValExpr,
@ -776,7 +776,7 @@ function getBindingNameAndInstruction(binding: ParsedProperty):
const attrMatches = bindingName.match(ATTR_REGEX); const attrMatches = bindingName.match(ATTR_REGEX);
if (attrMatches) { if (attrMatches) {
bindingName = attrMatches[1]; bindingName = attrMatches[1];
instruction = R3.elementAttribute; instruction = R3.attribute;
} else { } else {
if (binding.isAnimation) { if (binding.isAnimation) {
bindingName = prepareSyntheticPropertyName(bindingName); bindingName = prepareSyntheticPropertyName(bindingName);