Skip to content

Commit

Permalink
fixup! fix(core): handle multiple i18n attributes with expression bin…
Browse files Browse the repository at this point in the history
…dings
  • Loading branch information
petebacondarwin committed Apr 29, 2021
1 parent 32fa7e8 commit 89f19b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
21 changes: 11 additions & 10 deletions packages/core/src/render3/i18n/i18n_parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function i18nStartFirstCreatePassProcessTextNode(
const tNode = createTNodeAndAddOpCode(
tView, rootTNode, existingTNodes, lView, createOpCodes, hasBinding ? null : text, false);
if (hasBinding) {
generateBindingUpdateOpCodes(updateOpCodes, text, tNode.index);
generateBindingUpdateOpCodes(updateOpCodes, text, tNode.index, null, 0, null);
}
}

Expand Down Expand Up @@ -254,8 +254,8 @@ export function i18nAttributesFirstPass(tView: TView, index: number, values: str
// Since this may not be the first i18n attribute on this element we need to pass in how
// many previous bindings there have already been.
generateBindingUpdateOpCodes(
updateOpCodes, message, previousElementIndex, attrName, null,
countBindings(updateOpCodes));
updateOpCodes, message, previousElementIndex, attrName, countBindings(updateOpCodes),
null);
}
}
tView.data[index] = updateOpCodes;
Expand All @@ -274,9 +274,9 @@ export function i18nAttributesFirstPass(tView: TView, index: number, values: str
* @param bindingStart The lView index of the next expression that can be bound via an opCode.
* @returns The mask value for these bindings
*/
export function generateBindingUpdateOpCodes(
updateOpCodes: I18nUpdateOpCodes, str: string, destinationNode: number, attrName?: string,
sanitizeFn: SanitizerFn|null = null, bindingStart = 0): number {
function generateBindingUpdateOpCodes(
updateOpCodes: I18nUpdateOpCodes, str: string, destinationNode: number, attrName: string|null,
bindingStart: number, sanitizeFn: SanitizerFn|null): number {
ngDevMode &&
assertGreaterThanOrEqual(
destinationNode, HEADER_OFFSET, 'Index must be in absolute LView offset');
Expand Down Expand Up @@ -623,12 +623,12 @@ function walkIcuTree(
if (VALID_ATTRS.hasOwnProperty(lowerAttrName)) {
if (URI_ATTRS[lowerAttrName]) {
generateBindingUpdateOpCodes(
update, attr.value, newIndex, attr.name, _sanitizeUrl);
update, attr.value, newIndex, attr.name, 0, _sanitizeUrl);
} else if (SRCSET_ATTRS[lowerAttrName]) {
generateBindingUpdateOpCodes(
update, attr.value, newIndex, attr.name, sanitizeSrcset);
update, attr.value, newIndex, attr.name, 0, sanitizeSrcset);
} else {
generateBindingUpdateOpCodes(update, attr.value, newIndex, attr.name);
generateBindingUpdateOpCodes(update, attr.value, newIndex, attr.name, 0, null);
}
} else {
ngDevMode &&
Expand All @@ -655,7 +655,8 @@ function walkIcuTree(
addCreateNodeAndAppend(create, null, hasBinding ? '' : value, parentIdx, newIndex);
addRemoveNode(remove, newIndex, depth);
if (hasBinding) {
bindingMask = generateBindingUpdateOpCodes(update, value, newIndex) | bindingMask;
bindingMask =
generateBindingUpdateOpCodes(update, value, newIndex, null, 0, null) | bindingMask;
}
break;
case Node.COMMENT_NODE:
Expand Down
6 changes: 4 additions & 2 deletions packages/core/test/render3/i18n/i18n_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,10 @@ describe('Runtime i18n', () => {
}, undefined, nbConsts, HEADER_OFFSET + index);

expect(opCodes).toEqual(matchDebug([
'if (mask & 0b11) { (lView[21] as Element).setAttribute(\'title\', `Hello ${lView[i-1]} - ${lView[i-2]}!`); }',
'if (mask & 0b1100) { (lView[21] as Element).setAttribute(\'aria-label\', `Bye ${lView[i-3]} - ${lView[i-4]}!`); }',
`if (mask & 0b11) { (lView[${HEADER_OFFSET + 0}] as Element).` +
'setAttribute(\'title\', `Hello ${lView[i-1]} - ${lView[i-2]}!`); }',
`if (mask & 0b1100) { (lView[${HEADER_OFFSET + 0}] as Element).` +
'setAttribute(\'aria-label\', `Bye ${lView[i-3]} - ${lView[i-4]}!`); }',
]));
});
});
Expand Down

0 comments on commit 89f19b7

Please sign in to comment.