@@ -276,56 +276,70 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
276
276
({pexp_loc; pexp_desc = Pexp_record (fields, _); _}, _);
277
277
_;
278
278
};
279
- ] ->
279
+ ] -> (
280
280
let fromName = ref None in
281
- let importAttributesFromRecord =
282
- fields
283
- |> List. filter_map
284
- (fun
285
- ((l , exp ) :
286
- Longident. t Location. loc * Parsetree. expression )
287
- ->
288
- match exp.pexp_desc with
289
- | Pexp_constant (Pconst_string (s , _ )) -> (
290
- match l.txt with
291
- | Longident. Lident "from" ->
292
- fromName := Some s;
293
- None
294
- | Longident. Lident "type_" -> Some (" type" , s)
295
- | Longident. Lident txt -> Some (txt, s)
281
+ let with_ = ref None in
282
+ fields
283
+ |> List. iter
284
+ (fun
285
+ ((l , exp ) :
286
+ Longident. t Location. loc * Parsetree. expression )
287
+ ->
288
+ match (l, exp.pexp_desc) with
289
+ | ( {txt = Lident " from" ; _},
290
+ Pexp_constant (Pconst_string (s, _)) ) ->
291
+ fromName := Some s
292
+ | {txt = Lident "with" ; _} , Pexp_record (fields , _ ) ->
293
+ with_ := Some fields
294
+ | _ -> () );
295
+ match (! fromName, ! with_) with
296
+ | None , _ ->
297
+ Location. raise_errorf ~loc: pexp_loc
298
+ " @module annotations with import attributes must have a \
299
+ \" from\" field. This \" from\" field should point to the JS \
300
+ module to import, just like the string payload to @module \
301
+ normally does."
302
+ | Some _ , None ->
303
+ Location. raise_errorf ~loc: pexp_loc
304
+ " @module annotations with import attributes must have a \
305
+ \" with\" field. This \" with\" field should hold a record of \
306
+ the import attributes you want applied to the import."
307
+ | Some fromName , Some withFields ->
308
+ let importAttributesFromRecord =
309
+ withFields
310
+ |> List. filter_map
311
+ (fun
312
+ ((l , exp ) :
313
+ Longident. t Location. loc * Parsetree. expression )
314
+ ->
315
+ match exp.pexp_desc with
316
+ | Pexp_constant (Pconst_string (s , _ )) -> (
317
+ match l.txt with
318
+ | Longident. Lident "type_" -> Some (" type" , s)
319
+ | Longident. Lident txt -> Some (txt, s)
320
+ | _ ->
321
+ Location. raise_errorf ~loc: exp.pexp_loc
322
+ " Field must be a regular key." )
296
323
| _ ->
297
324
Location. raise_errorf ~loc: exp.pexp_loc
298
- " Field must be a regular key." )
299
- | _ ->
300
- Location. raise_errorf ~loc: exp.pexp_loc
301
- " Only string values are allowed here." )
302
- in
303
- let fromName =
304
- match ! fromName with
305
- | None ->
306
- Location. raise_errorf ~loc: pexp_loc
307
- " @module annotations with import attributes must have a \
308
- \" from\" field. This \" from\" field should point to the \
309
- JS module to import, just like the string payload to \
310
- @module normally does."
311
- | Some fromName -> fromName
312
- in
313
- let import_attributes =
314
- Hashtbl. create (List. length importAttributesFromRecord)
315
- in
316
- importAttributesFromRecord
317
- |> List. iter (fun (key , value ) ->
318
- Hashtbl. replace import_attributes key value);
319
- {
320
- st with
321
- external_module_name =
322
- Some
323
- {
324
- bundle = fromName;
325
- module_bind_name = Phint_nothing ;
326
- import_attributes = Some import_attributes;
327
- };
328
- }
325
+ " Only string values are allowed here." )
326
+ in
327
+ let import_attributes =
328
+ Hashtbl. create (List. length importAttributesFromRecord)
329
+ in
330
+ importAttributesFromRecord
331
+ |> List. iter (fun (key , value ) ->
332
+ Hashtbl. replace import_attributes key value);
333
+ {
334
+ st with
335
+ external_module_name =
336
+ Some
337
+ {
338
+ bundle = fromName;
339
+ module_bind_name = Phint_nothing ;
340
+ import_attributes = Some import_attributes;
341
+ };
342
+ })
329
343
| _ -> (
330
344
match Ast_payload. assert_strings loc payload with
331
345
| [bundle] ->
0 commit comments