@@ -41,22 +41,20 @@ import {
4141 ControlFlowBlockType ,
4242 DeferBlockData ,
4343 ForLoopBlockData ,
44- RepeaterMetadataShape ,
4544} from './control_flow_types' ;
4645import { TNode } from '../interfaces/node' ;
46+ import { RepeaterMetadata } from '../instructions/control_flow' ;
4747
4848/**
4949 * Gets all of the control flow blocks that are present inside the specified DOM node.
5050 * @param node Node in which to look for control flow blocks.
51- *
52- * @publicApi
5351 */
5452export function getControlFlowBlocks ( node : Node ) : ControlFlowBlock [ ] {
55- const results : ControlFlowBlock [ ] = [ ] ;
53+ let results : ControlFlowBlock [ ] = [ ] ;
5654 const lView = getLContext ( node ) ?. lView ;
5755
5856 if ( lView ) {
59- findControlFlowBlocks ( node , lView , results ) ;
57+ results = findControlFlowBlocks ( node , lView ) ;
6058 }
6159
6260 return results ;
@@ -91,8 +89,6 @@ const deferBlockFinder: ControlFlowBlockViewFinder = ({
9189 const tDetails = getTDeferBlockDetails ( tView , tNode ) ;
9290
9391 if ( isTDeferBlockDetails ( tDetails ) ) {
94- // return {lContainer, lView, tNode, tDetails};
95-
9692 const native = getNativeByTNode ( tNode , lView ) ;
9793 const lDetails = getLDeferBlockDetails ( lView , tNode ) ;
9894
@@ -174,7 +170,7 @@ const forLoopFinder: ControlFlowBlockViewFinder = ({
174170} : ControlFlowBlockViewFinderConfig ) => {
175171 const slot = lView [ slotIdx ] ;
176172
177- if ( ! isRepeaterMetadata ( slot ) ) {
173+ if ( ! ( slot instanceof RepeaterMetadata ) ) {
178174 return null ;
179175 }
180176
@@ -222,9 +218,14 @@ const CONTROL_FLOW_BLOCK_FINDERS: ControlFlowBlockViewFinder[] = [deferBlockFind
222218 *
223219 * @param node Node in which to search for blocks.
224220 * @param lView View within the node in which to search for blocks.
225- * @param results Array to which to add blocks once they're found.
221+ * @param results (Optional) Array to which to add blocks once they're found.
222+ * @returns Found control flow blocks results array.
226223 */
227- function findControlFlowBlocks ( node : Node , lView : LView , results : ControlFlowBlock [ ] ) {
224+ function findControlFlowBlocks (
225+ node : Node ,
226+ lView : LView ,
227+ results : ControlFlowBlock [ ] = [ ] ,
228+ ) : ControlFlowBlock [ ] {
228229 const tView = lView [ TVIEW ] ;
229230
230231 for ( let i = HEADER_OFFSET ; i < tView . bindingStartIndex ; i ++ ) {
@@ -255,6 +256,8 @@ function findControlFlowBlocks(node: Node, lView: LView, results: ControlFlowBlo
255256 findControlFlowBlocks ( node , slot , results ) ;
256257 }
257258 }
259+
260+ return results ;
258261}
259262
260263/**
@@ -318,27 +321,13 @@ function getRendererLView(lContainer: LContainer): LView | null {
318321 return lView ;
319322}
320323
321- /**
322- * Checks if a value looks like RepeaterMetadata by duck-typing.
323- * Can't use instanceof because that would require importing from control_flow.ts.
324- */
325- function isRepeaterMetadata ( value : unknown ) : value is RepeaterMetadataShape {
326- return (
327- value !== null &&
328- typeof value === 'object' &&
329- 'hasEmptyBlock' in value &&
330- 'trackByFn' in value &&
331- typeof ( value as RepeaterMetadataShape ) . trackByFn === 'function'
332- ) ;
333- }
334-
335324/**
336325 * Returns the string representation of the track expression.
337326 *
338327 * @param metadata Metadata containing the track function.
339328 * @returns
340329 */
341- function getTrackExpression ( metadata : RepeaterMetadataShape ) : string {
330+ function getTrackExpression ( metadata : RepeaterMetadata ) : string {
342331 const trackByFn = metadata . trackByFn ;
343332 if ( trackByFn . name === 'ɵɵrepeaterTrackByIndex' ) {
344333 return '$index' ;
0 commit comments