Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file source_map_io.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131# 1 "compiler/lib/source_map_yojson.ml.in"(* Js_of_ocaml compiler
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2017 Hugo Heuzard
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)openSource_map(* copied from ocaml/utils/misc.ml *)letget_build_path_prefix_map=letinit=reffalseinletmap_cache=refNoneinfun()->ifnot!initthenbegininit:=true;matchSys.getenv"BUILD_PATH_PREFIX_MAP"with|exceptionNot_found->()|encoded_map->matchBuild_path_prefix_map.decode_mapencoded_mapwith|Errorerr->failwith@@Printf.sprintf"Invalid value for the environment variable \
BUILD_PATH_PREFIX_MAP: %s"err|Okmap->map_cache:=Somemapend;!map_cacheletjsont=letrewrite_pathpath=ifFilename.is_relativepaththenpathelsematchget_build_path_prefix_map()with|Somemap->Build_path_prefix_map.rewritemappath|None->pathin`Assoc["version",`Float(float_of_intt.version);"file",`String(rewrite_patht.file);"sourceRoot",`String(matcht.sourcerootwithNone->""|Somes->rewrite_paths);"names",`List(List.map(funs->`Strings)t.names);"mappings",`String(string_of_mappingt.mappings);"sources",`List(List.map(funs->`String(rewrite_paths))t.sources);"sourcesContent",`List(matcht.sources_contentwith|None->[]|Somel->List.map(function|None->`Null|Somes->`Strings)l);]letinvalid()=invalid_arg"Source_map.of_json"letstringnamerest=trymatchList.assocnamerestwith|`Strings->Somes|`Null->None|_->invalid()withNot_found->Noneletlist_stringnamerest=trymatchList.assocnamerestwith|`Listl->Some(List.map(function|`Strings->s|_->invalid())l)|_->invalid()withNot_found->Noneletlist_string_optnamerest=trymatchList.assocnamerestwith|`Listl->Some(List.map(function|`Strings->Somes|`Null->None|_->invalid())l)|_->invalid()withNot_found->Noneletof_jsonjson=matchjsonwith|`Assoc(("version",`Floatversion)::rest)whenint_of_floatversion=3->letdefvd=matchvwithNone->d|Somev->vinletfile=string"file"restinletsourceroot=string"sourceRoot"restinletnames=list_string"names"restinletsources=list_string"sources"restinletsources_content=list_string_opt"sourcesContent"restinletmappings=string"mappings"restin{version=int_of_floatversion;file=deffile"";sourceroot;names=defnames[];sources_content=sources_content;sources=defsources[];mappings=mapping_of_string(defmappings"");}|_->invalid()letof_strings=of_json(Yojson.Basic.from_strings)letto_stringm=Yojson.Basic.to_string(jsonm)letto_filemfile=Yojson.Basic.to_filefile(jsonm)letenabled=true