@@ -241,8 +241,34 @@ let compile output_prefix =
241241 | Some index -> String. sub id.name 0 index
242242 | None -> id.name)
243243 in
244- let rec extract_nested_external_component_segments segments
245- ((lam : Lam.t ), (make_dynamic_import : bool option ref )) :
244+ let nested_component_path id dynamic_import segments =
245+ let root_name = root_module_name id in
246+ let denamespace_segment segment =
247+ let namespaced_prefix = root_name ^ " $" in
248+ if Ext_string. starts_with segment namespaced_prefix then
249+ match String. split_on_char '$' segment with
250+ | root :: _namespace :: rest when rest <> [] ->
251+ String. concat " $" (root :: rest)
252+ | _ -> segment
253+ else segment
254+ in
255+ let segments =
256+ match segments with
257+ | head :: rest
258+ when head = id.name || head = root_name
259+ || Ext_string. starts_with head (root_name ^ " $" ) ->
260+ rest
261+ | _ -> segments
262+ in
263+ match segments with
264+ | [] -> None
265+ | head :: rest ->
266+ Some
267+ ( id,
268+ dynamic_import,
269+ String. concat " $" (root_name :: denamespace_segment head :: rest) )
270+ in
271+ let rec extract_nested_external_component_segments segments (lam : Lam.t ) :
246272 (Ident. t * bool * string list ) option =
247273 match lam with
248274 | Lprim
@@ -251,21 +277,15 @@ let compile output_prefix =
251277 args = [arg];
252278 _;
253279 } ->
254- extract_nested_external_component_segments (name :: segments)
255- (arg, make_dynamic_import)
280+ extract_nested_external_component_segments (name :: segments) arg
256281 | Lprim {primitive = Pawait ; args = [arg]; _} ->
257- extract_nested_external_component_segments segments
258- (arg, make_dynamic_import)
282+ extract_nested_external_component_segments segments arg
259283 | Lvar id -> (
260284 match Map_ident. find_opt ! local_module_aliases id with
261285 | Some alias_lam ->
262- extract_nested_external_component_segments segments
263- (alias_lam, make_dynamic_import)
264- | None ->
265- make_dynamic_import := Some false ;
266- Some (id, false , List. rev segments))
286+ extract_nested_external_component_segments segments alias_lam
287+ | None -> Some (id, false , List. rev segments))
267288 | Lglobal_module (id , dynamic_import ) ->
268- make_dynamic_import := Some dynamic_import;
269289 Some (id, dynamic_import, List. rev segments)
270290 | _ -> None
271291 in
@@ -294,42 +314,9 @@ let compile output_prefix =
294314 in
295315 let extract_nested_external_component_path (lam : Lam.t ) :
296316 (Ident. t * bool * string ) option =
297- let dynamic_import = ref None in
298- match
299- extract_nested_external_component_segments [] (lam, dynamic_import)
300- with
301- | Some (id , dynamic_import , segments ) -> (
302- let denamespace_segment segment =
303- let root_name = root_module_name id in
304- let namespaced_prefix = root_name ^ " $" in
305- if Ext_string. starts_with segment namespaced_prefix then
306- match String. split_on_char '$' segment with
307- | root :: _namespace :: rest when rest <> [] ->
308- String. concat " $" (root :: rest)
309- | _ -> segment
310- else segment
311- in
312- let segments =
313- match segments with
314- | head :: rest
315- when head = id.name
316- || head = root_module_name id
317- || Ext_string. starts_with head (root_module_name id ^ " $" ) ->
318- rest
319- | _ -> segments
320- in
321- let segments =
322- match segments with
323- | head :: rest -> denamespace_segment head :: rest
324- | [] -> []
325- in
326- match segments with
327- | [] -> None
328- | _ ->
329- Some
330- ( id,
331- dynamic_import,
332- String. concat " $" (root_module_name id :: segments) ))
317+ match extract_nested_external_component_segments [] lam with
318+ | Some (id , dynamic_import , segments ) ->
319+ nested_component_path id dynamic_import segments
333320 | None -> None
334321 in
335322 let extract_nested_external_component_field (lam : Lam.t ) :
@@ -347,38 +334,8 @@ let compile output_prefix =
347334 let extract_static_nested_external_component_path (lam : Lam.t ) :
348335 (Ident. t * bool * string ) option =
349336 match extract_static_nested_external_component_segments [] lam with
350- | Some (id , dynamic_import , segments ) -> (
351- let denamespace_segment segment =
352- let root_name = root_module_name id in
353- let namespaced_prefix = root_name ^ " $" in
354- if Ext_string. starts_with segment namespaced_prefix then
355- match String. split_on_char '$' segment with
356- | root :: _namespace :: rest when rest <> [] ->
357- String. concat " $" (root :: rest)
358- | _ -> segment
359- else segment
360- in
361- let segments =
362- match segments with
363- | head :: rest
364- when head = id.name
365- || head = root_module_name id
366- || Ext_string. starts_with head (root_module_name id ^ " $" ) ->
367- rest
368- | _ -> segments
369- in
370- let segments =
371- match segments with
372- | head :: rest -> denamespace_segment head :: rest
373- | [] -> []
374- in
375- match segments with
376- | [] -> None
377- | _ ->
378- Some
379- ( id,
380- dynamic_import,
381- String. concat " $" (root_module_name id :: segments) ))
337+ | Some (id , dynamic_import , segments ) ->
338+ nested_component_path id dynamic_import segments
382339 | None -> None
383340 in
384341 let normalize_hidden_component_name (id : Ident.t ) (hidden_name : string ) =
0 commit comments