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

committed by
Jason Aden

parent
d2be3d5775
commit
21a14407f6
@ -28,6 +28,7 @@ describe('component', () => {
|
||||
type: CounterComponent,
|
||||
selectors: [['counter']],
|
||||
consts: 1,
|
||||
vars: 1,
|
||||
template: function(rf: RenderFlags, ctx: CounterComponent) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
text(0);
|
||||
@ -74,6 +75,7 @@ describe('component', () => {
|
||||
selectors: [['my-component']],
|
||||
factory: () => new MyComponent(directiveInject(MyService)),
|
||||
consts: 1,
|
||||
vars: 1,
|
||||
template: function(fs: RenderFlags, ctx: MyComponent) {
|
||||
if (fs & RenderFlags.Create) {
|
||||
text(0);
|
||||
@ -116,7 +118,7 @@ describe('component with a container', () => {
|
||||
containerRefreshStart(0);
|
||||
{
|
||||
for (const item of ctx.items) {
|
||||
const rf0 = embeddedViewStart(0, 1);
|
||||
const rf0 = embeddedViewStart(0, 1, 1);
|
||||
{
|
||||
if (rf0 & RenderFlags.Create) {
|
||||
text(0);
|
||||
@ -139,6 +141,7 @@ describe('component with a container', () => {
|
||||
type: WrapperComponent,
|
||||
selectors: [['wrapper']],
|
||||
consts: 1,
|
||||
vars: 0,
|
||||
template: function ChildComponentTemplate(rf: RenderFlags, ctx: {items: string[]}) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
container(0);
|
||||
@ -146,7 +149,7 @@ describe('component with a container', () => {
|
||||
if (rf & RenderFlags.Update) {
|
||||
containerRefreshStart(0);
|
||||
{
|
||||
const rf0 = embeddedViewStart(0, 1);
|
||||
const rf0 = embeddedViewStart(0, 1, 0);
|
||||
{ showItems(rf0, {items: ctx.items}); }
|
||||
embeddedViewEnd();
|
||||
}
|
||||
@ -171,10 +174,10 @@ describe('component with a container', () => {
|
||||
|
||||
it('should re-render on input change', () => {
|
||||
const ctx: {items: string[]} = {items: ['a']};
|
||||
expect(renderToHtml(template, ctx, 1, defs)).toEqual('<wrapper>a</wrapper>');
|
||||
expect(renderToHtml(template, ctx, 1, 1, defs)).toEqual('<wrapper>a</wrapper>');
|
||||
|
||||
ctx.items = [...ctx.items, 'b'];
|
||||
expect(renderToHtml(template, ctx, 1, defs)).toEqual('<wrapper>ab</wrapper>');
|
||||
expect(renderToHtml(template, ctx, 1, 1, defs)).toEqual('<wrapper>ab</wrapper>');
|
||||
});
|
||||
|
||||
});
|
||||
@ -187,6 +190,7 @@ describe('encapsulation', () => {
|
||||
type: WrapperComponent,
|
||||
selectors: [['wrapper']],
|
||||
consts: 1,
|
||||
vars: 0,
|
||||
template: function(rf: RenderFlags, ctx: WrapperComponent) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
element(0, 'encapsulated');
|
||||
@ -202,6 +206,7 @@ describe('encapsulation', () => {
|
||||
type: EncapsulatedComponent,
|
||||
selectors: [['encapsulated']],
|
||||
consts: 2,
|
||||
vars: 0,
|
||||
template: function(rf: RenderFlags, ctx: EncapsulatedComponent) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
text(0, 'foo');
|
||||
@ -221,6 +226,7 @@ describe('encapsulation', () => {
|
||||
type: LeafComponent,
|
||||
selectors: [['leaf']],
|
||||
consts: 2,
|
||||
vars: 0,
|
||||
template: function(rf: RenderFlags, ctx: LeafComponent) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
elementStart(0, 'span');
|
||||
@ -252,6 +258,7 @@ describe('encapsulation', () => {
|
||||
type: WrapperComponentWith,
|
||||
selectors: [['wrapper']],
|
||||
consts: 1,
|
||||
vars: 0,
|
||||
template: function(rf: RenderFlags, ctx: WrapperComponentWith) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
element(0, 'leaf');
|
||||
@ -270,6 +277,7 @@ describe('encapsulation', () => {
|
||||
type: LeafComponentwith,
|
||||
selectors: [['leaf']],
|
||||
consts: 1,
|
||||
vars: 0,
|
||||
template: function(rf: RenderFlags, ctx: LeafComponentwith) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
elementStart(0, 'span');
|
||||
@ -329,6 +337,7 @@ describe('recursive components', () => {
|
||||
selectors: [['tree-comp']],
|
||||
factory: () => new TreeComponent(),
|
||||
consts: 3,
|
||||
vars: 1,
|
||||
template: (rf: RenderFlags, ctx: TreeComponent) => {
|
||||
if (rf & RenderFlags.Create) {
|
||||
text(0);
|
||||
@ -340,7 +349,7 @@ describe('recursive components', () => {
|
||||
containerRefreshStart(1);
|
||||
{
|
||||
if (ctx.data.left != null) {
|
||||
let rf0 = embeddedViewStart(0, 1);
|
||||
let rf0 = embeddedViewStart(0, 1, 1);
|
||||
if (rf0 & RenderFlags.Create) {
|
||||
element(0, 'tree-comp');
|
||||
}
|
||||
@ -354,7 +363,7 @@ describe('recursive components', () => {
|
||||
containerRefreshStart(2);
|
||||
{
|
||||
if (ctx.data.right != null) {
|
||||
let rf0 = embeddedViewStart(0, 1);
|
||||
let rf0 = embeddedViewStart(0, 1, 1);
|
||||
if (rf0 & RenderFlags.Create) {
|
||||
element(0, 'tree-comp');
|
||||
}
|
||||
@ -389,12 +398,13 @@ describe('recursive components', () => {
|
||||
selectors: [['ng-if-tree']],
|
||||
factory: () => new NgIfTree(),
|
||||
consts: 3,
|
||||
vars: 3,
|
||||
template: (rf: RenderFlags, ctx: NgIfTree) => {
|
||||
|
||||
if (rf & RenderFlags.Create) {
|
||||
text(0);
|
||||
template(1, IfTemplate, 1, '', [AttributeMarker.SelectOnly, 'ngIf']);
|
||||
template(2, IfTemplate2, 1, '', [AttributeMarker.SelectOnly, 'ngIf']);
|
||||
template(1, IfTemplate, 1, 1, '', [AttributeMarker.SelectOnly, 'ngIf']);
|
||||
template(2, IfTemplate2, 1, 1, '', [AttributeMarker.SelectOnly, 'ngIf']);
|
||||
}
|
||||
if (rf & RenderFlags.Update) {
|
||||
textBinding(0, bind(ctx.data.value));
|
||||
@ -463,7 +473,7 @@ describe('recursive components', () => {
|
||||
if (rf & RenderFlags.Update) {
|
||||
containerRefreshStart(0);
|
||||
if (!ctx.skipContent) {
|
||||
const rf0 = embeddedViewStart(0, 1);
|
||||
const rf0 = embeddedViewStart(0, 1, 0);
|
||||
if (rf0 & RenderFlags.Create) {
|
||||
elementStart(0, 'tree-comp');
|
||||
elementEnd();
|
||||
@ -472,7 +482,7 @@ describe('recursive components', () => {
|
||||
}
|
||||
containerRefreshEnd();
|
||||
}
|
||||
}, 1, [TreeComponent]);
|
||||
}, 1, 0, [TreeComponent]);
|
||||
|
||||
const fixture = new ComponentFixture(App);
|
||||
expect(getRenderedText(fixture.component)).toEqual('6201534');
|
||||
@ -497,7 +507,7 @@ describe('recursive components', () => {
|
||||
if (rf & RenderFlags.Update) {
|
||||
containerRefreshStart(0);
|
||||
if (!ctx.skipContent) {
|
||||
const rf0 = embeddedViewStart(0, 1);
|
||||
const rf0 = embeddedViewStart(0, 1, 0);
|
||||
if (rf0 & RenderFlags.Create) {
|
||||
elementStart(0, 'ng-if-tree');
|
||||
elementEnd();
|
||||
@ -506,7 +516,7 @@ describe('recursive components', () => {
|
||||
}
|
||||
containerRefreshEnd();
|
||||
}
|
||||
}, 1, [NgIfTree]);
|
||||
}, 1, 0, [NgIfTree]);
|
||||
|
||||
const fixture = new ComponentFixture(App);
|
||||
expect(getRenderedText(fixture.component)).toEqual('6201534');
|
||||
@ -527,6 +537,7 @@ describe('recursive components', () => {
|
||||
selectors: [['test-inputs']],
|
||||
inputs: {minifiedName: 'unminifiedName'},
|
||||
consts: 0,
|
||||
vars: 0,
|
||||
factory: () => new TestInputsComponent(),
|
||||
template: function(rf: RenderFlags, ctx: TestInputsComponent): void {
|
||||
// Template not needed for this test
|
||||
|
Reference in New Issue
Block a user