diff --git a/packages/core/src/render3/index.ts b/packages/core/src/render3/index.ts index 9641e59adc..66f8e29eb9 100644 --- a/packages/core/src/render3/index.ts +++ b/packages/core/src/render3/index.ts @@ -119,7 +119,6 @@ export { QueryList, query, queryRefresh, - QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF } from './query'; export { registerContentQuery, @@ -139,7 +138,7 @@ export { pureFunctionV, } from './pure_function'; -export {templateRefExtractor} from './view_engine_compatibility'; +export {templateRefExtractor, QUERY_READ_ELEMENT_REF, QUERY_READ_CONTAINER_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF} from './view_engine_compatibility_prebound'; // clang-format on diff --git a/packages/core/src/render3/query.ts b/packages/core/src/render3/query.ts index 4d5a808ebf..279846a7cb 100644 --- a/packages/core/src/render3/query.ts +++ b/packages/core/src/render3/query.ts @@ -475,59 +475,3 @@ export function queryRefresh(queryList: QueryList): boolean { export class ReadFromInjectorFn { constructor(readonly read: (tNode: TNode, view: LViewData, directiveIndex?: number) => T) {} } - -// TODO: Remove wrapper function with TemplateRef when we turn on Ivy -// Necessary for now to avoid a circular dependency -export const QUERY_READ_TEMPLATE_REF = - (TemplateRefConstructor: typeof ViewEngine_TemplateRef, - ElementRefConstructor: typeof ViewEngine_ElementRef) => { - return new ReadFromInjectorFn>( - (tNode: TNode, view: LViewData) => { - return createTemplateRef(TemplateRefConstructor, ElementRefConstructor, tNode, view); - }) as any; - }; - -// TODO: Remove wrapper function with ViewContainerRef when we turn on Ivy -// Necessary for now to avoid a circular dependency -export const QUERY_READ_CONTAINER_REF = - (ViewContainerRefConstructor: typeof ViewEngine_ViewContainerRef, - ElementRefConstructor: typeof ViewEngine_ElementRef) => { - return >( - new ReadFromInjectorFn( - (tNode: TNode, view: LViewData) => createContainerRef( - ViewContainerRefConstructor, ElementRefConstructor, - tNode as TElementNode | TContainerNode | TElementContainerNode, view)) as any); - - }; - -// TODO: Remove wrapper function with ElementRef when we turn on Ivy -// Necessary for now to avoid a circular dependency -export const QUERY_READ_ELEMENT_REF = (ElementRefConstructor: typeof ViewEngine_ElementRef) => { - return >( - new ReadFromInjectorFn((tNode: TNode, view: LViewData) => { - return createElementRef(ElementRefConstructor, tNode, view); - }) as any); -}; - -// TODO: Remove wrapper function with TemplateRef when we turn on Ivy -export const QUERY_READ_FROM_NODE = - (TemplateRefConstructor: typeof ViewEngine_TemplateRef, - ElementRefConstructor: typeof ViewEngine_ElementRef) => { - return new ReadFromInjectorFn((tNode: TNode, view: LViewData, directiveIdx: number) => { - ngDevMode && assertNodeOfPossibleTypes( - tNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer); - if (directiveIdx > -1) { - return view[DIRECTIVES] ![directiveIdx]; - } - if (tNode.type === TNodeType.Element || tNode.type === TNodeType.ElementContainer) { - return createElementRef(ElementRefConstructor, tNode, view); - } - if (tNode.type === TNodeType.Container) { - return createTemplateRef(TemplateRefConstructor, ElementRefConstructor, tNode, view); - } - if (ngDevMode) { - // should never happen - throw new Error(`Unexpected node type: ${tNode.type}`); - } - }) as any as QueryReadType; - }; diff --git a/packages/core/src/render3/view_engine_compatibility.ts b/packages/core/src/render3/view_engine_compatibility.ts index 003328c9f6..9101be0436 100644 --- a/packages/core/src/render3/view_engine_compatibility.ts +++ b/packages/core/src/render3/view_engine_compatibility.ts @@ -125,19 +125,6 @@ export function createTemplateRef( getRenderer(), hostNode.data ![QUERIES]); } -/** - * Retrieves `TemplateRef` instance from `Injector` when a local reference is placed on the - * `` element. - */ -export function templateRefExtractor( - TemplateRefToken: typeof ViewEngine_TemplateRef, - ElementRefToken: typeof ViewEngine_ElementRef) { - return (tNode: TNode, currentView: LViewData) => { - return createTemplateRef(TemplateRefToken, ElementRefToken, tNode, currentView); - }; -} - - let R3ViewContainerRef: { new ( lContainer: LContainer, tContainerNode: TContainerNode, diff --git a/packages/core/src/render3/view_engine_compatibility_prebound.ts b/packages/core/src/render3/view_engine_compatibility_prebound.ts new file mode 100644 index 0000000000..79f8d5b1c4 --- /dev/null +++ b/packages/core/src/render3/view_engine_compatibility_prebound.ts @@ -0,0 +1,64 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + + +import {ElementRef as ViewEngine_ElementRef} from '../linker/element_ref'; +import {TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref'; +import {ViewContainerRef as ViewEngine_ViewContainerRef} from '../linker/view_container_ref'; + +import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType} from './interfaces/node'; +import {QueryReadType} from './interfaces/query'; +import {DIRECTIVES, LViewData} from './interfaces/view'; +import {assertNodeOfPossibleTypes} from './node_assert'; +import {ReadFromInjectorFn} from './query'; +import {createContainerRef, createElementRef, createTemplateRef} from './view_engine_compatibility'; + + + +/** + * Retrieves `TemplateRef` instance from `Injector` when a local reference is placed on the + * `` element. + */ +export function templateRefExtractor(tNode: TNode, currentView: LViewData) { + return createTemplateRef(ViewEngine_TemplateRef, ViewEngine_ElementRef, tNode, currentView); +} + +export const QUERY_READ_ELEMENT_REF = >( + new ReadFromInjectorFn((tNode: TNode, view: LViewData) => { + return createElementRef(ViewEngine_ElementRef, tNode, view); + }) as any); + +export const QUERY_READ_TEMPLATE_REF = + new ReadFromInjectorFn>((tNode: TNode, view: LViewData) => { + return createTemplateRef(ViewEngine_TemplateRef, ViewEngine_ElementRef, tNode, view); + }) as any; + +export const QUERY_READ_CONTAINER_REF = >( + new ReadFromInjectorFn( + (tNode: TNode, view: LViewData) => createContainerRef( + ViewEngine_ViewContainerRef, ViewEngine_ElementRef, + tNode as TElementNode | TContainerNode | TElementContainerNode, view)) as any); + +export const QUERY_READ_FROM_NODE = + new ReadFromInjectorFn((tNode: TNode, view: LViewData, directiveIdx: number) => { + ngDevMode && assertNodeOfPossibleTypes( + tNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer); + if (directiveIdx > -1) { + return view[DIRECTIVES] ![directiveIdx]; + } + if (tNode.type === TNodeType.Element || tNode.type === TNodeType.ElementContainer) { + return createElementRef(ViewEngine_ElementRef, tNode, view); + } + if (tNode.type === TNodeType.Container) { + return createTemplateRef(ViewEngine_TemplateRef, ViewEngine_ElementRef, tNode, view); + } + if (ngDevMode) { + // should never happen + throw new Error(`Unexpected node type: ${tNode.type}`); + } + }) as any as QueryReadType; diff --git a/packages/core/test/render3/animations/players_spec.ts b/packages/core/test/render3/animations/players_spec.ts index a5c21d75d1..bf09f3474f 100644 --- a/packages/core/test/render3/animations/players_spec.ts +++ b/packages/core/test/render3/animations/players_spec.ts @@ -289,7 +289,7 @@ class SuperComp { }, viewQuery: function(rf: RenderFlags, ctx: SuperComp) { if (rf & RenderFlags.Create) { - query(0, ['child'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['child'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; diff --git a/packages/core/test/render3/common_integration_spec.ts b/packages/core/test/render3/common_integration_spec.ts index d91d747477..367a3892a3 100644 --- a/packages/core/test/render3/common_integration_spec.ts +++ b/packages/core/test/render3/common_integration_spec.ts @@ -897,15 +897,11 @@ describe('@angular/common integration', () => { */ template: (rf: RenderFlags, myApp: MyApp) => { if (rf & RenderFlags.Create) { - template( - 0, - (rf1: RenderFlags) => { - if (rf1 & RenderFlags.Create) { - text(0, 'from tpl'); - } - }, - 1, 0, undefined, undefined, ['tpl', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, (rf1: RenderFlags) => { + if (rf1 & RenderFlags.Create) { + text(0, 'from tpl'); + } + }, 1, 0, undefined, undefined, ['tpl', ''], templateRefExtractor); template(2, null, 0, 0, null, [AttributeMarker.SelectOnly, 'ngTemplateOutlet']); } if (rf & RenderFlags.Update) { @@ -944,15 +940,11 @@ describe('@angular/common integration', () => { */ template: (rf: RenderFlags, myApp: MyApp) => { if (rf & RenderFlags.Create) { - template( - 0, - (rf1: RenderFlags) => { - if (rf1 & RenderFlags.Create) { - text(0, 'from tpl'); - } - }, - 1, 0, undefined, undefined, ['tpl', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, (rf1: RenderFlags) => { + if (rf1 & RenderFlags.Create) { + text(0, 'from tpl'); + } + }, 1, 0, undefined, undefined, ['tpl', ''], templateRefExtractor); elementContainerStart(2, [AttributeMarker.SelectOnly, 'ngTemplateOutlet']); elementContainerEnd(); } diff --git a/packages/core/test/render3/compiler_canonical/local_reference_spec.ts b/packages/core/test/render3/compiler_canonical/local_reference_spec.ts index ea9f58dff6..17e9898383 100644 --- a/packages/core/test/render3/compiler_canonical/local_reference_spec.ts +++ b/packages/core/test/render3/compiler_canonical/local_reference_spec.ts @@ -72,7 +72,7 @@ describe('local references', () => { if (rf & 1) { $r3$.ɵtemplate( 0, MyComponent_Template_0, 0, 0, null, null, ['tpl', ''], - $r3$.ɵtemplateRefExtractor(TemplateRef, ElementRef)); + $r3$.ɵtemplateRefExtractor); $r3$.ɵtext(2); } if (rf & 2) { diff --git a/packages/core/test/render3/query_spec.ts b/packages/core/test/render3/query_spec.ts index 00178fdee1..f7afbfd1d0 100644 --- a/packages/core/test/render3/query_spec.ts +++ b/packages/core/test/render3/query_spec.ts @@ -16,8 +16,8 @@ import {AttributeMarker, QueryList, defineComponent, defineDirective, detectChan import {bind, container, containerRefreshEnd, containerRefreshStart, element, elementContainerEnd, elementContainerStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, load, loadDirective, loadElement, loadQueryList, reference, registerContentQuery, template} from '../../src/render3/instructions'; import {RenderFlags} from '../../src/render3/interfaces/definition'; -import {query, queryRefresh, QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF} from '../../src/render3/query'; -import {templateRefExtractor} from '../../src/render3/view_engine_compatibility'; +import {query, queryRefresh} from '../../src/render3/query'; +import {templateRefExtractor, QUERY_READ_ELEMENT_REF, QUERY_READ_CONTAINER_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF} from '../../src/render3/view_engine_compatibility_prebound'; import {NgForOf, NgIf, NgTemplateOutlet} from './common_with_def'; import {ComponentFixture, TemplateFixture, createComponent, createDirective, renderComponent} from './render_util'; @@ -121,7 +121,7 @@ describe('query', () => { 2, 0, [Child], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, Child, false, QUERY_READ_ELEMENT_REF(ElementRef)); + query(0, Child, false, QUERY_READ_ELEMENT_REF); } if (rf & RenderFlags.Update) { let tmp: any; @@ -229,7 +229,7 @@ describe('query', () => { 4, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], false, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], false, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -266,8 +266,8 @@ describe('query', () => { 6, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], false, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); - query(1, ['bar'], false, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], false, QUERY_READ_FROM_NODE); + query(1, ['bar'], false, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -315,7 +315,7 @@ describe('query', () => { 6, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo', 'bar'], undefined, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo', 'bar'], undefined, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -352,7 +352,7 @@ describe('query', () => { 4, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], false, QUERY_READ_ELEMENT_REF(ElementRef)); + query(0, ['foo'], false, QUERY_READ_ELEMENT_REF); } if (rf & RenderFlags.Update) { let tmp: any; @@ -388,7 +388,7 @@ describe('query', () => { 3, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], false, QUERY_READ_ELEMENT_REF(ElementRef)); + query(0, ['foo'], false, QUERY_READ_ELEMENT_REF); } if (rf & RenderFlags.Update) { let tmp: any; @@ -424,7 +424,7 @@ describe('query', () => { 3, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -488,8 +488,8 @@ describe('query', () => { 5, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_ELEMENT_REF(ElementRef)); - query(1, ['foo'], false, QUERY_READ_ELEMENT_REF(ElementRef)); + query(0, ['foo'], true, QUERY_READ_ELEMENT_REF); + query(1, ['foo'], false, QUERY_READ_ELEMENT_REF); } if (rf & RenderFlags.Update) { let tmp: any; @@ -523,7 +523,7 @@ describe('query', () => { 3, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], false, QUERY_READ_CONTAINER_REF(ViewContainerRef, ElementRef)); + query(0, ['foo'], false, QUERY_READ_CONTAINER_REF); } if (rf & RenderFlags.Update) { let tmp: any; @@ -554,7 +554,7 @@ describe('query', () => { 3, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], false, QUERY_READ_CONTAINER_REF(ViewContainerRef, ElementRef)); + query(0, ['foo'], false, QUERY_READ_CONTAINER_REF); } if (rf & RenderFlags.Update) { let tmp: any; @@ -587,7 +587,7 @@ describe('query', () => { function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], false, QUERY_READ_ELEMENT_REF(ElementRef)); + query(0, ['foo'], false, QUERY_READ_ELEMENT_REF); } if (rf & RenderFlags.Update) { let tmp: any; @@ -621,7 +621,7 @@ describe('query', () => { 3, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], undefined, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], undefined, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -653,7 +653,7 @@ describe('query', () => { 3, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], false, QUERY_READ_TEMPLATE_REF(TemplateRef, ElementRef)); + query(0, ['foo'], false, QUERY_READ_TEMPLATE_REF); } if (rf & RenderFlags.Update) { let tmp: any; @@ -690,7 +690,7 @@ describe('query', () => { 3, 0, [Child], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -735,7 +735,7 @@ describe('query', () => { 3, 0, [Child], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -773,7 +773,7 @@ describe('query', () => { 3, 0, [Child], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -813,7 +813,7 @@ describe('query', () => { 4, 0, [Child1, Child2], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo', 'bar'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo', 'bar'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -852,8 +852,8 @@ describe('query', () => { 5, 0, [Child], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); - query(1, ['bar'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); + query(1, ['bar'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -896,7 +896,7 @@ describe('query', () => { 3, 0, [Child], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], undefined, QUERY_READ_ELEMENT_REF(ElementRef)); + query(0, ['foo'], undefined, QUERY_READ_ELEMENT_REF); } if (rf & RenderFlags.Update) { let tmp: any; @@ -934,7 +934,7 @@ describe('query', () => { 4, 0, [Child], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo', 'bar'], undefined, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo', 'bar'], undefined, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1042,7 +1042,7 @@ describe('query', () => { 3, 1, [NgIf], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1103,7 +1103,7 @@ describe('query', () => { viewQuery: function(rf: RenderFlags, ctx: Cmpt) { let tmp: any; if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { queryRefresh(tmp = load>(0)) && (ctx.query = tmp as QueryList); @@ -1173,12 +1173,10 @@ describe('query', () => { function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { template( - 1, Cmpt_Template_1, 2, 1, null, null, ['tpl1', ''], - templateRefExtractor(TemplateRef, ElementRef)); + 1, Cmpt_Template_1, 2, 1, null, null, ['tpl1', ''], templateRefExtractor); element(3, 'div', ['id', 'middle'], ['foo', '']); template( - 5, Cmpt_Template_5, 2, 1, null, null, ['tpl2', ''], - templateRefExtractor(TemplateRef, ElementRef)); + 5, Cmpt_Template_5, 2, 1, null, null, ['tpl2', ''], templateRefExtractor); template(7, null, 0, 0, null, [AttributeMarker.SelectOnly, 'vc']); } @@ -1191,7 +1189,7 @@ describe('query', () => { 9, 0, [ViewContainerManipulatorDirective], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1273,9 +1271,7 @@ describe('query', () => { template: function(rf: RenderFlags, ctx: any) { let tmp: any; if (rf & RenderFlags.Create) { - template( - 1, Cmpt_Template_1, 2, 1, null, [], ['tpl', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(1, Cmpt_Template_1, 2, 1, null, [], ['tpl', ''], templateRefExtractor); template(3, null, 0, 0, null, [AttributeMarker.SelectOnly, 'vc']); template(4, null, 0, 0, null, [AttributeMarker.SelectOnly, 'vc']); } @@ -1288,7 +1284,7 @@ describe('query', () => { viewQuery: (rf: RenderFlags, cmpt: Cmpt) => { let tmp: any; if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { queryRefresh(tmp = load>(0)) && @@ -1348,7 +1344,7 @@ describe('query', () => { if (rf & RenderFlags.Create) { template( 1, MyApp_Template_1, 2, 0, undefined, undefined, ['tpl', ''], - templateRefExtractor(TemplateRef, ElementRef)); + templateRefExtractor); template(3, null, 0, 0, null, [AttributeMarker.SelectOnly, 'ngTemplateOutlet']); } if (rf & RenderFlags.Update) { @@ -1360,7 +1356,7 @@ describe('query', () => { viewQuery: (rf: RenderFlags, myApp: MyApp) => { let tmp: any; if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { queryRefresh(tmp = load>(0)) && @@ -1425,7 +1421,7 @@ describe('query', () => { 2, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1490,7 +1486,7 @@ describe('query', () => { 6, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1567,7 +1563,7 @@ describe('query', () => { 2, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1647,7 +1643,7 @@ describe('query', () => { 2, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1716,8 +1712,8 @@ describe('query', () => { 5, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); - query(1, ['foo'], false, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); + query(1, ['foo'], false, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1797,7 +1793,7 @@ describe('query', () => { 2, 0, [], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], false, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], false, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1878,7 +1874,7 @@ describe('query', () => { 4, 0, [SomeDir], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -1915,10 +1911,8 @@ describe('query', () => { type: WithContentDirective, selectors: [['', 'with-content', '']], factory: () => new WithContentDirective(), - contentQueries: () => { - registerContentQuery( - query(null, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef))); - }, + contentQueries: + () => { registerContentQuery(query(null, ['foo'], true, QUERY_READ_FROM_NODE)); }, contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { let tmp: any; withContentInstance = loadDirective(dirIndex); @@ -1939,10 +1933,8 @@ describe('query', () => { template: function(rf: RenderFlags, ctx: any) {}, consts: 0, vars: 0, - contentQueries: () => { - registerContentQuery( - query(null, ['foo'], false, QUERY_READ_FROM_NODE(TemplateRef, ElementRef))); - }, + contentQueries: + () => { registerContentQuery(query(null, ['foo'], false, QUERY_READ_FROM_NODE)); }, contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { let tmp: any; shallowCompInstance = loadDirective(dirIndex); @@ -2058,7 +2050,7 @@ describe('query', () => { 6, 0, [WithContentDirective], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['foo', 'bar'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['foo', 'bar'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -2098,7 +2090,7 @@ describe('query', () => { 6, 0, [WithContentDirective], [], function(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - query(0, ['bar'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef)); + query(0, ['bar'], true, QUERY_READ_FROM_NODE); } if (rf & RenderFlags.Update) { let tmp: any; @@ -2122,8 +2114,7 @@ describe('query', () => { contentQueries: () => { // @ContentChildren('foo, bar, baz', {descendants: true}) fooBars: // QueryList; - registerContentQuery(query( - null, ['foo', 'bar', 'baz'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef))); + registerContentQuery(query(null, ['foo', 'bar', 'baz'], true, QUERY_READ_FROM_NODE)); }, contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { let tmp: any; @@ -2187,8 +2178,7 @@ describe('query', () => { contentQueries: () => { // @ContentChildren('foo, bar, baz', {descendants: true}) fooBars: // QueryList; - registerContentQuery( - query(null, ['foo'], false, QUERY_READ_FROM_NODE(TemplateRef, ElementRef))); + registerContentQuery(query(null, ['foo'], false, QUERY_READ_FROM_NODE)); }, contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { let tmp: any; @@ -2241,8 +2231,7 @@ describe('query', () => { factory: () => new ShallowQueryDirective(), contentQueries: () => { // @ContentChildren('foo', {descendants: false}) foos: QueryList; - registerContentQuery( - query(null, ['foo'], false, QUERY_READ_FROM_NODE(TemplateRef, ElementRef))); + registerContentQuery(query(null, ['foo'], false, QUERY_READ_FROM_NODE)); }, contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { let tmp: any; @@ -2262,8 +2251,7 @@ describe('query', () => { factory: () => new DeepQueryDirective(), contentQueries: () => { // @ContentChildren('foo', {descendants: false}) foos: QueryList; - registerContentQuery( - query(null, ['foo'], true, QUERY_READ_FROM_NODE(TemplateRef, ElementRef))); + registerContentQuery(query(null, ['foo'], true, QUERY_READ_FROM_NODE)); }, contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { let tmp: any; diff --git a/packages/core/test/render3/view_container_ref_spec.ts b/packages/core/test/render3/view_container_ref_spec.ts index dfa355a5ff..445bee9175 100644 --- a/packages/core/test/render3/view_container_ref_spec.ts +++ b/packages/core/test/render3/view_container_ref_spec.ts @@ -13,7 +13,7 @@ import {AttributeMarker, NgOnChangesFeature, defineComponent, defineDirective, d import {bind, container, containerRefreshEnd, containerRefreshStart, element, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, interpolation1, interpolation3, loadDirective, nextContext, projection, projectionDef, reference, template, text, textBinding} from '../../src/render3/instructions'; import {RenderFlags} from '../../src/render3/interfaces/definition'; -import {templateRefExtractor} from '../../src/render3/view_engine_compatibility'; +import {templateRefExtractor} from '../../src/render3/view_engine_compatibility_prebound'; import {NgModuleFactory} from '../../src/render3/ng_module_ref'; import {pipe, pipeBind1} from '../../src/render3/pipe'; import {NgForOf} from '../../test/render3/common_with_def'; @@ -67,9 +67,7 @@ describe('ViewContainerRef', () => { *

*/ function createTemplate() { - template( - 0, embeddedTemplate, 1, 1, null, null, ['tplRef', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, embeddedTemplate, 1, 1, null, null, ['tplRef', ''], templateRefExtractor); element(2, 'p', ['vcref', '']); } @@ -86,9 +84,7 @@ describe('ViewContainerRef', () => { *
*/ function createTemplate() { - template( - 0, embeddedTemplate, 1, 1, null, null, ['tplRef', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, embeddedTemplate, 1, 1, null, null, ['tplRef', ''], templateRefExtractor); element(2, 'header', ['vcref', '']); element(3, 'footer'); } @@ -124,9 +120,7 @@ describe('ViewContainerRef', () => { *
*/ function createTemplate() { - template( - 0, embeddedTemplate, 1, 1, null, [], ['tplRef', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, embeddedTemplate, 1, 1, null, [], ['tplRef', ''], templateRefExtractor); element(2, 'header-cmp', ['vcref', '']); element(3, 'footer'); } @@ -162,9 +156,7 @@ describe('ViewContainerRef', () => { *
*/ function createTemplate() { - template( - 0, embeddedTemplate, 1, 1, null, null, ['tplRef', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, embeddedTemplate, 1, 1, null, null, ['tplRef', ''], templateRefExtractor); element(2, 'div', ['vcref', '']); element(3, 'div', ['vcref', '']); @@ -195,8 +187,7 @@ describe('ViewContainerRef', () => { */ function createTemplate() { template( - 0, embeddedTemplate, 1, 1, null, ['vcref', ''], ['tplRef', ''], - templateRefExtractor(TemplateRef, ElementRef)); + 0, embeddedTemplate, 1, 1, null, ['vcref', ''], ['tplRef', ''], templateRefExtractor); element(2, 'footer'); } @@ -467,8 +458,7 @@ describe('ViewContainerRef', () => { template: (rf: RenderFlags, cmp: SomeComponent) => { if (rf & RenderFlags.Create) { template( - 0, SomeComponent_Template_0, 2, 3, null, [], ['foo', ''], - templateRefExtractor(TemplateRef, ElementRef)); + 0, SomeComponent_Template_0, 2, 3, null, [], ['foo', ''], templateRefExtractor); pipe(2, 'starPipe'); element(3, 'child', ['vcref', '']); pipe(4, 'starPipe'); @@ -559,9 +549,7 @@ describe('ViewContainerRef', () => { */ const Parent = createComponent('parent', function(rf: RenderFlags, parent: any) { if (rf & RenderFlags.Create) { - template( - 0, fooTemplate, 2, 1, null, null, ['foo', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, fooTemplate, 2, 1, null, null, ['foo', ''], templateRefExtractor); element(2, 'child'); } @@ -652,9 +640,7 @@ describe('ViewContainerRef', () => { */ const Parent = createComponent('parent', function(rf: RenderFlags, parent: any) { if (rf & RenderFlags.Create) { - template( - 0, rowTemplate, 3, 2, null, null, ['rowTemplate', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, rowTemplate, 3, 2, null, null, ['rowTemplate', ''], templateRefExtractor); element(2, 'loop-comp'); } @@ -668,9 +654,7 @@ describe('ViewContainerRef', () => { function rowTemplate(rf: RenderFlags, ctx: any) { if (rf & RenderFlags.Create) { - template( - 0, cellTemplate, 2, 3, null, null, ['cellTemplate', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, cellTemplate, 2, 3, null, null, ['cellTemplate', ''], templateRefExtractor); element(2, 'loop-comp'); } @@ -1215,9 +1199,7 @@ describe('ViewContainerRef', () => { vars: 2, template: (rf: RenderFlags, cmp: Parent) => { if (rf & RenderFlags.Create) { - template( - 0, embeddedTemplate, 2, 1, null, null, ['foo', ''], - templateRefExtractor(TemplateRef, ElementRef)); + template(0, embeddedTemplate, 2, 1, null, null, ['foo', ''], templateRefExtractor); elementStart(2, 'child'); { elementStart(3, 'header', ['vcref', '']); @@ -1312,8 +1294,7 @@ describe('ViewContainerRef', () => { template: (rf: RenderFlags, cmp: Parent) => { if (rf & RenderFlags.Create) { template( - 0, embeddedTemplate, 2, 1, null, undefined, ['foo', ''], - templateRefExtractor(TemplateRef, ElementRef)); + 0, embeddedTemplate, 2, 1, null, undefined, ['foo', ''], templateRefExtractor); elementStart(2, 'child-with-view'); text(3, 'Before projected'); elementStart(4, 'header', ['vcref', '']); @@ -1397,8 +1378,7 @@ describe('ViewContainerRef', () => { let tplRef: any; if (rf & RenderFlags.Create) { template( - 0, embeddedTemplate, 2, 1, null, null, ['foo', ''], - templateRefExtractor(TemplateRef, ElementRef)); + 0, embeddedTemplate, 2, 1, null, null, ['foo', ''], templateRefExtractor); elementStart(2, 'child-with-selector'); elementStart(3, 'header', ['vcref', '']); text(4, 'blah'); @@ -1451,8 +1431,7 @@ describe('ViewContainerRef', () => { let tplRef: any; if (rf & RenderFlags.Create) { template( - 0, embeddedTemplate, 2, 1, null, null, ['foo', ''], - templateRefExtractor(TemplateRef, ElementRef)); + 0, embeddedTemplate, 2, 1, null, null, ['foo', ''], templateRefExtractor); elementStart(2, 'child-with-selector'); elementStart(3, 'footer', ['vcref', '']); text(4, 'blah'); @@ -1557,8 +1536,7 @@ describe('ViewContainerRef', () => { template: (rf: RenderFlags, cmp: SomeComponent) => { if (rf & RenderFlags.Create) { template( - 0, SomeComponent_Template_0, 1, 1, null, [], ['foo', ''], - templateRefExtractor(TemplateRef, ElementRef)); + 0, SomeComponent_Template_0, 1, 1, null, [], ['foo', ''], templateRefExtractor); element(2, 'hooks', ['vcref', '']); element(3, 'hooks'); }