Hierarchical asset list with server side javascript (SSJ)

Of course, if you don’t mind having a hard coded limit to how many it can handle, you could do something really disgusting like

<script runat="server">
const children = %globals_asset_children_link_type_1:103^empty:[]%;

const grandChildren = 
[
 %globals_asset_children_link_type_1:103^index:0^as_asset:asset_children_link_type_1^empty:[]%
,%globals_asset_children_link_type_1:103^index:1^as_asset:asset_children_link_type_1^empty:[]%
,%globals_asset_children_link_type_1:103^index:3^as_asset:asset_children_link_type_1^empty:[]%
,%globals_asset_children_link_type_1:103^index:4^as_asset:asset_children_link_type_1^empty:[]%
,%globals_asset_children_link_type_1:103^index:5^as_asset:asset_children_link_type_1^empty:[]%
,%globals_asset_children_link_type_1:103^index:6^as_asset:asset_children_link_type_1^empty:[]%
,%globals_asset_children_link_type_1:103^index:7^as_asset:asset_children_link_type_1^empty:[]%
,%globals_asset_children_link_type_1:103^index:8^as_asset:asset_children_link_type_1^empty:[]%
,%globals_asset_children_link_type_1:103^index:9^as_asset:asset_children_link_type_1^empty:[]%
,%globals_asset_children_link_type_1:103^index:10^as_asset:asset_children_link_type_1^empty:[]%
]

children.forEach(function(child, i) {
  print('<li>%globals_asset_name:' + child + '%');
  if (grandChildren[i].length > 0) {
    print('<ul>');
    grandChildren[i].forEach(function(grandChild) {
      print('<li>%globals_asset_name:' + grandChild + '%</li>');
    });
    print('</ul>');
  }
  print('</li>');
});
</script>

which becomes something like

const children = ["179","107","111","115","119","123","127"];

const grandChildren = 
[
 []
,["131","135"]
,["147","151","155"]
,["159"]
,["163","167","171"]
,["175"]
,[]
,[]
,[]
,[]
]


children.forEach(function(child, i) {
 
  print('<li>%globals_asset_name:' + child + '%');
  
  if (grandChildren[i].length > 0) {
    print('<ul>');
    
    grandChildren[i].forEach(function(grandChild) {
      print('<li>%globals_asset_name:' + grandChild + '%</li>');
    });
    
    print('</ul>');
  }
  
  print('</li>');
});

but you’d have to really want to avoid using an Asset Listing to go with that. On the other hand, if a hardcoded limit is acceptable this might perform better than an Asset Listing. Or worse. ¯\_(ツ)_/¯