@@ -601,11 +601,32 @@ fn process_create_ops_with_child_recursion<'a>(
601601 }
602602 } // Borrow of job ends here
603603
604- // Process track_by_ops IMMEDIATELY after the create op, BEFORE child view recursion.
605- // This matches Angular's ops() generator which yields track_by_ops inline with the
606- // RepeaterCreate op. The switch statement in naming.ts processes the RepeaterCreate,
607- // then the generator yields track_by_ops (processed as Variable ops), and only then
608- // does the iteration continue to child views.
604+ // Recurse into any child views at this index BEFORE processing track_by_ops.
605+ // This matches TypeScript's naming.ts behavior:
606+ // 1. ops() yields RepeaterCreate
607+ // 2. switch case handles RepeaterCreate → IMMEDIATELY recurses into child views
608+ // 3. switch case ends, control returns to for loop
609+ // 4. ops() yields track_by_ops (which are processed in subsequent for iterations)
610+ //
611+ // So the order is: recurse into children FIRST, then name track_by_ops variables.
612+ if let Some ( children) = child_views_by_index. remove ( & index) {
613+ for ( child_xref, child_base_name) in children {
614+ add_names_to_child_view (
615+ job,
616+ child_xref,
617+ & child_base_name,
618+ allocator,
619+ state,
620+ var_names,
621+ semantic_var_names,
622+ ) ;
623+ }
624+ }
625+
626+ // Process track_by_ops AFTER child view recursion.
627+ // In TypeScript, the ops() generator yields track_by_ops after the RepeaterCreate,
628+ // and the switch statement has already recursed into child views during the
629+ // RepeaterCreate case. So track_by_ops are named AFTER all child view variables.
609630 if is_repeater_with_track_by {
610631 let create_ops = match view_xref {
611632 None => & mut job. root . create ,
@@ -634,22 +655,6 @@ fn process_create_ops_with_child_recursion<'a>(
634655 }
635656 }
636657 }
637-
638- // After processing the create op and its track_by_ops, recurse into any child views
639- // at this index. This is the key to depth-first processing!
640- if let Some ( children) = child_views_by_index. remove ( & index) {
641- for ( child_xref, child_base_name) in children {
642- add_names_to_child_view (
643- job,
644- child_xref,
645- & child_base_name,
646- allocator,
647- state,
648- var_names,
649- semantic_var_names,
650- ) ;
651- }
652- }
653658 }
654659}
655660
0 commit comments