@@ -268,28 +268,7 @@ let compile output_prefix =
268268 dynamic_import,
269269 String. concat " $" (root_name :: denamespace_segment head :: rest) )
270270 in
271- let rec extract_nested_external_component_segments segments (lam : Lam.t ) :
272- (Ident. t * bool * string list ) option =
273- match lam with
274- | Lprim
275- {
276- primitive = Pfield (_, Fld_module {name; jsx_component = _});
277- args = [arg];
278- _;
279- } ->
280- extract_nested_external_component_segments (name :: segments) arg
281- | Lprim {primitive = Pawait ; args = [arg]; _} ->
282- extract_nested_external_component_segments segments arg
283- | Lvar id -> (
284- match Map_ident. find_opt ! local_module_aliases id with
285- | Some alias_lam ->
286- extract_nested_external_component_segments segments alias_lam
287- | None -> Some (id, false , List. rev segments))
288- | Lglobal_module (id , dynamic_import ) ->
289- Some (id, dynamic_import, List. rev segments)
290- | _ -> None
291- in
292- let rec extract_static_nested_external_component_segments segments
271+ let rec extract_component_segments ~allow_import ~allow_unbound_var segments
293272 (lam : Lam.t ) : (Ident.t * bool * string list) option =
294273 match lam with
295274 | Lprim
@@ -298,23 +277,29 @@ let compile output_prefix =
298277 args = [arg];
299278 _;
300279 } ->
301- extract_static_nested_external_component_segments (name :: segments) arg
280+ extract_component_segments ~allow_import ~allow_unbound_var
281+ (name :: segments) arg
302282 | Lprim {primitive = Pawait ; args = [arg]; _} ->
303- extract_static_nested_external_component_segments segments arg
304- | Lprim {primitive = Pimport ; args = [arg]; _} ->
305- extract_static_nested_external_component_segments segments arg
283+ extract_component_segments ~allow_import ~allow_unbound_var segments arg
284+ | Lprim {primitive = Pimport ; args = [arg]; _} when allow_import ->
285+ extract_component_segments ~allow_import ~allow_unbound_var segments arg
306286 | Lvar id -> (
307287 match Map_ident. find_opt ! local_module_aliases id with
308288 | Some alias_lam ->
309- extract_static_nested_external_component_segments segments alias_lam
310- | None -> None )
289+ extract_component_segments ~allow_import ~allow_unbound_var segments
290+ alias_lam
291+ | None ->
292+ if allow_unbound_var then Some (id, false , List. rev segments) else None )
311293 | Lglobal_module (id , dynamic_import ) ->
312294 Some (id, dynamic_import, List. rev segments)
313295 | _ -> None
314296 in
315297 let extract_nested_external_component_path (lam : Lam.t ) :
316298 (Ident. t * bool * string ) option =
317- match extract_nested_external_component_segments [] lam with
299+ match
300+ extract_component_segments ~allow_import: false ~allow_unbound_var: true []
301+ lam
302+ with
318303 | Some (id , dynamic_import , segments ) ->
319304 nested_component_path id dynamic_import segments
320305 | None -> None
@@ -333,7 +318,10 @@ let compile output_prefix =
333318 in
334319 let extract_static_nested_external_component_path (lam : Lam.t ) :
335320 (Ident. t * bool * string ) option =
336- match extract_static_nested_external_component_segments [] lam with
321+ match
322+ extract_component_segments ~allow_import: true ~allow_unbound_var: false []
323+ lam
324+ with
337325 | Some (id , dynamic_import , segments ) ->
338326 nested_component_path id dynamic_import segments
339327 | None -> None
0 commit comments