@@ -41,25 +41,22 @@ 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 [ ] = [ ] ;
5653 const lView = getLContext ( node ) ?. lView ;
5754
5855 if ( lView ) {
59- findControlFlowBlocks ( node , lView , results ) ;
56+ return findControlFlowBlocks ( node , lView ) ;
6057 }
6158
62- return results ;
59+ return [ ] ;
6360}
6461
6562/**
@@ -91,8 +88,6 @@ const deferBlockFinder: ControlFlowBlockViewFinder = ({
9188 const tDetails = getTDeferBlockDetails ( tView , tNode ) ;
9289
9390 if ( isTDeferBlockDetails ( tDetails ) ) {
94- // return {lContainer, lView, tNode, tDetails};
95-
9691 const native = getNativeByTNode ( tNode , lView ) ;
9792 const lDetails = getLDeferBlockDetails ( lView , tNode ) ;
9893
@@ -174,7 +169,7 @@ const forLoopFinder: ControlFlowBlockViewFinder = ({
174169} : ControlFlowBlockViewFinderConfig ) => {
175170 const slot = lView [ slotIdx ] ;
176171
177- if ( ! isRepeaterMetadata ( slot ) ) {
172+ if ( ! ( slot instanceof RepeaterMetadata ) ) {
178173 return null ;
179174 }
180175
@@ -222,9 +217,14 @@ const CONTROL_FLOW_BLOCK_FINDERS: ControlFlowBlockViewFinder[] = [deferBlockFind
222217 *
223218 * @param node Node in which to search for blocks.
224219 * @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.
220+ * @param results (Optional) Array to which to add blocks once they're found.
221+ * @returns Found control flow blocks results array.
226222 */
227- function findControlFlowBlocks ( node : Node , lView : LView , results : ControlFlowBlock [ ] ) {
223+ function findControlFlowBlocks (
224+ node : Node ,
225+ lView : LView ,
226+ results : ControlFlowBlock [ ] = [ ] ,
227+ ) : ControlFlowBlock [ ] {
228228 const tView = lView [ TVIEW ] ;
229229
230230 for ( let i = HEADER_OFFSET ; i < tView . bindingStartIndex ; i ++ ) {
@@ -255,6 +255,8 @@ function findControlFlowBlocks(node: Node, lView: LView, results: ControlFlowBlo
255255 findControlFlowBlocks ( node , slot , results ) ;
256256 }
257257 }
258+
259+ return results ;
258260}
259261
260262/**
@@ -318,27 +320,13 @@ function getRendererLView(lContainer: LContainer): LView | null {
318320 return lView ;
319321}
320322
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-
335323/**
336324 * Returns the string representation of the track expression.
337325 *
338326 * @param metadata Metadata containing the track function.
339327 * @returns
340328 */
341- function getTrackExpression ( metadata : RepeaterMetadataShape ) : string {
329+ function getTrackExpression ( metadata : RepeaterMetadata ) : string {
342330 const trackByFn = metadata . trackByFn ;
343331 if ( trackByFn . name === 'ɵɵrepeaterTrackByIndex' ) {
344332 return '$index' ;
0 commit comments