fix(ivy): fix directive instantiation at slots above 2^12 (#27280)

PR Close #27280
This commit is contained in:
Kara Erickson 2018-11-26 14:57:45 -08:00 committed by Jason Aden
parent d62da4da12
commit a7ba05ad82
2 changed files with 45 additions and 1 deletions

View File

@ -1451,7 +1451,7 @@ function resolveDirectives(
*/
function instantiateAllDirectives(tView: TView, viewData: LViewData, previousOrParentTNode: TNode) {
const start = previousOrParentTNode.flags >> TNodeFlags.DirectiveStartingIndexShift;
const end = start + previousOrParentTNode.flags & TNodeFlags.DirectiveCountMask;
const end = start + (previousOrParentTNode.flags & TNodeFlags.DirectiveCountMask);
if (!getFirstTemplatePass() && start < end) {
getOrCreateNodeInjectorForNode(
previousOrParentTNode as TElementNode | TContainerNode | TElementContainerNode, viewData);

View File

@ -106,6 +106,50 @@ describe('component', () => {
});
it('should instantiate components at high indices', () => {
// {{ name }}
class Comp {
// @Input
name = '';
static ngComponentDef = defineComponent({
type: Comp,
selectors: [['comp']],
factory: () => new Comp(),
consts: 1,
vars: 1,
template: (rf: RenderFlags, ctx: Comp) => {
if (rf & RenderFlags.Create) {
text(0);
}
if (rf & RenderFlags.Update) {
textBinding(0, bind(ctx.name));
}
},
inputs: {name: 'name'}
});
}
// Artificially inflating the slot IDs of this app component to mimic an app
// with a very large view
const App = createComponent('app', (rf: RenderFlags, ctx: any) => {
if (rf & RenderFlags.Create) {
element(4097, 'comp');
}
if (rf & RenderFlags.Update) {
elementProperty(4097, 'name', bind(ctx.name));
}
}, 4098, 1, [Comp]);
const fixture = new ComponentFixture(App);
expect(fixture.html).toEqual('<comp></comp>');
fixture.component.name = 'some name';
fixture.update();
expect(fixture.html).toEqual('<comp>some name</comp>');
});
});
describe('component with a container', () => {