@@ -294,6 +294,11 @@ let string_of_stringlit (`Stringlit s) =
294294 | `String s -> s
295295 | _ -> invalid ()
296296
297+ let int_of_intlit (`Intlit s ) =
298+ match Yojson.Safe. from_string s with
299+ | `Int s -> s
300+ | _ -> invalid ()
301+
297302let stringlit name rest : [ `Stringlit of string ] option =
298303 try
299304 match List. assoc name rest with
@@ -325,6 +330,17 @@ let list_stringlit_opt name rest =
325330 | _ -> invalid ()
326331 with Not_found -> None
327332
333+ let list_intlit name rest =
334+ try
335+ match List. assoc name rest with
336+ | `List l ->
337+ Some
338+ (List. map l ~f: (function
339+ | `Intlit _ as s -> s
340+ | _ -> invalid () ))
341+ | _ -> invalid ()
342+ with Not_found -> None
343+
328344module Standard = struct
329345 type t =
330346 { version : int
@@ -334,6 +350,7 @@ module Standard = struct
334350 ; sources_content : Source_content .t option list option
335351 ; names : string list
336352 ; mappings : Mappings .t
353+ ; ignore_list : string list
337354 }
338355
339356 let empty ~inline_source_content =
@@ -344,6 +361,7 @@ module Standard = struct
344361 ; sources_content = (if inline_source_content then Some [] else None )
345362 ; names = []
346363 ; mappings = Mappings. empty
364+ ; ignore_list = []
347365 }
348366
349367 let maps ~sources_offset ~names_offset x =
@@ -472,6 +490,21 @@ module Standard = struct
472490 (List. map l ~f: (function
473491 | None -> `Null
474492 | Some x -> Source_content. to_json x))) )
493+ ; ( " ignoreList"
494+ , match t.ignore_list with
495+ | [] -> None
496+ | _ ->
497+ Some
498+ (`List
499+ (let s = StringSet. of_list t.ignore_list in
500+ List. filter_map
501+ ~f: (fun x -> x)
502+ (List. mapi
503+ ~f: (fun i nm ->
504+ if StringSet. mem nm s
505+ then Some (`Intlit (string_of_int i))
506+ else None )
507+ t.sources))) )
475508 ])
476509
477510 let of_json (json : Yojson.Raw.t ) =
@@ -505,13 +538,25 @@ module Standard = struct
505538 | None -> Mappings. empty
506539 | Some s -> Mappings. of_string_unsafe s
507540 in
541+ let ignore_list =
542+ let s =
543+ IntSet. of_list
544+ (List. map
545+ ~f: int_of_intlit
546+ (Option. value ~default: [] (list_intlit " ignoreList" rest)))
547+ in
548+ List. filter_map
549+ ~f: (fun x -> x)
550+ (List. mapi ~f: (fun i nm -> if IntSet. mem i s then Some nm else None ) sources)
551+ in
508552 { version = int_of_string version
509553 ; file
510554 ; sourceroot
511555 ; names
512556 ; sources_content
513557 ; sources
514558 ; mappings
559+ ; ignore_list
515560 }
516561 | _ -> invalid ()
517562
@@ -520,7 +565,8 @@ module Standard = struct
520565 let to_file m file = Yojson.Raw. to_file file (json m)
521566
522567 let invariant
523- { version; file = _ ; sourceroot = _ ; names; sources_content; sources; mappings } =
568+ { version; file = _ ; sourceroot = _ ; names; sources_content; sources; mappings; _ }
569+ =
524570 if not (version_is_valid version)
525571 then invalid_arg " Source_map.Standard.invariant: invalid version" ;
526572 match sources_content with
0 commit comments