diff --git a/.editorconfig b/.editorconfig index 806179634f..1d0fefdf34 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,8 +3,15 @@ root = true [*] charset = utf-8 -[*.{ml,mli,mll,mly}] -max_line_length = 80 +[*.{ml,mli,mll,mly}, *.{js,jsx,ts,tsx,vue,json}] +max_line_length = 92 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +[*.{js,jsx,ts,tsx,vue,json}] +max_line_length = 92 trim_trailing_whitespace = true insert_final_newline = true indent_style = space diff --git a/.ocamlformat-ignore b/.ocamlformat-ignore index 1c981dbae4..12d46a4376 100644 --- a/.ocamlformat-ignore +++ b/.ocamlformat-ignore @@ -1,2 +1,4 @@ # Files containing cppo directives that ocamlformat cannot parse -jscomp/core/js_name_of_module_id.ml +#jscomp/core/js_name_of_module_id.ml +#jscomp/core/js_cmj_load.ml +#jscomp/core/lam_compile_main.ml diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000..34189fac70 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +# Explicitly set to override .editorconfig with a lower value; see: +# +printWidth: 80 + +# Attempting to match existing style in the codebase +semi: false +singleQuote: true diff --git a/docs/docson/build-schema.json b/docs/docson/build-schema.json index 91e682c030..49b2fd38aa 100644 --- a/docs/docson/build-schema.json +++ b/docs/docson/build-schema.json @@ -18,6 +18,15 @@ "in-source": { "type": "boolean", "description": "Default: false." + }, + "suffix" : { + "enum" : [ + ".js", + ".mjs", + ".bs.js", + ".bs.mjs" + ], + "description": "suffix of generated JavaScript files, default varies by 'module' and 'in-source'" } }, "required": [ @@ -482,13 +491,6 @@ "type": "string" }, "description": "(Not needed usually) arguments to pass to `refmt` above. Default: `[\"--print\", \"binary\"]`." - }, - "suffix" : { - "enum" : [ - ".js", - ".bs.js" - ], - "description": "suffix of generated js files, default to [.js] " } }, "additionalProperties": false, diff --git a/jscomp/bsb/bsb_build_schemas.ml b/jscomp/bsb/bsb_build_schemas.ml index 67b7740613..dd53ea4fc9 100644 --- a/jscomp/bsb/bsb_build_schemas.ml +++ b/jscomp/bsb/bsb_build_schemas.ml @@ -75,11 +75,12 @@ let generators = "generators" let command = "command" let edge = "edge" let namespace = "namespace" +let _module = "module" let in_source = "in-source" +let suffix = "suffix" let warnings = "warnings" let number = "number" let error = "error" -let suffix = "suffix" let gentypeconfig = "gentypeconfig" let path = "path" let ignored_dirs = "ignored-dirs" diff --git a/jscomp/bsb/bsb_config_parse.ml b/jscomp/bsb/bsb_config_parse.ml index 3ebdf6f92d..22e7cebe56 100644 --- a/jscomp/bsb/bsb_config_parse.ml +++ b/jscomp/bsb/bsb_config_parse.ml @@ -85,13 +85,32 @@ let extract_main_entries (map : json_map) = #end +let deprecated_extract_bs_suffix_exn (map : json_map) = + match Map_string.find_opt map Bsb_build_schemas.suffix with + | None -> None + | Some (Str { str } as config) -> + if str = Literals.suffix_js then Some false + else if str = Literals.suffix_bs_js then Some true + else + Bsb_exception.config_error config + "DEPRECATED: This form of 'suffix' only supports either `.js` or \ + `.bs.js`. Use 'suffix' under 'package-specs' instead." + | Some config -> + Bsb_exception.config_error config + "DEPRECATED: This form of 'suffix' only supports a string" + + +let package_specs_from_obj_map (map : json_map) = + let deprecated_bs_suffix = deprecated_extract_bs_suffix_exn map in + match Map_string.find_opt map Bsb_build_schemas.package_specs with + | Some x -> Bsb_package_specs.from_json ?deprecated_bs_suffix x + | None -> Bsb_package_specs.default_package_specs ?deprecated_bs_suffix () + + let package_specs_from_bsconfig () = let json = Ext_json_parse.parse_json_from_file Literals.bsconfig_json in match json with - | Obj { map } -> ( - match Map_string.find_opt map Bsb_build_schemas.package_specs with - | Some x -> Bsb_package_specs.from_json x - | None -> Bsb_package_specs.default_package_specs ) + | Obj { map } -> package_specs_from_obj_map map | _ -> assert false @@ -159,17 +178,6 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) = | _ -> assert false ) -let extract_bs_suffix_exn (map : json_map) = - match Map_string.find_opt map Bsb_build_schemas.suffix with - | None -> false - | Some (Str { str } as config) -> - if str = Literals.suffix_js then false - else if str = Literals.suffix_bs_js then true - else Bsb_exception.config_error config "expect .bs.js or .js string here" - | Some config -> - Bsb_exception.config_error config "expect .bs.js or .js string here" - - let extract_gentype_config (map : json_map) cwd : Bsb_config_types.gentype_config option = match Map_string.find_opt map Bsb_build_schemas.gentypeconfig with @@ -375,13 +383,11 @@ let interpret_json ~toplevel_package_specs ~(per_proj_dir : string) : let package_name, namespace = extract_package_name_and_namespace map in let refmt = extract_refmt map per_proj_dir in let gentype_config = extract_gentype_config map per_proj_dir in - let bs_suffix = extract_bs_suffix_exn map in (* The default situation is empty *) let built_in_package = check_stdlib map per_proj_dir in - let package_specs = - match Map_string.find_opt map Bsb_build_schemas.package_specs with - | Some x -> Bsb_package_specs.from_json x - | None -> Bsb_package_specs.default_package_specs + let package_specs = package_specs_from_obj_map map in + let bs_suffixes = + Bsb_package_specs.extract_in_source_bs_suffixes package_specs in let pp_flags : string option = extract_string map Bsb_build_schemas.pp_flags (fun p -> @@ -411,12 +417,11 @@ let interpret_json ~toplevel_package_specs ~(per_proj_dir : string) : in let groups, number_of_dev_groups = Bsb_parse_sources.scan ~ignored_dirs:(extract_ignored_dirs map) - ~toplevel ~root:per_proj_dir ~cut_generators ~bs_suffix ~namespace - sources + ~toplevel ~root:per_proj_dir ~cut_generators ~bs_suffixes + ~namespace sources in { gentype_config; - bs_suffix; package_name; namespace; warning = extract_warning map; diff --git a/jscomp/bsb/bsb_config_types.ml b/jscomp/bsb/bsb_config_types.ml index ba1251e504..304c624f62 100644 --- a/jscomp/bsb/bsb_config_types.ml +++ b/jscomp/bsb/bsb_config_types.ml @@ -79,7 +79,6 @@ type t = entries : entries_t list ; generators : command Map_string.t ; cut_generators : bool; (* note when used as a dev mode, we will always ignore it *) - bs_suffix : bool ; (* true means [.bs.js] we should pass [-bs-suffix] flag *) gentype_config : gentype_config option; number_of_dev_groups : int } diff --git a/jscomp/bsb/bsb_ninja_file_groups.ml b/jscomp/bsb/bsb_ninja_file_groups.ml index d108533f2d..25522bd090 100644 --- a/jscomp/bsb/bsb_ninja_file_groups.ml +++ b/jscomp/bsb/bsb_ninja_file_groups.ml @@ -45,7 +45,7 @@ let make_common_shadows package_specs dirname dir_index : key = Bsb_ninja_global_vars.g_pkg_flg; op = Append - (Bsb_package_specs.package_flag_of_package_specs package_specs dirname); + (Bsb_package_specs.flags_of_package_specs package_specs dirname); } :: ( if Bsb_dir_index.is_lib_dir dir_index then [] @@ -60,7 +60,7 @@ let make_common_shadows package_specs dirname dir_index : let emit_module_build (rules : Bsb_ninja_rule.builtin) (package_specs : Bsb_package_specs.t) (group_dir_index : Bsb_dir_index.t) oc - ~bs_suffix js_post_build_cmd namespace (module_info : Bsb_db.module_info) = + js_post_build_cmd namespace (module_info : Bsb_db.module_info) = let has_intf_file = module_info.info = Ml_mli in let is_re = module_info.is_re in let filename_sans_extension = module_info.name_sans_extension in @@ -90,7 +90,7 @@ let emit_module_build (rules : Bsb_ninja_rule.builtin) let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in let output_js = - Bsb_package_specs.get_list_of_output_js package_specs bs_suffix + Bsb_package_specs.get_list_of_output_js package_specs output_filename_sans_extension in let common_shadows = @@ -155,8 +155,8 @@ let emit_module_build (rules : Bsb_ninja_rule.builtin) ~order_only_deps:[ output_d ] ~rule -let handle_files_per_dir oc ~bs_suffix ~(rules : Bsb_ninja_rule.builtin) - ~package_specs ~js_post_build_cmd ~(files_to_install : Hash_set_string.t) +let handle_files_per_dir oc ~(rules : Bsb_ninja_rule.builtin) ~package_specs + ~js_post_build_cmd ~(files_to_install : Hash_set_string.t) ~(namespace : string option) (group : Bsb_file_groups.file_group) : unit = handle_generators oc group rules.customs; let installable = @@ -168,7 +168,7 @@ let handle_files_per_dir oc ~bs_suffix ~(rules : Bsb_ninja_rule.builtin) Map_string.iter group.sources (fun module_name module_info -> if installable module_name then Hash_set_string.add files_to_install module_info.name_sans_extension; - emit_module_build rules package_specs group.dir_index oc ~bs_suffix - js_post_build_cmd namespace module_info) + emit_module_build rules package_specs group.dir_index oc js_post_build_cmd + namespace module_info) (* pseuduo targets per directory *) diff --git a/jscomp/bsb/bsb_ninja_file_groups.mli b/jscomp/bsb/bsb_ninja_file_groups.mli index b3d02de284..fd028582f7 100644 --- a/jscomp/bsb/bsb_ninja_file_groups.mli +++ b/jscomp/bsb/bsb_ninja_file_groups.mli @@ -24,7 +24,6 @@ val handle_files_per_dir : out_channel -> - bs_suffix:bool -> rules:Bsb_ninja_rule.builtin -> package_specs:Bsb_package_specs.t -> js_post_build_cmd:string option -> diff --git a/jscomp/bsb/bsb_ninja_gen.ml b/jscomp/bsb/bsb_ninja_gen.ml index f168fe2a05..b83c568217 100644 --- a/jscomp/bsb/bsb_ninja_gen.ml +++ b/jscomp/bsb/bsb_ninja_gen.ml @@ -70,7 +70,6 @@ let output_static_resources (static_resources : string list) copy_rule oc = let output_ninja_and_namespace_map ~per_proj_dir ~toplevel ({ - bs_suffix; package_name; external_includes; bsc_flags; @@ -195,7 +194,7 @@ let output_ninja_and_namespace_map ~per_proj_dir ~toplevel ~has_postbuild:(js_post_build_cmd <> None) ~has_ppx:(ppx_files <> []) ~has_pp:(pp_file <> None) ~has_builtin:(built_in_dependency <> None) - ~reason_react_jsx ~bs_suffix ~digest generators + ~reason_react_jsx ~digest generators in emit_bsc_lib_includes bs_dependencies bsc_lib_dirs external_includes namespace @@ -203,9 +202,8 @@ let output_ninja_and_namespace_map ~per_proj_dir ~toplevel output_static_resources static_resources rules.copy_resources oc; (* Generate build statement for each file *) Ext_list.iter bs_file_groups (fun files_per_dir -> - Bsb_ninja_file_groups.handle_files_per_dir oc ~bs_suffix ~rules - ~js_post_build_cmd ~package_specs ~files_to_install ~namespace - files_per_dir); + Bsb_ninja_file_groups.handle_files_per_dir oc ~rules ~js_post_build_cmd + ~package_specs ~files_to_install ~namespace files_per_dir); Ext_option.iter namespace (fun ns -> let namespace_dir = per_proj_dir // Bsb_config.lib_bs in diff --git a/jscomp/bsb/bsb_ninja_rule.ml b/jscomp/bsb/bsb_ninja_rule.ml index 21caff1445..39a33cf1f1 100644 --- a/jscomp/bsb/bsb_ninja_rule.ml +++ b/jscomp/bsb/bsb_ninja_rule.ml @@ -89,7 +89,7 @@ type builtin = { } let make_custom_rules ~(has_gentype : bool) ~(has_postbuild : bool) - ~(has_ppx : bool) ~(has_pp : bool) ~(has_builtin : bool) ~(bs_suffix : bool) + ~(has_ppx : bool) ~(has_pp : bool) ~(has_builtin : bool) ~(reason_react_jsx : Bsb_config_types.reason_react_jsx option) ~(digest : string) ~(refmt : string option) (* set refmt path when needed *) @@ -100,7 +100,6 @@ let make_custom_rules ~(has_gentype : bool) ~(has_postbuild : bool) let mk_ml_cmj_cmd ~read_cmi ~is_dev ~postbuild : string = Buffer.clear buf; Buffer.add_string buf "$bsc -nostdlib $g_pkg_flg -color always"; - if bs_suffix then Buffer.add_string buf " -bs-suffix"; if read_cmi then Buffer.add_string buf " -bs-read-cmi"; if is_dev then Buffer.add_string buf " $g_dev_incls"; Buffer.add_string buf " $g_lib_incls"; diff --git a/jscomp/bsb/bsb_ninja_rule.mli b/jscomp/bsb/bsb_ninja_rule.mli index 4c2b0f9339..204852365b 100644 --- a/jscomp/bsb/bsb_ninja_rule.mli +++ b/jscomp/bsb/bsb_ninja_rule.mli @@ -56,7 +56,6 @@ val make_custom_rules : has_ppx:bool -> has_pp:bool -> has_builtin:bool -> - bs_suffix:bool -> reason_react_jsx:Bsb_config_types.reason_react_jsx option -> digest:string -> refmt:string option -> diff --git a/jscomp/bsb/bsb_package_specs.ml b/jscomp/bsb/bsb_package_specs.ml index adc633f061..fcb0f8bd75 100644 --- a/jscomp/bsb/bsb_package_specs.ml +++ b/jscomp/bsb/bsb_package_specs.ml @@ -24,10 +24,10 @@ let ( // ) = Ext_path.combine -(* TODO: sync up with {!Js_packages_info.module_system} *) +(* TODO: sync up with {!Js_package_info.module_system} *) type format = NodeJS | Es6 | Es6_global -type spec = { format : format; in_source : bool } +type spec = { format : format; in_source : bool; suffix : string } module Spec_set = Set.Make (struct type t = spec @@ -64,35 +64,117 @@ let prefix_of_format (x : format) = | Es6_global -> Bsb_config.lib_es6_global -let rec from_array (arr : Ext_json_types.t array) : Spec_set.t = - let spec = ref Spec_set.empty in - let has_in_source = ref false in +let deprecated_bs_suffix_message_warn () = + Bsb_log.warn + "@{DEPRECATED@}: @[top-level 'suffix' field is deprecated;@ \ + please lower your extension-configuration into@ 'package-specs'.@]@." + + +let bad_suffix_message_warn suffix = + let open Literals in + Bsb_log.warn + "@{UNSUPPORTED@}: @[package-specs: extension `%s` is \ + unsupported;@ consider one of: %s, %s, %s; %s, %s,@ or %s.@]@." + suffix suffix_js suffix_mjs suffix_cjs suffix_bs_js suffix_bs_mjs + suffix_bs_cjs + + +let supported_suffix (x : string) = + if + not + (List.mem x + Literals. + [ + suffix_js; + suffix_mjs; + suffix_cjs; + suffix_bs_js; + suffix_bs_mjs; + suffix_bs_cjs; + ]) + then bad_suffix_message_warn x; + x + + +let default_suffix ~deprecated_bs_suffix _format _in_source = + (* match (format, in_source) with *) + (* | NodeJS, false -> Literals.suffix_js *) + (* | NodeJS, true -> Literals.suffix_bs_js *) + (* | _, false -> Literals.suffix_mjs *) + (* | _, true -> Literals.suffix_bs_mjs *) + + (* TODO: In the absence of direction to the contrary, the suffix should + eventually depend on [format] and [in_source]. For now, for + backwards-compatibility, I'm hardcoding. *) + if deprecated_bs_suffix then Literals.suffix_bs_js else Literals.suffix_js + + +module SS = Set.Make (String) + +let supported_bs_suffixes = + Literals.[ suffix_bs_js; suffix_bs_mjs; suffix_bs_cjs ] + + +(** Produces a [list] of supported, bs-prefixed file-suffixes used in + [in-source] package-specs. *) +let extract_in_source_bs_suffixes (package_specs : Spec_set.t) = + let f spec suffixes = + if spec.in_source && List.mem spec.suffix supported_bs_suffixes then + SS.add spec.suffix suffixes + else suffixes + in + let suffixes = Spec_set.fold f package_specs SS.empty in + SS.elements suffixes + + +let rec from_array ~deprecated_bs_suffix (arr : Ext_json_types.t array) : + Spec_set.t = + let specs = ref Spec_set.empty in Ext_array.iter arr (fun x -> - let result = from_json_single x in - if result.in_source then - if not !has_in_source then has_in_source := true - else - Bsb_exception.errorf ~loc:(Ext_json.loc_of x) - "package-specs: we've detected two module formats that are both \ - configured to be in-source."; - spec := Spec_set.add result !spec); - !spec - - -(* TODO: FIXME: better API without mutating *) -and from_json_single (x : Ext_json_types.t) : spec = + let spec = from_json_single ~deprecated_bs_suffix x in + if + Spec_set.exists + (fun o -> + spec.in_source == o.in_source && String.equal spec.suffix o.suffix) + !specs + then + Bsb_exception.errorf ~loc:(Ext_json.loc_of x) + "package-specs: two conflicting module formats with the extension \ + `%s` are both configured to be in-source." + spec.suffix + else specs := Spec_set.add spec !specs); + !specs + + +(* FIXME: better API without mutating *) +and from_json_single ~deprecated_bs_suffix (x : Ext_json_types.t) : spec = match x with | Str { str = format; loc } -> - { format = supported_format format loc; in_source = false } + let format = supported_format format loc in + { + format; + in_source = false; + suffix = default_suffix ~deprecated_bs_suffix format false; + } | Obj { map; loc } -> ( - match Map_string.find_exn map "module" with + match Map_string.find_exn map Bsb_build_schemas._module with | Str { str = format } -> + let format = supported_format format loc in let in_source = match Map_string.find_opt map Bsb_build_schemas.in_source with | Some (True _) -> true | Some _ | None -> false in - { format = supported_format format loc; in_source } + let suffix = + match Map_string.find_opt map Bsb_build_schemas.suffix with + | Some (Str { str = suffix; loc }) -> supported_suffix suffix + | Some _ -> + Bsb_exception.errorf ~loc + "package-specs: the `suffix` field of the configuration \ + object must be absent, or a string." + | None -> default_suffix ~deprecated_bs_suffix format in_source + in + { format; in_source; suffix } | Arr _ -> Bsb_exception.errorf ~loc "package-specs: when the configuration is an object, `module` \ @@ -112,42 +194,53 @@ and from_json_single (x : Ext_json_types.t) : spec = "package-specs: we expect either a string or an object." -let from_json (x : Ext_json_types.t) : Spec_set.t = +let from_json ?(deprecated_bs_suffix = false) (x : Ext_json_types.t) : + Spec_set.t = + if deprecated_bs_suffix then deprecated_bs_suffix_message_warn (); match x with - | Arr { content; _ } -> from_array content - | _ -> Spec_set.singleton (from_json_single x) + | Arr { content; _ } -> from_array ~deprecated_bs_suffix content + | _ -> Spec_set.singleton (from_json_single ~deprecated_bs_suffix x) let bs_package_output = "-bs-package-output" (** Assume input is valid - {[ -bs-package-output commonjs:lib/js/jscomp/test ]} *) -let package_flag ({ format; in_source } : spec) dir = + {[ -bs-package-output commonjs:lib/js/jscomp/test:mjs ]} *) +let package_flag ({ format; in_source; suffix } : spec) dir = Ext_string.inter2 bs_package_output - (Ext_string.concat3 (string_of_format format) Ext_string.single_colon - (if in_source then dir else prefix_of_format format // dir)) + (Ext_string.concat5 (string_of_format format) Ext_string.single_colon + (if in_source then dir else prefix_of_format format // dir) + Ext_string.single_colon suffix) -let package_flag_of_package_specs (package_specs : t) (dirname : string) : - string = +let flags_of_package_specs (package_specs : t) (dirname : string) : string = Spec_set.fold (fun format acc -> Ext_string.inter2 acc (package_flag format dirname)) package_specs Ext_string.empty -let default_package_specs = - Spec_set.singleton { format = NodeJS; in_source = false } +let default_package_specs ?deprecated_bs_suffix () = + let deprecated_bs_suffix = match deprecated_bs_suffix with + | Some x -> deprecated_bs_suffix_message_warn (); x + | None -> false + in + Spec_set.singleton + { + format = NodeJS; + in_source = false; + suffix = default_suffix ~deprecated_bs_suffix NodeJS false; + } (** [get_list_of_output_js specs true "src/hi/hello"] *) -let get_list_of_output_js (package_specs : Spec_set.t) (bs_suffix : bool) +let get_list_of_output_js (package_specs : Spec_set.t) (output_file_sans_extension : string) = Spec_set.fold - (fun (spec : spec) acc -> + (fun spec acc -> let basename = - Ext_namespace.change_ext_ns_suffix output_file_sans_extension - (if bs_suffix then Literals.suffix_bs_js else Literals.suffix_js) + Ext_namespace.replace_namespace_with_extension + ~name:output_file_sans_extension ~ext:spec.suffix in ( Bsb_config.proj_rel @@ diff --git a/jscomp/bsb/bsb_package_specs.mli b/jscomp/bsb/bsb_package_specs.mli index 7948f389d8..1ac3ed6c6f 100644 --- a/jscomp/bsb/bsb_package_specs.mli +++ b/jscomp/bsb/bsb_package_specs.mli @@ -24,15 +24,17 @@ type t -val default_package_specs : t +val default_package_specs : ?deprecated_bs_suffix:bool -> unit -> t -val from_json : Ext_json_types.t -> t +val from_json : ?deprecated_bs_suffix:bool -> Ext_json_types.t -> t -val get_list_of_output_js : t -> bool -> string -> string list +val get_list_of_output_js : t -> string -> string list -val package_flag_of_package_specs : t -> string -> string +val extract_in_source_bs_suffixes : t -> string list + +val flags_of_package_specs : t -> string -> string (** Sample output: - {[ -bs-package-output commonjs:lib/js/jscomp/test ]} *) + {[ -bs-package-output commonjs:lib/js/jscomp/test:mjs ]} *) val list_dirs_by : t -> (string -> unit) -> unit diff --git a/jscomp/bsb/bsb_parse_sources.ml b/jscomp/bsb/bsb_parse_sources.ml index 3901840c78..78e7483aba 100644 --- a/jscomp/bsb/bsb_parse_sources.ml +++ b/jscomp/bsb/bsb_parse_sources.ml @@ -44,7 +44,7 @@ type cxt = { cut_generators : bool; traverse : bool; namespace : string option; - bs_suffix : bool; + bs_suffixes : string list; ignored_dirs : Set_string.t; } @@ -204,6 +204,13 @@ let classify_suffix (x : string) : suffix_kind = if i >= 0 then Cmti i else Not_any +(** Attempt to delete any [.bs.[cm]?js] files for a given artifact. *) +let unlink_bs_suffixes context artifact = + List.iter + (fun suffix -> try_unlink (Filename.concat context.cwd (artifact ^ suffix))) + context.bs_suffixes + + (* This is the only place where we do some removal during scanning, configurably. *) let prune_staled_bs_js_files (context : cxt) (cur_sources : _ Map_string.t) : @@ -234,12 +241,7 @@ let prune_staled_bs_js_files (context : cxt) (cur_sources : _ Map_string.t) : if cmd <> "" then Ext_pervasives.try_it (fun _ -> Sys.command (cmd ^ " -cmt-rm " ^ filepath)) - | Cmj _ -> - (* remove .bs.js *) - if context.bs_suffix then - try_unlink - (Filename.concat context.cwd - (String.sub x 0 j ^ Literals.suffix_bs_js)) + | Cmj _ -> unlink_bs_suffixes context (String.sub x 0 j) | _ -> () ); try_unlink filepath ) else () @@ -399,8 +401,8 @@ and parse_sources (cxt : cxt) (sources : Ext_json_types.t) = | _ -> parsing_single_source cxt sources -let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffix ~ignored_dirs x : - t * int = +let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffixes ~ignored_dirs x + : t * int = Bsb_dir_index.reset (); let output = parse_sources @@ -412,7 +414,7 @@ let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffix ~ignored_dirs x : root; cut_generators; namespace; - bs_suffix; + bs_suffixes; traverse = false; } x diff --git a/jscomp/bsb/bsb_parse_sources.mli b/jscomp/bsb/bsb_parse_sources.mli index 311f0d0e50..327a436c0e 100644 --- a/jscomp/bsb/bsb_parse_sources.mli +++ b/jscomp/bsb/bsb_parse_sources.mli @@ -27,7 +27,7 @@ val scan : root:string -> cut_generators:bool -> namespace:string option -> - bs_suffix:bool -> + bs_suffixes:string list -> ignored_dirs:Set_string.t -> Ext_json_types.t -> Bsb_file_groups.t * int diff --git a/jscomp/build_tests/bucklescript-tea/bsconfig.json b/jscomp/build_tests/bucklescript-tea/bsconfig.json index f1ca7466bd..8d10a6d44a 100644 --- a/jscomp/build_tests/bucklescript-tea/bsconfig.json +++ b/jscomp/build_tests/bucklescript-tea/bsconfig.json @@ -4,7 +4,8 @@ "bsc-flags": ["-bs-cross-module-opt"], "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, "sources": [ "src", @@ -12,6 +13,5 @@ "dir": "test", "type": "dev" } - ], - "suffix": ".bs.js" + ] } diff --git a/jscomp/build_tests/case3/bsconfig.json b/jscomp/build_tests/case3/bsconfig.json index bca3a013e6..73d285e314 100644 --- a/jscomp/build_tests/case3/bsconfig.json +++ b/jscomp/build_tests/case3/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/custom_namespace/bsconfig.json b/jscomp/build_tests/custom_namespace/bsconfig.json index 9677227f12..1c6384a108 100644 --- a/jscomp/build_tests/custom_namespace/bsconfig.json +++ b/jscomp/build_tests/custom_namespace/bsconfig.json @@ -8,13 +8,13 @@ "namespace": "Foo_bar", "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, "bsc-flags": ["-bs-no-version-header"], "bs-dependencies": [], "warnings": { "number": "-40+6+7", "error": true - }, - "suffix": ".bs.js" + } } diff --git a/jscomp/build_tests/customize_namespace/bsconfig.json b/jscomp/build_tests/customize_namespace/bsconfig.json index 238047fd17..27496286d0 100644 --- a/jscomp/build_tests/customize_namespace/bsconfig.json +++ b/jscomp/build_tests/customize_namespace/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": ["depa", "depb"], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/customize_namespace/node_modules/depa/bsconfig.json b/jscomp/build_tests/customize_namespace/node_modules/depa/bsconfig.json index 838dcdf9bf..98c0494db5 100644 --- a/jscomp/build_tests/customize_namespace/node_modules/depa/bsconfig.json +++ b/jscomp/build_tests/customize_namespace/node_modules/depa/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "namespace": "depx", "warnings": { "error": "+101" diff --git a/jscomp/build_tests/customize_namespace/node_modules/depb/bsconfig.json b/jscomp/build_tests/customize_namespace/node_modules/depb/bsconfig.json index 20075ad1a7..2b61628096 100644 --- a/jscomp/build_tests/customize_namespace/node_modules/depb/bsconfig.json +++ b/jscomp/build_tests/customize_namespace/node_modules/depb/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "namespace": true, "warnings": { "error": "+101" diff --git a/jscomp/build_tests/cycle/bsconfig.json b/jscomp/build_tests/cycle/bsconfig.json index 273ef42d05..5517bc5d12 100644 --- a/jscomp/build_tests/cycle/bsconfig.json +++ b/jscomp/build_tests/cycle/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/deprecated_bs_suffix/.gitignore b/jscomp/build_tests/deprecated_bs_suffix/.gitignore new file mode 100644 index 0000000000..fc9778a089 --- /dev/null +++ b/jscomp/build_tests/deprecated_bs_suffix/.gitignore @@ -0,0 +1,26 @@ +*.exe +*.obj +*.out +*.compile +*.native +*.byte +*.cmo +*.annot +*.cmi +*.cmx +*.cmt +*.cmti +*.cma +*.a +*.cmxa +*.obj +*~ +*.annot +*.cmj +*.bak +lib/bs +*.mlast +*.mliast +.vscode +.merlin +**/*.bs.js diff --git a/jscomp/build_tests/deprecated_bs_suffix/bsconfig.json b/jscomp/build_tests/deprecated_bs_suffix/bsconfig.json new file mode 100644 index 0000000000..277875bda2 --- /dev/null +++ b/jscomp/build_tests/deprecated_bs_suffix/bsconfig.json @@ -0,0 +1,11 @@ +{ + "name": "x", + "sources": ".", + "package-specs": [ + { + "module": "commonjs", + "in-source": true + } + ], + "suffix": ".bs.js" +} diff --git a/jscomp/build_tests/deprecated_bs_suffix/demo.ml b/jscomp/build_tests/deprecated_bs_suffix/demo.ml new file mode 100644 index 0000000000..e269467cdc --- /dev/null +++ b/jscomp/build_tests/deprecated_bs_suffix/demo.ml @@ -0,0 +1 @@ +let str = "Hello, world!" diff --git a/jscomp/build_tests/deprecated_bs_suffix/input.js b/jscomp/build_tests/deprecated_bs_suffix/input.js new file mode 100644 index 0000000000..0309c87c0d --- /dev/null +++ b/jscomp/build_tests/deprecated_bs_suffix/input.js @@ -0,0 +1,19 @@ +var child_process = require('child_process') + +var assert = require('assert').strict + +var output = child_process.spawnSync('bsb -clean-world && bsb -make-world', + { + cwd: __dirname, + encoding: 'utf8', + stdio : ['inherit','inherit','pipe'], + shell : true + } +) + +// Should warn the user about the deprecation, +assert.match(output.stderr, /top-level 'suffix' field is deprecated/) + +// ... but still respect it +assert.equal(output.status, 0) +assert.ok(require('./demo.bs')) diff --git a/jscomp/build_tests/devdeps/bsconfig.json b/jscomp/build_tests/devdeps/bsconfig.json index 304c66a63b..f228f4e86e 100644 --- a/jscomp/build_tests/devdeps/bsconfig.json +++ b/jscomp/build_tests/devdeps/bsconfig.json @@ -13,9 +13,9 @@ ], "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "bs-dev-dependencies": ["weird"], "warnings": { diff --git a/jscomp/build_tests/devonly/bsconfig.json b/jscomp/build_tests/devonly/bsconfig.json index fa04b30f8c..d6f1cca34a 100644 --- a/jscomp/build_tests/devonly/bsconfig.json +++ b/jscomp/build_tests/devonly/bsconfig.json @@ -14,9 +14,9 @@ ], "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/duplicated_symlinked_packages/a/bsconfig.json b/jscomp/build_tests/duplicated_symlinked_packages/a/bsconfig.json index b29cabbd4f..fcb68294b7 100644 --- a/jscomp/build_tests/duplicated_symlinked_packages/a/bsconfig.json +++ b/jscomp/build_tests/duplicated_symlinked_packages/a/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": ["c", "z"], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/duplicated_symlinked_packages/a/node_modules/z/bsconfig.json b/jscomp/build_tests/duplicated_symlinked_packages/a/node_modules/z/bsconfig.json index f9e19b37ff..f5f176ba7b 100644 --- a/jscomp/build_tests/duplicated_symlinked_packages/a/node_modules/z/bsconfig.json +++ b/jscomp/build_tests/duplicated_symlinked_packages/a/node_modules/z/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/duplicated_symlinked_packages/b/bsconfig.json b/jscomp/build_tests/duplicated_symlinked_packages/b/bsconfig.json index ed00ca26c7..f25c11a917 100644 --- a/jscomp/build_tests/duplicated_symlinked_packages/b/bsconfig.json +++ b/jscomp/build_tests/duplicated_symlinked_packages/b/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": ["c"], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/duplicated_symlinked_packages/c/bsconfig.json b/jscomp/build_tests/duplicated_symlinked_packages/c/bsconfig.json index 3c8493d2e7..86a4769fc8 100644 --- a/jscomp/build_tests/duplicated_symlinked_packages/c/bsconfig.json +++ b/jscomp/build_tests/duplicated_symlinked_packages/c/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/duplicated_symlinked_packages/node_modules/z/bsconfig.json b/jscomp/build_tests/duplicated_symlinked_packages/node_modules/z/bsconfig.json index f9e19b37ff..f5f176ba7b 100644 --- a/jscomp/build_tests/duplicated_symlinked_packages/node_modules/z/bsconfig.json +++ b/jscomp/build_tests/duplicated_symlinked_packages/node_modules/z/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/in_source/input.js b/jscomp/build_tests/in_source/input.js index 8b51852cc3..cf638fc829 100644 --- a/jscomp/build_tests/in_source/input.js +++ b/jscomp/build_tests/in_source/input.js @@ -10,13 +10,11 @@ assert.throws( }) }, function (err) { - if (err.message.match(/detected two module formats/)) { + if ( + err.message.match(/two conflicting module formats with the extension/) + ) { return true } return false } ) - -// assert.throws(()=>{ -// throw new Error('Wrong value') -// }, /x/) diff --git a/jscomp/build_tests/install/bsconfig.json b/jscomp/build_tests/install/bsconfig.json index e07e5a79f2..103083d9c6 100644 --- a/jscomp/build_tests/install/bsconfig.json +++ b/jscomp/build_tests/install/bsconfig.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/namespace/bsconfig.json b/jscomp/build_tests/namespace/bsconfig.json index eee924f1c3..47f3d7f26a 100644 --- a/jscomp/build_tests/namespace/bsconfig.json +++ b/jscomp/build_tests/namespace/bsconfig.json @@ -8,13 +8,13 @@ "namespace": true, "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, "bsc-flags": ["-bs-no-version-header"], "bs-dependencies": ["liba", "libb"], "warnings": { "number": "-40+6+7", "error": true - }, - "suffix": ".bs.js" + } } diff --git a/jscomp/build_tests/namespace/node_modules/liba/bsconfig.json b/jscomp/build_tests/namespace/node_modules/liba/bsconfig.json index f4581eb36e..61cd80e5b9 100644 --- a/jscomp/build_tests/namespace/node_modules/liba/bsconfig.json +++ b/jscomp/build_tests/namespace/node_modules/liba/bsconfig.json @@ -6,5 +6,8 @@ "warnings": { "error": true }, - "suffix": ".bs.js" + "package-specs": { + "module": "commonjs", + "suffix": ".bs.js" + } } diff --git a/jscomp/build_tests/ocamlgraph/bsconfig.json b/jscomp/build_tests/ocamlgraph/bsconfig.json index 3154a3a9fb..8438330d3d 100644 --- a/jscomp/build_tests/ocamlgraph/bsconfig.json +++ b/jscomp/build_tests/ocamlgraph/bsconfig.json @@ -33,9 +33,9 @@ ], "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "generators": [ { "name": "lex", diff --git a/jscomp/build_tests/react_ppx/bsconfig.json b/jscomp/build_tests/react_ppx/bsconfig.json index f449c93cd0..0c21d706ec 100644 --- a/jscomp/build_tests/react_ppx/bsconfig.json +++ b/jscomp/build_tests/react_ppx/bsconfig.json @@ -10,10 +10,10 @@ "package-specs": [ { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" } ], - "suffix": ".bs.js", "namespace": true, "refmt": 3 } diff --git a/jscomp/build_tests/top/bsconfig.json b/jscomp/build_tests/top/bsconfig.json index d3352c6b90..6c748b17de 100644 --- a/jscomp/build_tests/top/bsconfig.json +++ b/jscomp/build_tests/top/bsconfig.json @@ -16,9 +16,9 @@ ], "package-specs": { "module": "commonjs", - "in-source": true + "in-source": true, + "suffix": ".bs.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" diff --git a/jscomp/build_tests/zerocycle/bsconfig.json b/jscomp/build_tests/zerocycle/bsconfig.json index 3cd7e90d96..810e300cb0 100644 --- a/jscomp/build_tests/zerocycle/bsconfig.json +++ b/jscomp/build_tests/zerocycle/bsconfig.json @@ -4,10 +4,7 @@ "sources": ["src"], "package-specs": { "module": "commonjs", - "in-source": true - }, - "suffix": ".bs.js", - "bs-dependencies": [ - // add your bs-dependencies here - ] + "in-source": true, + "suffix": ".bs.js" + } } diff --git a/jscomp/common/bs_warnings.ml b/jscomp/common/bs_warnings.ml index f6f43718ce..f36dc33754 100644 --- a/jscomp/common/bs_warnings.ml +++ b/jscomp/common/bs_warnings.ml @@ -39,11 +39,11 @@ let to_string t = let warning_formatter = Format.err_formatter -let print_string_warning (loc : Location.t) x = +let print_string_warning (loc : Location.t) ?(kind = "Warning") x = if loc.loc_ghost then Format.fprintf warning_formatter "File %s@." !Location.input_name else Location.print warning_formatter loc; - Format.fprintf warning_formatter "@{Warning@}: %s@." x + Format.fprintf warning_formatter "@{%s@}: %s@." kind x let prerr_bs_ffi_warning loc x = @@ -72,6 +72,14 @@ let () = | _ -> None) +let warn_deprecated_bs_suffix_flag () = + if not !Clflags.bs_quiet then ( + print_string_warning Location.none ~kind:"DEPRECATED" + "`-bs-suffix` used; consider using third field of `-bs-package-output` \ + instead"; + Format.pp_print_flush warning_formatter () ) + + let warn_missing_primitive loc txt = if (not !Js_config.no_warn_unimplemented_external) && not !Clflags.bs_quiet then ( diff --git a/jscomp/common/bs_warnings.mli b/jscomp/common/bs_warnings.mli index 48ac704537..4a6ae8c0e1 100644 --- a/jscomp/common/bs_warnings.mli +++ b/jscomp/common/bs_warnings.mli @@ -26,6 +26,8 @@ type t = Unsafe_poly_variant_type val prerr_bs_ffi_warning : Location.t -> t -> unit +val warn_deprecated_bs_suffix_flag : unit -> unit + val warn_missing_primitive : Location.t -> string -> unit val warn_literal_overflow : Location.t -> unit diff --git a/jscomp/common/js_config.ml b/jscomp/common/js_config.ml index bded3505a9..1045407e64 100644 --- a/jscomp/common/js_config.ml +++ b/jscomp/common/js_config.ml @@ -35,8 +35,6 @@ let set_diagnose b = diagnose := b let ( // ) = Filename.concat -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx_ml = ref false let no_builtin_ppx_mli = ref false diff --git a/jscomp/common/js_config.mli b/jscomp/common/js_config.mli index eae410d915..594f4e69c8 100644 --- a/jscomp/common/js_config.mli +++ b/jscomp/common/js_config.mli @@ -22,15 +22,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* val get_packages_info : unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) (** return [package_name] and [path] when in script mode: *) -(* val get_current_package_name_and_path : Js_packages_info.module_system -> - Js_packages_info.info_query *) +(* val get_current_package_name_and_path : Js_package_info.module_system -> + Js_package_info.info_query *) (* val set_package_name : string -> unit val get_package_name : unit -> string option *) @@ -71,7 +69,6 @@ val syntax_only : bool ref val binary_ast : bool ref val simple_binary_ast : bool ref -val bs_suffix : bool ref val debug : bool ref val cmi_only : bool ref diff --git a/jscomp/core/js_cmj_format.ml b/jscomp/core/js_cmj_format.ml index 9cafb6926b..d74488c18c 100644 --- a/jscomp/core/js_cmj_format.ml +++ b/jscomp/core/js_cmj_format.ml @@ -34,29 +34,27 @@ type effect = string option (* we don't force people to use package *) let single_na = Single Lam_arity.na -type cmj_case = Ext_namespace.file_kind - type keyed_cmj_values = (string * cmj_value) array type t = { values : keyed_cmj_values; pure : bool; - npm_package_path : Js_packages_info.t; - cmj_case : cmj_case; + package_info : Js_package_info.t; + leading_case : Ext_namespace.leading_case; } let empty_values = [||] -let mk ~values ~effect ~npm_package_path ~cmj_case : t = +let mk ~values ~effect ~package_info ~leading_case : t = { values = Map_string.to_sorted_array values; pure = effect = None; - npm_package_path; - cmj_case; + package_info; + leading_case; } -let cmj_magic_number = "BUCKLE20171012" +let cmj_magic_number = "BUCKLE20200410" let cmj_magic_number_length = String.length cmj_magic_number let digest_length = 16 (*16 chars *) @@ -174,26 +172,24 @@ let query_by_name (cmj_table : t) name = let is_pure (cmj_table : t) = cmj_table.pure -let get_npm_package_path (cmj_table : t) = cmj_table.npm_package_path +let get_package_info (cmj_table : t) = cmj_table.package_info -let get_cmj_case (cmj_table : t) = cmj_table.cmj_case +let get_leading_case (cmj_table : t) = cmj_table.leading_case (* start dumping *) let f fmt = Printf.fprintf stdout fmt -let pp_cmj_case (cmj_case : cmj_case) : unit = - match cmj_case with - | Little_js -> f "case : little, .js\n" - | Little_bs -> f "case : little, .bs.js\n" - | Upper_js -> f "case: upper, .js\n" - | Upper_bs -> f "case: upper, .bs.js\n" +let pp_leading_case (leading_case : Ext_namespace.leading_case) : unit = + match leading_case with + | Upper -> f "case: upper\n" + | Lower -> f "case: lower\n" -let pp_cmj ({ values; pure; npm_package_path; cmj_case } : t) = +let pp_cmj ({ values; pure; package_info; leading_case } : t) = f "package info: %s\n" - (Format.asprintf "%a" Js_packages_info.dump_packages_info npm_package_path); - pp_cmj_case cmj_case; + (Format.asprintf "%a" Js_package_info.dump_package_info package_info); + pp_leading_case leading_case; f "effect: %s\n" (if pure then "pure" else "not pure"); Ext_array.iter values (fun (k, { arity; persistent_closed_lambda }) -> diff --git a/jscomp/core/js_cmj_format.mli b/jscomp/core/js_cmj_format.mli index 1c52e92ff6..67f7615334 100644 --- a/jscomp/core/js_cmj_format.mli +++ b/jscomp/core/js_cmj_format.mli @@ -46,24 +46,22 @@ type cmj_value = { type effect = string option -type cmj_case = Ext_namespace.file_kind - type t val mk : values:cmj_value Map_string.t -> effect:effect -> - npm_package_path:Js_packages_info.t -> - cmj_case:cmj_case -> + package_info:Js_package_info.t -> + leading_case:Ext_namespace.leading_case -> t val query_by_name : t -> string -> arity * Lam.t option val is_pure : t -> bool -val get_npm_package_path : t -> Js_packages_info.t +val get_package_info : t -> Js_package_info.t -val get_cmj_case : t -> cmj_case +val get_leading_case : t -> Ext_namespace.leading_case val single_na : arity diff --git a/jscomp/core/js_cmj_load.ml b/jscomp/core/js_cmj_load.ml index 70af1e1c8d..6c31ae8f25 100644 --- a/jscomp/core/js_cmj_load.ml +++ b/jscomp/core/js_cmj_load.ml @@ -42,7 +42,7 @@ let find_cmj_exn file : cmj_load_info = Bs_exception.error (Cmj_not_found file) | v -> { cmj_path = "BROWSER"; cmj_table = v } - (* see {!Js_packages_info.string_of_module_id} *) ) + (* see {!Js_package_info.string_of_module_id} *) ) | exception Not_found -> Bs_exception.error (Cmj_not_found file) #else diff --git a/jscomp/core/js_packages_state.ml b/jscomp/core/js_current_package_info.ml similarity index 78% rename from jscomp/core/js_packages_state.ml rename to jscomp/core/js_current_package_info.ml index 7d53cabe63..8e0fd035b0 100644 --- a/jscomp/core/js_packages_state.ml +++ b/jscomp/core/js_current_package_info.ml @@ -22,11 +22,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let packages_info = ref Js_packages_info.empty +let packages_info = ref Js_package_info.empty let set_package_name name = - if Js_packages_info.is_empty !packages_info then - packages_info := Js_packages_info.from_name name + if Js_package_info.is_empty !packages_info then + packages_info := Js_package_info.from_name name else Ext_arg.bad_argf "duplicated flag for -bs-package-name" @@ -35,8 +35,10 @@ let set_package_map module_name = Clflags.open_modules := module_name :: !Clflags.open_modules -let update_npm_package_path s = - packages_info := Js_packages_info.add_npm_package_path !packages_info s - +let append_location_descriptor_of_string s = + if Js_package_info.is_empty !packages_info then + Ext_arg.bad_argf "please set package name first using -bs-package-name or -bs-ns" + else + packages_info := Js_package_info.append_location_descriptor_of_string !packages_info s let get_packages_info () = !packages_info diff --git a/jscomp/core/js_packages_state.mli b/jscomp/core/js_current_package_info.mli similarity index 92% rename from jscomp/core/js_packages_state.mli rename to jscomp/core/js_current_package_info.mli index ffa1799402..b26a2f9935 100644 --- a/jscomp/core/js_packages_state.mli +++ b/jscomp/core/js_current_package_info.mli @@ -26,6 +26,6 @@ val set_package_name : string -> unit val set_package_map : string -> unit -val get_packages_info : unit -> Js_packages_info.t +val get_packages_info : unit -> Js_package_info.t -val update_npm_package_path : string -> unit +val append_location_descriptor_of_string : string -> unit diff --git a/jscomp/core/js_dump_import_export.mli b/jscomp/core/js_dump_import_export.mli index 255b6ac92f..daa7645b96 100644 --- a/jscomp/core/js_dump_import_export.mli +++ b/jscomp/core/js_dump_import_export.mli @@ -39,4 +39,4 @@ val imports : Ext_pp_scope.t -> Ext_pp.t -> (Ident.t * string) list -> - Ext_pp_scope.t \ No newline at end of file + Ext_pp_scope.t diff --git a/jscomp/core/js_dump_program.ml b/jscomp/core/js_dump_program.ml index 8dd9614ad6..11f4fa64a9 100644 --- a/jscomp/core/js_dump_program.ml +++ b/jscomp/core/js_dump_program.ml @@ -53,24 +53,25 @@ let dump_program (x : J.program) oc = ignore (program (P.from_channel oc) Ext_pp_scope.empty x) -let node_program ~output_dir f (x : J.deps_program) = +let node_program ~output_dir ~ext f (x : J.deps_program) = P.string f L.strict_directive; P.newline f; let cxt = Js_dump_import_export.requires L.require Ext_pp_scope.empty f (Ext_list.map x.modules (fun x -> ( Lam_module_ident.id x, - Js_name_of_module_id.string_of_module_id x ~output_dir NodeJS ))) + Js_name_of_module_id.string_of_module_id x ~output_dir ~ext NodeJS + ))) in program f cxt x.program -let es6_program ~output_dir fmt f (x : J.deps_program) = +let es6_program ~output_dir ~ext fmt f (x : J.deps_program) = let cxt = Js_dump_import_export.imports Ext_pp_scope.empty f (Ext_list.map x.modules (fun x -> ( Lam_module_ident.id x, - Js_name_of_module_id.string_of_module_id x ~output_dir fmt ))) + Js_name_of_module_id.string_of_module_id x ~output_dir ~ext fmt ))) in let () = P.force_newline f in let cxt = Js_dump.statement_list true cxt f x.program.block in @@ -85,7 +86,7 @@ let es6_program ~output_dir fmt f (x : J.deps_program) = Linguist::FileBlob.new('jscomp/test/test_u.js').generated? ]} *) -let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) +let pp_deps_program ~output_prefix ~ext (kind : Js_package_info.module_system) (program : J.deps_program) (f : Ext_pp.t) = if not !Js_config.no_version_header then ( P.string f Bs_version.header; @@ -96,8 +97,8 @@ let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) let output_dir = Filename.dirname output_prefix in ignore ( match kind with - | Es6 | Es6_global -> es6_program ~output_dir kind f program - | NodeJS -> node_program ~output_dir f program ); + | Es6 | Es6_global -> es6_program ~output_dir ~ext kind f program + | NodeJS -> node_program ~output_dir ~ext f program ); P.newline f; P.string f ( match program.side_effect with @@ -107,5 +108,5 @@ let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) P.flush f () -let dump_deps_program ~output_prefix kind x (oc : out_channel) = - pp_deps_program ~output_prefix kind x (P.from_channel oc) +let dump_deps_program ~output_prefix ~ext kind x (oc : out_channel) = + pp_deps_program ~output_prefix ~ext kind x (P.from_channel oc) diff --git a/jscomp/core/js_dump_program.mli b/jscomp/core/js_dump_program.mli index e86159a1f7..ca1ac1fa06 100644 --- a/jscomp/core/js_dump_program.mli +++ b/jscomp/core/js_dump_program.mli @@ -27,14 +27,16 @@ val dump_program : J.program -> out_channel -> unit val pp_deps_program : output_prefix:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> J.deps_program -> Ext_pp.t -> unit val dump_deps_program : output_prefix:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> J.deps_program -> out_channel -> unit diff --git a/jscomp/core/js_name_of_module_id.ml b/jscomp/core/js_name_of_module_id.ml index d0a31fa3df..66afee5ce5 100644 --- a/jscomp/core/js_name_of_module_id.ml +++ b/jscomp/core/js_name_of_module_id.ml @@ -41,29 +41,30 @@ let fix_path_for_windows : string -> string = let get_runtime_module_path (dep_module_id : Lam_module_ident.t) - (current_package_info : Js_packages_info.t) module_system = - let current_info_query = - Js_packages_info.query_package_infos current_package_info module_system + (current_package_info : Js_package_info.t) module_system = + let loc = + Js_package_info.query_package_location_by_module_system current_package_info + module_system in let js_file = - Ext_namespace.js_name_of_modulename dep_module_id.id.name Little_js + Ext_namespace.js_filename_of_modulename ~name:dep_module_id.id.name + ~ext:".js" Lower in - match current_info_query with + match loc with | Package_not_found -> assert false - | Package_script -> - Js_packages_info.runtime_package_path module_system js_file + | Package_script -> Js_package_info.runtime_package_path module_system js_file | Package_found pkg -> ( let dep_path = - "lib" // Js_packages_info.runtime_dir_of_module_system module_system + "lib" // Js_package_info.runtime_dir_of_module_system module_system in - if Js_packages_info.is_runtime_package current_package_info then + if Js_package_info.is_runtime_package current_package_info then Ext_path.node_rebase_file ~from:pkg.rel_path ~to_:dep_path js_file (* TODO: we assume that both [x] and [path] could only be relative path which is guaranteed by [-bs-package-output] *) else match module_system with | NodeJS | Es6 -> - Js_packages_info.runtime_package_path module_system js_file + Js_package_info.runtime_package_path module_system js_file (* Note we did a post-processing when working on Windows *) | Es6_global -> (* lib/ocaml/xx.cmj -- @@ -73,7 +74,7 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t) (* assert false *) Ext_path.rel_normalized_absolute_path ~from: - (Js_packages_info.get_output_dir current_package_info + (Js_package_info.get_output_dir current_package_info ~package_dir:(Lazy.force Ext_path.package_dir) module_system) (Lazy.force runtime_package_path // dep_path // js_file) ) @@ -81,9 +82,9 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t) (* [output_dir] is decided by the command line argument *) let string_of_module_id (dep_module_id : Lam_module_ident.t) - ~(output_dir : string) (module_system : Js_packages_info.module_system) : - string = - let current_package_info = Js_packages_state.get_packages_info () in + ~(output_dir : string) ~(ext : string) + (module_system : Js_package_info.module_system) : string = + let current_package_info = Js_current_package_info.get_packages_info () in fix_path_for_windows ( match dep_module_id.kind with | External name -> name (* the literal string for external package *) @@ -97,38 +98,43 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t) | Runtime -> get_runtime_module_path dep_module_id current_package_info module_system | Ml -> ( - let current_info_query = - Js_packages_info.query_package_infos current_package_info - module_system - in + let query = Js_package_info.query_package_location_by_module_system in + let current_loc = query current_package_info module_system in match Lam_compile_env.get_package_path_from_cmj dep_module_id with - | cmj_path, dep_package_info, little -> ( - let js_file = - Ext_namespace.js_name_of_modulename dep_module_id.id.name little - in - let dep_info_query = - Js_packages_info.query_package_infos dep_package_info - module_system - in - match (dep_info_query, current_info_query) with + | cmj_path, dep_package_info, case -> ( + let dep_loc = query dep_package_info module_system in + match (dep_loc, current_loc) with | Package_not_found, _ -> Bs_exception.error (Missing_ml_dependency dep_module_id.id.name) | Package_script, Package_found _ -> + let js_file = + Ext_namespace.js_filename_of_modulename + (* FIXME: Unsure how to infer a useful file-extension here. *) + ~name:dep_module_id.id.name ~ext:"" case + in Bs_exception.error (Dependency_script_module_dependent_not js_file) | (Package_script | Package_found _), Package_not_found -> assert false - | Package_found pkg, Package_script -> + | Package_found dep_pkg, Package_script -> + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext:dep_pkg.extension case + in #if BS_NATIVE then - if Filename.is_relative pkg.rel_path then - pkg.pkg_rel_path // js_file - else pkg.rel_path // js_file + if Filename.is_relative dep_pkg.rel_path then + dep_pkg.pkg_rel_path // js_file + else dep_pkg.rel_path // js_file #else - pkg.pkg_rel_path // js_file + dep_pkg.pkg_rel_path // js_file #end | Package_found dep_pkg, Package_found cur_pkg -> ( + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext:dep_pkg.extension case + in if - Js_packages_info.same_package_by_name current_package_info + Js_package_info.same_package_by_name current_package_info dep_package_info then Ext_path.node_rebase_file ~from:cur_pkg.rel_path @@ -154,13 +160,17 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t) (* assert false *) Ext_path.rel_normalized_absolute_path ~from: - (Js_packages_info.get_output_dir current_package_info + (Js_package_info.get_output_dir current_package_info ~package_dir:(Lazy.force Ext_path.package_dir) module_system) ( Filename.dirname (Filename.dirname (Filename.dirname cmj_path)) // dep_pkg.rel_path // js_file ) ) | Package_script, Package_script -> ( + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext case + in match Config_util.find_opt js_file with | Some file -> let basename = Filename.basename file in @@ -182,6 +192,6 @@ let string_of_module_id_in_browser (x : Lam_module_ident.t) = let string_of_module_id (id : Lam_module_ident.t) ~output_dir:(_ : string) - (_module_system : Js_packages_info.module_system) = + ~ext:(_ : string) (_module_system : Js_package_info.module_system) = string_of_module_id_in_browser id #end diff --git a/jscomp/core/js_name_of_module_id.mli b/jscomp/core/js_name_of_module_id.mli index 1c07901e5c..0975365e2f 100644 --- a/jscomp/core/js_name_of_module_id.mli +++ b/jscomp/core/js_name_of_module_id.mli @@ -25,7 +25,8 @@ val string_of_module_id : Lam_module_ident.t -> output_dir:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> string (** generate the mdoule path so that it can be spliced here: diff --git a/jscomp/core/js_packages_info.ml b/jscomp/core/js_package_info.ml similarity index 61% rename from jscomp/core/js_packages_info.ml rename to jscomp/core/js_package_info.ml index 55b6a045d9..190ff5d683 100644 --- a/jscomp/core/js_packages_info.ml +++ b/jscomp/core/js_package_info.ml @@ -41,10 +41,16 @@ let compatible (dep : module_system) (query : module_system) = | Es6_global -> dep = Es6_global || dep = Es6 -type package_info = { module_system : module_system; path : string } +type location_descriptor = { + module_system : module_system; + path : string; + extension : string; +} type package_name = Pkg_empty | Pkg_runtime | Pkg_normal of string +let deprecated_use_bs_extension = ref false + let runtime_package_name = "bs-platform" let ( // ) = Filename.concat @@ -60,23 +66,22 @@ let runtime_package_path (ms : module_system) js_file = runtime_package_name // "lib" // runtime_dir_of_module_system ms // js_file -type t = { name : package_name; module_systems : package_info list } +type t = { name : package_name; locations : location_descriptor list } let same_package_by_name (x : t) (y : t) = x.name = y.name let is_runtime_package (x : t) = x.name = Pkg_runtime -let iter (x : t) cb = Ext_list.iter x.module_systems cb +let iter (x : t) = Ext_list.iter x.locations (* TODO: not allowing user to provide such specific package name For empty package, [-bs-package-output] does not make sense it is only allowed to generate commonjs file in the same directory *) -let empty : t = { name = Pkg_empty; module_systems = [] } +let empty : t = { name = Pkg_empty; locations = [] } let from_name (name : string) = - if name = runtime_package_name then - { name = Pkg_runtime; module_systems = [] } - else { name = Pkg_normal name; module_systems = [] } + if name = runtime_package_name then { name = Pkg_runtime; locations = [] } + else { name = Pkg_normal name; locations = [] } let is_empty (x : t) = x.name = Pkg_empty @@ -96,9 +101,11 @@ let module_system_of_string package_name : module_system option = | _ -> None -let dump_package_info (fmt : Format.formatter) - ({ module_system = ms; path = name } : package_info) = - Format.fprintf fmt "@[%s:@ %s@]" (string_of_module_system ms) name +let dump_location_descriptor (fmt : Format.formatter) + { module_system = ms; path; extension } = + Format.fprintf fmt "@[%s:@ %s:@ %s@]" + (string_of_module_system ms) + path extension let dump_package_name fmt (x : package_name) = @@ -108,52 +115,53 @@ let dump_package_name fmt (x : package_name) = | Pkg_runtime -> Format.pp_print_string fmt runtime_package_name -let dump_packages_info (fmt : Format.formatter) - ({ name; module_systems = ls } : t) = +let dump_package_info (fmt : Format.formatter) ({ name; locations } : t) = Format.fprintf fmt "@[%a;@ @[%a@]@]" dump_package_name name (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.pp_print_space fmt ()) - dump_package_info) - ls + dump_location_descriptor) + locations -type package_found_info = { rel_path : string; pkg_rel_path : string } -type info_query = +type package_paths = { + rel_path : string; + pkg_rel_path : string; + extension : string; +} +type query_result = | Package_script | Package_not_found - | Package_found of package_found_info + | Package_found of package_paths (* Note that package-name has to be exactly the same as npm package name, otherwise the path resolution will be wrong *) -let query_package_infos ({ name; module_systems } : t) - (module_system : module_system) : info_query = +let query_package_location_by_module_system ({ name; locations } : t) + (module_system : module_system) : query_result = match name with | Pkg_empty -> Package_script | Pkg_normal name -> ( match - Ext_list.find_first module_systems (fun k -> + Ext_list.find_first locations (fun k -> compatible k.module_system module_system) with - | Some k -> - let rel_path = k.path in + | Some { path = rel_path; extension; module_system = _ms } -> let pkg_rel_path = name // rel_path in - Package_found { rel_path; pkg_rel_path } + Package_found { rel_path; pkg_rel_path; extension } | None -> Package_not_found ) | Pkg_runtime -> ( match - Ext_list.find_first module_systems (fun k -> + Ext_list.find_first locations (fun k -> compatible k.module_system module_system) with - | Some k -> - let rel_path = k.path in + | Some { path = rel_path; extension; module_system = _ms } -> let pkg_rel_path = runtime_package_name // rel_path in - Package_found { rel_path; pkg_rel_path } + Package_found { rel_path; pkg_rel_path; extension } | None -> Package_not_found ) let get_js_path (x : t) module_system = match - Ext_list.find_first x.module_systems (fun k -> + Ext_list.find_first x.locations (fun k -> compatible k.module_system module_system) with | Some k -> k.path @@ -165,31 +173,43 @@ let get_output_dir (info : t) ~package_dir module_system = Filename.concat package_dir (get_js_path info module_system) -let add_npm_package_path (packages_info : t) (s : string) : t = - if is_empty packages_info then - Ext_arg.bad_argf "please set package name first using -bs-package-name " - else - let module_system, path = - match Ext_string.split ~keep_empty:false s ':' with - | [ module_system; path ] -> - ( ( match module_system_of_string module_system with - | Some x -> x - | None -> Ext_arg.bad_argf "invalid module system %s" module_system - ), - path ) - | [ path ] -> (NodeJS, path) - | module_system :: path -> - ( ( match module_system_of_string module_system with - | Some x -> x - | None -> Ext_arg.bad_argf "invalid module system %s" module_system - ), - String.concat ":" path ) - | _ -> Ext_arg.bad_argf "invalid npm package path: %s" s - in - { - packages_info with - module_systems = { module_system; path } :: packages_info.module_systems; - } +let deprecated_set_bs_extension () = + Bs_warnings.warn_deprecated_bs_suffix_flag (); + deprecated_use_bs_extension := true + + +let deprecated_get_default_extension () = + if !deprecated_use_bs_extension then Literals.suffix_bs_js + else Literals.suffix_js + + +(* FIXME: The deprecated -bs-suffix will only affect -bs-package-output flags + passed *after* it. *) +let append_location_descriptor_of_string (packages_info : t) (s : string) : t = + let module_system, path, extension = + match Ext_string.split ~keep_empty:false s ':' with + | [ module_system; path; extension ] -> (module_system, path, extension) + (* Note that, for most users, the default values for [module_system] and + [extension] come not from here, but from [bsb], which always invokes this + with a fully-populated [-bs-package-output]. + + If you're changing the default, make sure both places match! *) + | [ module_system; path ] -> + (module_system, path, deprecated_get_default_extension ()) + | [ path ] -> ("NodeJS", path, deprecated_get_default_extension ()) + | _ -> Ext_arg.bad_argf "invalid value for -bs-package-output: %s" s + in + let module_system = + match module_system_of_string module_system with + | Some x -> x + | None -> + Ext_arg.bad_argf "invalid module system in -bs-package-output: %s" + module_system + in + { + packages_info with + locations = { module_system; path; extension } :: packages_info.locations; + } (* support es6 modules instead diff --git a/jscomp/core/js_packages_info.mli b/jscomp/core/js_package_info.mli similarity index 77% rename from jscomp/core/js_packages_info.mli rename to jscomp/core/js_package_info.mli index 0d3a154de6..7d060378ed 100644 --- a/jscomp/core/js_packages_info.mli +++ b/jscomp/core/js_package_info.mli @@ -28,7 +28,11 @@ val runtime_dir_of_module_system : module_system -> string val runtime_package_path : module_system -> string -> string -type package_info = { module_system : module_system; path : string } +type location_descriptor = { + module_system : module_system; + path : string; + extension : string; +} type t @@ -36,26 +40,32 @@ val is_runtime_package : t -> bool val same_package_by_name : t -> t -> bool -val iter : t -> (package_info -> unit) -> unit +val iter : t -> (location_descriptor -> unit) -> unit val empty : t val from_name : string -> t val is_empty : t -> bool -val dump_packages_info : Format.formatter -> t -> unit +val dump_package_info : Format.formatter -> t -> unit -val add_npm_package_path : t -> string -> t -(** used by command line option e.g [-bs-package-output commonjs:xx/path] *) +val deprecated_set_bs_extension : unit -> unit -type package_found_info = { rel_path : string; pkg_rel_path : string } +val append_location_descriptor_of_string : t -> string -> t +(** used by command line option e.g [-bs-package-output commonjs:xx/path:ext] *) -type info_query = +type package_paths = { + rel_path : string; + pkg_rel_path : string; + extension : string; +} + +type query_result = | Package_script | Package_not_found - | Package_found of package_found_info + | Package_found of package_paths val get_output_dir : t -> package_dir:string -> module_system -> string (* Note here we compare the package info by order in theory, we can compare it by set semantics *) -val query_package_infos : t -> module_system -> info_query +val query_package_location_by_module_system : t -> module_system -> query_result diff --git a/jscomp/core/lam_compile_env.ml b/jscomp/core/lam_compile_env.ml index e66fc8aee0..2505be2c24 100644 --- a/jscomp/core/lam_compile_env.ml +++ b/jscomp/core/lam_compile_env.ml @@ -95,8 +95,8 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) = match Lam_module_ident.Hash.find_opt cached_tbl id with | Some (Ml { cmj_table; cmj_path }) -> ( cmj_path, - Js_cmj_format.get_npm_package_path cmj_table, - Js_cmj_format.get_cmj_case cmj_table ) + Js_cmj_format.get_package_info cmj_table, + Js_cmj_format.get_leading_case cmj_table ) | Some (External | Runtime _) -> assert false (* called by {!Js_name_of_module_id.string_of_module_id} can not be @@ -111,8 +111,8 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) = in id +> Ml cmj_load_info; ( cmj_load_info.cmj_path, - Js_cmj_format.get_npm_package_path cmj_table, - Js_cmj_format.get_cmj_case cmj_table ) ) + Js_cmj_format.get_package_info cmj_table, + Js_cmj_format.get_leading_case cmj_table ) ) let add = Lam_module_ident.Hash_set.add diff --git a/jscomp/core/lam_compile_env.mli b/jscomp/core/lam_compile_env.mli index d1fedee5f5..49609496e3 100644 --- a/jscomp/core/lam_compile_env.mli +++ b/jscomp/core/lam_compile_env.mli @@ -63,12 +63,15 @@ val query_external_id_info : Ident.t -> string -> ident_info val is_pure_module : Lam_module_ident.t -> bool val get_package_path_from_cmj : - Lam_module_ident.t -> string * Js_packages_info.t * Js_cmj_format.cmj_case + Lam_module_ident.t -> string * Js_package_info.t * Ext_namespace.leading_case -(* The second argument is mostly from [runtime] modules will change the input - [hard_dependencies] [get_required_modules extra hard_dependencies] [extra] - maybe removed if it is pure and not in [hard_dependencies] *) val get_required_modules : Lam_module_ident.Hash_set.t -> Lam_module_ident.Hash_set.t -> Lam_module_ident.t list +(** The second argument is mostly from [runtime] modules + + will change the input [hard_dependencies] + + [get_required_modules extra hard_dependencies] - [extra] maybe removed if it + is pure and not in [hard_dependencies] *) diff --git a/jscomp/core/lam_compile_main.ml b/jscomp/core/lam_compile_main.ml index d491d165dd..d752bb6766 100644 --- a/jscomp/core/lam_compile_main.ml +++ b/jscomp/core/lam_compile_main.ml @@ -25,13 +25,9 @@ module E = Js_exp_make module S = Js_stmt_make -let get_cmj_case output_prefix : Ext_namespace.file_kind = - let little = Ext_char.is_lower_case (Filename.basename output_prefix).[0] in - match (little, !Js_config.bs_suffix) with - | true, true -> Little_bs - | true, false -> Little_js - | false, true -> Upper_bs - | false, false -> Upper_js +let get_leading_case output_prefix : Ext_namespace.leading_case = + if Ext_char.is_lower_case (Filename.basename output_prefix).[0] then Lower + else Upper let compile_group (meta : Lam_stats.t) (x : Lam_group.t) : Js_output.t = @@ -244,7 +240,7 @@ let compile (output_prefix : string) (lam : Lambda.lambda) = in let v : Js_cmj_format.t = Lam_stats_export.export_to_cmj meta effect coerced_input.export_map - (get_cmj_case output_prefix) + (get_leading_case output_prefix) in if not @@ !Clflags.dont_write_files then Js_cmj_format.to_file ~check_exists:(not !Js_config.force_cmj) @@ -257,20 +253,21 @@ let ( // ) = Filename.concat let lambda_as_module (lambda_output : J.deps_program) (output_prefix : string) : unit = - let basename = - Ext_namespace.change_ext_ns_suffix - (Filename.basename output_prefix) - ( if !Js_config.bs_suffix then Literals.suffix_bs_js - else Literals.suffix_js ) - in - let package_info = Js_packages_state.get_packages_info () in - if Js_packages_info.is_empty package_info && !Js_config.js_stdout then - Js_dump_program.dump_deps_program ~output_prefix NodeJS lambda_output stdout + let package_info = Js_current_package_info.get_packages_info () in + if Js_package_info.is_empty package_info && !Js_config.js_stdout then + Js_dump_program.dump_deps_program ~ext:".js" ~output_prefix NodeJS + lambda_output stdout else - Js_packages_info.iter package_info (fun { module_system; path = _path } -> + Js_package_info.iter package_info + (fun { module_system; path = _path; extension } -> + let basename = + Ext_namespace.replace_namespace_with_extension + ~name:(Filename.basename output_prefix) + ~ext:extension + in let output_chan chan = - Js_dump_program.dump_deps_program ~output_prefix module_system - lambda_output chan + Js_dump_program.dump_deps_program ~output_prefix ~ext:extension + module_system lambda_output chan in if not @@ !Clflags.dont_write_files then Ext_pervasives.with_file_as_chan diff --git a/jscomp/core/lam_stats_export.ml b/jscomp/core/lam_stats_export.ml index ee072b1348..707b9174f3 100644 --- a/jscomp/core/lam_stats_export.ml +++ b/jscomp/core/lam_stats_export.ml @@ -105,12 +105,12 @@ let get_dependent_module_effect (meta : Lam_stats.t) backend, we compile to js for the inliner, we try to seriaize it -- relies on other optimizations to make this happen {[ exports.Make = function () {.....} ]} TODO: check that we don't do this in browser environment *) -let export_to_cmj (meta : Lam_stats.t) effect export_map cmj_case : - Js_cmj_format.t = +let export_to_cmj (meta : Lam_stats.t) effect export_map + (leading_case : Ext_namespace.leading_case) : Js_cmj_format.t = let values = values_of_export meta export_map in (* FIXME: make sure [-o] would not change its case *) (* FIXME: add test for ns/non-ns *) Js_cmj_format.mk ~values ~effect - ~npm_package_path:(Js_packages_state.get_packages_info ()) - ~cmj_case + ~package_info:(Js_current_package_info.get_packages_info ()) + ~leading_case diff --git a/jscomp/core/lam_stats_export.mli b/jscomp/core/lam_stats_export.mli index 7e672dbbd9..f8effbe9c3 100644 --- a/jscomp/core/lam_stats_export.mli +++ b/jscomp/core/lam_stats_export.mli @@ -29,5 +29,5 @@ val export_to_cmj : Lam_stats.t -> Js_cmj_format.effect -> Lam.t Map_ident.t -> - Js_cmj_format.cmj_case -> + Ext_namespace.leading_case -> Js_cmj_format.t diff --git a/jscomp/ext/ext_namespace.ml b/jscomp/ext/ext_namespace.ml index 814f2b7069..d887552fd4 100644 --- a/jscomp/ext/ext_namespace.ml +++ b/jscomp/ext/ext_namespace.ml @@ -53,7 +53,7 @@ let rec rindex_rec s i = #1933 when removing ns suffix, don't pass the bound of basename FIXME: micro-optimizaiton *) -let change_ext_ns_suffix name ext = +let replace_namespace_with_extension ~name ~ext = let i = rindex_rec name (String.length name - 1) in if i < 0 then name ^ ext else String.sub name 0 i ^ ext @@ -65,18 +65,15 @@ let try_split_module_name name = else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -let js_name_of_modulename s little = - match little with - | Little_js -> - change_ext_ns_suffix (Ext_string.uncapitalize_ascii s) Literals.suffix_js - | Little_bs -> - change_ext_ns_suffix - (Ext_string.uncapitalize_ascii s) - Literals.suffix_bs_js - | Upper_js -> change_ext_ns_suffix s Literals.suffix_js - | Upper_bs -> change_ext_ns_suffix s Literals.suffix_bs_js +let js_filename_of_modulename ~name ~ext (leading_case : leading_case) = + match leading_case with + | Lower -> + replace_namespace_with_extension + ~name:(Ext_string.uncapitalize_ascii name) + ~ext + | Upper -> replace_namespace_with_extension ~name ~ext (** https://docs.npmjs.com/files/package.json diff --git a/jscomp/ext/ext_namespace.mli b/jscomp/ext/ext_namespace.mli index d8bbf93823..e01d1f0de1 100644 --- a/jscomp/ext/ext_namespace.mli +++ b/jscomp/ext/ext_namespace.mli @@ -28,14 +28,18 @@ val make : ?ns:string -> string -> string val try_split_module_name : string -> (string * string) option -val change_ext_ns_suffix : string -> string -> string +val replace_namespace_with_extension : name:string -> ext:string -> string +(** [replace_namespace_with_extension ~name ~ext] removes the part of [name] + after [ns_sep_char], if any; and appends [ext]. +*) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -val js_name_of_modulename : string -> file_kind -> string +val js_filename_of_modulename : + name:string -> ext:string -> leading_case -> string (** Predicts the JavaScript filename for a given (possibly namespaced) module- - name; i.e. [js_name_of_modulename "AA-Ns" Little_bs] would produce - ["aA.bs.js"]. *) + name; i.e. [js_filename_of_modulename ~name:"AA-Ns" ~ext:".js" Lower] would + produce ["aA.bs.js"]. *) val is_valid_npm_package_name : string -> bool diff --git a/jscomp/ext/literals.ml b/jscomp/ext/literals.ml index e66e27ff59..fbce259a67 100644 --- a/jscomp/ext/literals.ml +++ b/jscomp/ext/literals.ml @@ -99,8 +99,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" diff --git a/jscomp/ext/literals.mli b/jscomp/ext/literals.mli index 588df07e36..79cb6207ba 100644 --- a/jscomp/ext/literals.mli +++ b/jscomp/ext/literals.mli @@ -99,7 +99,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string diff --git a/jscomp/main/js_main.ml b/jscomp/main/js_main.ml index c445380b7f..7ec58999b4 100644 --- a/jscomp/main/js_main.ml +++ b/jscomp/main/js_main.ml @@ -150,7 +150,10 @@ let buckle_script_flags : (string * Arg.spec * string) list = :: ( "-bs-gentype", Arg.String (fun s -> Clflags.bs_gentype := Some s), " Pass gentype command" ) - :: ("-bs-suffix", Arg.Set Js_config.bs_suffix, " Set suffix to .bs.js") + :: ( "-bs-suffix", + Arg.Unit Js_package_info.deprecated_set_bs_extension, + " (DEPRECATED) Set default suffix to .bs.js - use third compoment of \ + -bs-package-output instead" ) :: ( "-bs-no-implicit-include", Arg.Set Clflags.no_implicit_current_dir, " Don't include current dir implicitly" ) @@ -203,19 +206,19 @@ let buckle_script_flags : (string * Arg.spec * string) list = Arg.Clear Js_config.sort_imports, " No sort (see -bs-sort-imports)" ) :: ( "-bs-package-name", - Arg.String Js_packages_state.set_package_name, + Arg.String Js_current_package_info.set_package_name, " set package name, useful when you want to produce npm packages" ) :: ( "-bs-ns", - Arg.String Js_packages_state.set_package_map, + Arg.String Js_current_package_info.set_package_map, " set package map, not only set package name but also use it as a \ namespace" ) :: ( "-bs-no-version-header", Arg.Set Js_config.no_version_header, " Don't print version header" ) :: ( "-bs-package-output", - Arg.String Js_packages_state.update_npm_package_path, - " set npm-output-path: [opt_module]:path, for example: 'lib/cjs', \ - 'amdjs:lib/amdjs', 'es6:lib/es6' " ) + Arg.String Js_current_package_info.append_location_descriptor_of_string, + " set npm-output-path: [opt_module]:path:[ext], for example: 'lib/cjs', \ + 'amdjs:lib/amdjs', 'es6:lib/es6:mjs' " ) :: ( "-bs-no-warn-unimplemented-external", Arg.Set Js_config.no_warn_unimplemented_external, " disable warnings on unimplmented c externals" ) diff --git a/jscomp/main/jsoo_main.ml b/jscomp/main/jsoo_main.ml index c1f292a161..503dec78fa 100644 --- a/jscomp/main/jsoo_main.ml +++ b/jscomp/main/jsoo_main.ml @@ -90,7 +90,7 @@ let implementation ~use_super_errors ?(react_ppx_version = V3) prefix impl str : let buffer = Buffer.create 1000 in let () = Js_dump_program.pp_deps_program (* does not matter here *) - ~output_prefix:"" NodeJS + ~output_prefix:"" ~ext:".js" NodeJS (Lam_compile_main.compile "" lam) (Ext_pp.from_buffer buffer) in diff --git a/jscomp/main/jsoo_refmt_main.ml b/jscomp/main/jsoo_refmt_main.ml index 8569922ce5..dcbfd256ae 100644 --- a/jscomp/main/jsoo_refmt_main.ml +++ b/jscomp/main/jsoo_refmt_main.ml @@ -84,7 +84,7 @@ let implementation ?prefix ~use_super_errors ?(react_ppx_version = V3) impl str let buffer = Buffer.create 1000 in let () = Js_dump_program.pp_deps_program (* does not matter here *) - ~output_prefix:"" NodeJS + ~output_prefix:"" ~ext:".js" NodeJS (Lam_compile_main.compile "" lam) (Ext_pp.from_buffer buffer) in diff --git a/jscomp/ounit_tests/ounit_string_tests.ml b/jscomp/ounit_tests/ounit_string_tests.ml index 3938a89392..80fdebd74d 100644 --- a/jscomp/ounit_tests/ounit_string_tests.ml +++ b/jscomp/ounit_tests/ounit_string_tests.ml @@ -378,14 +378,23 @@ let suites = =~"ABb" end; __LOC__ >:: begin fun _ -> - Ext_namespace.change_ext_ns_suffix "a-b" Literals.suffix_js =~ "a.js"; - Ext_namespace.change_ext_ns_suffix "a-" Literals.suffix_js =~ "a.js"; - Ext_namespace.change_ext_ns_suffix "a--" Literals.suffix_js =~ "a-.js"; - Ext_namespace.change_ext_ns_suffix "AA-b" Literals.suffix_js =~ "AA.js"; - Ext_namespace.js_name_of_modulename "AA-b" Little_js =~ "aA.js"; - Ext_namespace.js_name_of_modulename "AA-b" Upper_js =~ "AA.js"; - Ext_namespace.js_name_of_modulename "AA-b" Upper_bs =~ "AA.bs.js" - end; + Ext_namespace.replace_namespace_with_extension + ~name:"a-b" ~ext:Literals.suffix_js =~ "a.js"; + Ext_namespace.replace_namespace_with_extension + ~name:"a-" ~ext:Literals.suffix_js =~ "a.js"; + Ext_namespace.replace_namespace_with_extension + ~name:"a--" ~ext:Literals.suffix_js =~ "a-.js"; + Ext_namespace.replace_namespace_with_extension + ~name:"AA-b" ~ext:Literals.suffix_js =~ "AA.js"; + Ext_namespace.replace_namespace_with_extension + ~name:"AA-b" ~ext:Literals.suffix_js =~ "AA.js"; + Ext_namespace.js_filename_of_modulename + ~name:"AA-b" ~ext:Literals.suffix_js Lower =~ "aA.js"; + Ext_namespace.js_filename_of_modulename + ~name:"AA-b" ~ext:Literals.suffix_js Upper =~ "AA.js"; + Ext_namespace.js_filename_of_modulename + ~name:"AA-b" ~ext:Literals.suffix_bs_js Upper =~ "AA.bs.js"; + end; __LOC__ >:: begin fun _ -> let (=~) = OUnit.assert_equal ~printer:(fun x -> match x with diff --git a/lib/4.06.1/bsb.ml b/lib/4.06.1/bsb.ml index 11d29ef87c..7c59c3a086 100644 --- a/lib/4.06.1/bsb.ml +++ b/lib/4.06.1/bsb.ml @@ -141,11 +141,12 @@ let generators = "generators" let command = "command" let edge = "edge" let namespace = "namespace" +let _module = "module" let in_source = "in-source" +let suffix = "suffix" let warnings = "warnings" let number = "number" let error = "error" -let suffix = "suffix" let gentypeconfig = "gentypeconfig" let path = "path" let ignored_dirs = "ignored-dirs" @@ -4465,7 +4466,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -4603,8 +4608,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" @@ -5861,344 +5871,159 @@ let () = ) end -module Ext_buffer : sig -#1 "ext_buffer.mli" -(***********************************************************************) -(* *) -(* OCaml *) -(* *) -(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1999 Institut National de Recherche en Informatique et *) -(* en Automatique. All rights reserved. This file is distributed *) -(* under the terms of the GNU Library General Public License, with *) -(* the special exception on linking described in file ../LICENSE. *) -(* *) -(***********************************************************************) - -(** Extensible buffers. - - This module implements buffers that automatically expand - as necessary. It provides accumulative concatenation of strings - in quasi-linear time (instead of quadratic time when strings are - concatenated pairwise). -*) - -(* BuckleScript customization: customized for efficient digest *) - -type t -(** The abstract type of buffers. *) - -val create : int -> t -(** [create n] returns a fresh buffer, initially empty. - The [n] parameter is the initial size of the internal byte sequence - that holds the buffer contents. That byte sequence is automatically - reallocated when more than [n] characters are stored in the buffer, - but shrinks back to [n] characters when [reset] is called. - For best performance, [n] should be of the same order of magnitude - as the number of characters that are expected to be stored in - the buffer (for instance, 80 for a buffer that holds one output - line). Nothing bad will happen if the buffer grows beyond that - limit, however. In doubt, take [n = 16] for instance. - If [n] is not between 1 and {!Sys.max_string_length}, it will - be clipped to that interval. *) +module Ext_color : sig +#1 "ext_color.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) -val contents : t -> string -(** Return a copy of the current contents of the buffer. - The buffer itself is unchanged. *) +type color + = Black + | Red + | Green + | Yellow + | Blue + | Magenta + | Cyan + | White -val length : t -> int -(** Return the number of characters currently contained in the buffer. *) +type style + = FG of color + | BG of color + | Bold + | Dim -val is_empty : t -> bool +(** Input is the tag for example `@{@}` return escape code *) +val ansi_of_tag : string -> string -val clear : t -> unit -(** Empty the buffer. *) +val reset_lit : string +end = struct +#1 "ext_color.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) -val add_char : t -> char -> unit -(** [add_char b c] appends the character [c] at the end of the buffer [b]. *) -val add_string : t -> string -> unit -(** [add_string b s] appends the string [s] at the end of the buffer [b]. *) -val add_bytes : t -> bytes -> unit -(** [add_string b s] appends the string [s] at the end of the buffer [b]. - @since 4.02 *) -val add_substring : t -> string -> int -> int -> unit -(** [add_substring b s ofs len] takes [len] characters from offset - [ofs] in string [s] and appends them at the end of the buffer [b]. *) +type color + = Black + | Red + | Green + | Yellow + | Blue + | Magenta + | Cyan + | White -val add_subbytes : t -> bytes -> int -> int -> unit -(** [add_substring b s ofs len] takes [len] characters from offset - [ofs] in byte sequence [s] and appends them at the end of the buffer [b]. - @since 4.02 *) +type style + = FG of color + | BG of color + | Bold + | Dim -val add_buffer : t -> t -> unit -(** [add_buffer b1 b2] appends the current contents of buffer [b2] - at the end of buffer [b1]. [b2] is not modified. *) -val add_channel : t -> in_channel -> int -> unit -(** [add_channel b ic n] reads exactly [n] character from the - input channel [ic] and stores them at the end of buffer [b]. - Raise [End_of_file] if the channel contains fewer than [n] - characters. *) +let ansi_of_color = function + | Black -> "0" + | Red -> "1" + | Green -> "2" + | Yellow -> "3" + | Blue -> "4" + | Magenta -> "5" + | Cyan -> "6" + | White -> "7" -val output_buffer : out_channel -> t -> unit -(** [output_buffer oc b] writes the current contents of buffer [b] - on the output channel [oc]. *) +let code_of_style = function + | FG Black -> "30" + | FG Red -> "31" + | FG Green -> "32" + | FG Yellow -> "33" + | FG Blue -> "34" + | FG Magenta -> "35" + | FG Cyan -> "36" + | FG White -> "37" + + | BG Black -> "40" + | BG Red -> "41" + | BG Green -> "42" + | BG Yellow -> "43" + | BG Blue -> "44" + | BG Magenta -> "45" + | BG Cyan -> "46" + | BG White -> "47" -val digest : t -> Digest.t + | Bold -> "1" + | Dim -> "2" -val not_equal : - t -> - string -> - bool -val add_int_1 : - t -> int -> unit -val add_int_2 : - t -> int -> unit +(** TODO: add more styles later *) +let style_of_tag s = match s with + | "error" -> [Bold; FG Red] + | "warning" -> [Bold; FG Magenta] + | "info" -> [Bold; FG Yellow] + | "dim" -> [Dim] + | "filename" -> [FG Cyan] + | _ -> [] -val add_int_3 : - t -> int -> unit +let ansi_of_tag s = + let l = style_of_tag s in + let s = String.concat ";" (Ext_list.map l code_of_style) in + "\x1b[" ^ s ^ "m" -val add_int_4 : - t -> int -> unit -val add_string_char : - t -> - string -> - char -> - unit -val add_char_string : - t -> - char -> - string -> - unit -end = struct -#1 "ext_buffer.ml" -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1999 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) +let reset_lit = "\x1b[0m" -(* Extensible buffers *) - -type t = - {mutable buffer : bytes; - mutable position : int; - mutable length : int; - initial_buffer : bytes} - -let create n = - let n = if n < 1 then 1 else n in - - let n = if n > Sys.max_string_length then Sys.max_string_length else n in - - let s = Bytes.create n in - {buffer = s; position = 0; length = n; initial_buffer = s} - -let contents b = Bytes.sub_string b.buffer 0 b.position -let to_bytes b = Bytes.sub b.buffer 0 b.position - -let sub b ofs len = - if ofs < 0 || len < 0 || ofs > b.position - len - then invalid_arg "Ext_buffer.sub" - else Bytes.sub_string b.buffer ofs len - - -let blit src srcoff dst dstoff len = - if len < 0 || srcoff < 0 || srcoff > src.position - len - || dstoff < 0 || dstoff > (Bytes.length dst) - len - then invalid_arg "Ext_buffer.blit" - else - Bytes.unsafe_blit src.buffer srcoff dst dstoff len - -let length b = b.position -let is_empty b = b.position = 0 -let clear b = b.position <- 0 - -let reset b = - b.position <- 0; b.buffer <- b.initial_buffer; - b.length <- Bytes.length b.buffer - -let resize b more = - let len = b.length in - let new_len = ref len in - while b.position + more > !new_len do new_len := 2 * !new_len done; - - if !new_len > Sys.max_string_length then begin - if b.position + more <= Sys.max_string_length - then new_len := Sys.max_string_length - else failwith "Ext_buffer.add: cannot grow buffer" - end; - - let new_buffer = Bytes.create !new_len in - (* PR#6148: let's keep using [blit] rather than [unsafe_blit] in - this tricky function that is slow anyway. *) - Bytes.blit b.buffer 0 new_buffer 0 b.position; - b.buffer <- new_buffer; - b.length <- !new_len ; - assert (b.position + more <= b.length) - -let add_char b c = - let pos = b.position in - if pos >= b.length then resize b 1; - Bytes.unsafe_set b.buffer pos c; - b.position <- pos + 1 - -let add_substring b s offset len = - if offset < 0 || len < 0 || offset > String.length s - len - then invalid_arg "Ext_buffer.add_substring/add_subbytes"; - let new_position = b.position + len in - if new_position > b.length then resize b len; - Ext_bytes.unsafe_blit_string s offset b.buffer b.position len; - b.position <- new_position - - -let add_subbytes b s offset len = - add_substring b (Bytes.unsafe_to_string s) offset len - -let add_string b s = - let len = String.length s in - let new_position = b.position + len in - if new_position > b.length then resize b len; - Ext_bytes.unsafe_blit_string s 0 b.buffer b.position len; - b.position <- new_position - -(* TODO: micro-optimzie *) -let add_string_char b s c = - let s_len = String.length s in - let len = s_len + 1 in - let new_position = b.position + len in - if new_position > b.length then resize b len; - let b_buffer = b.buffer in - Ext_bytes.unsafe_blit_string s 0 b_buffer b.position s_len; - Bytes.unsafe_set b_buffer (new_position - 1) c; - b.position <- new_position - -let add_char_string b c s = - let s_len = String.length s in - let len = s_len + 1 in - let new_position = b.position + len in - if new_position > b.length then resize b len; - let b_buffer = b.buffer in - let b_position = b.position in - Bytes.unsafe_set b_buffer b_position c ; - Ext_bytes.unsafe_blit_string s 0 b_buffer (b_position + 1) s_len; - b.position <- new_position - - -let add_bytes b s = add_string b (Bytes.unsafe_to_string s) - -let add_buffer b bs = - add_subbytes b bs.buffer 0 bs.position - -let add_channel b ic len = - if len < 0 - - || len > Sys.max_string_length - - then (* PR#5004 *) - invalid_arg "Ext_buffer.add_channel"; - if b.position + len > b.length then resize b len; - really_input ic b.buffer b.position len; - b.position <- b.position + len - -let output_buffer oc b = - output oc b.buffer 0 b.position - -external unsafe_string: bytes -> int -> int -> Digest.t = "caml_md5_string" - -let digest b = - unsafe_string - b.buffer 0 b.position - -let rec not_equal_aux (b : bytes) (s : string) i len = - if i >= len then false - else - (Bytes.unsafe_get b i - <> - String.unsafe_get s i ) - || not_equal_aux b s (i + 1) len - -(** avoid a large copy *) -let not_equal (b : t) (s : string) = - let b_len = b.position in - let s_len = String.length s in - b_len <> s_len - || not_equal_aux b.buffer s 0 s_len - - -(** - It could be one byte, two bytes, three bytes and four bytes - TODO: inline for better performance -*) -let add_int_1 (b : t ) (x : int ) = - let c = (Char.unsafe_chr (x land 0xff)) in - let pos = b.position in - if pos >= b.length then resize b 1; - Bytes.unsafe_set b.buffer pos c; - b.position <- pos + 1 - -let add_int_2 (b : t ) (x : int ) = - let c1 = (Char.unsafe_chr (x land 0xff)) in - let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in - let pos = b.position in - if pos + 1 >= b.length then resize b 2; - let b_buffer = b.buffer in - Bytes.unsafe_set b_buffer pos c1; - Bytes.unsafe_set b_buffer (pos + 1) c2; - b.position <- pos + 2 - -let add_int_3 (b : t ) (x : int ) = - let c1 = (Char.unsafe_chr (x land 0xff)) in - let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in - let c3 = (Char.unsafe_chr (x lsr 16 land 0xff)) in - let pos = b.position in - if pos + 2 >= b.length then resize b 3; - let b_buffer = b.buffer in - Bytes.unsafe_set b_buffer pos c1; - Bytes.unsafe_set b_buffer (pos + 1) c2; - Bytes.unsafe_set b_buffer (pos + 2) c3; - b.position <- pos + 3 - - -let add_int_4 (b : t ) (x : int ) = - let c1 = (Char.unsafe_chr (x land 0xff)) in - let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in - let c3 = (Char.unsafe_chr (x lsr 16 land 0xff)) in - let c4 = (Char.unsafe_chr (x lsr 24 land 0xff)) in - let pos = b.position in - if pos + 3 >= b.length then resize b 4; - let b_buffer = b.buffer in - Bytes.unsafe_set b_buffer pos c1; - Bytes.unsafe_set b_buffer (pos + 1) c2; - Bytes.unsafe_set b_buffer (pos + 2) c3; - Bytes.unsafe_set b_buffer (pos + 3) c4; - b.position <- pos + 4 end -module Ext_filename : sig -#1 "ext_filename.mli" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. +module Bsb_log : sig +#1 "bsb_log.mli" +(* Copyright (C) 2017 Authors of BuckleScript * * 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 @@ -6223,69 +6048,31 @@ module Ext_filename : sig * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +val setup : unit -> unit +type level = + | Debug + | Info + | Warn + | Error +val log_level : level ref -(* TODO: - Change the module name, this code is not really an extension of the standard - library but rather specific to JS Module name convention. -*) - - - - - -(** An extension module to calculate relative path follow node/npm style. - TODO : this short name will have to change upon renaming the file. -*) - -val is_dir_sep : - char -> bool - -val maybe_quote: - string -> - string - -val chop_extension_maybe: - string -> - string - -(* return an empty string if no extension found *) -val get_extension_maybe: - string -> - string - - -val new_extension: - string -> - string -> - string - -val chop_all_extensions_maybe: - string -> - string - -(* OCaml specific abstraction*) -val module_name: - string -> - string - - - +type 'a fmt = Format.formatter -> ('a, Format.formatter, unit) format -> 'a -type module_info = { - module_name : string ; - case : bool; -} +type 'a log = ('a, Format.formatter, unit) format -> 'a +val verbose : unit -> unit +val debug : 'a log +val info : 'a log +val warn : 'a log +val error : 'a log +val info_args : string array -> unit -val as_module: - basename:string -> - module_info option end = struct -#1 "ext_filename.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. +#1 "bsb_log.ml" +(* Copyright (C) 2017- Authors of BuckleScript * * 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 @@ -6311,382 +6098,430 @@ end = struct +let ninja_ansi_forced = lazy + (try Sys.getenv "NINJA_ANSI_FORCED" with + Not_found ->"" + ) +let color_enabled = lazy (Unix.isatty Unix.stdout) -let is_dir_sep_unix c = c = '/' -let is_dir_sep_win_cygwin c = - c = '/' || c = '\\' || c = ':' +(* same logic as [ninja.exe] *) +let get_color_enabled () = + let colorful = + match ninja_ansi_forced with + | lazy "1" -> true + | lazy ("0" | "false") -> false + | _ -> + Lazy.force color_enabled in + colorful -let is_dir_sep = - if Sys.unix then is_dir_sep_unix else is_dir_sep_win_cygwin -(* reference ninja.cc IsKnownShellSafeCharacter *) -let maybe_quote ( s : string) = - let noneed_quote = - Ext_string.for_all s (function - | '0' .. '9' - | 'a' .. 'z' - | 'A' .. 'Z' - | '_' | '+' - | '-' | '.' - | '/' - | '@' -> true - | _ -> false - ) in - if noneed_quote then - s - else Filename.quote s +let color_functions : Format.formatter_tag_functions = { + mark_open_tag = (fun s -> if get_color_enabled () then Ext_color.ansi_of_tag s else Ext_string.empty) ; + mark_close_tag = (fun _ -> if get_color_enabled () then Ext_color.reset_lit else Ext_string.empty); + print_open_tag = (fun _ -> ()); + print_close_tag = (fun _ -> ()) +} -let chop_extension_maybe name = - let rec search_dot i = - if i < 0 || is_dir_sep (String.unsafe_get name i) then name - else if String.unsafe_get name i = '.' then String.sub name 0 i - else search_dot (i - 1) in - search_dot (String.length name - 1) +let set_color ppf = + Format.pp_set_formatter_tag_functions ppf color_functions -let get_extension_maybe name = - let name_len = String.length name in - let rec search_dot name i name_len = - if i < 0 || is_dir_sep (String.unsafe_get name i) then "" - else if String.unsafe_get name i = '.' then String.sub name i (name_len - i) - else search_dot name (i - 1) name_len in - search_dot name (name_len - 1) name_len -let chop_all_extensions_maybe name = - let rec search_dot i last = - if i < 0 || is_dir_sep (String.unsafe_get name i) then - (match last with - | None -> name - | Some i -> String.sub name 0 i) - else if String.unsafe_get name i = '.' then - search_dot (i - 1) (Some i) - else search_dot (i - 1) last in - search_dot (String.length name - 1) None +let setup () = + begin + Format.pp_set_mark_tags Format.std_formatter true ; + Format.pp_set_mark_tags Format.err_formatter true; + Format.pp_set_formatter_tag_functions + Format.std_formatter color_functions; + Format.pp_set_formatter_tag_functions + Format.err_formatter color_functions + end +type level = + | Debug + | Info + | Warn + | Error -let new_extension name (ext : string) = - let rec search_dot name i ext = - if i < 0 || is_dir_sep (String.unsafe_get name i) then - name ^ ext - else if String.unsafe_get name i = '.' then - let ext_len = String.length ext in - let buf = Bytes.create (i + ext_len) in - Bytes.blit_string name 0 buf 0 i; - Bytes.blit_string ext 0 buf i ext_len; - Bytes.unsafe_to_string buf - else search_dot name (i - 1) ext in - search_dot name (String.length name - 1) ext +let int_of_level (x : level) = + match x with + | Debug -> 0 + | Info -> 1 + | Warn -> 2 + | Error -> 3 +let log_level = ref Warn +let verbose () = + log_level := Debug +let dfprintf level fmt = + if int_of_level level >= int_of_level !log_level then + Format.fprintf fmt + else Format.ifprintf fmt -(** TODO: improve efficiency - given a path, calcuate its module name - Note that `ocamlc.opt -c aa.xx.mli` gives `aa.xx.cmi` - we can not strip all extensions, otherwise - we can not tell the difference between "x.cpp.ml" - and "x.ml" +type 'a fmt = + Format.formatter -> ('a, Format.formatter, unit) format -> 'a +type 'a log = + ('a, Format.formatter, unit) format -> 'a + +let debug fmt = dfprintf Debug Format.std_formatter fmt +let info fmt = dfprintf Info Format.std_formatter fmt +let warn fmt = dfprintf Warn Format.err_formatter fmt +let error fmt = dfprintf Error Format.err_formatter fmt + + +let info_args (args : string array) = + if int_of_level Info >= int_of_level !log_level then + begin + for i = 0 to Array.length args - 1 do + Format.pp_print_string Format.std_formatter (Array.unsafe_get args i) ; + Format.pp_print_string Format.std_formatter Ext_string.single_space; + done ; + Format.pp_print_newline Format.std_formatter () + end + else () + + +end +module Ext_buffer : sig +#1 "ext_buffer.mli" +(***********************************************************************) +(* *) +(* OCaml *) +(* *) +(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(** Extensible buffers. + + This module implements buffers that automatically expand + as necessary. It provides accumulative concatenation of strings + in quasi-linear time (instead of quadratic time when strings are + concatenated pairwise). *) -let module_name name = - let rec search_dot i name = - if i < 0 then - Ext_string.capitalize_ascii name - else - if String.unsafe_get name i = '.' then - Ext_string.capitalize_sub name i - else - search_dot (i - 1) name in - let name = Filename.basename name in - let name_len = String.length name in - search_dot (name_len - 1) name -type module_info = { - module_name : string ; - case : bool; -} +(* BuckleScript customization: customized for efficient digest *) +type t +(** The abstract type of buffers. *) +val create : int -> t +(** [create n] returns a fresh buffer, initially empty. + The [n] parameter is the initial size of the internal byte sequence + that holds the buffer contents. That byte sequence is automatically + reallocated when more than [n] characters are stored in the buffer, + but shrinks back to [n] characters when [reset] is called. + For best performance, [n] should be of the same order of magnitude + as the number of characters that are expected to be stored in + the buffer (for instance, 80 for a buffer that holds one output + line). Nothing bad will happen if the buffer grows beyond that + limit, however. In doubt, take [n = 16] for instance. + If [n] is not between 1 and {!Sys.max_string_length}, it will + be clipped to that interval. *) -let rec valid_module_name_aux name off len = - if off >= len then true - else - let c = String.unsafe_get name off in - match c with - | 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '\'' -> - valid_module_name_aux name (off + 1) len - | _ -> false +val contents : t -> string +(** Return a copy of the current contents of the buffer. + The buffer itself is unchanged. *) -type state = - | Invalid - | Upper - | Lower +val length : t -> int +(** Return the number of characters currently contained in the buffer. *) -let valid_module_name name len = - if len = 0 then Invalid - else - let c = String.unsafe_get name 0 in - match c with - | 'A' .. 'Z' - -> - if valid_module_name_aux name 1 len then - Upper - else Invalid - | 'a' .. 'z' - -> - if valid_module_name_aux name 1 len then - Lower - else Invalid - | _ -> Invalid +val is_empty : t -> bool +val clear : t -> unit +(** Empty the buffer. *) -let as_module ~basename = - let rec search_dot i name name_len = - if i < 0 then - (* Input e.g, [a_b] *) - match valid_module_name name name_len with - | Invalid -> None - | Upper -> Some {module_name = name; case = true } - | Lower -> Some {module_name = Ext_string.capitalize_ascii name; case = false} - else - if String.unsafe_get name i = '.' then - (*Input e.g, [A_b] *) - match valid_module_name name i with - | Invalid -> None - | Upper -> - Some {module_name = Ext_string.capitalize_sub name i; case = true} - | Lower -> - Some {module_name = Ext_string.capitalize_sub name i; case = false} - else - search_dot (i - 1) name name_len in - let name_len = String.length basename in - search_dot (name_len - 1) basename name_len - -end -module Ext_namespace : sig -#1 "ext_namespace.mli" -(* Copyright (C) 2017- Authors of BuckleScript - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) -val make : ?ns:string -> string -> string -(** [make ~ns:"Ns" "a"] A typical example would return "a-Ns" Note the namespace - comes from the output of [namespace_of_package_name] *) +val add_char : t -> char -> unit +(** [add_char b c] appends the character [c] at the end of the buffer [b]. *) -val try_split_module_name : string -> (string * string) option +val add_string : t -> string -> unit +(** [add_string b s] appends the string [s] at the end of the buffer [b]. *) -val change_ext_ns_suffix : string -> string -> string +val add_bytes : t -> bytes -> unit +(** [add_string b s] appends the string [s] at the end of the buffer [b]. + @since 4.02 *) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +val add_substring : t -> string -> int -> int -> unit +(** [add_substring b s ofs len] takes [len] characters from offset + [ofs] in string [s] and appends them at the end of the buffer [b]. *) -val js_name_of_modulename : string -> file_kind -> string -(** Predicts the JavaScript filename for a given (possibly namespaced) module- - name; i.e. [js_name_of_modulename "AA-Ns" Little_bs] would produce - ["aA.bs.js"]. *) +val add_subbytes : t -> bytes -> int -> int -> unit +(** [add_substring b s ofs len] takes [len] characters from offset + [ofs] in byte sequence [s] and appends them at the end of the buffer [b]. + @since 4.02 *) -val is_valid_npm_package_name : string -> bool +val add_buffer : t -> t -> unit +(** [add_buffer b1 b2] appends the current contents of buffer [b2] + at the end of buffer [b1]. [b2] is not modified. *) -val namespace_of_package_name : string -> string +val add_channel : t -> in_channel -> int -> unit +(** [add_channel b ic n] reads exactly [n] character from the + input channel [ic] and stores them at the end of buffer [b]. + Raise [End_of_file] if the channel contains fewer than [n] + characters. *) + +val output_buffer : out_channel -> t -> unit +(** [output_buffer oc b] writes the current contents of buffer [b] + on the output channel [oc]. *) + +val digest : t -> Digest.t + +val not_equal : + t -> + string -> + bool + +val add_int_1 : + t -> int -> unit + +val add_int_2 : + t -> int -> unit +val add_int_3 : + t -> int -> unit + +val add_int_4 : + t -> int -> unit + +val add_string_char : + t -> + string -> + char -> + unit + +val add_char_string : + t -> + char -> + string -> + unit end = struct -#1 "ext_namespace.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) +#1 "ext_buffer.ml" +(**************************************************************************) +(* *) +(* OCaml *) +(* *) +(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. *) +(* *) +(* All rights reserved. This file is distributed under the terms of *) +(* the GNU Lesser General Public License version 2.1, with the *) +(* special exception on linking described in the file LICENSE. *) +(* *) +(**************************************************************************) -(* Note the build system should check the validity of filenames espeically, it - should not contain '-' *) -let ns_sep_char = '-' -let ns_sep = "-" +(* Extensible buffers *) -let make ?ns cunit = - match ns with - | None -> cunit - | Some ns -> cunit ^ ns_sep ^ ns +type t = + {mutable buffer : bytes; + mutable position : int; + mutable length : int; + initial_buffer : bytes} +let create n = + let n = if n < 1 then 1 else n in + + let n = if n > Sys.max_string_length then Sys.max_string_length else n in + + let s = Bytes.create n in + {buffer = s; position = 0; length = n; initial_buffer = s} -(** Starting from the end, search for [ns_sep_char]. Returns the index, if - found, or [-1] if [ns_sep_char] is not found before reaching a - directory-separator. *) -let rec rindex_rec s i = - if i < 0 then i +let contents b = Bytes.sub_string b.buffer 0 b.position +let to_bytes b = Bytes.sub b.buffer 0 b.position + +let sub b ofs len = + if ofs < 0 || len < 0 || ofs > b.position - len + then invalid_arg "Ext_buffer.sub" + else Bytes.sub_string b.buffer ofs len + + +let blit src srcoff dst dstoff len = + if len < 0 || srcoff < 0 || srcoff > src.position - len + || dstoff < 0 || dstoff > (Bytes.length dst) - len + then invalid_arg "Ext_buffer.blit" else - let char = String.unsafe_get s i in - if Ext_filename.is_dir_sep char then -1 - else if char = ns_sep_char then i - else rindex_rec s (i - 1) + Bytes.unsafe_blit src.buffer srcoff dst dstoff len +let length b = b.position +let is_empty b = b.position = 0 +let clear b = b.position <- 0 -(* Note we have to output uncapitalized file Name, or at least be consistent, - since by reading cmi file on Case insensitive OS, we don't really know - whether it is `list.cmi` or `List.cmi`, so that `require(./list.js)` or - `require(./List.js)`. Relevant issues: #1609, #913 +let reset b = + b.position <- 0; b.buffer <- b.initial_buffer; + b.length <- Bytes.length b.buffer - #1933 when removing ns suffix, don't pass the bound of basename +let resize b more = + let len = b.length in + let new_len = ref len in + while b.position + more > !new_len do new_len := 2 * !new_len done; + + if !new_len > Sys.max_string_length then begin + if b.position + more <= Sys.max_string_length + then new_len := Sys.max_string_length + else failwith "Ext_buffer.add: cannot grow buffer" + end; + + let new_buffer = Bytes.create !new_len in + (* PR#6148: let's keep using [blit] rather than [unsafe_blit] in + this tricky function that is slow anyway. *) + Bytes.blit b.buffer 0 new_buffer 0 b.position; + b.buffer <- new_buffer; + b.length <- !new_len ; + assert (b.position + more <= b.length) - FIXME: micro-optimizaiton *) -let change_ext_ns_suffix name ext = - let i = rindex_rec name (String.length name - 1) in - if i < 0 then name ^ ext else String.sub name 0 i ^ ext +let add_char b c = + let pos = b.position in + if pos >= b.length then resize b 1; + Bytes.unsafe_set b.buffer pos c; + b.position <- pos + 1 + +let add_substring b s offset len = + if offset < 0 || len < 0 || offset > String.length s - len + then invalid_arg "Ext_buffer.add_substring/add_subbytes"; + let new_position = b.position + len in + if new_position > b.length then resize b len; + Ext_bytes.unsafe_blit_string s offset b.buffer b.position len; + b.position <- new_position + + +let add_subbytes b s offset len = + add_substring b (Bytes.unsafe_to_string s) offset len + +let add_string b s = + let len = String.length s in + let new_position = b.position + len in + if new_position > b.length then resize b len; + Ext_bytes.unsafe_blit_string s 0 b.buffer b.position len; + b.position <- new_position +(* TODO: micro-optimzie *) +let add_string_char b s c = + let s_len = String.length s in + let len = s_len + 1 in + let new_position = b.position + len in + if new_position > b.length then resize b len; + let b_buffer = b.buffer in + Ext_bytes.unsafe_blit_string s 0 b_buffer b.position s_len; + Bytes.unsafe_set b_buffer (new_position - 1) c; + b.position <- new_position -let try_split_module_name name = - let len = String.length name in - let i = rindex_rec name (len - 1) in - if i < 0 then None - else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) +let add_char_string b c s = + let s_len = String.length s in + let len = s_len + 1 in + let new_position = b.position + len in + if new_position > b.length then resize b len; + let b_buffer = b.buffer in + let b_position = b.position in + Bytes.unsafe_set b_buffer b_position c ; + Ext_bytes.unsafe_blit_string s 0 b_buffer (b_position + 1) s_len; + b.position <- new_position -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +let add_bytes b s = add_string b (Bytes.unsafe_to_string s) -let js_name_of_modulename s little = - match little with - | Little_js -> - change_ext_ns_suffix (Ext_string.uncapitalize_ascii s) Literals.suffix_js - | Little_bs -> - change_ext_ns_suffix - (Ext_string.uncapitalize_ascii s) - Literals.suffix_bs_js - | Upper_js -> change_ext_ns_suffix s Literals.suffix_js - | Upper_bs -> change_ext_ns_suffix s Literals.suffix_bs_js +let add_buffer b bs = + add_subbytes b bs.buffer 0 bs.position +let add_channel b ic len = + if len < 0 -(** https://docs.npmjs.com/files/package.json + || len > Sys.max_string_length - Some rules: + then (* PR#5004 *) + invalid_arg "Ext_buffer.add_channel"; + if b.position + len > b.length then resize b len; + really_input ic b.buffer b.position len; + b.position <- b.position + len - - The name must be less than or equal to 214 characters. This includes the - scope for scoped packages. - - The name can't start with a dot or an underscore. - - New packages must not have uppercase letters in the name. - - The name ends up being part of a URL, an argument on the command line, and - a folder name. Therefore, the name can't contain any non-URL-safe - characters. +let output_buffer oc b = + output oc b.buffer 0 b.position - TODO: handle cases like '\@angular/core'. its directory structure is like: +external unsafe_string: bytes -> int -> int -> Digest.t = "caml_md5_string" - {[ - @angular - |-------- core - ]} *) -let is_valid_npm_package_name (s : string) = - let len = String.length s in - len <= 214 (* magic number forced by npm *) - && len > 0 - && - match String.unsafe_get s 0 with - | 'a' .. 'z' | '@' -> - Ext_string.for_all_from s 1 (fun x -> - match x with - | 'a' .. 'z' | '0' .. '9' | '_' | '-' -> true - | _ -> false) - | _ -> false +let digest b = + unsafe_string + b.buffer 0 b.position +let rec not_equal_aux (b : bytes) (s : string) i len = + if i >= len then false + else + (Bytes.unsafe_get b i + <> + String.unsafe_get s i ) + || not_equal_aux b s (i + 1) len -let namespace_of_package_name (s : string) : string = - let len = String.length s in - let buf = Ext_buffer.create len in - let add capital ch = - Ext_buffer.add_char buf (if capital then Char.uppercase_ascii ch else ch) - in - let rec aux capital off len = - if off >= len then () - else - let ch = String.unsafe_get s off in - match ch with - | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' -> - add capital ch; - aux false (off + 1) len - | '/' | '-' -> aux true (off + 1) len - | _ -> aux capital (off + 1) len - in - aux true 0 len; - Ext_buffer.contents buf +(** avoid a large copy *) +let not_equal (b : t) (s : string) = + let b_len = b.position in + let s_len = String.length s in + b_len <> s_len + || not_equal_aux b.buffer s 0 s_len -end -module Bsb_package_specs : sig -#1 "bsb_package_specs.mli" -(* Copyright (C) 2017 Authors of BuckleScript - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) -type t +(** + It could be one byte, two bytes, three bytes and four bytes + TODO: inline for better performance +*) +let add_int_1 (b : t ) (x : int ) = + let c = (Char.unsafe_chr (x land 0xff)) in + let pos = b.position in + if pos >= b.length then resize b 1; + Bytes.unsafe_set b.buffer pos c; + b.position <- pos + 1 + +let add_int_2 (b : t ) (x : int ) = + let c1 = (Char.unsafe_chr (x land 0xff)) in + let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in + let pos = b.position in + if pos + 1 >= b.length then resize b 2; + let b_buffer = b.buffer in + Bytes.unsafe_set b_buffer pos c1; + Bytes.unsafe_set b_buffer (pos + 1) c2; + b.position <- pos + 2 -val default_package_specs : t +let add_int_3 (b : t ) (x : int ) = + let c1 = (Char.unsafe_chr (x land 0xff)) in + let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in + let c3 = (Char.unsafe_chr (x lsr 16 land 0xff)) in + let pos = b.position in + if pos + 2 >= b.length then resize b 3; + let b_buffer = b.buffer in + Bytes.unsafe_set b_buffer pos c1; + Bytes.unsafe_set b_buffer (pos + 1) c2; + Bytes.unsafe_set b_buffer (pos + 2) c3; + b.position <- pos + 3 -val from_json : Ext_json_types.t -> t -val get_list_of_output_js : t -> bool -> string -> string list +let add_int_4 (b : t ) (x : int ) = + let c1 = (Char.unsafe_chr (x land 0xff)) in + let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in + let c3 = (Char.unsafe_chr (x lsr 16 land 0xff)) in + let c4 = (Char.unsafe_chr (x lsr 24 land 0xff)) in + let pos = b.position in + if pos + 3 >= b.length then resize b 4; + let b_buffer = b.buffer in + Bytes.unsafe_set b_buffer pos c1; + Bytes.unsafe_set b_buffer (pos + 1) c2; + Bytes.unsafe_set b_buffer (pos + 2) c3; + Bytes.unsafe_set b_buffer (pos + 3) c4; + b.position <- pos + 4 -val package_flag_of_package_specs : t -> string -> string -(** Sample output: - {[ -bs-package-output commonjs:lib/js/jscomp/test ]} *) -val list_dirs_by : t -> (string -> unit) -> unit -end = struct -#1 "bsb_package_specs.ml" -(* Copyright (C) 2017 Authors of BuckleScript - * +end +module Ext_filename : sig +#1 "ext_filename.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * * 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, either version 3 of the License, or @@ -6704,158 +6539,76 @@ end = struct * 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. *) -let ( // ) = Ext_path.combine - -(* TODO: sync up with {!Js_packages_info.module_system} *) -type format = NodeJS | Es6 | Es6_global - -type spec = { format : format; in_source : bool } - -module Spec_set = Set.Make (struct - type t = spec - let compare = Pervasives.compare -end) - -type t = Spec_set.t - -let bad_module_format_message_exn ~loc format = - Bsb_exception.errorf ~loc - "package-specs: `%s` isn't a valid output module format. It has to be one \ - of: %s, %s or %s" - format Literals.commonjs Literals.es6 Literals.es6_global - - -let supported_format (x : string) loc = - if x = Literals.commonjs then NodeJS - else if x = Literals.es6 then Es6 - else if x = Literals.es6_global then Es6_global - else bad_module_format_message_exn ~loc x -let string_of_format (x : format) = - match x with - | NodeJS -> Literals.commonjs - | Es6 -> Literals.es6 - | Es6_global -> Literals.es6_global -let prefix_of_format (x : format) = - match x with - | NodeJS -> Bsb_config.lib_js - | Es6 -> Bsb_config.lib_es6 - | Es6_global -> Bsb_config.lib_es6_global +(* TODO: + Change the module name, this code is not really an extension of the standard + library but rather specific to JS Module name convention. +*) -let rec from_array (arr : Ext_json_types.t array) : Spec_set.t = - let spec = ref Spec_set.empty in - let has_in_source = ref false in - Ext_array.iter arr (fun x -> - let result = from_json_single x in - if result.in_source then - if not !has_in_source then has_in_source := true - else - Bsb_exception.errorf ~loc:(Ext_json.loc_of x) - "package-specs: we've detected two module formats that are both \ - configured to be in-source."; - spec := Spec_set.add result !spec); - !spec -(* TODO: FIXME: better API without mutating *) -and from_json_single (x : Ext_json_types.t) : spec = - match x with - | Str { str = format; loc } -> - { format = supported_format format loc; in_source = false } - | Obj { map; loc } -> ( - match Map_string.find_exn map "module" with - | Str { str = format } -> - let in_source = - match Map_string.find_opt map Bsb_build_schemas.in_source with - | Some (True _) -> true - | Some _ | None -> false - in - { format = supported_format format loc; in_source } - | Arr _ -> - Bsb_exception.errorf ~loc - "package-specs: when the configuration is an object, `module` \ - field should be a string, not an array. If you want to pass \ - multiple module specs, try turning package-specs into an array of \ - objects (or strings) instead." - | _ -> - Bsb_exception.errorf ~loc - "package-specs: the `module` field of the configuration object \ - should be a string." - | exception _ -> - Bsb_exception.errorf ~loc - "package-specs: when the configuration is an object, the `module` \ - field is mandatory." ) - | _ -> - Bsb_exception.errorf ~loc:(Ext_json.loc_of x) - "package-specs: we expect either a string or an object." +(** An extension module to calculate relative path follow node/npm style. + TODO : this short name will have to change upon renaming the file. +*) -let from_json (x : Ext_json_types.t) : Spec_set.t = - match x with - | Arr { content; _ } -> from_array content - | _ -> Spec_set.singleton (from_json_single x) +val is_dir_sep : + char -> bool + +val maybe_quote: + string -> + string +val chop_extension_maybe: + string -> + string -let bs_package_output = "-bs-package-output" +(* return an empty string if no extension found *) +val get_extension_maybe: + string -> + string -(** Assume input is valid - {[ -bs-package-output commonjs:lib/js/jscomp/test ]} *) -let package_flag ({ format; in_source } : spec) dir = - Ext_string.inter2 bs_package_output - (Ext_string.concat3 (string_of_format format) Ext_string.single_colon - (if in_source then dir else prefix_of_format format // dir)) +val new_extension: + string -> + string -> + string +val chop_all_extensions_maybe: + string -> + string -let package_flag_of_package_specs (package_specs : t) (dirname : string) : - string = - Spec_set.fold - (fun format acc -> Ext_string.inter2 acc (package_flag format dirname)) - package_specs Ext_string.empty +(* OCaml specific abstraction*) +val module_name: + string -> + string -let default_package_specs = - Spec_set.singleton { format = NodeJS; in_source = false } -(** [get_list_of_output_js specs true "src/hi/hello"] *) -let get_list_of_output_js (package_specs : Spec_set.t) (bs_suffix : bool) - (output_file_sans_extension : string) = - Spec_set.fold - (fun (spec : spec) acc -> - let basename = - Ext_namespace.change_ext_ns_suffix output_file_sans_extension - (if bs_suffix then Literals.suffix_bs_js else Literals.suffix_js) - in - ( Bsb_config.proj_rel - @@ - if spec.in_source then basename - else prefix_of_format spec.format // basename ) - :: acc) - package_specs [] +type module_info = { + module_name : string ; + case : bool; +} -let list_dirs_by (package_specs : Spec_set.t) (f : string -> unit) = - Spec_set.iter - (fun (spec : spec) -> - if not spec.in_source then f (prefix_of_format spec.format)) - package_specs -end -module Bsc_warnings -= struct -#1 "bsc_warnings.ml" -(* Copyright (C) 2020- Authors of BuckleScript - * +val as_module: + basename:string -> + module_info option +end = struct +#1 "ext_filename.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * * 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, either version 3 of the License, or @@ -6872,38 +6625,167 @@ module Bsc_warnings * 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. *) -(** - See the meanings of the warning codes here: https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec281 - - 30 Two labels or constructors of the same name are defined in two mutually recursive types. - - 40 Constructor or label name used out of scope. +let is_dir_sep_unix c = c = '/' +let is_dir_sep_win_cygwin c = + c = '/' || c = '\\' || c = ':' + +let is_dir_sep = + if Sys.unix then is_dir_sep_unix else is_dir_sep_win_cygwin + +(* reference ninja.cc IsKnownShellSafeCharacter *) +let maybe_quote ( s : string) = + let noneed_quote = + Ext_string.for_all s (function + | '0' .. '9' + | 'a' .. 'z' + | 'A' .. 'Z' + | '_' | '+' + | '-' | '.' + | '/' + | '@' -> true + | _ -> false + ) in + if noneed_quote then + s + else Filename.quote s + + +let chop_extension_maybe name = + let rec search_dot i = + if i < 0 || is_dir_sep (String.unsafe_get name i) then name + else if String.unsafe_get name i = '.' then String.sub name 0 i + else search_dot (i - 1) in + search_dot (String.length name - 1) + +let get_extension_maybe name = + let name_len = String.length name in + let rec search_dot name i name_len = + if i < 0 || is_dir_sep (String.unsafe_get name i) then "" + else if String.unsafe_get name i = '.' then String.sub name i (name_len - i) + else search_dot name (i - 1) name_len in + search_dot name (name_len - 1) name_len + +let chop_all_extensions_maybe name = + let rec search_dot i last = + if i < 0 || is_dir_sep (String.unsafe_get name i) then + (match last with + | None -> name + | Some i -> String.sub name 0 i) + else if String.unsafe_get name i = '.' then + search_dot (i - 1) (Some i) + else search_dot (i - 1) last in + search_dot (String.length name - 1) None + + +let new_extension name (ext : string) = + let rec search_dot name i ext = + if i < 0 || is_dir_sep (String.unsafe_get name i) then + name ^ ext + else if String.unsafe_get name i = '.' then + let ext_len = String.length ext in + let buf = Bytes.create (i + ext_len) in + Bytes.blit_string name 0 buf 0 i; + Bytes.blit_string ext 0 buf i ext_len; + Bytes.unsafe_to_string buf + else search_dot name (i - 1) ext in + search_dot name (String.length name - 1) ext + + + +(** TODO: improve efficiency + given a path, calcuate its module name + Note that `ocamlc.opt -c aa.xx.mli` gives `aa.xx.cmi` + we can not strip all extensions, otherwise + we can not tell the difference between "x.cpp.ml" + and "x.ml" +*) +let module_name name = + let rec search_dot i name = + if i < 0 then + Ext_string.capitalize_ascii name + else + if String.unsafe_get name i = '.' then + Ext_string.capitalize_sub name i + else + search_dot (i - 1) name in + let name = Filename.basename name in + let name_len = String.length name in + search_dot (name_len - 1) name + +type module_info = { + module_name : string ; + case : bool; +} + + + +let rec valid_module_name_aux name off len = + if off >= len then true + else + let c = String.unsafe_get name off in + match c with + | 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '\'' -> + valid_module_name_aux name (off + 1) len + | _ -> false + +type state = + | Invalid + | Upper + | Lower + +let valid_module_name name len = + if len = 0 then Invalid + else + let c = String.unsafe_get name 0 in + match c with + | 'A' .. 'Z' + -> + if valid_module_name_aux name 1 len then + Upper + else Invalid + | 'a' .. 'z' + -> + if valid_module_name_aux name 1 len then + Lower + else Invalid + | _ -> Invalid - - 6 Label omitted in function application. - - 7 Method overridden. - - 9 Missing fields in a record pattern. (*Not always desired, in some cases need [@@@warning "+9"] *) - - 27 Innocuous unused variable: unused variable that is not bound with let nor as, and doesn’t start with an underscore (_) character. - - 29 Unescaped end-of-line in a string constant (non-portable code). - - 32 .. 39 Unused blabla - - 44 Open statement shadows an already defined identifier. - - 45 Open statement shadows an already defined label or constructor. - - 48 Implicit elimination of optional arguments. https://caml.inria.fr/mantis/view.php?id=6352 - - 101 (bsb-specific) unsafe polymorphic comparison. -*) -let defaults_w = "-30-40+6+7+27+32..39+44+45+101" -let defaults_warn_error = "-a+5+101";; +let as_module ~basename = + let rec search_dot i name name_len = + if i < 0 then + (* Input e.g, [a_b] *) + match valid_module_name name name_len with + | Invalid -> None + | Upper -> Some {module_name = name; case = true } + | Lower -> Some {module_name = Ext_string.capitalize_ascii name; case = false} + else + if String.unsafe_get name i = '.' then + (*Input e.g, [A_b] *) + match valid_module_name name i with + | Invalid -> None + | Upper -> + Some {module_name = Ext_string.capitalize_sub name i; case = true} + | Lower -> + Some {module_name = Ext_string.capitalize_sub name i; case = false} + else + search_dot (i - 1) name name_len in + let name_len = String.length basename in + search_dot (name_len - 1) basename name_len + end -module Bsb_warning : sig -#1 "bsb_warning.mli" -(* Copyright (C) 2017 Authors of BuckleScript +module Ext_namespace : sig +#1 "ext_namespace.mli" +(* Copyright (C) 2017- Authors of BuckleScript * * 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 @@ -6927,29 +6809,32 @@ module Bsb_warning : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +val make : ?ns:string -> string -> string +(** [make ~ns:"Ns" "a"] A typical example would return "a-Ns" Note the namespace + comes from the output of [namespace_of_package_name] *) +val try_split_module_name : string -> (string * string) option +val replace_namespace_with_extension : name:string -> ext:string -> string +(** [replace_namespace_with_extension ~name ~ext] removes the part of [name] + after [ns_sep_char], if any; and appends [ext]. +*) -type t - -(** Extra work is need to make merlin happy *) -val to_merlin_string : t -> string - - - -val from_map : Ext_json_types.t Map_string.t -> t +type leading_case = Upper | Lower -(** [to_bsb_string not_dev warning] -*) -val to_bsb_string : - toplevel:bool -> - t -> - string +val js_filename_of_modulename : + name:string -> ext:string -> leading_case -> string +(** Predicts the JavaScript filename for a given (possibly namespaced) module- + name; i.e. [js_filename_of_modulename ~name:"AA-Ns" ~ext:".js" Lower] would + produce ["aA.bs.js"]. *) + +val is_valid_npm_package_name : string -> bool + +val namespace_of_package_name : string -> string -val use_default : t end = struct -#1 "bsb_warning.ml" -(* Copyright (C) 2017 Authors of BuckleScript +#1 "ext_namespace.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * 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 @@ -6973,120 +6858,117 @@ end = struct * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +(* Note the build system should check the validity of filenames espeically, it + should not contain '-' *) +let ns_sep_char = '-' +let ns_sep = "-" -type warning_error = - | Warn_error_false - (* default [false] to make our changes non-intrusive *) - | Warn_error_true - | Warn_error_number of string - -type t0 = { - number : string option; - error : warning_error -} +let make ?ns cunit = + match ns with + | None -> cunit + | Some ns -> cunit ^ ns_sep ^ ns -type nonrec t = t0 option -let use_default = None +(** Starting from the end, search for [ns_sep_char]. Returns the index, if + found, or [-1] if [ns_sep_char] is not found before reaching a + directory-separator. *) +let rec rindex_rec s i = + if i < 0 then i + else + let char = String.unsafe_get s i in + if Ext_filename.is_dir_sep char then -1 + else if char = ns_sep_char then i + else rindex_rec s (i - 1) -let prepare_warning_concat ~(beg : bool) s = - let s = Ext_string.trim s in - if s = "" then s - else - match s.[0] with - | '0' .. '9' -> if beg then "-w +" ^ s else "+" ^ s - | 'a' .. 'z' -> - if beg then "-w " ^ s else "+" ^ s - | _ -> - if beg then "-w " ^ s else s -let to_merlin_string x = - "-w " ^ Bsc_warnings.defaults_w - ^ - (match x with - | Some {number =None} - | None -> Ext_string.empty - | Some {number = Some x} -> - prepare_warning_concat ~beg:false x ) +(* Note we have to output uncapitalized file Name, or at least be consistent, + since by reading cmi file on Case insensitive OS, we don't really know + whether it is `list.cmi` or `List.cmi`, so that `require(./list.js)` or + `require(./List.js)`. Relevant issues: #1609, #913 + #1933 when removing ns suffix, don't pass the bound of basename - -let from_map (m : Ext_json_types.t Map_string.t) = - let number_opt = Map_string.find_opt m Bsb_build_schemas.number in - let error_opt = Map_string.find_opt m Bsb_build_schemas.error in - match number_opt, error_opt with - | None, None -> None - | _, _ -> - let error = - match error_opt with - | Some (True _) -> Warn_error_true - | Some (False _) -> Warn_error_false - | Some (Str {str ; }) - -> Warn_error_number str - | Some x -> Bsb_exception.config_error x "expect true/false or string" - | None -> Warn_error_false - (** To make it less intrusive : warning error has to be enabled*) - in - let number = - match number_opt with - | Some (Str { str = number}) -> Some number - | None -> None - | Some x -> Bsb_exception.config_error x "expect a string" - in - Some {number; error } + FIXME: micro-optimizaiton *) +let replace_namespace_with_extension ~name ~ext = + let i = rindex_rec name (String.length name - 1) in + if i < 0 then name ^ ext else String.sub name 0 i ^ ext -let to_bsb_string ~toplevel warning = - match warning with - | None -> Ext_string.empty - | Some warning -> - (match warning.number with - | None -> - Ext_string.empty - | Some x -> - prepare_warning_concat ~beg:true x - ) ^ - if toplevel then - match warning.error with - | Warn_error_true -> - " -warn-error A" - | Warn_error_number y -> - " -warn-error " ^ y - | Warn_error_false -> - Ext_string.empty - else Ext_string.empty +let try_split_module_name name = + let len = String.length name in + let i = rindex_rec name (len - 1) in + if i < 0 then None + else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) -end -module Bs_hash_stubs -= struct -#1 "bs_hash_stubs.ml" +type leading_case = Upper | Lower -external hash_string : string -> int = "caml_bs_hash_string" [@@noalloc];; +let js_filename_of_modulename ~name ~ext (leading_case : leading_case) = + match leading_case with + | Lower -> + replace_namespace_with_extension + ~name:(Ext_string.uncapitalize_ascii name) + ~ext + | Upper -> replace_namespace_with_extension ~name ~ext -external hash_string_int : string -> int -> int = "caml_bs_hash_string_and_int" [@@noalloc];; -external hash_string_small_int : string -> int -> int = "caml_bs_hash_string_and_small_int" [@@noalloc];; +(** https://docs.npmjs.com/files/package.json -external hash_stamp_and_name : int -> string -> int = "caml_bs_hash_stamp_and_name" [@@noalloc];; + Some rules: -external hash_small_int : int -> int = "caml_bs_hash_small_int" [@@noalloc];; + - The name must be less than or equal to 214 characters. This includes the + scope for scoped packages. + - The name can't start with a dot or an underscore. + - New packages must not have uppercase letters in the name. + - The name ends up being part of a URL, an argument on the command line, and + a folder name. Therefore, the name can't contain any non-URL-safe + characters. -external hash_int : int -> int = "caml_bs_hash_int" [@@noalloc];; + TODO: handle cases like '\@angular/core'. its directory structure is like: -external string_length_based_compare : string -> string -> int = "caml_string_length_based_compare" [@@noalloc];; + {[ + @angular + |-------- core + ]} *) +let is_valid_npm_package_name (s : string) = + let len = String.length s in + len <= 214 (* magic number forced by npm *) + && len > 0 + && + match String.unsafe_get s 0 with + | 'a' .. 'z' | '@' -> + Ext_string.for_all_from s 1 (fun x -> + match x with + | 'a' .. 'z' | '0' .. '9' | '_' | '-' -> true + | _ -> false) + | _ -> false -external - int_unsafe_blit : - int array -> int -> int array -> int -> int -> unit = "caml_int_array_blit" [@@noalloc];; - +let namespace_of_package_name (s : string) : string = + let len = String.length s in + let buf = Ext_buffer.create len in + let add capital ch = + Ext_buffer.add_char buf (if capital then Char.uppercase_ascii ch else ch) + in + let rec aux capital off len = + if off >= len then () + else + let ch = String.unsafe_get s off in + match ch with + | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' -> + add capital ch; + aux false (off + 1) len + | '/' | '-' -> aux true (off + 1) len + | _ -> aux capital (off + 1) len + in + aux true 0 len; + Ext_buffer.contents buf end -module Ext_util : sig -#1 "ext_util.mli" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * +module Bsb_package_specs : sig +#1 "bsb_package_specs.mli" +(* Copyright (C) 2017 Authors of BuckleScript + * * 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, either version 3 of the License, or @@ -7104,21 +6986,32 @@ module Ext_util : sig * 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. *) +type t + +val default_package_specs : ?deprecated_bs_suffix:bool -> unit -> t - -val power_2_above : int -> int -> int +val from_json : ?deprecated_bs_suffix:bool -> Ext_json_types.t -> t +val get_list_of_output_js : t -> string -> string list + +val extract_in_source_bs_suffixes : t -> string list + +val flags_of_package_specs : t -> string -> string +(** Sample output: + + {[ -bs-package-output commonjs:lib/js/jscomp/test:mjs ]} *) + +val list_dirs_by : t -> (string -> unit) -> unit -val stats_to_string : Hashtbl.statistics -> string end = struct -#1 "ext_util.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * +#1 "bsb_package_specs.ml" +(* Copyright (C) 2017 Authors of BuckleScript + * * 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, either version 3 of the License, or @@ -7136,220 +7029,251 @@ end = struct * 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. *) -(** - {[ - (power_2_above 16 63 = 64) - (power_2_above 16 76 = 128) - ]} -*) -let rec power_2_above x n = - if x >= n then x - else if x * 2 > Sys.max_array_length then x - else power_2_above (x * 2) n +let ( // ) = Ext_path.combine +(* TODO: sync up with {!Js_package_info.module_system} *) +type format = NodeJS | Es6 | Es6_global -let stats_to_string ({num_bindings; num_buckets; max_bucket_length; bucket_histogram} : Hashtbl.statistics) = - Printf.sprintf - "bindings: %d,buckets: %d, longest: %d, hist:[%s]" - num_bindings - num_buckets - max_bucket_length - (String.concat "," (Array.to_list (Array.map string_of_int bucket_histogram))) -end -module Hash_set_gen -= struct -#1 "hash_set_gen.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) +type spec = { format : format; in_source : bool; suffix : string } + +module Spec_set = Set.Make (struct + type t = spec + let compare = Pervasives.compare +end) + +type t = Spec_set.t + +let bad_module_format_message_exn ~loc format = + Bsb_exception.errorf ~loc + "package-specs: `%s` isn't a valid output module format. It has to be one \ + of: %s, %s or %s" + format Literals.commonjs Literals.es6 Literals.es6_global -(* We do dynamic hashing, and resize the table and rehash the elements - when buckets become too long. *) +let supported_format (x : string) loc = + if x = Literals.commonjs then NodeJS + else if x = Literals.es6 then Es6 + else if x = Literals.es6_global then Es6_global + else bad_module_format_message_exn ~loc x -type 'a bucket = - | Empty - | Cons of { - mutable key : 'a ; - mutable next : 'a bucket - } -type 'a t = - { mutable size: int; (* number of entries *) - mutable data: 'a bucket array; (* the buckets *) - initial_size: int; (* initial array size *) - } +let string_of_format (x : format) = + match x with + | NodeJS -> Literals.commonjs + | Es6 -> Literals.es6 + | Es6_global -> Literals.es6_global +let prefix_of_format (x : format) = + match x with + | NodeJS -> Bsb_config.lib_js + | Es6 -> Bsb_config.lib_es6 + | Es6_global -> Bsb_config.lib_es6_global -let create initial_size = - let s = Ext_util.power_2_above 16 initial_size in - { initial_size = s; size = 0; data = Array.make s Empty } +let deprecated_bs_suffix_message_warn () = + Bsb_log.warn + "@{DEPRECATED@}: @[top-level 'suffix' field is deprecated;@ \ + please lower your extension-configuration into@ 'package-specs'.@]@." + + +let bad_suffix_message_warn suffix = + let open Literals in + Bsb_log.warn + "@{UNSUPPORTED@}: @[package-specs: extension `%s` is \ + unsupported;@ consider one of: %s, %s, %s; %s, %s,@ or %s.@]@." + suffix suffix_js suffix_mjs suffix_cjs suffix_bs_js suffix_bs_mjs + suffix_bs_cjs + + +let supported_suffix (x : string) = + if + not + (List.mem x + Literals. + [ + suffix_js; + suffix_mjs; + suffix_cjs; + suffix_bs_js; + suffix_bs_mjs; + suffix_bs_cjs; + ]) + then bad_suffix_message_warn x; + x -let clear h = - h.size <- 0; - let len = Array.length h.data in - for i = 0 to len - 1 do - Array.unsafe_set h.data i Empty - done -let reset h = - h.size <- 0; - h.data <- Array.make h.initial_size Empty +let default_suffix ~deprecated_bs_suffix _format _in_source = + (* match (format, in_source) with *) + (* | NodeJS, false -> Literals.suffix_js *) + (* | NodeJS, true -> Literals.suffix_bs_js *) + (* | _, false -> Literals.suffix_mjs *) + (* | _, true -> Literals.suffix_bs_mjs *) -let length h = h.size + (* TODO: In the absence of direction to the contrary, the suffix should + eventually depend on [format] and [in_source]. For now, for + backwards-compatibility, I'm hardcoding. *) + if deprecated_bs_suffix then Literals.suffix_bs_js else Literals.suffix_js -let resize indexfun h = - let odata = h.data in - let osize = Array.length odata in - let nsize = osize * 2 in - if nsize < Sys.max_array_length then begin - let ndata = Array.make nsize Empty in - let ndata_tail = Array.make nsize Empty in - h.data <- ndata; (* so that indexfun sees the new bucket count *) - let rec insert_bucket = function - Empty -> () - | Cons {key; next} as cell -> - let nidx = indexfun h key in - begin match Array.unsafe_get ndata_tail nidx with - | Empty -> - Array.unsafe_set ndata nidx cell - | Cons tail -> - tail.next <- cell - end; - Array.unsafe_set ndata_tail nidx cell; - insert_bucket next - in - for i = 0 to osize - 1 do - insert_bucket (Array.unsafe_get odata i) - done; - for i = 0 to nsize - 1 do - match Array.unsafe_get ndata_tail i with - | Empty -> () - | Cons tail -> tail.next <- Empty - done - end -let iter h f = - let rec do_bucket = function - | Empty -> - () - | Cons l -> - f l.key ; do_bucket l.next in - let d = h.data in - for i = 0 to Array.length d - 1 do - do_bucket (Array.unsafe_get d i) - done +module SS = Set.Make (String) -let fold h init f = - let rec do_bucket b accu = - match b with - Empty -> - accu - | Cons l -> - do_bucket l.next (f l.key accu) in - let d = h.data in - let accu = ref init in - for i = 0 to Array.length d - 1 do - accu := do_bucket (Array.unsafe_get d i) !accu - done; - !accu +let supported_bs_suffixes = + Literals.[ suffix_bs_js; suffix_bs_mjs; suffix_bs_cjs ] -let elements set = - fold set [] List.cons +(** Produces a [list] of supported, bs-prefixed file-suffixes used in + [in-source] package-specs. *) +let extract_in_source_bs_suffixes (package_specs : Spec_set.t) = + let f spec suffixes = + if spec.in_source && List.mem spec.suffix supported_bs_suffixes then + SS.add spec.suffix suffixes + else suffixes + in + let suffixes = Spec_set.fold f package_specs SS.empty in + SS.elements suffixes + + +let rec from_array ~deprecated_bs_suffix (arr : Ext_json_types.t array) : + Spec_set.t = + let specs = ref Spec_set.empty in + Ext_array.iter arr (fun x -> + let spec = from_json_single ~deprecated_bs_suffix x in + if + Spec_set.exists + (fun o -> + spec.in_source == o.in_source && String.equal spec.suffix o.suffix) + !specs + then + Bsb_exception.errorf ~loc:(Ext_json.loc_of x) + "package-specs: two conflicting module formats with the extension \ + `%s` are both configured to be in-source." + spec.suffix + else specs := Spec_set.add spec !specs); + !specs + + +(* FIXME: better API without mutating *) +and from_json_single ~deprecated_bs_suffix (x : Ext_json_types.t) : spec = + match x with + | Str { str = format; loc } -> + let format = supported_format format loc in + { + format; + in_source = false; + suffix = default_suffix ~deprecated_bs_suffix format false; + } + | Obj { map; loc } -> ( + match Map_string.find_exn map Bsb_build_schemas._module with + | Str { str = format } -> + let format = supported_format format loc in + let in_source = + match Map_string.find_opt map Bsb_build_schemas.in_source with + | Some (True _) -> true + | Some _ | None -> false + in + let suffix = + match Map_string.find_opt map Bsb_build_schemas.suffix with + | Some (Str { str = suffix; loc }) -> supported_suffix suffix + | Some _ -> + Bsb_exception.errorf ~loc + "package-specs: the `suffix` field of the configuration \ + object must be absent, or a string." + | None -> default_suffix ~deprecated_bs_suffix format in_source + in + { format; in_source; suffix } + | Arr _ -> + Bsb_exception.errorf ~loc + "package-specs: when the configuration is an object, `module` \ + field should be a string, not an array. If you want to pass \ + multiple module specs, try turning package-specs into an array of \ + objects (or strings) instead." + | _ -> + Bsb_exception.errorf ~loc + "package-specs: the `module` field of the configuration object \ + should be a string." + | exception _ -> + Bsb_exception.errorf ~loc + "package-specs: when the configuration is an object, the `module` \ + field is mandatory." ) + | _ -> + Bsb_exception.errorf ~loc:(Ext_json.loc_of x) + "package-specs: we expect either a string or an object." +let from_json ?(deprecated_bs_suffix = false) (x : Ext_json_types.t) : + Spec_set.t = + if deprecated_bs_suffix then deprecated_bs_suffix_message_warn (); + match x with + | Arr { content; _ } -> from_array ~deprecated_bs_suffix content + | _ -> Spec_set.singleton (from_json_single ~deprecated_bs_suffix x) -let rec small_bucket_mem eq key lst = - match lst with - | Empty -> false - | Cons lst -> - eq key lst.key || - match lst.next with - | Empty -> false - | Cons lst -> - eq key lst.key || - match lst.next with - | Empty -> false - | Cons lst -> - eq key lst.key || - small_bucket_mem eq key lst.next +let bs_package_output = "-bs-package-output" -let rec remove_bucket - (h : _ t) (i : int) - key - ~(prec : _ bucket) - (buck : _ bucket) - eq_key = - match buck with - | Empty -> - () - | Cons {key=k; next } -> - if eq_key k key - then begin - h.size <- h.size - 1; - match prec with - | Empty -> Array.unsafe_set h.data i next - | Cons c -> c.next <- next - end - else remove_bucket h i key ~prec:buck next eq_key +(** Assume input is valid + {[ -bs-package-output commonjs:lib/js/jscomp/test:mjs ]} *) +let package_flag ({ format; in_source; suffix } : spec) dir = + Ext_string.inter2 bs_package_output + (Ext_string.concat5 (string_of_format format) Ext_string.single_colon + (if in_source then dir else prefix_of_format format // dir) + Ext_string.single_colon suffix) -module type S = -sig - type key - type t - val create: int -> t - val clear : t -> unit - val reset : t -> unit - (* val copy: t -> t *) - val remove: t -> key -> unit - val add : t -> key -> unit - val of_array : key array -> t - val check_add : t -> key -> bool - val mem : t -> key -> bool - val iter: t -> (key -> unit) -> unit - val fold: t -> 'b -> (key -> 'b -> 'b) -> 'b - val length: t -> int - (* val stats: t -> Hashtbl.statistics *) - val elements : t -> key list -end + +let flags_of_package_specs (package_specs : t) (dirname : string) : string = + Spec_set.fold + (fun format acc -> Ext_string.inter2 acc (package_flag format dirname)) + package_specs Ext_string.empty + + +let default_package_specs ?deprecated_bs_suffix () = + let deprecated_bs_suffix = match deprecated_bs_suffix with + | Some x -> deprecated_bs_suffix_message_warn (); x + | None -> false + in + Spec_set.singleton + { + format = NodeJS; + in_source = false; + suffix = default_suffix ~deprecated_bs_suffix NodeJS false; + } + + +(** [get_list_of_output_js specs true "src/hi/hello"] *) +let get_list_of_output_js (package_specs : Spec_set.t) + (output_file_sans_extension : string) = + Spec_set.fold + (fun spec acc -> + let basename = + Ext_namespace.replace_namespace_with_extension + ~name:output_file_sans_extension ~ext:spec.suffix + in + ( Bsb_config.proj_rel + @@ + if spec.in_source then basename + else prefix_of_format spec.format // basename ) + :: acc) + package_specs [] +let list_dirs_by (package_specs : Spec_set.t) (f : string -> unit) = + Spec_set.iter + (fun (spec : spec) -> + if not spec.in_source then f (prefix_of_format spec.format)) + package_specs end -module Hash_set_string : sig -#1 "hash_set_string.mli" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * +module Bsc_warnings += struct +#1 "bsc_warnings.ml" +(* Copyright (C) 2020- Authors of BuckleScript + * * 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, either version 3 of the License, or @@ -7366,20 +7290,39 @@ module Hash_set_string : sig * 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. *) -include Hash_set_gen.S with type key = string -end = struct -#1 "hash_set_string.ml" -# 1 "ext/hash_set.cppo.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * +(** + See the meanings of the warning codes here: https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec281 + + - 30 Two labels or constructors of the same name are defined in two mutually recursive types. + - 40 Constructor or label name used out of scope. + + - 6 Label omitted in function application. + - 7 Method overridden. + - 9 Missing fields in a record pattern. (*Not always desired, in some cases need [@@@warning "+9"] *) + - 27 Innocuous unused variable: unused variable that is not bound with let nor as, and doesn’t start with an underscore (_) character. + - 29 Unescaped end-of-line in a string constant (non-portable code). + - 32 .. 39 Unused blabla + - 44 Open statement shadows an already defined identifier. + - 45 Open statement shadows an already defined label or constructor. + - 48 Implicit elimination of optional arguments. https://caml.inria.fr/mantis/view.php?id=6352 + - 101 (bsb-specific) unsafe polymorphic comparison. +*) +let defaults_w = "-30-40+6+7+27+32..39+44+45+101" +let defaults_warn_error = "-a+5+101";; + +end +module Bsb_warning : sig +#1 "bsb_warning.mli" +(* Copyright (C) 2017 Authors of BuckleScript + * * 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, either version 3 of the License, or @@ -7397,82 +7340,34 @@ end = struct * 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. *) -# 31 "ext/hash_set.cppo.ml" -type key = string -let key_index (h : _ Hash_set_gen.t ) (key : key) = - (Bs_hash_stubs.hash_string key) land (Array.length h.data - 1) -let eq_key = Ext_string.equal -type t = key Hash_set_gen.t - - -# 64 "ext/hash_set.cppo.ml" -let create = Hash_set_gen.create -let clear = Hash_set_gen.clear -let reset = Hash_set_gen.reset -(* let copy = Hash_set_gen.copy *) -let iter = Hash_set_gen.iter -let fold = Hash_set_gen.fold -let length = Hash_set_gen.length -(* let stats = Hash_set_gen.stats *) -let elements = Hash_set_gen.elements -let remove (h : _ Hash_set_gen.t ) key = - let i = key_index h key in - let h_data = h.data in - Hash_set_gen.remove_bucket h i key ~prec:Empty (Array.unsafe_get h_data i) eq_key - +type t -let add (h : _ Hash_set_gen.t) key = - let i = key_index h key in - let h_data = h.data in - let old_bucket = (Array.unsafe_get h_data i) in - if not (Hash_set_gen.small_bucket_mem eq_key key old_bucket) then - begin - Array.unsafe_set h_data i (Cons {key = key ; next = old_bucket}); - h.size <- h.size + 1 ; - if h.size > Array.length h_data lsl 1 then Hash_set_gen.resize key_index h - end +(** Extra work is need to make merlin happy *) +val to_merlin_string : t -> string -let of_array arr = - let len = Array.length arr in - let tbl = create len in - for i = 0 to len - 1 do - add tbl (Array.unsafe_get arr i); - done ; - tbl - - -let check_add (h : _ Hash_set_gen.t) key : bool = - let i = key_index h key in - let h_data = h.data in - let old_bucket = (Array.unsafe_get h_data i) in - if not (Hash_set_gen.small_bucket_mem eq_key key old_bucket) then - begin - Array.unsafe_set h_data i (Cons { key = key ; next = old_bucket}); - h.size <- h.size + 1 ; - if h.size > Array.length h_data lsl 1 then Hash_set_gen.resize key_index h; - true - end - else false -let mem (h : _ Hash_set_gen.t) key = - Hash_set_gen.small_bucket_mem eq_key key (Array.unsafe_get h.data (key_index h key)) +val from_map : Ext_json_types.t Map_string.t -> t - +(** [to_bsb_string not_dev warning] +*) +val to_bsb_string : + toplevel:bool -> + t -> + string -end -module Bsb_config_types -= struct -#1 "bsb_config_types.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. +val use_default : t +end = struct +#1 "bsb_warning.ml" +(* Copyright (C) 2017 Authors of BuckleScript * * 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 @@ -7497,70 +7392,149 @@ module Bsb_config_types * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type dependency = - { - package_name : Bsb_pkg_types.t ; - package_install_path : string ; - } -type dependencies = dependency list +type warning_error = + | Warn_error_false + (* default [false] to make our changes non-intrusive *) + | Warn_error_true + | Warn_error_number of string -(* `string` is a path to the entrypoint *) -type entries_t = JsTarget of string | NativeTarget of string | BytecodeTarget of string +type t0 = { + number : string option; + error : warning_error +} -type compilation_kind_t = Js | Bytecode | Native +type nonrec t = t0 option -type reason_react_jsx = - | Jsx_v2 - | Jsx_v3 - (* string option *) +let use_default = None -type refmt = string option +let prepare_warning_concat ~(beg : bool) s = + let s = Ext_string.trim s in + if s = "" then s + else + match s.[0] with + | '0' .. '9' -> if beg then "-w +" ^ s else "+" ^ s + | 'a' .. 'z' -> + if beg then "-w " ^ s else "+" ^ s + | _ -> + if beg then "-w " ^ s else s -type gentype_config = { - path : string (* resolved *) -} -type command = string +let to_merlin_string x = + "-w " ^ Bsc_warnings.defaults_w + ^ + (match x with + | Some {number =None} + | None -> Ext_string.empty + | Some {number = Some x} -> + prepare_warning_concat ~beg:false x ) -type ppx = { - name : string; - args : string list -} -type t = - { - package_name : string ; - (* [captial-package] *) - namespace : string option; - (* CapitalPackage *) - external_includes : string list ; - bsc_flags : string list ; - ppx_files : ppx list ; - pp_file : string option; - bs_dependencies : dependencies; - bs_dev_dependencies : dependencies; - built_in_dependency : dependency option; - warning : Bsb_warning.t; - (*TODO: maybe we should always resolve bs-platform - so that we can calculate correct relative path in - [.merlin] - *) - refmt : refmt; - js_post_build_cmd : string option; - package_specs : Bsb_package_specs.t ; - file_groups : Bsb_file_groups.t; - files_to_install : Hash_set_string.t ; - generate_merlin : bool ; - reason_react_jsx : reason_react_jsx option; (* whether apply PPX transform or not*) - entries : entries_t list ; - generators : command Map_string.t ; - cut_generators : bool; (* note when used as a dev mode, we will always ignore it *) - bs_suffix : bool ; (* true means [.bs.js] we should pass [-bs-suffix] flag *) - gentype_config : gentype_config option; - number_of_dev_groups : int - } -end -module Ext_color : sig -#1 "ext_color.mli" + +let from_map (m : Ext_json_types.t Map_string.t) = + let number_opt = Map_string.find_opt m Bsb_build_schemas.number in + let error_opt = Map_string.find_opt m Bsb_build_schemas.error in + match number_opt, error_opt with + | None, None -> None + | _, _ -> + let error = + match error_opt with + | Some (True _) -> Warn_error_true + | Some (False _) -> Warn_error_false + | Some (Str {str ; }) + -> Warn_error_number str + | Some x -> Bsb_exception.config_error x "expect true/false or string" + | None -> Warn_error_false + (** To make it less intrusive : warning error has to be enabled*) + in + let number = + match number_opt with + | Some (Str { str = number}) -> Some number + | None -> None + | Some x -> Bsb_exception.config_error x "expect a string" + in + Some {number; error } + +let to_bsb_string ~toplevel warning = + match warning with + | None -> Ext_string.empty + | Some warning -> + (match warning.number with + | None -> + Ext_string.empty + | Some x -> + prepare_warning_concat ~beg:true x + ) ^ + if toplevel then + match warning.error with + | Warn_error_true -> + " -warn-error A" + | Warn_error_number y -> + " -warn-error " ^ y + | Warn_error_false -> + Ext_string.empty + else Ext_string.empty + + +end +module Bs_hash_stubs += struct +#1 "bs_hash_stubs.ml" + + +external hash_string : string -> int = "caml_bs_hash_string" [@@noalloc];; + +external hash_string_int : string -> int -> int = "caml_bs_hash_string_and_int" [@@noalloc];; + +external hash_string_small_int : string -> int -> int = "caml_bs_hash_string_and_small_int" [@@noalloc];; + +external hash_stamp_and_name : int -> string -> int = "caml_bs_hash_stamp_and_name" [@@noalloc];; + +external hash_small_int : int -> int = "caml_bs_hash_small_int" [@@noalloc];; + +external hash_int : int -> int = "caml_bs_hash_int" [@@noalloc];; + +external string_length_based_compare : string -> string -> int = "caml_string_length_based_compare" [@@noalloc];; + +external + int_unsafe_blit : + int array -> int -> int array -> int -> int -> unit = "caml_int_array_blit" [@@noalloc];; + + + +end +module Ext_util : sig +#1 "ext_util.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + + + +val power_2_above : int -> int -> int + + +val stats_to_string : Hashtbl.statistics -> string +end = struct +#1 "ext_util.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * This program is free software: you can redistribute it and/or modify @@ -7585,29 +7559,29 @@ module Ext_color : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type color - = Black - | Red - | Green - | Yellow - | Blue - | Magenta - | Cyan - | White - -type style - = FG of color - | BG of color - | Bold - | Dim - -(** Input is the tag for example `@{@}` return escape code *) -val ansi_of_tag : string -> string +(** + {[ + (power_2_above 16 63 = 64) + (power_2_above 16 76 = 128) + ]} +*) +let rec power_2_above x n = + if x >= n then x + else if x * 2 > Sys.max_array_length then x + else power_2_above (x * 2) n -val reset_lit : string -end = struct -#1 "ext_color.ml" +let stats_to_string ({num_bindings; num_buckets; max_bucket_length; bucket_histogram} : Hashtbl.statistics) = + Printf.sprintf + "bindings: %d,buckets: %d, longest: %d, hist:[%s]" + num_bindings + num_buckets + max_bucket_length + (String.concat "," (Array.to_list (Array.map string_of_int bucket_histogram))) +end +module Hash_set_gen += struct +#1 "hash_set_gen.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * This program is free software: you can redistribute it and/or modify @@ -7633,85 +7607,166 @@ end = struct * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +(* We do dynamic hashing, and resize the table and rehash the elements + when buckets become too long. *) + +type 'a bucket = + | Empty + | Cons of { + mutable key : 'a ; + mutable next : 'a bucket + } +type 'a t = + { mutable size: int; (* number of entries *) + mutable data: 'a bucket array; (* the buckets *) + initial_size: int; (* initial array size *) + } -type color - = Black - | Red - | Green - | Yellow - | Blue - | Magenta - | Cyan - | White -type style - = FG of color - | BG of color - | Bold - | Dim -let ansi_of_color = function - | Black -> "0" - | Red -> "1" - | Green -> "2" - | Yellow -> "3" - | Blue -> "4" - | Magenta -> "5" - | Cyan -> "6" - | White -> "7" +let create initial_size = + let s = Ext_util.power_2_above 16 initial_size in + { initial_size = s; size = 0; data = Array.make s Empty } -let code_of_style = function - | FG Black -> "30" - | FG Red -> "31" - | FG Green -> "32" - | FG Yellow -> "33" - | FG Blue -> "34" - | FG Magenta -> "35" - | FG Cyan -> "36" - | FG White -> "37" - - | BG Black -> "40" - | BG Red -> "41" - | BG Green -> "42" - | BG Yellow -> "43" - | BG Blue -> "44" - | BG Magenta -> "45" - | BG Cyan -> "46" - | BG White -> "47" +let clear h = + h.size <- 0; + let len = Array.length h.data in + for i = 0 to len - 1 do + Array.unsafe_set h.data i Empty + done - | Bold -> "1" - | Dim -> "2" +let reset h = + h.size <- 0; + h.data <- Array.make h.initial_size Empty +let length h = h.size +let resize indexfun h = + let odata = h.data in + let osize = Array.length odata in + let nsize = osize * 2 in + if nsize < Sys.max_array_length then begin + let ndata = Array.make nsize Empty in + let ndata_tail = Array.make nsize Empty in + h.data <- ndata; (* so that indexfun sees the new bucket count *) + let rec insert_bucket = function + Empty -> () + | Cons {key; next} as cell -> + let nidx = indexfun h key in + begin match Array.unsafe_get ndata_tail nidx with + | Empty -> + Array.unsafe_set ndata nidx cell + | Cons tail -> + tail.next <- cell + end; + Array.unsafe_set ndata_tail nidx cell; + insert_bucket next + in + for i = 0 to osize - 1 do + insert_bucket (Array.unsafe_get odata i) + done; + for i = 0 to nsize - 1 do + match Array.unsafe_get ndata_tail i with + | Empty -> () + | Cons tail -> tail.next <- Empty + done + end -(** TODO: add more styles later *) -let style_of_tag s = match s with - | "error" -> [Bold; FG Red] - | "warning" -> [Bold; FG Magenta] - | "info" -> [Bold; FG Yellow] - | "dim" -> [Dim] - | "filename" -> [FG Cyan] - | _ -> [] +let iter h f = + let rec do_bucket = function + | Empty -> + () + | Cons l -> + f l.key ; do_bucket l.next in + let d = h.data in + for i = 0 to Array.length d - 1 do + do_bucket (Array.unsafe_get d i) + done -let ansi_of_tag s = - let l = style_of_tag s in - let s = String.concat ";" (Ext_list.map l code_of_style) in - "\x1b[" ^ s ^ "m" +let fold h init f = + let rec do_bucket b accu = + match b with + Empty -> + accu + | Cons l -> + do_bucket l.next (f l.key accu) in + let d = h.data in + let accu = ref init in + for i = 0 to Array.length d - 1 do + accu := do_bucket (Array.unsafe_get d i) !accu + done; + !accu +let elements set = + fold set [] List.cons -let reset_lit = "\x1b[0m" +let rec small_bucket_mem eq key lst = + match lst with + | Empty -> false + | Cons lst -> + eq key lst.key || + match lst.next with + | Empty -> false + | Cons lst -> + eq key lst.key || + match lst.next with + | Empty -> false + | Cons lst -> + eq key lst.key || + small_bucket_mem eq key lst.next + +let rec remove_bucket + (h : _ t) (i : int) + key + ~(prec : _ bucket) + (buck : _ bucket) + eq_key = + match buck with + | Empty -> + () + | Cons {key=k; next } -> + if eq_key k key + then begin + h.size <- h.size - 1; + match prec with + | Empty -> Array.unsafe_set h.data i next + | Cons c -> c.next <- next + end + else remove_bucket h i key ~prec:buck next eq_key +module type S = +sig + type key + type t + val create: int -> t + val clear : t -> unit + val reset : t -> unit + (* val copy: t -> t *) + val remove: t -> key -> unit + val add : t -> key -> unit + val of_array : key array -> t + val check_add : t -> key -> bool + val mem : t -> key -> bool + val iter: t -> (key -> unit) -> unit + val fold: t -> 'b -> (key -> 'b -> 'b) -> 'b + val length: t -> int + (* val stats: t -> Hashtbl.statistics *) + val elements : t -> key list end -module Bsb_log : sig -#1 "bsb_log.mli" -(* Copyright (C) 2017 Authors of BuckleScript + + + +end +module Hash_set_string : sig +#1 "hash_set_string.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * 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 @@ -7736,31 +7791,12 @@ module Bsb_log : sig * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -val setup : unit -> unit - -type level = - | Debug - | Info - | Warn - | Error - -val log_level : level ref - -type 'a fmt = Format.formatter -> ('a, Format.formatter, unit) format -> 'a - -type 'a log = ('a, Format.formatter, unit) format -> 'a - -val verbose : unit -> unit -val debug : 'a log -val info : 'a log -val warn : 'a log -val error : 'a log - -val info_args : string array -> unit +include Hash_set_gen.S with type key = string end = struct -#1 "bsb_log.ml" -(* Copyright (C) 2017- Authors of BuckleScript +#1 "hash_set_string.ml" +# 1 "ext/hash_set.cppo.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * 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 @@ -7783,92 +7819,161 @@ end = struct * 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. *) +# 31 "ext/hash_set.cppo.ml" +type key = string +let key_index (h : _ Hash_set_gen.t ) (key : key) = + (Bs_hash_stubs.hash_string key) land (Array.length h.data - 1) +let eq_key = Ext_string.equal +type t = key Hash_set_gen.t +# 64 "ext/hash_set.cppo.ml" +let create = Hash_set_gen.create +let clear = Hash_set_gen.clear +let reset = Hash_set_gen.reset +(* let copy = Hash_set_gen.copy *) +let iter = Hash_set_gen.iter +let fold = Hash_set_gen.fold +let length = Hash_set_gen.length +(* let stats = Hash_set_gen.stats *) +let elements = Hash_set_gen.elements -let ninja_ansi_forced = lazy - (try Sys.getenv "NINJA_ANSI_FORCED" with - Not_found ->"" - ) -let color_enabled = lazy (Unix.isatty Unix.stdout) -(* same logic as [ninja.exe] *) -let get_color_enabled () = - let colorful = - match ninja_ansi_forced with - | lazy "1" -> true - | lazy ("0" | "false") -> false - | _ -> - Lazy.force color_enabled in - colorful +let remove (h : _ Hash_set_gen.t ) key = + let i = key_index h key in + let h_data = h.data in + Hash_set_gen.remove_bucket h i key ~prec:Empty (Array.unsafe_get h_data i) eq_key -let color_functions : Format.formatter_tag_functions = { - mark_open_tag = (fun s -> if get_color_enabled () then Ext_color.ansi_of_tag s else Ext_string.empty) ; - mark_close_tag = (fun _ -> if get_color_enabled () then Ext_color.reset_lit else Ext_string.empty); - print_open_tag = (fun _ -> ()); - print_close_tag = (fun _ -> ()) -} -let set_color ppf = - Format.pp_set_formatter_tag_functions ppf color_functions +let add (h : _ Hash_set_gen.t) key = + let i = key_index h key in + let h_data = h.data in + let old_bucket = (Array.unsafe_get h_data i) in + if not (Hash_set_gen.small_bucket_mem eq_key key old_bucket) then + begin + Array.unsafe_set h_data i (Cons {key = key ; next = old_bucket}); + h.size <- h.size + 1 ; + if h.size > Array.length h_data lsl 1 then Hash_set_gen.resize key_index h + end +let of_array arr = + let len = Array.length arr in + let tbl = create len in + for i = 0 to len - 1 do + add tbl (Array.unsafe_get arr i); + done ; + tbl + + +let check_add (h : _ Hash_set_gen.t) key : bool = + let i = key_index h key in + let h_data = h.data in + let old_bucket = (Array.unsafe_get h_data i) in + if not (Hash_set_gen.small_bucket_mem eq_key key old_bucket) then + begin + Array.unsafe_set h_data i (Cons { key = key ; next = old_bucket}); + h.size <- h.size + 1 ; + if h.size > Array.length h_data lsl 1 then Hash_set_gen.resize key_index h; + true + end + else false -let setup () = - begin - Format.pp_set_mark_tags Format.std_formatter true ; - Format.pp_set_mark_tags Format.err_formatter true; - Format.pp_set_formatter_tag_functions - Format.std_formatter color_functions; - Format.pp_set_formatter_tag_functions - Format.err_formatter color_functions - end -type level = - | Debug - | Info - | Warn - | Error +let mem (h : _ Hash_set_gen.t) key = + Hash_set_gen.small_bucket_mem eq_key key (Array.unsafe_get h.data (key_index h key)) -let int_of_level (x : level) = - match x with - | Debug -> 0 - | Info -> 1 - | Warn -> 2 - | Error -> 3 + -let log_level = ref Warn +end +module Bsb_config_types += struct +#1 "bsb_config_types.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) -let verbose () = - log_level := Debug -let dfprintf level fmt = - if int_of_level level >= int_of_level !log_level then - Format.fprintf fmt - else Format.ifprintf fmt -type 'a fmt = - Format.formatter -> ('a, Format.formatter, unit) format -> 'a -type 'a log = - ('a, Format.formatter, unit) format -> 'a +type dependency = + { + package_name : Bsb_pkg_types.t ; + package_install_path : string ; + } +type dependencies = dependency list -let debug fmt = dfprintf Debug Format.std_formatter fmt -let info fmt = dfprintf Info Format.std_formatter fmt -let warn fmt = dfprintf Warn Format.err_formatter fmt -let error fmt = dfprintf Error Format.err_formatter fmt +(* `string` is a path to the entrypoint *) +type entries_t = JsTarget of string | NativeTarget of string | BytecodeTarget of string +type compilation_kind_t = Js | Bytecode | Native -let info_args (args : string array) = - if int_of_level Info >= int_of_level !log_level then - begin - for i = 0 to Array.length args - 1 do - Format.pp_print_string Format.std_formatter (Array.unsafe_get args i) ; - Format.pp_print_string Format.std_formatter Ext_string.single_space; - done ; - Format.pp_print_newline Format.std_formatter () - end - else () - +type reason_react_jsx = + | Jsx_v2 + | Jsx_v3 + (* string option *) + +type refmt = string option + +type gentype_config = { + path : string (* resolved *) +} +type command = string + +type ppx = { + name : string; + args : string list +} +type t = + { + package_name : string ; + (* [captial-package] *) + namespace : string option; + (* CapitalPackage *) + external_includes : string list ; + bsc_flags : string list ; + ppx_files : ppx list ; + pp_file : string option; + bs_dependencies : dependencies; + bs_dev_dependencies : dependencies; + built_in_dependency : dependency option; + warning : Bsb_warning.t; + (*TODO: maybe we should always resolve bs-platform + so that we can calculate correct relative path in + [.merlin] + *) + refmt : refmt; + js_post_build_cmd : string option; + package_specs : Bsb_package_specs.t ; + file_groups : Bsb_file_groups.t; + files_to_install : Hash_set_string.t ; + generate_merlin : bool ; + reason_react_jsx : reason_react_jsx option; (* whether apply PPX transform or not*) + entries : entries_t list ; + generators : command Map_string.t ; + cut_generators : bool; (* note when used as a dev mode, we will always ignore it *) + gentype_config : gentype_config option; + number_of_dev_groups : int + } end module Bsb_real_path : sig @@ -10233,7 +10338,7 @@ val scan : root:string -> cut_generators:bool -> namespace:string option -> - bs_suffix:bool -> + bs_suffixes:string list -> ignored_dirs:Set_string.t -> Ext_json_types.t -> Bsb_file_groups.t * int @@ -10292,7 +10397,7 @@ type cxt = { cut_generators : bool; traverse : bool; namespace : string option; - bs_suffix : bool; + bs_suffixes : string list; ignored_dirs : Set_string.t; } @@ -10452,6 +10557,13 @@ let classify_suffix (x : string) : suffix_kind = if i >= 0 then Cmti i else Not_any +(** Attempt to delete any [.bs.[cm]?js] files for a given artifact. *) +let unlink_bs_suffixes context artifact = + List.iter + (fun suffix -> try_unlink (Filename.concat context.cwd (artifact ^ suffix))) + context.bs_suffixes + + (* This is the only place where we do some removal during scanning, configurably. *) let prune_staled_bs_js_files (context : cxt) (cur_sources : _ Map_string.t) : @@ -10482,12 +10594,7 @@ let prune_staled_bs_js_files (context : cxt) (cur_sources : _ Map_string.t) : if cmd <> "" then Ext_pervasives.try_it (fun _ -> Sys.command (cmd ^ " -cmt-rm " ^ filepath)) - | Cmj _ -> - (* remove .bs.js *) - if context.bs_suffix then - try_unlink - (Filename.concat context.cwd - (String.sub x 0 j ^ Literals.suffix_bs_js)) + | Cmj _ -> unlink_bs_suffixes context (String.sub x 0 j) | _ -> () ); try_unlink filepath ) else () @@ -10647,8 +10754,8 @@ and parse_sources (cxt : cxt) (sources : Ext_json_types.t) = | _ -> parsing_single_source cxt sources -let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffix ~ignored_dirs x : - t * int = +let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffixes ~ignored_dirs x + : t * int = Bsb_dir_index.reset (); let output = parse_sources @@ -10660,7 +10767,7 @@ let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffix ~ignored_dirs x : root; cut_generators; namespace; - bs_suffix; + bs_suffixes; traverse = false; } x @@ -11085,13 +11192,32 @@ let extract_main_entries (map : json_map) = +let deprecated_extract_bs_suffix_exn (map : json_map) = + match Map_string.find_opt map Bsb_build_schemas.suffix with + | None -> None + | Some (Str { str } as config) -> + if str = Literals.suffix_js then Some false + else if str = Literals.suffix_bs_js then Some true + else + Bsb_exception.config_error config + "DEPRECATED: This form of 'suffix' only supports either `.js` or \ + `.bs.js`. Use 'suffix' under 'package-specs' instead." + | Some config -> + Bsb_exception.config_error config + "DEPRECATED: This form of 'suffix' only supports a string" + + +let package_specs_from_obj_map (map : json_map) = + let deprecated_bs_suffix = deprecated_extract_bs_suffix_exn map in + match Map_string.find_opt map Bsb_build_schemas.package_specs with + | Some x -> Bsb_package_specs.from_json ?deprecated_bs_suffix x + | None -> Bsb_package_specs.default_package_specs ?deprecated_bs_suffix () + + let package_specs_from_bsconfig () = let json = Ext_json_parse.parse_json_from_file Literals.bsconfig_json in match json with - | Obj { map } -> ( - match Map_string.find_opt map Bsb_build_schemas.package_specs with - | Some x -> Bsb_package_specs.from_json x - | None -> Bsb_package_specs.default_package_specs ) + | Obj { map } -> package_specs_from_obj_map map | _ -> assert false @@ -11159,17 +11285,6 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) = | _ -> assert false ) -let extract_bs_suffix_exn (map : json_map) = - match Map_string.find_opt map Bsb_build_schemas.suffix with - | None -> false - | Some (Str { str } as config) -> - if str = Literals.suffix_js then false - else if str = Literals.suffix_bs_js then true - else Bsb_exception.config_error config "expect .bs.js or .js string here" - | Some config -> - Bsb_exception.config_error config "expect .bs.js or .js string here" - - let extract_gentype_config (map : json_map) cwd : Bsb_config_types.gentype_config option = match Map_string.find_opt map Bsb_build_schemas.gentypeconfig with @@ -11375,13 +11490,11 @@ let interpret_json ~toplevel_package_specs ~(per_proj_dir : string) : let package_name, namespace = extract_package_name_and_namespace map in let refmt = extract_refmt map per_proj_dir in let gentype_config = extract_gentype_config map per_proj_dir in - let bs_suffix = extract_bs_suffix_exn map in (* The default situation is empty *) let built_in_package = check_stdlib map per_proj_dir in - let package_specs = - match Map_string.find_opt map Bsb_build_schemas.package_specs with - | Some x -> Bsb_package_specs.from_json x - | None -> Bsb_package_specs.default_package_specs + let package_specs = package_specs_from_obj_map map in + let bs_suffixes = + Bsb_package_specs.extract_in_source_bs_suffixes package_specs in let pp_flags : string option = extract_string map Bsb_build_schemas.pp_flags (fun p -> @@ -11411,12 +11524,11 @@ let interpret_json ~toplevel_package_specs ~(per_proj_dir : string) : in let groups, number_of_dev_groups = Bsb_parse_sources.scan ~ignored_dirs:(extract_ignored_dirs map) - ~toplevel ~root:per_proj_dir ~cut_generators ~bs_suffix ~namespace - sources + ~toplevel ~root:per_proj_dir ~cut_generators ~bs_suffixes + ~namespace sources in { gentype_config; - bs_suffix; package_name; namespace; warning = extract_warning map; @@ -12403,7 +12515,6 @@ val make_custom_rules : has_ppx:bool -> has_pp:bool -> has_builtin:bool -> - bs_suffix:bool -> reason_react_jsx:Bsb_config_types.reason_react_jsx option -> digest:string -> refmt:string option -> @@ -12513,7 +12624,7 @@ type builtin = { } let make_custom_rules ~(has_gentype : bool) ~(has_postbuild : bool) - ~(has_ppx : bool) ~(has_pp : bool) ~(has_builtin : bool) ~(bs_suffix : bool) + ~(has_ppx : bool) ~(has_pp : bool) ~(has_builtin : bool) ~(reason_react_jsx : Bsb_config_types.reason_react_jsx option) ~(digest : string) ~(refmt : string option) (* set refmt path when needed *) @@ -12524,7 +12635,6 @@ let make_custom_rules ~(has_gentype : bool) ~(has_postbuild : bool) let mk_ml_cmj_cmd ~read_cmi ~is_dev ~postbuild : string = Buffer.clear buf; Buffer.add_string buf "$bsc -nostdlib $g_pkg_flg -color always"; - if bs_suffix then Buffer.add_string buf " -bs-suffix"; if read_cmi then Buffer.add_string buf " -bs-read-cmi"; if is_dev then Buffer.add_string buf " $g_dev_incls"; Buffer.add_string buf " $g_lib_incls"; @@ -12871,7 +12981,6 @@ module Bsb_ninja_file_groups : sig val handle_files_per_dir : out_channel -> - bs_suffix:bool -> rules:Bsb_ninja_rule.builtin -> package_specs:Bsb_package_specs.t -> js_post_build_cmd:string option -> @@ -12929,7 +13038,7 @@ let make_common_shadows package_specs dirname dir_index : key = Bsb_ninja_global_vars.g_pkg_flg; op = Append - (Bsb_package_specs.package_flag_of_package_specs package_specs dirname); + (Bsb_package_specs.flags_of_package_specs package_specs dirname); } :: ( if Bsb_dir_index.is_lib_dir dir_index then [] @@ -12944,7 +13053,7 @@ let make_common_shadows package_specs dirname dir_index : let emit_module_build (rules : Bsb_ninja_rule.builtin) (package_specs : Bsb_package_specs.t) (group_dir_index : Bsb_dir_index.t) oc - ~bs_suffix js_post_build_cmd namespace (module_info : Bsb_db.module_info) = + js_post_build_cmd namespace (module_info : Bsb_db.module_info) = let has_intf_file = module_info.info = Ml_mli in let is_re = module_info.is_re in let filename_sans_extension = module_info.name_sans_extension in @@ -12974,7 +13083,7 @@ let emit_module_build (rules : Bsb_ninja_rule.builtin) let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in let output_js = - Bsb_package_specs.get_list_of_output_js package_specs bs_suffix + Bsb_package_specs.get_list_of_output_js package_specs output_filename_sans_extension in let common_shadows = @@ -13039,8 +13148,8 @@ let emit_module_build (rules : Bsb_ninja_rule.builtin) ~order_only_deps:[ output_d ] ~rule -let handle_files_per_dir oc ~bs_suffix ~(rules : Bsb_ninja_rule.builtin) - ~package_specs ~js_post_build_cmd ~(files_to_install : Hash_set_string.t) +let handle_files_per_dir oc ~(rules : Bsb_ninja_rule.builtin) ~package_specs + ~js_post_build_cmd ~(files_to_install : Hash_set_string.t) ~(namespace : string option) (group : Bsb_file_groups.file_group) : unit = handle_generators oc group rules.customs; let installable = @@ -13052,8 +13161,8 @@ let handle_files_per_dir oc ~bs_suffix ~(rules : Bsb_ninja_rule.builtin) Map_string.iter group.sources (fun module_name module_info -> if installable module_name then Hash_set_string.add files_to_install module_info.name_sans_extension; - emit_module_build rules package_specs group.dir_index oc ~bs_suffix - js_post_build_cmd namespace module_info) + emit_module_build rules package_specs group.dir_index oc js_post_build_cmd + namespace module_info) (* pseuduo targets per directory *) @@ -13162,7 +13271,6 @@ let output_static_resources (static_resources : string list) copy_rule oc = let output_ninja_and_namespace_map ~per_proj_dir ~toplevel ({ - bs_suffix; package_name; external_includes; bsc_flags; @@ -13287,7 +13395,7 @@ let output_ninja_and_namespace_map ~per_proj_dir ~toplevel ~has_postbuild:(js_post_build_cmd <> None) ~has_ppx:(ppx_files <> []) ~has_pp:(pp_file <> None) ~has_builtin:(built_in_dependency <> None) - ~reason_react_jsx ~bs_suffix ~digest generators + ~reason_react_jsx ~digest generators in emit_bsc_lib_includes bs_dependencies bsc_lib_dirs external_includes namespace @@ -13295,9 +13403,8 @@ let output_ninja_and_namespace_map ~per_proj_dir ~toplevel output_static_resources static_resources rules.copy_resources oc; (* Generate build statement for each file *) Ext_list.iter bs_file_groups (fun files_per_dir -> - Bsb_ninja_file_groups.handle_files_per_dir oc ~bs_suffix ~rules - ~js_post_build_cmd ~package_specs ~files_to_install ~namespace - files_per_dir); + Bsb_ninja_file_groups.handle_files_per_dir oc ~rules ~js_post_build_cmd + ~package_specs ~files_to_install ~namespace files_per_dir); Ext_option.iter namespace (fun ns -> let namespace_dir = per_proj_dir // Bsb_config.lib_bs in diff --git a/lib/4.06.1/bsb_helper.ml b/lib/4.06.1/bsb_helper.ml index 9fd114d11f..3f8fb6fab6 100644 --- a/lib/4.06.1/bsb_helper.ml +++ b/lib/4.06.1/bsb_helper.ml @@ -2977,7 +2977,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -3115,8 +3119,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" @@ -3681,14 +3690,18 @@ val make : ?ns:string -> string -> string val try_split_module_name : string -> (string * string) option -val change_ext_ns_suffix : string -> string -> string +val replace_namespace_with_extension : name:string -> ext:string -> string +(** [replace_namespace_with_extension ~name ~ext] removes the part of [name] + after [ns_sep_char], if any; and appends [ext]. +*) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -val js_name_of_modulename : string -> file_kind -> string +val js_filename_of_modulename : + name:string -> ext:string -> leading_case -> string (** Predicts the JavaScript filename for a given (possibly namespaced) module- - name; i.e. [js_name_of_modulename "AA-Ns" Little_bs] would produce - ["aA.bs.js"]. *) + name; i.e. [js_filename_of_modulename ~name:"AA-Ns" ~ext:".js" Lower] would + produce ["aA.bs.js"]. *) val is_valid_npm_package_name : string -> bool @@ -3751,7 +3764,7 @@ let rec rindex_rec s i = #1933 when removing ns suffix, don't pass the bound of basename FIXME: micro-optimizaiton *) -let change_ext_ns_suffix name ext = +let replace_namespace_with_extension ~name ~ext = let i = rindex_rec name (String.length name - 1) in if i < 0 then name ^ ext else String.sub name 0 i ^ ext @@ -3763,18 +3776,15 @@ let try_split_module_name name = else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -let js_name_of_modulename s little = - match little with - | Little_js -> - change_ext_ns_suffix (Ext_string.uncapitalize_ascii s) Literals.suffix_js - | Little_bs -> - change_ext_ns_suffix - (Ext_string.uncapitalize_ascii s) - Literals.suffix_bs_js - | Upper_js -> change_ext_ns_suffix s Literals.suffix_js - | Upper_bs -> change_ext_ns_suffix s Literals.suffix_bs_js +let js_filename_of_modulename ~name ~ext (leading_case : leading_case) = + match leading_case with + | Lower -> + replace_namespace_with_extension + ~name:(Ext_string.uncapitalize_ascii name) + ~ext + | Upper -> replace_namespace_with_extension ~name ~ext (** https://docs.npmjs.com/files/package.json diff --git a/lib/4.06.1/bsdep.ml b/lib/4.06.1/bsdep.ml index 542f8f894a..a9ae60fca1 100644 --- a/lib/4.06.1/bsdep.ml +++ b/lib/4.06.1/bsdep.ml @@ -36173,15 +36173,13 @@ module Js_config : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* val get_packages_info : unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) (** return [package_name] and [path] when in script mode: *) -(* val get_current_package_name_and_path : Js_packages_info.module_system -> - Js_packages_info.info_query *) +(* val get_current_package_name_and_path : Js_package_info.module_system -> + Js_package_info.info_query *) (* val set_package_name : string -> unit val get_package_name : unit -> string option *) @@ -36222,7 +36220,6 @@ val syntax_only : bool ref val binary_ast : bool ref val simple_binary_ast : bool ref -val bs_suffix : bool ref val debug : bool ref val cmi_only : bool ref @@ -36279,8 +36276,6 @@ let set_diagnose b = diagnose := b let ( // ) = Filename.concat -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx_ml = ref false let no_builtin_ppx_mli = ref false @@ -36328,7 +36323,7 @@ end module Bs_warnings : sig #1 "bs_warnings.mli" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -36346,29 +36341,27 @@ module Bs_warnings : sig * 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. *) - -type t = - | Unsafe_poly_variant_type +type t = Unsafe_poly_variant_type val prerr_bs_ffi_warning : Location.t -> t -> unit +val warn_deprecated_bs_suffix_flag : unit -> unit -val warn_missing_primitive : Location.t -> string -> unit +val warn_missing_primitive : Location.t -> string -> unit -val warn_literal_overflow : Location.t -> unit +val warn_literal_overflow : Location.t -> unit -val error_unescaped_delimiter : - Location.t -> string -> unit +val error_unescaped_delimiter : Location.t -> string -> unit end = struct #1 "bs_warnings.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -36386,117 +36379,106 @@ end = struct * 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. *) - - type t = | Unsafe_poly_variant_type - (* for users write code like this: - {[ external f : [`a of int ] -> string = ""]} - Here users forget about `[@bs.string]` or `[@bs.int]` - *) + (** for users write code like this: + {[ external f : [ `a of int ] -> string = "" ]} + Here users forget about `[@bs.string]` or `[@bs.int]` *) let to_string t = match t with - | Unsafe_poly_variant_type - -> - "Here a OCaml polymorphic variant type passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]` " + | Unsafe_poly_variant_type -> + "Here a OCaml polymorphic variant type passed into JS, probably you \ + forgot annotations like `[@bs.int]` or `[@bs.string]` " + let warning_formatter = Format.err_formatter -let print_string_warning (loc : Location.t) x = - if loc.loc_ghost then - Format.fprintf warning_formatter "File %s@." !Location.input_name - else - Location.print warning_formatter loc ; - Format.fprintf warning_formatter "@{Warning@}: %s@." x +let print_string_warning (loc : Location.t) ?(kind = "Warning") x = + if loc.loc_ghost then + Format.fprintf warning_formatter "File %s@." !Location.input_name + else Location.print warning_formatter loc; + Format.fprintf warning_formatter "@{%s@}: %s@." kind x -let prerr_bs_ffi_warning loc x = - Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) -let unimplemented_primitive = "Unimplemented primitive used:" -type error = +let prerr_bs_ffi_warning loc x = + Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) + + +let unimplemented_primitive = "Unimplemented primitive used:" +type error = | Uninterpreted_delimiters of string - | Unimplemented_primitive of string -exception Error of Location.t * error + | Unimplemented_primitive of string +exception Error of Location.t * error let pp_error fmt x = - match x with - | Unimplemented_primitive str -> - Format.pp_print_string fmt unimplemented_primitive; - Format.pp_print_string fmt str - - | Uninterpreted_delimiters str -> - Format.pp_print_string fmt "Uninterpreted delimiters" ; - Format.pp_print_string fmt str + match x with + | Unimplemented_primitive str -> + Format.pp_print_string fmt unimplemented_primitive; + Format.pp_print_string fmt str + | Uninterpreted_delimiters str -> + Format.pp_print_string fmt "Uninterpreted delimiters"; + Format.pp_print_string fmt str +let () = + Location.register_error_of_exn (function + | Error (loc, err) -> Some (Location.error_of_printer loc pp_error err) + | _ -> None) -let () = - Location.register_error_of_exn (function - | Error (loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) +let warn_deprecated_bs_suffix_flag () = + if not !Clflags.bs_quiet then ( + print_string_warning Location.none ~kind:"DEPRECATED" + "`-bs-suffix` used; consider using third field of `-bs-package-output` \ + instead"; + Format.pp_print_flush warning_formatter () ) +let warn_missing_primitive loc txt = + if (not !Js_config.no_warn_unimplemented_external) && not !Clflags.bs_quiet + then ( + print_string_warning loc (unimplemented_primitive ^ txt ^ " \n"); + Format.pp_print_flush warning_formatter () ) -let warn_missing_primitive loc txt = - if not !Js_config.no_warn_unimplemented_external && not !Clflags.bs_quiet then - begin - print_string_warning loc ( unimplemented_primitive ^ txt ^ " \n" ); - Format.pp_print_flush warning_formatter () - end -let warn_literal_overflow loc = - if not !Clflags.bs_quiet then - begin - print_string_warning loc +let warn_literal_overflow loc = + if not !Clflags.bs_quiet then ( + print_string_warning loc "Integer literal exceeds the range of representable integers of type int"; - Format.pp_print_flush warning_formatter () - end + Format.pp_print_flush warning_formatter () ) +let error_unescaped_delimiter loc txt = + raise (Error (loc, Uninterpreted_delimiters txt)) -let error_unescaped_delimiter loc txt = - raise (Error(loc, Uninterpreted_delimiters txt)) +(** Note the standard way of reporting error in compiler: + val Location.register_error_of_exn : (exn -> Location.error option) -> unit + val Location.error_of_printer : Location.t -> (Format.formatter -> error -> + unit) -> error -> Location.error + Define an error type + type error exception Error of Location.t * error + Provide a printer to error -(** - Note the standard way of reporting error in compiler: - - val Location.register_error_of_exn : (exn -> Location.error option) -> unit - val Location.error_of_printer : Location.t -> - (Format.formatter -> error -> unit) -> error -> Location.error - - Define an error type - - type error - exception Error of Location.t * error - - Provide a printer to error - - {[ - let () = - Location.register_error_of_exn - (function - | Error(loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) - ]} -*) + {[ + let () = + Location.register_error_of_exn (function + | Error (loc, err) -> + Some (Location.error_of_printer loc pp_error err) + | _ -> None) + ]} *) end module Ext_util : sig @@ -37200,7 +37182,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -37338,8 +37324,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" diff --git a/lib/4.06.1/bsppx.ml b/lib/4.06.1/bsppx.ml index 82402d9fa2..c879eac508 100644 --- a/lib/4.06.1/bsppx.ml +++ b/lib/4.06.1/bsppx.ml @@ -4841,15 +4841,13 @@ module Js_config : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* val get_packages_info : unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) (** return [package_name] and [path] when in script mode: *) -(* val get_current_package_name_and_path : Js_packages_info.module_system -> - Js_packages_info.info_query *) +(* val get_current_package_name_and_path : Js_package_info.module_system -> + Js_package_info.info_query *) (* val set_package_name : string -> unit val get_package_name : unit -> string option *) @@ -4890,7 +4888,6 @@ val syntax_only : bool ref val binary_ast : bool ref val simple_binary_ast : bool ref -val bs_suffix : bool ref val debug : bool ref val cmi_only : bool ref @@ -4947,8 +4944,6 @@ let set_diagnose b = diagnose := b let ( // ) = Filename.concat -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx_ml = ref false let no_builtin_ppx_mli = ref false @@ -293504,7 +293499,7 @@ end module Bs_warnings : sig #1 "bs_warnings.mli" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -293522,29 +293517,27 @@ module Bs_warnings : sig * 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. *) - -type t = - | Unsafe_poly_variant_type +type t = Unsafe_poly_variant_type val prerr_bs_ffi_warning : Location.t -> t -> unit +val warn_deprecated_bs_suffix_flag : unit -> unit -val warn_missing_primitive : Location.t -> string -> unit +val warn_missing_primitive : Location.t -> string -> unit -val warn_literal_overflow : Location.t -> unit +val warn_literal_overflow : Location.t -> unit -val error_unescaped_delimiter : - Location.t -> string -> unit +val error_unescaped_delimiter : Location.t -> string -> unit end = struct #1 "bs_warnings.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -293562,117 +293555,106 @@ end = struct * 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. *) - - type t = | Unsafe_poly_variant_type - (* for users write code like this: - {[ external f : [`a of int ] -> string = ""]} - Here users forget about `[@bs.string]` or `[@bs.int]` - *) + (** for users write code like this: + {[ external f : [ `a of int ] -> string = "" ]} + Here users forget about `[@bs.string]` or `[@bs.int]` *) let to_string t = match t with - | Unsafe_poly_variant_type - -> - "Here a OCaml polymorphic variant type passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]` " + | Unsafe_poly_variant_type -> + "Here a OCaml polymorphic variant type passed into JS, probably you \ + forgot annotations like `[@bs.int]` or `[@bs.string]` " + let warning_formatter = Format.err_formatter -let print_string_warning (loc : Location.t) x = - if loc.loc_ghost then - Format.fprintf warning_formatter "File %s@." !Location.input_name - else - Location.print warning_formatter loc ; - Format.fprintf warning_formatter "@{Warning@}: %s@." x +let print_string_warning (loc : Location.t) ?(kind = "Warning") x = + if loc.loc_ghost then + Format.fprintf warning_formatter "File %s@." !Location.input_name + else Location.print warning_formatter loc; + Format.fprintf warning_formatter "@{%s@}: %s@." kind x -let prerr_bs_ffi_warning loc x = - Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) -let unimplemented_primitive = "Unimplemented primitive used:" -type error = +let prerr_bs_ffi_warning loc x = + Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) + + +let unimplemented_primitive = "Unimplemented primitive used:" +type error = | Uninterpreted_delimiters of string - | Unimplemented_primitive of string -exception Error of Location.t * error + | Unimplemented_primitive of string +exception Error of Location.t * error let pp_error fmt x = - match x with - | Unimplemented_primitive str -> - Format.pp_print_string fmt unimplemented_primitive; - Format.pp_print_string fmt str - - | Uninterpreted_delimiters str -> - Format.pp_print_string fmt "Uninterpreted delimiters" ; - Format.pp_print_string fmt str + match x with + | Unimplemented_primitive str -> + Format.pp_print_string fmt unimplemented_primitive; + Format.pp_print_string fmt str + | Uninterpreted_delimiters str -> + Format.pp_print_string fmt "Uninterpreted delimiters"; + Format.pp_print_string fmt str +let () = + Location.register_error_of_exn (function + | Error (loc, err) -> Some (Location.error_of_printer loc pp_error err) + | _ -> None) -let () = - Location.register_error_of_exn (function - | Error (loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) +let warn_deprecated_bs_suffix_flag () = + if not !Clflags.bs_quiet then ( + print_string_warning Location.none ~kind:"DEPRECATED" + "`-bs-suffix` used; consider using third field of `-bs-package-output` \ + instead"; + Format.pp_print_flush warning_formatter () ) +let warn_missing_primitive loc txt = + if (not !Js_config.no_warn_unimplemented_external) && not !Clflags.bs_quiet + then ( + print_string_warning loc (unimplemented_primitive ^ txt ^ " \n"); + Format.pp_print_flush warning_formatter () ) -let warn_missing_primitive loc txt = - if not !Js_config.no_warn_unimplemented_external && not !Clflags.bs_quiet then - begin - print_string_warning loc ( unimplemented_primitive ^ txt ^ " \n" ); - Format.pp_print_flush warning_formatter () - end -let warn_literal_overflow loc = - if not !Clflags.bs_quiet then - begin - print_string_warning loc +let warn_literal_overflow loc = + if not !Clflags.bs_quiet then ( + print_string_warning loc "Integer literal exceeds the range of representable integers of type int"; - Format.pp_print_flush warning_formatter () - end - - + Format.pp_print_flush warning_formatter () ) -let error_unescaped_delimiter loc txt = - raise (Error(loc, Uninterpreted_delimiters txt)) +let error_unescaped_delimiter loc txt = + raise (Error (loc, Uninterpreted_delimiters txt)) +(** Note the standard way of reporting error in compiler: + val Location.register_error_of_exn : (exn -> Location.error option) -> unit + val Location.error_of_printer : Location.t -> (Format.formatter -> error -> + unit) -> error -> Location.error + Define an error type -(** - Note the standard way of reporting error in compiler: - - val Location.register_error_of_exn : (exn -> Location.error option) -> unit - val Location.error_of_printer : Location.t -> - (Format.formatter -> error -> unit) -> error -> Location.error - - Define an error type + type error exception Error of Location.t * error - type error - exception Error of Location.t * error + Provide a printer to error - Provide a printer to error - - {[ - let () = - Location.register_error_of_exn - (function - | Error(loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) - ]} -*) + {[ + let () = + Location.register_error_of_exn (function + | Error (loc, err) -> + Some (Location.error_of_printer loc pp_error err) + | _ -> None) + ]} *) end module Ext_util : sig @@ -294376,7 +294358,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -294514,8 +294500,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" diff --git a/lib/4.06.1/unstable/all_ounit_tests.ml b/lib/4.06.1/unstable/all_ounit_tests.ml index 40651494fa..7486340c9f 100644 --- a/lib/4.06.1/unstable/all_ounit_tests.ml +++ b/lib/4.06.1/unstable/all_ounit_tests.ml @@ -5106,7 +5106,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -5244,8 +5248,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" @@ -7682,15 +7691,13 @@ module Js_config : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* val get_packages_info : unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) (** return [package_name] and [path] when in script mode: *) -(* val get_current_package_name_and_path : Js_packages_info.module_system -> - Js_packages_info.info_query *) +(* val get_current_package_name_and_path : Js_package_info.module_system -> + Js_package_info.info_query *) (* val set_package_name : string -> unit val get_package_name : unit -> string option *) @@ -7731,7 +7738,6 @@ val syntax_only : bool ref val binary_ast : bool ref val simple_binary_ast : bool ref -val bs_suffix : bool ref val debug : bool ref val cmi_only : bool ref @@ -7788,8 +7794,6 @@ let set_diagnose b = diagnose := b let ( // ) = Filename.concat -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx_ml = ref false let no_builtin_ppx_mli = ref false @@ -16312,14 +16316,18 @@ val make : ?ns:string -> string -> string val try_split_module_name : string -> (string * string) option -val change_ext_ns_suffix : string -> string -> string +val replace_namespace_with_extension : name:string -> ext:string -> string +(** [replace_namespace_with_extension ~name ~ext] removes the part of [name] + after [ns_sep_char], if any; and appends [ext]. +*) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -val js_name_of_modulename : string -> file_kind -> string +val js_filename_of_modulename : + name:string -> ext:string -> leading_case -> string (** Predicts the JavaScript filename for a given (possibly namespaced) module- - name; i.e. [js_name_of_modulename "AA-Ns" Little_bs] would produce - ["aA.bs.js"]. *) + name; i.e. [js_filename_of_modulename ~name:"AA-Ns" ~ext:".js" Lower] would + produce ["aA.bs.js"]. *) val is_valid_npm_package_name : string -> bool @@ -16382,7 +16390,7 @@ let rec rindex_rec s i = #1933 when removing ns suffix, don't pass the bound of basename FIXME: micro-optimizaiton *) -let change_ext_ns_suffix name ext = +let replace_namespace_with_extension ~name ~ext = let i = rindex_rec name (String.length name - 1) in if i < 0 then name ^ ext else String.sub name 0 i ^ ext @@ -16394,18 +16402,15 @@ let try_split_module_name name = else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -let js_name_of_modulename s little = - match little with - | Little_js -> - change_ext_ns_suffix (Ext_string.uncapitalize_ascii s) Literals.suffix_js - | Little_bs -> - change_ext_ns_suffix - (Ext_string.uncapitalize_ascii s) - Literals.suffix_bs_js - | Upper_js -> change_ext_ns_suffix s Literals.suffix_js - | Upper_bs -> change_ext_ns_suffix s Literals.suffix_bs_js +let js_filename_of_modulename ~name ~ext (leading_case : leading_case) = + match leading_case with + | Lower -> + replace_namespace_with_extension + ~name:(Ext_string.uncapitalize_ascii name) + ~ext + | Upper -> replace_namespace_with_extension ~name ~ext (** https://docs.npmjs.com/files/package.json @@ -16857,14 +16862,23 @@ let suites = =~"ABb" end; __LOC__ >:: begin fun _ -> - Ext_namespace.change_ext_ns_suffix "a-b" Literals.suffix_js =~ "a.js"; - Ext_namespace.change_ext_ns_suffix "a-" Literals.suffix_js =~ "a.js"; - Ext_namespace.change_ext_ns_suffix "a--" Literals.suffix_js =~ "a-.js"; - Ext_namespace.change_ext_ns_suffix "AA-b" Literals.suffix_js =~ "AA.js"; - Ext_namespace.js_name_of_modulename "AA-b" Little_js =~ "aA.js"; - Ext_namespace.js_name_of_modulename "AA-b" Upper_js =~ "AA.js"; - Ext_namespace.js_name_of_modulename "AA-b" Upper_bs =~ "AA.bs.js" - end; + Ext_namespace.replace_namespace_with_extension + ~name:"a-b" ~ext:Literals.suffix_js =~ "a.js"; + Ext_namespace.replace_namespace_with_extension + ~name:"a-" ~ext:Literals.suffix_js =~ "a.js"; + Ext_namespace.replace_namespace_with_extension + ~name:"a--" ~ext:Literals.suffix_js =~ "a-.js"; + Ext_namespace.replace_namespace_with_extension + ~name:"AA-b" ~ext:Literals.suffix_js =~ "AA.js"; + Ext_namespace.replace_namespace_with_extension + ~name:"AA-b" ~ext:Literals.suffix_js =~ "AA.js"; + Ext_namespace.js_filename_of_modulename + ~name:"AA-b" ~ext:Literals.suffix_js Lower =~ "aA.js"; + Ext_namespace.js_filename_of_modulename + ~name:"AA-b" ~ext:Literals.suffix_js Upper =~ "AA.js"; + Ext_namespace.js_filename_of_modulename + ~name:"AA-b" ~ext:Literals.suffix_bs_js Upper =~ "AA.bs.js"; + end; __LOC__ >:: begin fun _ -> let (=~) = OUnit.assert_equal ~printer:(fun x -> match x with diff --git a/lib/4.06.1/unstable/bsb_native.ml b/lib/4.06.1/unstable/bsb_native.ml index 88bc6f7678..be7ab05cfc 100644 --- a/lib/4.06.1/unstable/bsb_native.ml +++ b/lib/4.06.1/unstable/bsb_native.ml @@ -141,11 +141,12 @@ let generators = "generators" let command = "command" let edge = "edge" let namespace = "namespace" +let _module = "module" let in_source = "in-source" +let suffix = "suffix" let warnings = "warnings" let number = "number" let error = "error" -let suffix = "suffix" let gentypeconfig = "gentypeconfig" let path = "path" let ignored_dirs = "ignored-dirs" @@ -4465,7 +4466,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -4603,8 +4608,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" @@ -5861,344 +5871,159 @@ let () = ) end -module Ext_buffer : sig -#1 "ext_buffer.mli" -(***********************************************************************) -(* *) -(* OCaml *) -(* *) -(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1999 Institut National de Recherche en Informatique et *) -(* en Automatique. All rights reserved. This file is distributed *) -(* under the terms of the GNU Library General Public License, with *) -(* the special exception on linking described in file ../LICENSE. *) -(* *) -(***********************************************************************) - -(** Extensible buffers. - - This module implements buffers that automatically expand - as necessary. It provides accumulative concatenation of strings - in quasi-linear time (instead of quadratic time when strings are - concatenated pairwise). -*) - -(* BuckleScript customization: customized for efficient digest *) - -type t -(** The abstract type of buffers. *) - -val create : int -> t -(** [create n] returns a fresh buffer, initially empty. - The [n] parameter is the initial size of the internal byte sequence - that holds the buffer contents. That byte sequence is automatically - reallocated when more than [n] characters are stored in the buffer, - but shrinks back to [n] characters when [reset] is called. - For best performance, [n] should be of the same order of magnitude - as the number of characters that are expected to be stored in - the buffer (for instance, 80 for a buffer that holds one output - line). Nothing bad will happen if the buffer grows beyond that - limit, however. In doubt, take [n = 16] for instance. - If [n] is not between 1 and {!Sys.max_string_length}, it will - be clipped to that interval. *) +module Ext_color : sig +#1 "ext_color.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) -val contents : t -> string -(** Return a copy of the current contents of the buffer. - The buffer itself is unchanged. *) +type color + = Black + | Red + | Green + | Yellow + | Blue + | Magenta + | Cyan + | White -val length : t -> int -(** Return the number of characters currently contained in the buffer. *) +type style + = FG of color + | BG of color + | Bold + | Dim -val is_empty : t -> bool +(** Input is the tag for example `@{@}` return escape code *) +val ansi_of_tag : string -> string -val clear : t -> unit -(** Empty the buffer. *) +val reset_lit : string +end = struct +#1 "ext_color.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) -val add_char : t -> char -> unit -(** [add_char b c] appends the character [c] at the end of the buffer [b]. *) -val add_string : t -> string -> unit -(** [add_string b s] appends the string [s] at the end of the buffer [b]. *) -val add_bytes : t -> bytes -> unit -(** [add_string b s] appends the string [s] at the end of the buffer [b]. - @since 4.02 *) -val add_substring : t -> string -> int -> int -> unit -(** [add_substring b s ofs len] takes [len] characters from offset - [ofs] in string [s] and appends them at the end of the buffer [b]. *) +type color + = Black + | Red + | Green + | Yellow + | Blue + | Magenta + | Cyan + | White -val add_subbytes : t -> bytes -> int -> int -> unit -(** [add_substring b s ofs len] takes [len] characters from offset - [ofs] in byte sequence [s] and appends them at the end of the buffer [b]. - @since 4.02 *) +type style + = FG of color + | BG of color + | Bold + | Dim -val add_buffer : t -> t -> unit -(** [add_buffer b1 b2] appends the current contents of buffer [b2] - at the end of buffer [b1]. [b2] is not modified. *) -val add_channel : t -> in_channel -> int -> unit -(** [add_channel b ic n] reads exactly [n] character from the - input channel [ic] and stores them at the end of buffer [b]. - Raise [End_of_file] if the channel contains fewer than [n] - characters. *) +let ansi_of_color = function + | Black -> "0" + | Red -> "1" + | Green -> "2" + | Yellow -> "3" + | Blue -> "4" + | Magenta -> "5" + | Cyan -> "6" + | White -> "7" -val output_buffer : out_channel -> t -> unit -(** [output_buffer oc b] writes the current contents of buffer [b] - on the output channel [oc]. *) +let code_of_style = function + | FG Black -> "30" + | FG Red -> "31" + | FG Green -> "32" + | FG Yellow -> "33" + | FG Blue -> "34" + | FG Magenta -> "35" + | FG Cyan -> "36" + | FG White -> "37" + + | BG Black -> "40" + | BG Red -> "41" + | BG Green -> "42" + | BG Yellow -> "43" + | BG Blue -> "44" + | BG Magenta -> "45" + | BG Cyan -> "46" + | BG White -> "47" -val digest : t -> Digest.t + | Bold -> "1" + | Dim -> "2" -val not_equal : - t -> - string -> - bool -val add_int_1 : - t -> int -> unit -val add_int_2 : - t -> int -> unit +(** TODO: add more styles later *) +let style_of_tag s = match s with + | "error" -> [Bold; FG Red] + | "warning" -> [Bold; FG Magenta] + | "info" -> [Bold; FG Yellow] + | "dim" -> [Dim] + | "filename" -> [FG Cyan] + | _ -> [] -val add_int_3 : - t -> int -> unit +let ansi_of_tag s = + let l = style_of_tag s in + let s = String.concat ";" (Ext_list.map l code_of_style) in + "\x1b[" ^ s ^ "m" -val add_int_4 : - t -> int -> unit -val add_string_char : - t -> - string -> - char -> - unit -val add_char_string : - t -> - char -> - string -> - unit -end = struct -#1 "ext_buffer.ml" -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1999 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) +let reset_lit = "\x1b[0m" -(* Extensible buffers *) - -type t = - {mutable buffer : bytes; - mutable position : int; - mutable length : int; - initial_buffer : bytes} - -let create n = - let n = if n < 1 then 1 else n in - - let n = if n > Sys.max_string_length then Sys.max_string_length else n in - - let s = Bytes.create n in - {buffer = s; position = 0; length = n; initial_buffer = s} - -let contents b = Bytes.sub_string b.buffer 0 b.position -let to_bytes b = Bytes.sub b.buffer 0 b.position - -let sub b ofs len = - if ofs < 0 || len < 0 || ofs > b.position - len - then invalid_arg "Ext_buffer.sub" - else Bytes.sub_string b.buffer ofs len - - -let blit src srcoff dst dstoff len = - if len < 0 || srcoff < 0 || srcoff > src.position - len - || dstoff < 0 || dstoff > (Bytes.length dst) - len - then invalid_arg "Ext_buffer.blit" - else - Bytes.unsafe_blit src.buffer srcoff dst dstoff len - -let length b = b.position -let is_empty b = b.position = 0 -let clear b = b.position <- 0 - -let reset b = - b.position <- 0; b.buffer <- b.initial_buffer; - b.length <- Bytes.length b.buffer - -let resize b more = - let len = b.length in - let new_len = ref len in - while b.position + more > !new_len do new_len := 2 * !new_len done; - - if !new_len > Sys.max_string_length then begin - if b.position + more <= Sys.max_string_length - then new_len := Sys.max_string_length - else failwith "Ext_buffer.add: cannot grow buffer" - end; - - let new_buffer = Bytes.create !new_len in - (* PR#6148: let's keep using [blit] rather than [unsafe_blit] in - this tricky function that is slow anyway. *) - Bytes.blit b.buffer 0 new_buffer 0 b.position; - b.buffer <- new_buffer; - b.length <- !new_len ; - assert (b.position + more <= b.length) - -let add_char b c = - let pos = b.position in - if pos >= b.length then resize b 1; - Bytes.unsafe_set b.buffer pos c; - b.position <- pos + 1 - -let add_substring b s offset len = - if offset < 0 || len < 0 || offset > String.length s - len - then invalid_arg "Ext_buffer.add_substring/add_subbytes"; - let new_position = b.position + len in - if new_position > b.length then resize b len; - Ext_bytes.unsafe_blit_string s offset b.buffer b.position len; - b.position <- new_position - - -let add_subbytes b s offset len = - add_substring b (Bytes.unsafe_to_string s) offset len - -let add_string b s = - let len = String.length s in - let new_position = b.position + len in - if new_position > b.length then resize b len; - Ext_bytes.unsafe_blit_string s 0 b.buffer b.position len; - b.position <- new_position - -(* TODO: micro-optimzie *) -let add_string_char b s c = - let s_len = String.length s in - let len = s_len + 1 in - let new_position = b.position + len in - if new_position > b.length then resize b len; - let b_buffer = b.buffer in - Ext_bytes.unsafe_blit_string s 0 b_buffer b.position s_len; - Bytes.unsafe_set b_buffer (new_position - 1) c; - b.position <- new_position - -let add_char_string b c s = - let s_len = String.length s in - let len = s_len + 1 in - let new_position = b.position + len in - if new_position > b.length then resize b len; - let b_buffer = b.buffer in - let b_position = b.position in - Bytes.unsafe_set b_buffer b_position c ; - Ext_bytes.unsafe_blit_string s 0 b_buffer (b_position + 1) s_len; - b.position <- new_position - - -let add_bytes b s = add_string b (Bytes.unsafe_to_string s) - -let add_buffer b bs = - add_subbytes b bs.buffer 0 bs.position - -let add_channel b ic len = - if len < 0 - - || len > Sys.max_string_length - - then (* PR#5004 *) - invalid_arg "Ext_buffer.add_channel"; - if b.position + len > b.length then resize b len; - really_input ic b.buffer b.position len; - b.position <- b.position + len - -let output_buffer oc b = - output oc b.buffer 0 b.position - -external unsafe_string: bytes -> int -> int -> Digest.t = "caml_md5_string" - -let digest b = - unsafe_string - b.buffer 0 b.position - -let rec not_equal_aux (b : bytes) (s : string) i len = - if i >= len then false - else - (Bytes.unsafe_get b i - <> - String.unsafe_get s i ) - || not_equal_aux b s (i + 1) len - -(** avoid a large copy *) -let not_equal (b : t) (s : string) = - let b_len = b.position in - let s_len = String.length s in - b_len <> s_len - || not_equal_aux b.buffer s 0 s_len - - -(** - It could be one byte, two bytes, three bytes and four bytes - TODO: inline for better performance -*) -let add_int_1 (b : t ) (x : int ) = - let c = (Char.unsafe_chr (x land 0xff)) in - let pos = b.position in - if pos >= b.length then resize b 1; - Bytes.unsafe_set b.buffer pos c; - b.position <- pos + 1 - -let add_int_2 (b : t ) (x : int ) = - let c1 = (Char.unsafe_chr (x land 0xff)) in - let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in - let pos = b.position in - if pos + 1 >= b.length then resize b 2; - let b_buffer = b.buffer in - Bytes.unsafe_set b_buffer pos c1; - Bytes.unsafe_set b_buffer (pos + 1) c2; - b.position <- pos + 2 - -let add_int_3 (b : t ) (x : int ) = - let c1 = (Char.unsafe_chr (x land 0xff)) in - let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in - let c3 = (Char.unsafe_chr (x lsr 16 land 0xff)) in - let pos = b.position in - if pos + 2 >= b.length then resize b 3; - let b_buffer = b.buffer in - Bytes.unsafe_set b_buffer pos c1; - Bytes.unsafe_set b_buffer (pos + 1) c2; - Bytes.unsafe_set b_buffer (pos + 2) c3; - b.position <- pos + 3 - - -let add_int_4 (b : t ) (x : int ) = - let c1 = (Char.unsafe_chr (x land 0xff)) in - let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in - let c3 = (Char.unsafe_chr (x lsr 16 land 0xff)) in - let c4 = (Char.unsafe_chr (x lsr 24 land 0xff)) in - let pos = b.position in - if pos + 3 >= b.length then resize b 4; - let b_buffer = b.buffer in - Bytes.unsafe_set b_buffer pos c1; - Bytes.unsafe_set b_buffer (pos + 1) c2; - Bytes.unsafe_set b_buffer (pos + 2) c3; - Bytes.unsafe_set b_buffer (pos + 3) c4; - b.position <- pos + 4 end -module Ext_filename : sig -#1 "ext_filename.mli" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. +module Bsb_log : sig +#1 "bsb_log.mli" +(* Copyright (C) 2017 Authors of BuckleScript * * 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 @@ -6223,69 +6048,31 @@ module Ext_filename : sig * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +val setup : unit -> unit +type level = + | Debug + | Info + | Warn + | Error +val log_level : level ref -(* TODO: - Change the module name, this code is not really an extension of the standard - library but rather specific to JS Module name convention. -*) - - - - - -(** An extension module to calculate relative path follow node/npm style. - TODO : this short name will have to change upon renaming the file. -*) - -val is_dir_sep : - char -> bool - -val maybe_quote: - string -> - string - -val chop_extension_maybe: - string -> - string - -(* return an empty string if no extension found *) -val get_extension_maybe: - string -> - string - - -val new_extension: - string -> - string -> - string - -val chop_all_extensions_maybe: - string -> - string - -(* OCaml specific abstraction*) -val module_name: - string -> - string - - - +type 'a fmt = Format.formatter -> ('a, Format.formatter, unit) format -> 'a -type module_info = { - module_name : string ; - case : bool; -} +type 'a log = ('a, Format.formatter, unit) format -> 'a +val verbose : unit -> unit +val debug : 'a log +val info : 'a log +val warn : 'a log +val error : 'a log +val info_args : string array -> unit -val as_module: - basename:string -> - module_info option end = struct -#1 "ext_filename.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. +#1 "bsb_log.ml" +(* Copyright (C) 2017- Authors of BuckleScript * * 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 @@ -6311,382 +6098,430 @@ end = struct +let ninja_ansi_forced = lazy + (try Sys.getenv "NINJA_ANSI_FORCED" with + Not_found ->"" + ) +let color_enabled = lazy (Unix.isatty Unix.stdout) -let is_dir_sep_unix c = c = '/' -let is_dir_sep_win_cygwin c = - c = '/' || c = '\\' || c = ':' +(* same logic as [ninja.exe] *) +let get_color_enabled () = + let colorful = + match ninja_ansi_forced with + | lazy "1" -> true + | lazy ("0" | "false") -> false + | _ -> + Lazy.force color_enabled in + colorful -let is_dir_sep = - if Sys.unix then is_dir_sep_unix else is_dir_sep_win_cygwin -(* reference ninja.cc IsKnownShellSafeCharacter *) -let maybe_quote ( s : string) = - let noneed_quote = - Ext_string.for_all s (function - | '0' .. '9' - | 'a' .. 'z' - | 'A' .. 'Z' - | '_' | '+' - | '-' | '.' - | '/' - | '@' -> true - | _ -> false - ) in - if noneed_quote then - s - else Filename.quote s +let color_functions : Format.formatter_tag_functions = { + mark_open_tag = (fun s -> if get_color_enabled () then Ext_color.ansi_of_tag s else Ext_string.empty) ; + mark_close_tag = (fun _ -> if get_color_enabled () then Ext_color.reset_lit else Ext_string.empty); + print_open_tag = (fun _ -> ()); + print_close_tag = (fun _ -> ()) +} -let chop_extension_maybe name = - let rec search_dot i = - if i < 0 || is_dir_sep (String.unsafe_get name i) then name - else if String.unsafe_get name i = '.' then String.sub name 0 i - else search_dot (i - 1) in - search_dot (String.length name - 1) +let set_color ppf = + Format.pp_set_formatter_tag_functions ppf color_functions -let get_extension_maybe name = - let name_len = String.length name in - let rec search_dot name i name_len = - if i < 0 || is_dir_sep (String.unsafe_get name i) then "" - else if String.unsafe_get name i = '.' then String.sub name i (name_len - i) - else search_dot name (i - 1) name_len in - search_dot name (name_len - 1) name_len -let chop_all_extensions_maybe name = - let rec search_dot i last = - if i < 0 || is_dir_sep (String.unsafe_get name i) then - (match last with - | None -> name - | Some i -> String.sub name 0 i) - else if String.unsafe_get name i = '.' then - search_dot (i - 1) (Some i) - else search_dot (i - 1) last in - search_dot (String.length name - 1) None +let setup () = + begin + Format.pp_set_mark_tags Format.std_formatter true ; + Format.pp_set_mark_tags Format.err_formatter true; + Format.pp_set_formatter_tag_functions + Format.std_formatter color_functions; + Format.pp_set_formatter_tag_functions + Format.err_formatter color_functions + end +type level = + | Debug + | Info + | Warn + | Error -let new_extension name (ext : string) = - let rec search_dot name i ext = - if i < 0 || is_dir_sep (String.unsafe_get name i) then - name ^ ext - else if String.unsafe_get name i = '.' then - let ext_len = String.length ext in - let buf = Bytes.create (i + ext_len) in - Bytes.blit_string name 0 buf 0 i; - Bytes.blit_string ext 0 buf i ext_len; - Bytes.unsafe_to_string buf - else search_dot name (i - 1) ext in - search_dot name (String.length name - 1) ext +let int_of_level (x : level) = + match x with + | Debug -> 0 + | Info -> 1 + | Warn -> 2 + | Error -> 3 +let log_level = ref Warn +let verbose () = + log_level := Debug +let dfprintf level fmt = + if int_of_level level >= int_of_level !log_level then + Format.fprintf fmt + else Format.ifprintf fmt -(** TODO: improve efficiency - given a path, calcuate its module name - Note that `ocamlc.opt -c aa.xx.mli` gives `aa.xx.cmi` - we can not strip all extensions, otherwise - we can not tell the difference between "x.cpp.ml" - and "x.ml" +type 'a fmt = + Format.formatter -> ('a, Format.formatter, unit) format -> 'a +type 'a log = + ('a, Format.formatter, unit) format -> 'a + +let debug fmt = dfprintf Debug Format.std_formatter fmt +let info fmt = dfprintf Info Format.std_formatter fmt +let warn fmt = dfprintf Warn Format.err_formatter fmt +let error fmt = dfprintf Error Format.err_formatter fmt + + +let info_args (args : string array) = + if int_of_level Info >= int_of_level !log_level then + begin + for i = 0 to Array.length args - 1 do + Format.pp_print_string Format.std_formatter (Array.unsafe_get args i) ; + Format.pp_print_string Format.std_formatter Ext_string.single_space; + done ; + Format.pp_print_newline Format.std_formatter () + end + else () + + +end +module Ext_buffer : sig +#1 "ext_buffer.mli" +(***********************************************************************) +(* *) +(* OCaml *) +(* *) +(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(** Extensible buffers. + + This module implements buffers that automatically expand + as necessary. It provides accumulative concatenation of strings + in quasi-linear time (instead of quadratic time when strings are + concatenated pairwise). *) -let module_name name = - let rec search_dot i name = - if i < 0 then - Ext_string.capitalize_ascii name - else - if String.unsafe_get name i = '.' then - Ext_string.capitalize_sub name i - else - search_dot (i - 1) name in - let name = Filename.basename name in - let name_len = String.length name in - search_dot (name_len - 1) name -type module_info = { - module_name : string ; - case : bool; -} +(* BuckleScript customization: customized for efficient digest *) +type t +(** The abstract type of buffers. *) +val create : int -> t +(** [create n] returns a fresh buffer, initially empty. + The [n] parameter is the initial size of the internal byte sequence + that holds the buffer contents. That byte sequence is automatically + reallocated when more than [n] characters are stored in the buffer, + but shrinks back to [n] characters when [reset] is called. + For best performance, [n] should be of the same order of magnitude + as the number of characters that are expected to be stored in + the buffer (for instance, 80 for a buffer that holds one output + line). Nothing bad will happen if the buffer grows beyond that + limit, however. In doubt, take [n = 16] for instance. + If [n] is not between 1 and {!Sys.max_string_length}, it will + be clipped to that interval. *) -let rec valid_module_name_aux name off len = - if off >= len then true - else - let c = String.unsafe_get name off in - match c with - | 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '\'' -> - valid_module_name_aux name (off + 1) len - | _ -> false +val contents : t -> string +(** Return a copy of the current contents of the buffer. + The buffer itself is unchanged. *) -type state = - | Invalid - | Upper - | Lower +val length : t -> int +(** Return the number of characters currently contained in the buffer. *) -let valid_module_name name len = - if len = 0 then Invalid - else - let c = String.unsafe_get name 0 in - match c with - | 'A' .. 'Z' - -> - if valid_module_name_aux name 1 len then - Upper - else Invalid - | 'a' .. 'z' - -> - if valid_module_name_aux name 1 len then - Lower - else Invalid - | _ -> Invalid +val is_empty : t -> bool +val clear : t -> unit +(** Empty the buffer. *) -let as_module ~basename = - let rec search_dot i name name_len = - if i < 0 then - (* Input e.g, [a_b] *) - match valid_module_name name name_len with - | Invalid -> None - | Upper -> Some {module_name = name; case = true } - | Lower -> Some {module_name = Ext_string.capitalize_ascii name; case = false} - else - if String.unsafe_get name i = '.' then - (*Input e.g, [A_b] *) - match valid_module_name name i with - | Invalid -> None - | Upper -> - Some {module_name = Ext_string.capitalize_sub name i; case = true} - | Lower -> - Some {module_name = Ext_string.capitalize_sub name i; case = false} - else - search_dot (i - 1) name name_len in - let name_len = String.length basename in - search_dot (name_len - 1) basename name_len - -end -module Ext_namespace : sig -#1 "ext_namespace.mli" -(* Copyright (C) 2017- Authors of BuckleScript - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) -val make : ?ns:string -> string -> string -(** [make ~ns:"Ns" "a"] A typical example would return "a-Ns" Note the namespace - comes from the output of [namespace_of_package_name] *) +val add_char : t -> char -> unit +(** [add_char b c] appends the character [c] at the end of the buffer [b]. *) -val try_split_module_name : string -> (string * string) option +val add_string : t -> string -> unit +(** [add_string b s] appends the string [s] at the end of the buffer [b]. *) -val change_ext_ns_suffix : string -> string -> string +val add_bytes : t -> bytes -> unit +(** [add_string b s] appends the string [s] at the end of the buffer [b]. + @since 4.02 *) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +val add_substring : t -> string -> int -> int -> unit +(** [add_substring b s ofs len] takes [len] characters from offset + [ofs] in string [s] and appends them at the end of the buffer [b]. *) -val js_name_of_modulename : string -> file_kind -> string -(** Predicts the JavaScript filename for a given (possibly namespaced) module- - name; i.e. [js_name_of_modulename "AA-Ns" Little_bs] would produce - ["aA.bs.js"]. *) +val add_subbytes : t -> bytes -> int -> int -> unit +(** [add_substring b s ofs len] takes [len] characters from offset + [ofs] in byte sequence [s] and appends them at the end of the buffer [b]. + @since 4.02 *) -val is_valid_npm_package_name : string -> bool +val add_buffer : t -> t -> unit +(** [add_buffer b1 b2] appends the current contents of buffer [b2] + at the end of buffer [b1]. [b2] is not modified. *) -val namespace_of_package_name : string -> string +val add_channel : t -> in_channel -> int -> unit +(** [add_channel b ic n] reads exactly [n] character from the + input channel [ic] and stores them at the end of buffer [b]. + Raise [End_of_file] if the channel contains fewer than [n] + characters. *) + +val output_buffer : out_channel -> t -> unit +(** [output_buffer oc b] writes the current contents of buffer [b] + on the output channel [oc]. *) + +val digest : t -> Digest.t + +val not_equal : + t -> + string -> + bool + +val add_int_1 : + t -> int -> unit + +val add_int_2 : + t -> int -> unit +val add_int_3 : + t -> int -> unit + +val add_int_4 : + t -> int -> unit + +val add_string_char : + t -> + string -> + char -> + unit + +val add_char_string : + t -> + char -> + string -> + unit end = struct -#1 "ext_namespace.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) +#1 "ext_buffer.ml" +(**************************************************************************) +(* *) +(* OCaml *) +(* *) +(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. *) +(* *) +(* All rights reserved. This file is distributed under the terms of *) +(* the GNU Lesser General Public License version 2.1, with the *) +(* special exception on linking described in the file LICENSE. *) +(* *) +(**************************************************************************) -(* Note the build system should check the validity of filenames espeically, it - should not contain '-' *) -let ns_sep_char = '-' -let ns_sep = "-" +(* Extensible buffers *) -let make ?ns cunit = - match ns with - | None -> cunit - | Some ns -> cunit ^ ns_sep ^ ns +type t = + {mutable buffer : bytes; + mutable position : int; + mutable length : int; + initial_buffer : bytes} +let create n = + let n = if n < 1 then 1 else n in + + let n = if n > Sys.max_string_length then Sys.max_string_length else n in + + let s = Bytes.create n in + {buffer = s; position = 0; length = n; initial_buffer = s} -(** Starting from the end, search for [ns_sep_char]. Returns the index, if - found, or [-1] if [ns_sep_char] is not found before reaching a - directory-separator. *) -let rec rindex_rec s i = - if i < 0 then i +let contents b = Bytes.sub_string b.buffer 0 b.position +let to_bytes b = Bytes.sub b.buffer 0 b.position + +let sub b ofs len = + if ofs < 0 || len < 0 || ofs > b.position - len + then invalid_arg "Ext_buffer.sub" + else Bytes.sub_string b.buffer ofs len + + +let blit src srcoff dst dstoff len = + if len < 0 || srcoff < 0 || srcoff > src.position - len + || dstoff < 0 || dstoff > (Bytes.length dst) - len + then invalid_arg "Ext_buffer.blit" else - let char = String.unsafe_get s i in - if Ext_filename.is_dir_sep char then -1 - else if char = ns_sep_char then i - else rindex_rec s (i - 1) + Bytes.unsafe_blit src.buffer srcoff dst dstoff len +let length b = b.position +let is_empty b = b.position = 0 +let clear b = b.position <- 0 -(* Note we have to output uncapitalized file Name, or at least be consistent, - since by reading cmi file on Case insensitive OS, we don't really know - whether it is `list.cmi` or `List.cmi`, so that `require(./list.js)` or - `require(./List.js)`. Relevant issues: #1609, #913 +let reset b = + b.position <- 0; b.buffer <- b.initial_buffer; + b.length <- Bytes.length b.buffer - #1933 when removing ns suffix, don't pass the bound of basename +let resize b more = + let len = b.length in + let new_len = ref len in + while b.position + more > !new_len do new_len := 2 * !new_len done; + + if !new_len > Sys.max_string_length then begin + if b.position + more <= Sys.max_string_length + then new_len := Sys.max_string_length + else failwith "Ext_buffer.add: cannot grow buffer" + end; + + let new_buffer = Bytes.create !new_len in + (* PR#6148: let's keep using [blit] rather than [unsafe_blit] in + this tricky function that is slow anyway. *) + Bytes.blit b.buffer 0 new_buffer 0 b.position; + b.buffer <- new_buffer; + b.length <- !new_len ; + assert (b.position + more <= b.length) - FIXME: micro-optimizaiton *) -let change_ext_ns_suffix name ext = - let i = rindex_rec name (String.length name - 1) in - if i < 0 then name ^ ext else String.sub name 0 i ^ ext +let add_char b c = + let pos = b.position in + if pos >= b.length then resize b 1; + Bytes.unsafe_set b.buffer pos c; + b.position <- pos + 1 + +let add_substring b s offset len = + if offset < 0 || len < 0 || offset > String.length s - len + then invalid_arg "Ext_buffer.add_substring/add_subbytes"; + let new_position = b.position + len in + if new_position > b.length then resize b len; + Ext_bytes.unsafe_blit_string s offset b.buffer b.position len; + b.position <- new_position + + +let add_subbytes b s offset len = + add_substring b (Bytes.unsafe_to_string s) offset len + +let add_string b s = + let len = String.length s in + let new_position = b.position + len in + if new_position > b.length then resize b len; + Ext_bytes.unsafe_blit_string s 0 b.buffer b.position len; + b.position <- new_position +(* TODO: micro-optimzie *) +let add_string_char b s c = + let s_len = String.length s in + let len = s_len + 1 in + let new_position = b.position + len in + if new_position > b.length then resize b len; + let b_buffer = b.buffer in + Ext_bytes.unsafe_blit_string s 0 b_buffer b.position s_len; + Bytes.unsafe_set b_buffer (new_position - 1) c; + b.position <- new_position -let try_split_module_name name = - let len = String.length name in - let i = rindex_rec name (len - 1) in - if i < 0 then None - else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) +let add_char_string b c s = + let s_len = String.length s in + let len = s_len + 1 in + let new_position = b.position + len in + if new_position > b.length then resize b len; + let b_buffer = b.buffer in + let b_position = b.position in + Bytes.unsafe_set b_buffer b_position c ; + Ext_bytes.unsafe_blit_string s 0 b_buffer (b_position + 1) s_len; + b.position <- new_position -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +let add_bytes b s = add_string b (Bytes.unsafe_to_string s) -let js_name_of_modulename s little = - match little with - | Little_js -> - change_ext_ns_suffix (Ext_string.uncapitalize_ascii s) Literals.suffix_js - | Little_bs -> - change_ext_ns_suffix - (Ext_string.uncapitalize_ascii s) - Literals.suffix_bs_js - | Upper_js -> change_ext_ns_suffix s Literals.suffix_js - | Upper_bs -> change_ext_ns_suffix s Literals.suffix_bs_js +let add_buffer b bs = + add_subbytes b bs.buffer 0 bs.position +let add_channel b ic len = + if len < 0 -(** https://docs.npmjs.com/files/package.json + || len > Sys.max_string_length - Some rules: + then (* PR#5004 *) + invalid_arg "Ext_buffer.add_channel"; + if b.position + len > b.length then resize b len; + really_input ic b.buffer b.position len; + b.position <- b.position + len - - The name must be less than or equal to 214 characters. This includes the - scope for scoped packages. - - The name can't start with a dot or an underscore. - - New packages must not have uppercase letters in the name. - - The name ends up being part of a URL, an argument on the command line, and - a folder name. Therefore, the name can't contain any non-URL-safe - characters. +let output_buffer oc b = + output oc b.buffer 0 b.position - TODO: handle cases like '\@angular/core'. its directory structure is like: +external unsafe_string: bytes -> int -> int -> Digest.t = "caml_md5_string" - {[ - @angular - |-------- core - ]} *) -let is_valid_npm_package_name (s : string) = - let len = String.length s in - len <= 214 (* magic number forced by npm *) - && len > 0 - && - match String.unsafe_get s 0 with - | 'a' .. 'z' | '@' -> - Ext_string.for_all_from s 1 (fun x -> - match x with - | 'a' .. 'z' | '0' .. '9' | '_' | '-' -> true - | _ -> false) - | _ -> false +let digest b = + unsafe_string + b.buffer 0 b.position +let rec not_equal_aux (b : bytes) (s : string) i len = + if i >= len then false + else + (Bytes.unsafe_get b i + <> + String.unsafe_get s i ) + || not_equal_aux b s (i + 1) len -let namespace_of_package_name (s : string) : string = - let len = String.length s in - let buf = Ext_buffer.create len in - let add capital ch = - Ext_buffer.add_char buf (if capital then Char.uppercase_ascii ch else ch) - in - let rec aux capital off len = - if off >= len then () - else - let ch = String.unsafe_get s off in - match ch with - | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' -> - add capital ch; - aux false (off + 1) len - | '/' | '-' -> aux true (off + 1) len - | _ -> aux capital (off + 1) len - in - aux true 0 len; - Ext_buffer.contents buf +(** avoid a large copy *) +let not_equal (b : t) (s : string) = + let b_len = b.position in + let s_len = String.length s in + b_len <> s_len + || not_equal_aux b.buffer s 0 s_len -end -module Bsb_package_specs : sig -#1 "bsb_package_specs.mli" -(* Copyright (C) 2017 Authors of BuckleScript - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) -type t +(** + It could be one byte, two bytes, three bytes and four bytes + TODO: inline for better performance +*) +let add_int_1 (b : t ) (x : int ) = + let c = (Char.unsafe_chr (x land 0xff)) in + let pos = b.position in + if pos >= b.length then resize b 1; + Bytes.unsafe_set b.buffer pos c; + b.position <- pos + 1 + +let add_int_2 (b : t ) (x : int ) = + let c1 = (Char.unsafe_chr (x land 0xff)) in + let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in + let pos = b.position in + if pos + 1 >= b.length then resize b 2; + let b_buffer = b.buffer in + Bytes.unsafe_set b_buffer pos c1; + Bytes.unsafe_set b_buffer (pos + 1) c2; + b.position <- pos + 2 -val default_package_specs : t +let add_int_3 (b : t ) (x : int ) = + let c1 = (Char.unsafe_chr (x land 0xff)) in + let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in + let c3 = (Char.unsafe_chr (x lsr 16 land 0xff)) in + let pos = b.position in + if pos + 2 >= b.length then resize b 3; + let b_buffer = b.buffer in + Bytes.unsafe_set b_buffer pos c1; + Bytes.unsafe_set b_buffer (pos + 1) c2; + Bytes.unsafe_set b_buffer (pos + 2) c3; + b.position <- pos + 3 -val from_json : Ext_json_types.t -> t -val get_list_of_output_js : t -> bool -> string -> string list +let add_int_4 (b : t ) (x : int ) = + let c1 = (Char.unsafe_chr (x land 0xff)) in + let c2 = (Char.unsafe_chr (x lsr 8 land 0xff)) in + let c3 = (Char.unsafe_chr (x lsr 16 land 0xff)) in + let c4 = (Char.unsafe_chr (x lsr 24 land 0xff)) in + let pos = b.position in + if pos + 3 >= b.length then resize b 4; + let b_buffer = b.buffer in + Bytes.unsafe_set b_buffer pos c1; + Bytes.unsafe_set b_buffer (pos + 1) c2; + Bytes.unsafe_set b_buffer (pos + 2) c3; + Bytes.unsafe_set b_buffer (pos + 3) c4; + b.position <- pos + 4 -val package_flag_of_package_specs : t -> string -> string -(** Sample output: - {[ -bs-package-output commonjs:lib/js/jscomp/test ]} *) -val list_dirs_by : t -> (string -> unit) -> unit -end = struct -#1 "bsb_package_specs.ml" -(* Copyright (C) 2017 Authors of BuckleScript - * +end +module Ext_filename : sig +#1 "ext_filename.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * * 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, either version 3 of the License, or @@ -6704,158 +6539,76 @@ end = struct * 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. *) -let ( // ) = Ext_path.combine - -(* TODO: sync up with {!Js_packages_info.module_system} *) -type format = NodeJS | Es6 | Es6_global - -type spec = { format : format; in_source : bool } - -module Spec_set = Set.Make (struct - type t = spec - let compare = Pervasives.compare -end) - -type t = Spec_set.t - -let bad_module_format_message_exn ~loc format = - Bsb_exception.errorf ~loc - "package-specs: `%s` isn't a valid output module format. It has to be one \ - of: %s, %s or %s" - format Literals.commonjs Literals.es6 Literals.es6_global - - -let supported_format (x : string) loc = - if x = Literals.commonjs then NodeJS - else if x = Literals.es6 then Es6 - else if x = Literals.es6_global then Es6_global - else bad_module_format_message_exn ~loc x -let string_of_format (x : format) = - match x with - | NodeJS -> Literals.commonjs - | Es6 -> Literals.es6 - | Es6_global -> Literals.es6_global -let prefix_of_format (x : format) = - match x with - | NodeJS -> Bsb_config.lib_js - | Es6 -> Bsb_config.lib_es6 - | Es6_global -> Bsb_config.lib_es6_global +(* TODO: + Change the module name, this code is not really an extension of the standard + library but rather specific to JS Module name convention. +*) -let rec from_array (arr : Ext_json_types.t array) : Spec_set.t = - let spec = ref Spec_set.empty in - let has_in_source = ref false in - Ext_array.iter arr (fun x -> - let result = from_json_single x in - if result.in_source then - if not !has_in_source then has_in_source := true - else - Bsb_exception.errorf ~loc:(Ext_json.loc_of x) - "package-specs: we've detected two module formats that are both \ - configured to be in-source."; - spec := Spec_set.add result !spec); - !spec -(* TODO: FIXME: better API without mutating *) -and from_json_single (x : Ext_json_types.t) : spec = - match x with - | Str { str = format; loc } -> - { format = supported_format format loc; in_source = false } - | Obj { map; loc } -> ( - match Map_string.find_exn map "module" with - | Str { str = format } -> - let in_source = - match Map_string.find_opt map Bsb_build_schemas.in_source with - | Some (True _) -> true - | Some _ | None -> false - in - { format = supported_format format loc; in_source } - | Arr _ -> - Bsb_exception.errorf ~loc - "package-specs: when the configuration is an object, `module` \ - field should be a string, not an array. If you want to pass \ - multiple module specs, try turning package-specs into an array of \ - objects (or strings) instead." - | _ -> - Bsb_exception.errorf ~loc - "package-specs: the `module` field of the configuration object \ - should be a string." - | exception _ -> - Bsb_exception.errorf ~loc - "package-specs: when the configuration is an object, the `module` \ - field is mandatory." ) - | _ -> - Bsb_exception.errorf ~loc:(Ext_json.loc_of x) - "package-specs: we expect either a string or an object." +(** An extension module to calculate relative path follow node/npm style. + TODO : this short name will have to change upon renaming the file. +*) -let from_json (x : Ext_json_types.t) : Spec_set.t = - match x with - | Arr { content; _ } -> from_array content - | _ -> Spec_set.singleton (from_json_single x) +val is_dir_sep : + char -> bool + +val maybe_quote: + string -> + string +val chop_extension_maybe: + string -> + string -let bs_package_output = "-bs-package-output" +(* return an empty string if no extension found *) +val get_extension_maybe: + string -> + string -(** Assume input is valid - {[ -bs-package-output commonjs:lib/js/jscomp/test ]} *) -let package_flag ({ format; in_source } : spec) dir = - Ext_string.inter2 bs_package_output - (Ext_string.concat3 (string_of_format format) Ext_string.single_colon - (if in_source then dir else prefix_of_format format // dir)) +val new_extension: + string -> + string -> + string +val chop_all_extensions_maybe: + string -> + string -let package_flag_of_package_specs (package_specs : t) (dirname : string) : - string = - Spec_set.fold - (fun format acc -> Ext_string.inter2 acc (package_flag format dirname)) - package_specs Ext_string.empty +(* OCaml specific abstraction*) +val module_name: + string -> + string -let default_package_specs = - Spec_set.singleton { format = NodeJS; in_source = false } -(** [get_list_of_output_js specs true "src/hi/hello"] *) -let get_list_of_output_js (package_specs : Spec_set.t) (bs_suffix : bool) - (output_file_sans_extension : string) = - Spec_set.fold - (fun (spec : spec) acc -> - let basename = - Ext_namespace.change_ext_ns_suffix output_file_sans_extension - (if bs_suffix then Literals.suffix_bs_js else Literals.suffix_js) - in - ( Bsb_config.proj_rel - @@ - if spec.in_source then basename - else prefix_of_format spec.format // basename ) - :: acc) - package_specs [] +type module_info = { + module_name : string ; + case : bool; +} -let list_dirs_by (package_specs : Spec_set.t) (f : string -> unit) = - Spec_set.iter - (fun (spec : spec) -> - if not spec.in_source then f (prefix_of_format spec.format)) - package_specs -end -module Bsc_warnings -= struct -#1 "bsc_warnings.ml" -(* Copyright (C) 2020- Authors of BuckleScript - * +val as_module: + basename:string -> + module_info option +end = struct +#1 "ext_filename.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * * 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, either version 3 of the License, or @@ -6872,38 +6625,167 @@ module Bsc_warnings * 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. *) -(** - See the meanings of the warning codes here: https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec281 - - 30 Two labels or constructors of the same name are defined in two mutually recursive types. - - 40 Constructor or label name used out of scope. +let is_dir_sep_unix c = c = '/' +let is_dir_sep_win_cygwin c = + c = '/' || c = '\\' || c = ':' + +let is_dir_sep = + if Sys.unix then is_dir_sep_unix else is_dir_sep_win_cygwin + +(* reference ninja.cc IsKnownShellSafeCharacter *) +let maybe_quote ( s : string) = + let noneed_quote = + Ext_string.for_all s (function + | '0' .. '9' + | 'a' .. 'z' + | 'A' .. 'Z' + | '_' | '+' + | '-' | '.' + | '/' + | '@' -> true + | _ -> false + ) in + if noneed_quote then + s + else Filename.quote s + + +let chop_extension_maybe name = + let rec search_dot i = + if i < 0 || is_dir_sep (String.unsafe_get name i) then name + else if String.unsafe_get name i = '.' then String.sub name 0 i + else search_dot (i - 1) in + search_dot (String.length name - 1) + +let get_extension_maybe name = + let name_len = String.length name in + let rec search_dot name i name_len = + if i < 0 || is_dir_sep (String.unsafe_get name i) then "" + else if String.unsafe_get name i = '.' then String.sub name i (name_len - i) + else search_dot name (i - 1) name_len in + search_dot name (name_len - 1) name_len + +let chop_all_extensions_maybe name = + let rec search_dot i last = + if i < 0 || is_dir_sep (String.unsafe_get name i) then + (match last with + | None -> name + | Some i -> String.sub name 0 i) + else if String.unsafe_get name i = '.' then + search_dot (i - 1) (Some i) + else search_dot (i - 1) last in + search_dot (String.length name - 1) None + + +let new_extension name (ext : string) = + let rec search_dot name i ext = + if i < 0 || is_dir_sep (String.unsafe_get name i) then + name ^ ext + else if String.unsafe_get name i = '.' then + let ext_len = String.length ext in + let buf = Bytes.create (i + ext_len) in + Bytes.blit_string name 0 buf 0 i; + Bytes.blit_string ext 0 buf i ext_len; + Bytes.unsafe_to_string buf + else search_dot name (i - 1) ext in + search_dot name (String.length name - 1) ext + + + +(** TODO: improve efficiency + given a path, calcuate its module name + Note that `ocamlc.opt -c aa.xx.mli` gives `aa.xx.cmi` + we can not strip all extensions, otherwise + we can not tell the difference between "x.cpp.ml" + and "x.ml" +*) +let module_name name = + let rec search_dot i name = + if i < 0 then + Ext_string.capitalize_ascii name + else + if String.unsafe_get name i = '.' then + Ext_string.capitalize_sub name i + else + search_dot (i - 1) name in + let name = Filename.basename name in + let name_len = String.length name in + search_dot (name_len - 1) name + +type module_info = { + module_name : string ; + case : bool; +} + + + +let rec valid_module_name_aux name off len = + if off >= len then true + else + let c = String.unsafe_get name off in + match c with + | 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '\'' -> + valid_module_name_aux name (off + 1) len + | _ -> false + +type state = + | Invalid + | Upper + | Lower + +let valid_module_name name len = + if len = 0 then Invalid + else + let c = String.unsafe_get name 0 in + match c with + | 'A' .. 'Z' + -> + if valid_module_name_aux name 1 len then + Upper + else Invalid + | 'a' .. 'z' + -> + if valid_module_name_aux name 1 len then + Lower + else Invalid + | _ -> Invalid - - 6 Label omitted in function application. - - 7 Method overridden. - - 9 Missing fields in a record pattern. (*Not always desired, in some cases need [@@@warning "+9"] *) - - 27 Innocuous unused variable: unused variable that is not bound with let nor as, and doesn’t start with an underscore (_) character. - - 29 Unescaped end-of-line in a string constant (non-portable code). - - 32 .. 39 Unused blabla - - 44 Open statement shadows an already defined identifier. - - 45 Open statement shadows an already defined label or constructor. - - 48 Implicit elimination of optional arguments. https://caml.inria.fr/mantis/view.php?id=6352 - - 101 (bsb-specific) unsafe polymorphic comparison. -*) -let defaults_w = "-30-40+6+7+27+32..39+44+45+101" -let defaults_warn_error = "-a+5+101";; +let as_module ~basename = + let rec search_dot i name name_len = + if i < 0 then + (* Input e.g, [a_b] *) + match valid_module_name name name_len with + | Invalid -> None + | Upper -> Some {module_name = name; case = true } + | Lower -> Some {module_name = Ext_string.capitalize_ascii name; case = false} + else + if String.unsafe_get name i = '.' then + (*Input e.g, [A_b] *) + match valid_module_name name i with + | Invalid -> None + | Upper -> + Some {module_name = Ext_string.capitalize_sub name i; case = true} + | Lower -> + Some {module_name = Ext_string.capitalize_sub name i; case = false} + else + search_dot (i - 1) name name_len in + let name_len = String.length basename in + search_dot (name_len - 1) basename name_len + end -module Bsb_warning : sig -#1 "bsb_warning.mli" -(* Copyright (C) 2017 Authors of BuckleScript +module Ext_namespace : sig +#1 "ext_namespace.mli" +(* Copyright (C) 2017- Authors of BuckleScript * * 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 @@ -6927,29 +6809,32 @@ module Bsb_warning : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +val make : ?ns:string -> string -> string +(** [make ~ns:"Ns" "a"] A typical example would return "a-Ns" Note the namespace + comes from the output of [namespace_of_package_name] *) +val try_split_module_name : string -> (string * string) option +val replace_namespace_with_extension : name:string -> ext:string -> string +(** [replace_namespace_with_extension ~name ~ext] removes the part of [name] + after [ns_sep_char], if any; and appends [ext]. +*) -type t - -(** Extra work is need to make merlin happy *) -val to_merlin_string : t -> string - - - -val from_map : Ext_json_types.t Map_string.t -> t +type leading_case = Upper | Lower -(** [to_bsb_string not_dev warning] -*) -val to_bsb_string : - toplevel:bool -> - t -> - string +val js_filename_of_modulename : + name:string -> ext:string -> leading_case -> string +(** Predicts the JavaScript filename for a given (possibly namespaced) module- + name; i.e. [js_filename_of_modulename ~name:"AA-Ns" ~ext:".js" Lower] would + produce ["aA.bs.js"]. *) + +val is_valid_npm_package_name : string -> bool + +val namespace_of_package_name : string -> string -val use_default : t end = struct -#1 "bsb_warning.ml" -(* Copyright (C) 2017 Authors of BuckleScript +#1 "ext_namespace.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * 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 @@ -6973,120 +6858,117 @@ end = struct * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +(* Note the build system should check the validity of filenames espeically, it + should not contain '-' *) +let ns_sep_char = '-' +let ns_sep = "-" -type warning_error = - | Warn_error_false - (* default [false] to make our changes non-intrusive *) - | Warn_error_true - | Warn_error_number of string - -type t0 = { - number : string option; - error : warning_error -} +let make ?ns cunit = + match ns with + | None -> cunit + | Some ns -> cunit ^ ns_sep ^ ns -type nonrec t = t0 option -let use_default = None +(** Starting from the end, search for [ns_sep_char]. Returns the index, if + found, or [-1] if [ns_sep_char] is not found before reaching a + directory-separator. *) +let rec rindex_rec s i = + if i < 0 then i + else + let char = String.unsafe_get s i in + if Ext_filename.is_dir_sep char then -1 + else if char = ns_sep_char then i + else rindex_rec s (i - 1) -let prepare_warning_concat ~(beg : bool) s = - let s = Ext_string.trim s in - if s = "" then s - else - match s.[0] with - | '0' .. '9' -> if beg then "-w +" ^ s else "+" ^ s - | 'a' .. 'z' -> - if beg then "-w " ^ s else "+" ^ s - | _ -> - if beg then "-w " ^ s else s -let to_merlin_string x = - "-w " ^ Bsc_warnings.defaults_w - ^ - (match x with - | Some {number =None} - | None -> Ext_string.empty - | Some {number = Some x} -> - prepare_warning_concat ~beg:false x ) +(* Note we have to output uncapitalized file Name, or at least be consistent, + since by reading cmi file on Case insensitive OS, we don't really know + whether it is `list.cmi` or `List.cmi`, so that `require(./list.js)` or + `require(./List.js)`. Relevant issues: #1609, #913 + #1933 when removing ns suffix, don't pass the bound of basename - -let from_map (m : Ext_json_types.t Map_string.t) = - let number_opt = Map_string.find_opt m Bsb_build_schemas.number in - let error_opt = Map_string.find_opt m Bsb_build_schemas.error in - match number_opt, error_opt with - | None, None -> None - | _, _ -> - let error = - match error_opt with - | Some (True _) -> Warn_error_true - | Some (False _) -> Warn_error_false - | Some (Str {str ; }) - -> Warn_error_number str - | Some x -> Bsb_exception.config_error x "expect true/false or string" - | None -> Warn_error_false - (** To make it less intrusive : warning error has to be enabled*) - in - let number = - match number_opt with - | Some (Str { str = number}) -> Some number - | None -> None - | Some x -> Bsb_exception.config_error x "expect a string" - in - Some {number; error } + FIXME: micro-optimizaiton *) +let replace_namespace_with_extension ~name ~ext = + let i = rindex_rec name (String.length name - 1) in + if i < 0 then name ^ ext else String.sub name 0 i ^ ext -let to_bsb_string ~toplevel warning = - match warning with - | None -> Ext_string.empty - | Some warning -> - (match warning.number with - | None -> - Ext_string.empty - | Some x -> - prepare_warning_concat ~beg:true x - ) ^ - if toplevel then - match warning.error with - | Warn_error_true -> - " -warn-error A" - | Warn_error_number y -> - " -warn-error " ^ y - | Warn_error_false -> - Ext_string.empty - else Ext_string.empty +let try_split_module_name name = + let len = String.length name in + let i = rindex_rec name (len - 1) in + if i < 0 then None + else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) -end -module Bs_hash_stubs -= struct -#1 "bs_hash_stubs.ml" +type leading_case = Upper | Lower -external hash_string : string -> int = "caml_bs_hash_string" [@@noalloc];; +let js_filename_of_modulename ~name ~ext (leading_case : leading_case) = + match leading_case with + | Lower -> + replace_namespace_with_extension + ~name:(Ext_string.uncapitalize_ascii name) + ~ext + | Upper -> replace_namespace_with_extension ~name ~ext -external hash_string_int : string -> int -> int = "caml_bs_hash_string_and_int" [@@noalloc];; -external hash_string_small_int : string -> int -> int = "caml_bs_hash_string_and_small_int" [@@noalloc];; +(** https://docs.npmjs.com/files/package.json -external hash_stamp_and_name : int -> string -> int = "caml_bs_hash_stamp_and_name" [@@noalloc];; + Some rules: -external hash_small_int : int -> int = "caml_bs_hash_small_int" [@@noalloc];; + - The name must be less than or equal to 214 characters. This includes the + scope for scoped packages. + - The name can't start with a dot or an underscore. + - New packages must not have uppercase letters in the name. + - The name ends up being part of a URL, an argument on the command line, and + a folder name. Therefore, the name can't contain any non-URL-safe + characters. -external hash_int : int -> int = "caml_bs_hash_int" [@@noalloc];; + TODO: handle cases like '\@angular/core'. its directory structure is like: -external string_length_based_compare : string -> string -> int = "caml_string_length_based_compare" [@@noalloc];; + {[ + @angular + |-------- core + ]} *) +let is_valid_npm_package_name (s : string) = + let len = String.length s in + len <= 214 (* magic number forced by npm *) + && len > 0 + && + match String.unsafe_get s 0 with + | 'a' .. 'z' | '@' -> + Ext_string.for_all_from s 1 (fun x -> + match x with + | 'a' .. 'z' | '0' .. '9' | '_' | '-' -> true + | _ -> false) + | _ -> false -external - int_unsafe_blit : - int array -> int -> int array -> int -> int -> unit = "caml_int_array_blit" [@@noalloc];; - +let namespace_of_package_name (s : string) : string = + let len = String.length s in + let buf = Ext_buffer.create len in + let add capital ch = + Ext_buffer.add_char buf (if capital then Char.uppercase_ascii ch else ch) + in + let rec aux capital off len = + if off >= len then () + else + let ch = String.unsafe_get s off in + match ch with + | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' -> + add capital ch; + aux false (off + 1) len + | '/' | '-' -> aux true (off + 1) len + | _ -> aux capital (off + 1) len + in + aux true 0 len; + Ext_buffer.contents buf end -module Ext_util : sig -#1 "ext_util.mli" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * +module Bsb_package_specs : sig +#1 "bsb_package_specs.mli" +(* Copyright (C) 2017 Authors of BuckleScript + * * 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, either version 3 of the License, or @@ -7104,21 +6986,32 @@ module Ext_util : sig * 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. *) +type t + +val default_package_specs : ?deprecated_bs_suffix:bool -> unit -> t - -val power_2_above : int -> int -> int +val from_json : ?deprecated_bs_suffix:bool -> Ext_json_types.t -> t +val get_list_of_output_js : t -> string -> string list + +val extract_in_source_bs_suffixes : t -> string list + +val flags_of_package_specs : t -> string -> string +(** Sample output: + + {[ -bs-package-output commonjs:lib/js/jscomp/test:mjs ]} *) + +val list_dirs_by : t -> (string -> unit) -> unit -val stats_to_string : Hashtbl.statistics -> string end = struct -#1 "ext_util.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * +#1 "bsb_package_specs.ml" +(* Copyright (C) 2017 Authors of BuckleScript + * * 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, either version 3 of the License, or @@ -7136,220 +7029,251 @@ end = struct * 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. *) -(** - {[ - (power_2_above 16 63 = 64) - (power_2_above 16 76 = 128) - ]} -*) -let rec power_2_above x n = - if x >= n then x - else if x * 2 > Sys.max_array_length then x - else power_2_above (x * 2) n +let ( // ) = Ext_path.combine +(* TODO: sync up with {!Js_package_info.module_system} *) +type format = NodeJS | Es6 | Es6_global -let stats_to_string ({num_bindings; num_buckets; max_bucket_length; bucket_histogram} : Hashtbl.statistics) = - Printf.sprintf - "bindings: %d,buckets: %d, longest: %d, hist:[%s]" - num_bindings - num_buckets - max_bucket_length - (String.concat "," (Array.to_list (Array.map string_of_int bucket_histogram))) -end -module Hash_set_gen -= struct -#1 "hash_set_gen.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) +type spec = { format : format; in_source : bool; suffix : string } + +module Spec_set = Set.Make (struct + type t = spec + let compare = Pervasives.compare +end) + +type t = Spec_set.t + +let bad_module_format_message_exn ~loc format = + Bsb_exception.errorf ~loc + "package-specs: `%s` isn't a valid output module format. It has to be one \ + of: %s, %s or %s" + format Literals.commonjs Literals.es6 Literals.es6_global -(* We do dynamic hashing, and resize the table and rehash the elements - when buckets become too long. *) +let supported_format (x : string) loc = + if x = Literals.commonjs then NodeJS + else if x = Literals.es6 then Es6 + else if x = Literals.es6_global then Es6_global + else bad_module_format_message_exn ~loc x -type 'a bucket = - | Empty - | Cons of { - mutable key : 'a ; - mutable next : 'a bucket - } -type 'a t = - { mutable size: int; (* number of entries *) - mutable data: 'a bucket array; (* the buckets *) - initial_size: int; (* initial array size *) - } +let string_of_format (x : format) = + match x with + | NodeJS -> Literals.commonjs + | Es6 -> Literals.es6 + | Es6_global -> Literals.es6_global +let prefix_of_format (x : format) = + match x with + | NodeJS -> Bsb_config.lib_js + | Es6 -> Bsb_config.lib_es6 + | Es6_global -> Bsb_config.lib_es6_global -let create initial_size = - let s = Ext_util.power_2_above 16 initial_size in - { initial_size = s; size = 0; data = Array.make s Empty } +let deprecated_bs_suffix_message_warn () = + Bsb_log.warn + "@{DEPRECATED@}: @[top-level 'suffix' field is deprecated;@ \ + please lower your extension-configuration into@ 'package-specs'.@]@." + + +let bad_suffix_message_warn suffix = + let open Literals in + Bsb_log.warn + "@{UNSUPPORTED@}: @[package-specs: extension `%s` is \ + unsupported;@ consider one of: %s, %s, %s; %s, %s,@ or %s.@]@." + suffix suffix_js suffix_mjs suffix_cjs suffix_bs_js suffix_bs_mjs + suffix_bs_cjs + + +let supported_suffix (x : string) = + if + not + (List.mem x + Literals. + [ + suffix_js; + suffix_mjs; + suffix_cjs; + suffix_bs_js; + suffix_bs_mjs; + suffix_bs_cjs; + ]) + then bad_suffix_message_warn x; + x -let clear h = - h.size <- 0; - let len = Array.length h.data in - for i = 0 to len - 1 do - Array.unsafe_set h.data i Empty - done -let reset h = - h.size <- 0; - h.data <- Array.make h.initial_size Empty +let default_suffix ~deprecated_bs_suffix _format _in_source = + (* match (format, in_source) with *) + (* | NodeJS, false -> Literals.suffix_js *) + (* | NodeJS, true -> Literals.suffix_bs_js *) + (* | _, false -> Literals.suffix_mjs *) + (* | _, true -> Literals.suffix_bs_mjs *) -let length h = h.size + (* TODO: In the absence of direction to the contrary, the suffix should + eventually depend on [format] and [in_source]. For now, for + backwards-compatibility, I'm hardcoding. *) + if deprecated_bs_suffix then Literals.suffix_bs_js else Literals.suffix_js -let resize indexfun h = - let odata = h.data in - let osize = Array.length odata in - let nsize = osize * 2 in - if nsize < Sys.max_array_length then begin - let ndata = Array.make nsize Empty in - let ndata_tail = Array.make nsize Empty in - h.data <- ndata; (* so that indexfun sees the new bucket count *) - let rec insert_bucket = function - Empty -> () - | Cons {key; next} as cell -> - let nidx = indexfun h key in - begin match Array.unsafe_get ndata_tail nidx with - | Empty -> - Array.unsafe_set ndata nidx cell - | Cons tail -> - tail.next <- cell - end; - Array.unsafe_set ndata_tail nidx cell; - insert_bucket next - in - for i = 0 to osize - 1 do - insert_bucket (Array.unsafe_get odata i) - done; - for i = 0 to nsize - 1 do - match Array.unsafe_get ndata_tail i with - | Empty -> () - | Cons tail -> tail.next <- Empty - done - end -let iter h f = - let rec do_bucket = function - | Empty -> - () - | Cons l -> - f l.key ; do_bucket l.next in - let d = h.data in - for i = 0 to Array.length d - 1 do - do_bucket (Array.unsafe_get d i) - done +module SS = Set.Make (String) -let fold h init f = - let rec do_bucket b accu = - match b with - Empty -> - accu - | Cons l -> - do_bucket l.next (f l.key accu) in - let d = h.data in - let accu = ref init in - for i = 0 to Array.length d - 1 do - accu := do_bucket (Array.unsafe_get d i) !accu - done; - !accu +let supported_bs_suffixes = + Literals.[ suffix_bs_js; suffix_bs_mjs; suffix_bs_cjs ] -let elements set = - fold set [] List.cons +(** Produces a [list] of supported, bs-prefixed file-suffixes used in + [in-source] package-specs. *) +let extract_in_source_bs_suffixes (package_specs : Spec_set.t) = + let f spec suffixes = + if spec.in_source && List.mem spec.suffix supported_bs_suffixes then + SS.add spec.suffix suffixes + else suffixes + in + let suffixes = Spec_set.fold f package_specs SS.empty in + SS.elements suffixes + + +let rec from_array ~deprecated_bs_suffix (arr : Ext_json_types.t array) : + Spec_set.t = + let specs = ref Spec_set.empty in + Ext_array.iter arr (fun x -> + let spec = from_json_single ~deprecated_bs_suffix x in + if + Spec_set.exists + (fun o -> + spec.in_source == o.in_source && String.equal spec.suffix o.suffix) + !specs + then + Bsb_exception.errorf ~loc:(Ext_json.loc_of x) + "package-specs: two conflicting module formats with the extension \ + `%s` are both configured to be in-source." + spec.suffix + else specs := Spec_set.add spec !specs); + !specs + + +(* FIXME: better API without mutating *) +and from_json_single ~deprecated_bs_suffix (x : Ext_json_types.t) : spec = + match x with + | Str { str = format; loc } -> + let format = supported_format format loc in + { + format; + in_source = false; + suffix = default_suffix ~deprecated_bs_suffix format false; + } + | Obj { map; loc } -> ( + match Map_string.find_exn map Bsb_build_schemas._module with + | Str { str = format } -> + let format = supported_format format loc in + let in_source = + match Map_string.find_opt map Bsb_build_schemas.in_source with + | Some (True _) -> true + | Some _ | None -> false + in + let suffix = + match Map_string.find_opt map Bsb_build_schemas.suffix with + | Some (Str { str = suffix; loc }) -> supported_suffix suffix + | Some _ -> + Bsb_exception.errorf ~loc + "package-specs: the `suffix` field of the configuration \ + object must be absent, or a string." + | None -> default_suffix ~deprecated_bs_suffix format in_source + in + { format; in_source; suffix } + | Arr _ -> + Bsb_exception.errorf ~loc + "package-specs: when the configuration is an object, `module` \ + field should be a string, not an array. If you want to pass \ + multiple module specs, try turning package-specs into an array of \ + objects (or strings) instead." + | _ -> + Bsb_exception.errorf ~loc + "package-specs: the `module` field of the configuration object \ + should be a string." + | exception _ -> + Bsb_exception.errorf ~loc + "package-specs: when the configuration is an object, the `module` \ + field is mandatory." ) + | _ -> + Bsb_exception.errorf ~loc:(Ext_json.loc_of x) + "package-specs: we expect either a string or an object." +let from_json ?(deprecated_bs_suffix = false) (x : Ext_json_types.t) : + Spec_set.t = + if deprecated_bs_suffix then deprecated_bs_suffix_message_warn (); + match x with + | Arr { content; _ } -> from_array ~deprecated_bs_suffix content + | _ -> Spec_set.singleton (from_json_single ~deprecated_bs_suffix x) -let rec small_bucket_mem eq key lst = - match lst with - | Empty -> false - | Cons lst -> - eq key lst.key || - match lst.next with - | Empty -> false - | Cons lst -> - eq key lst.key || - match lst.next with - | Empty -> false - | Cons lst -> - eq key lst.key || - small_bucket_mem eq key lst.next +let bs_package_output = "-bs-package-output" -let rec remove_bucket - (h : _ t) (i : int) - key - ~(prec : _ bucket) - (buck : _ bucket) - eq_key = - match buck with - | Empty -> - () - | Cons {key=k; next } -> - if eq_key k key - then begin - h.size <- h.size - 1; - match prec with - | Empty -> Array.unsafe_set h.data i next - | Cons c -> c.next <- next - end - else remove_bucket h i key ~prec:buck next eq_key +(** Assume input is valid + {[ -bs-package-output commonjs:lib/js/jscomp/test:mjs ]} *) +let package_flag ({ format; in_source; suffix } : spec) dir = + Ext_string.inter2 bs_package_output + (Ext_string.concat5 (string_of_format format) Ext_string.single_colon + (if in_source then dir else prefix_of_format format // dir) + Ext_string.single_colon suffix) -module type S = -sig - type key - type t - val create: int -> t - val clear : t -> unit - val reset : t -> unit - (* val copy: t -> t *) - val remove: t -> key -> unit - val add : t -> key -> unit - val of_array : key array -> t - val check_add : t -> key -> bool - val mem : t -> key -> bool - val iter: t -> (key -> unit) -> unit - val fold: t -> 'b -> (key -> 'b -> 'b) -> 'b - val length: t -> int - (* val stats: t -> Hashtbl.statistics *) - val elements : t -> key list -end + +let flags_of_package_specs (package_specs : t) (dirname : string) : string = + Spec_set.fold + (fun format acc -> Ext_string.inter2 acc (package_flag format dirname)) + package_specs Ext_string.empty + + +let default_package_specs ?deprecated_bs_suffix () = + let deprecated_bs_suffix = match deprecated_bs_suffix with + | Some x -> deprecated_bs_suffix_message_warn (); x + | None -> false + in + Spec_set.singleton + { + format = NodeJS; + in_source = false; + suffix = default_suffix ~deprecated_bs_suffix NodeJS false; + } + + +(** [get_list_of_output_js specs true "src/hi/hello"] *) +let get_list_of_output_js (package_specs : Spec_set.t) + (output_file_sans_extension : string) = + Spec_set.fold + (fun spec acc -> + let basename = + Ext_namespace.replace_namespace_with_extension + ~name:output_file_sans_extension ~ext:spec.suffix + in + ( Bsb_config.proj_rel + @@ + if spec.in_source then basename + else prefix_of_format spec.format // basename ) + :: acc) + package_specs [] +let list_dirs_by (package_specs : Spec_set.t) (f : string -> unit) = + Spec_set.iter + (fun (spec : spec) -> + if not spec.in_source then f (prefix_of_format spec.format)) + package_specs end -module Hash_set_string : sig -#1 "hash_set_string.mli" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * +module Bsc_warnings += struct +#1 "bsc_warnings.ml" +(* Copyright (C) 2020- Authors of BuckleScript + * * 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, either version 3 of the License, or @@ -7366,20 +7290,39 @@ module Hash_set_string : sig * 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. *) -include Hash_set_gen.S with type key = string -end = struct -#1 "hash_set_string.ml" -# 1 "ext/hash_set.cppo.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * +(** + See the meanings of the warning codes here: https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec281 + + - 30 Two labels or constructors of the same name are defined in two mutually recursive types. + - 40 Constructor or label name used out of scope. + + - 6 Label omitted in function application. + - 7 Method overridden. + - 9 Missing fields in a record pattern. (*Not always desired, in some cases need [@@@warning "+9"] *) + - 27 Innocuous unused variable: unused variable that is not bound with let nor as, and doesn’t start with an underscore (_) character. + - 29 Unescaped end-of-line in a string constant (non-portable code). + - 32 .. 39 Unused blabla + - 44 Open statement shadows an already defined identifier. + - 45 Open statement shadows an already defined label or constructor. + - 48 Implicit elimination of optional arguments. https://caml.inria.fr/mantis/view.php?id=6352 + - 101 (bsb-specific) unsafe polymorphic comparison. +*) +let defaults_w = "-30-40+6+7+27+32..39+44+45+101" +let defaults_warn_error = "-a+5+101";; + +end +module Bsb_warning : sig +#1 "bsb_warning.mli" +(* Copyright (C) 2017 Authors of BuckleScript + * * 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, either version 3 of the License, or @@ -7397,82 +7340,34 @@ end = struct * 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. *) -# 31 "ext/hash_set.cppo.ml" -type key = string -let key_index (h : _ Hash_set_gen.t ) (key : key) = - (Bs_hash_stubs.hash_string key) land (Array.length h.data - 1) -let eq_key = Ext_string.equal -type t = key Hash_set_gen.t - - -# 64 "ext/hash_set.cppo.ml" -let create = Hash_set_gen.create -let clear = Hash_set_gen.clear -let reset = Hash_set_gen.reset -(* let copy = Hash_set_gen.copy *) -let iter = Hash_set_gen.iter -let fold = Hash_set_gen.fold -let length = Hash_set_gen.length -(* let stats = Hash_set_gen.stats *) -let elements = Hash_set_gen.elements -let remove (h : _ Hash_set_gen.t ) key = - let i = key_index h key in - let h_data = h.data in - Hash_set_gen.remove_bucket h i key ~prec:Empty (Array.unsafe_get h_data i) eq_key - +type t -let add (h : _ Hash_set_gen.t) key = - let i = key_index h key in - let h_data = h.data in - let old_bucket = (Array.unsafe_get h_data i) in - if not (Hash_set_gen.small_bucket_mem eq_key key old_bucket) then - begin - Array.unsafe_set h_data i (Cons {key = key ; next = old_bucket}); - h.size <- h.size + 1 ; - if h.size > Array.length h_data lsl 1 then Hash_set_gen.resize key_index h - end +(** Extra work is need to make merlin happy *) +val to_merlin_string : t -> string -let of_array arr = - let len = Array.length arr in - let tbl = create len in - for i = 0 to len - 1 do - add tbl (Array.unsafe_get arr i); - done ; - tbl - - -let check_add (h : _ Hash_set_gen.t) key : bool = - let i = key_index h key in - let h_data = h.data in - let old_bucket = (Array.unsafe_get h_data i) in - if not (Hash_set_gen.small_bucket_mem eq_key key old_bucket) then - begin - Array.unsafe_set h_data i (Cons { key = key ; next = old_bucket}); - h.size <- h.size + 1 ; - if h.size > Array.length h_data lsl 1 then Hash_set_gen.resize key_index h; - true - end - else false -let mem (h : _ Hash_set_gen.t) key = - Hash_set_gen.small_bucket_mem eq_key key (Array.unsafe_get h.data (key_index h key)) +val from_map : Ext_json_types.t Map_string.t -> t - +(** [to_bsb_string not_dev warning] +*) +val to_bsb_string : + toplevel:bool -> + t -> + string -end -module Bsb_config_types -= struct -#1 "bsb_config_types.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. +val use_default : t +end = struct +#1 "bsb_warning.ml" +(* Copyright (C) 2017 Authors of BuckleScript * * 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 @@ -7497,70 +7392,149 @@ module Bsb_config_types * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type dependency = - { - package_name : Bsb_pkg_types.t ; - package_install_path : string ; - } -type dependencies = dependency list +type warning_error = + | Warn_error_false + (* default [false] to make our changes non-intrusive *) + | Warn_error_true + | Warn_error_number of string -(* `string` is a path to the entrypoint *) -type entries_t = JsTarget of string | NativeTarget of string | BytecodeTarget of string +type t0 = { + number : string option; + error : warning_error +} -type compilation_kind_t = Js | Bytecode | Native +type nonrec t = t0 option -type reason_react_jsx = - | Jsx_v2 - | Jsx_v3 - (* string option *) +let use_default = None -type refmt = string option +let prepare_warning_concat ~(beg : bool) s = + let s = Ext_string.trim s in + if s = "" then s + else + match s.[0] with + | '0' .. '9' -> if beg then "-w +" ^ s else "+" ^ s + | 'a' .. 'z' -> + if beg then "-w " ^ s else "+" ^ s + | _ -> + if beg then "-w " ^ s else s -type gentype_config = { - path : string (* resolved *) -} -type command = string +let to_merlin_string x = + "-w " ^ Bsc_warnings.defaults_w + ^ + (match x with + | Some {number =None} + | None -> Ext_string.empty + | Some {number = Some x} -> + prepare_warning_concat ~beg:false x ) -type ppx = { - name : string; - args : string list -} -type t = - { - package_name : string ; - (* [captial-package] *) - namespace : string option; - (* CapitalPackage *) - external_includes : string list ; - bsc_flags : string list ; - ppx_files : ppx list ; - pp_file : string option; - bs_dependencies : dependencies; - bs_dev_dependencies : dependencies; - built_in_dependency : dependency option; - warning : Bsb_warning.t; - (*TODO: maybe we should always resolve bs-platform - so that we can calculate correct relative path in - [.merlin] - *) - refmt : refmt; - js_post_build_cmd : string option; - package_specs : Bsb_package_specs.t ; - file_groups : Bsb_file_groups.t; - files_to_install : Hash_set_string.t ; - generate_merlin : bool ; - reason_react_jsx : reason_react_jsx option; (* whether apply PPX transform or not*) - entries : entries_t list ; - generators : command Map_string.t ; - cut_generators : bool; (* note when used as a dev mode, we will always ignore it *) - bs_suffix : bool ; (* true means [.bs.js] we should pass [-bs-suffix] flag *) - gentype_config : gentype_config option; - number_of_dev_groups : int - } -end -module Ext_color : sig -#1 "ext_color.mli" + +let from_map (m : Ext_json_types.t Map_string.t) = + let number_opt = Map_string.find_opt m Bsb_build_schemas.number in + let error_opt = Map_string.find_opt m Bsb_build_schemas.error in + match number_opt, error_opt with + | None, None -> None + | _, _ -> + let error = + match error_opt with + | Some (True _) -> Warn_error_true + | Some (False _) -> Warn_error_false + | Some (Str {str ; }) + -> Warn_error_number str + | Some x -> Bsb_exception.config_error x "expect true/false or string" + | None -> Warn_error_false + (** To make it less intrusive : warning error has to be enabled*) + in + let number = + match number_opt with + | Some (Str { str = number}) -> Some number + | None -> None + | Some x -> Bsb_exception.config_error x "expect a string" + in + Some {number; error } + +let to_bsb_string ~toplevel warning = + match warning with + | None -> Ext_string.empty + | Some warning -> + (match warning.number with + | None -> + Ext_string.empty + | Some x -> + prepare_warning_concat ~beg:true x + ) ^ + if toplevel then + match warning.error with + | Warn_error_true -> + " -warn-error A" + | Warn_error_number y -> + " -warn-error " ^ y + | Warn_error_false -> + Ext_string.empty + else Ext_string.empty + + +end +module Bs_hash_stubs += struct +#1 "bs_hash_stubs.ml" + + +external hash_string : string -> int = "caml_bs_hash_string" [@@noalloc];; + +external hash_string_int : string -> int -> int = "caml_bs_hash_string_and_int" [@@noalloc];; + +external hash_string_small_int : string -> int -> int = "caml_bs_hash_string_and_small_int" [@@noalloc];; + +external hash_stamp_and_name : int -> string -> int = "caml_bs_hash_stamp_and_name" [@@noalloc];; + +external hash_small_int : int -> int = "caml_bs_hash_small_int" [@@noalloc];; + +external hash_int : int -> int = "caml_bs_hash_int" [@@noalloc];; + +external string_length_based_compare : string -> string -> int = "caml_string_length_based_compare" [@@noalloc];; + +external + int_unsafe_blit : + int array -> int -> int array -> int -> int -> unit = "caml_int_array_blit" [@@noalloc];; + + + +end +module Ext_util : sig +#1 "ext_util.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + + + +val power_2_above : int -> int -> int + + +val stats_to_string : Hashtbl.statistics -> string +end = struct +#1 "ext_util.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * This program is free software: you can redistribute it and/or modify @@ -7585,29 +7559,29 @@ module Ext_color : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type color - = Black - | Red - | Green - | Yellow - | Blue - | Magenta - | Cyan - | White - -type style - = FG of color - | BG of color - | Bold - | Dim - -(** Input is the tag for example `@{@}` return escape code *) -val ansi_of_tag : string -> string +(** + {[ + (power_2_above 16 63 = 64) + (power_2_above 16 76 = 128) + ]} +*) +let rec power_2_above x n = + if x >= n then x + else if x * 2 > Sys.max_array_length then x + else power_2_above (x * 2) n -val reset_lit : string -end = struct -#1 "ext_color.ml" +let stats_to_string ({num_bindings; num_buckets; max_bucket_length; bucket_histogram} : Hashtbl.statistics) = + Printf.sprintf + "bindings: %d,buckets: %d, longest: %d, hist:[%s]" + num_bindings + num_buckets + max_bucket_length + (String.concat "," (Array.to_list (Array.map string_of_int bucket_histogram))) +end +module Hash_set_gen += struct +#1 "hash_set_gen.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * This program is free software: you can redistribute it and/or modify @@ -7633,85 +7607,166 @@ end = struct * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +(* We do dynamic hashing, and resize the table and rehash the elements + when buckets become too long. *) + +type 'a bucket = + | Empty + | Cons of { + mutable key : 'a ; + mutable next : 'a bucket + } +type 'a t = + { mutable size: int; (* number of entries *) + mutable data: 'a bucket array; (* the buckets *) + initial_size: int; (* initial array size *) + } -type color - = Black - | Red - | Green - | Yellow - | Blue - | Magenta - | Cyan - | White -type style - = FG of color - | BG of color - | Bold - | Dim -let ansi_of_color = function - | Black -> "0" - | Red -> "1" - | Green -> "2" - | Yellow -> "3" - | Blue -> "4" - | Magenta -> "5" - | Cyan -> "6" - | White -> "7" +let create initial_size = + let s = Ext_util.power_2_above 16 initial_size in + { initial_size = s; size = 0; data = Array.make s Empty } -let code_of_style = function - | FG Black -> "30" - | FG Red -> "31" - | FG Green -> "32" - | FG Yellow -> "33" - | FG Blue -> "34" - | FG Magenta -> "35" - | FG Cyan -> "36" - | FG White -> "37" - - | BG Black -> "40" - | BG Red -> "41" - | BG Green -> "42" - | BG Yellow -> "43" - | BG Blue -> "44" - | BG Magenta -> "45" - | BG Cyan -> "46" - | BG White -> "47" +let clear h = + h.size <- 0; + let len = Array.length h.data in + for i = 0 to len - 1 do + Array.unsafe_set h.data i Empty + done - | Bold -> "1" - | Dim -> "2" +let reset h = + h.size <- 0; + h.data <- Array.make h.initial_size Empty +let length h = h.size +let resize indexfun h = + let odata = h.data in + let osize = Array.length odata in + let nsize = osize * 2 in + if nsize < Sys.max_array_length then begin + let ndata = Array.make nsize Empty in + let ndata_tail = Array.make nsize Empty in + h.data <- ndata; (* so that indexfun sees the new bucket count *) + let rec insert_bucket = function + Empty -> () + | Cons {key; next} as cell -> + let nidx = indexfun h key in + begin match Array.unsafe_get ndata_tail nidx with + | Empty -> + Array.unsafe_set ndata nidx cell + | Cons tail -> + tail.next <- cell + end; + Array.unsafe_set ndata_tail nidx cell; + insert_bucket next + in + for i = 0 to osize - 1 do + insert_bucket (Array.unsafe_get odata i) + done; + for i = 0 to nsize - 1 do + match Array.unsafe_get ndata_tail i with + | Empty -> () + | Cons tail -> tail.next <- Empty + done + end -(** TODO: add more styles later *) -let style_of_tag s = match s with - | "error" -> [Bold; FG Red] - | "warning" -> [Bold; FG Magenta] - | "info" -> [Bold; FG Yellow] - | "dim" -> [Dim] - | "filename" -> [FG Cyan] - | _ -> [] +let iter h f = + let rec do_bucket = function + | Empty -> + () + | Cons l -> + f l.key ; do_bucket l.next in + let d = h.data in + for i = 0 to Array.length d - 1 do + do_bucket (Array.unsafe_get d i) + done -let ansi_of_tag s = - let l = style_of_tag s in - let s = String.concat ";" (Ext_list.map l code_of_style) in - "\x1b[" ^ s ^ "m" +let fold h init f = + let rec do_bucket b accu = + match b with + Empty -> + accu + | Cons l -> + do_bucket l.next (f l.key accu) in + let d = h.data in + let accu = ref init in + for i = 0 to Array.length d - 1 do + accu := do_bucket (Array.unsafe_get d i) !accu + done; + !accu +let elements set = + fold set [] List.cons -let reset_lit = "\x1b[0m" +let rec small_bucket_mem eq key lst = + match lst with + | Empty -> false + | Cons lst -> + eq key lst.key || + match lst.next with + | Empty -> false + | Cons lst -> + eq key lst.key || + match lst.next with + | Empty -> false + | Cons lst -> + eq key lst.key || + small_bucket_mem eq key lst.next + +let rec remove_bucket + (h : _ t) (i : int) + key + ~(prec : _ bucket) + (buck : _ bucket) + eq_key = + match buck with + | Empty -> + () + | Cons {key=k; next } -> + if eq_key k key + then begin + h.size <- h.size - 1; + match prec with + | Empty -> Array.unsafe_set h.data i next + | Cons c -> c.next <- next + end + else remove_bucket h i key ~prec:buck next eq_key +module type S = +sig + type key + type t + val create: int -> t + val clear : t -> unit + val reset : t -> unit + (* val copy: t -> t *) + val remove: t -> key -> unit + val add : t -> key -> unit + val of_array : key array -> t + val check_add : t -> key -> bool + val mem : t -> key -> bool + val iter: t -> (key -> unit) -> unit + val fold: t -> 'b -> (key -> 'b -> 'b) -> 'b + val length: t -> int + (* val stats: t -> Hashtbl.statistics *) + val elements : t -> key list end -module Bsb_log : sig -#1 "bsb_log.mli" -(* Copyright (C) 2017 Authors of BuckleScript + + + +end +module Hash_set_string : sig +#1 "hash_set_string.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * 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 @@ -7736,31 +7791,12 @@ module Bsb_log : sig * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -val setup : unit -> unit - -type level = - | Debug - | Info - | Warn - | Error - -val log_level : level ref - -type 'a fmt = Format.formatter -> ('a, Format.formatter, unit) format -> 'a - -type 'a log = ('a, Format.formatter, unit) format -> 'a - -val verbose : unit -> unit -val debug : 'a log -val info : 'a log -val warn : 'a log -val error : 'a log - -val info_args : string array -> unit +include Hash_set_gen.S with type key = string end = struct -#1 "bsb_log.ml" -(* Copyright (C) 2017- Authors of BuckleScript +#1 "hash_set_string.ml" +# 1 "ext/hash_set.cppo.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * 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 @@ -7783,92 +7819,161 @@ end = struct * 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. *) +# 31 "ext/hash_set.cppo.ml" +type key = string +let key_index (h : _ Hash_set_gen.t ) (key : key) = + (Bs_hash_stubs.hash_string key) land (Array.length h.data - 1) +let eq_key = Ext_string.equal +type t = key Hash_set_gen.t +# 64 "ext/hash_set.cppo.ml" +let create = Hash_set_gen.create +let clear = Hash_set_gen.clear +let reset = Hash_set_gen.reset +(* let copy = Hash_set_gen.copy *) +let iter = Hash_set_gen.iter +let fold = Hash_set_gen.fold +let length = Hash_set_gen.length +(* let stats = Hash_set_gen.stats *) +let elements = Hash_set_gen.elements -let ninja_ansi_forced = lazy - (try Sys.getenv "NINJA_ANSI_FORCED" with - Not_found ->"" - ) -let color_enabled = lazy (Unix.isatty Unix.stdout) -(* same logic as [ninja.exe] *) -let get_color_enabled () = - let colorful = - match ninja_ansi_forced with - | lazy "1" -> true - | lazy ("0" | "false") -> false - | _ -> - Lazy.force color_enabled in - colorful +let remove (h : _ Hash_set_gen.t ) key = + let i = key_index h key in + let h_data = h.data in + Hash_set_gen.remove_bucket h i key ~prec:Empty (Array.unsafe_get h_data i) eq_key -let color_functions : Format.formatter_tag_functions = { - mark_open_tag = (fun s -> if get_color_enabled () then Ext_color.ansi_of_tag s else Ext_string.empty) ; - mark_close_tag = (fun _ -> if get_color_enabled () then Ext_color.reset_lit else Ext_string.empty); - print_open_tag = (fun _ -> ()); - print_close_tag = (fun _ -> ()) -} -let set_color ppf = - Format.pp_set_formatter_tag_functions ppf color_functions +let add (h : _ Hash_set_gen.t) key = + let i = key_index h key in + let h_data = h.data in + let old_bucket = (Array.unsafe_get h_data i) in + if not (Hash_set_gen.small_bucket_mem eq_key key old_bucket) then + begin + Array.unsafe_set h_data i (Cons {key = key ; next = old_bucket}); + h.size <- h.size + 1 ; + if h.size > Array.length h_data lsl 1 then Hash_set_gen.resize key_index h + end +let of_array arr = + let len = Array.length arr in + let tbl = create len in + for i = 0 to len - 1 do + add tbl (Array.unsafe_get arr i); + done ; + tbl + + +let check_add (h : _ Hash_set_gen.t) key : bool = + let i = key_index h key in + let h_data = h.data in + let old_bucket = (Array.unsafe_get h_data i) in + if not (Hash_set_gen.small_bucket_mem eq_key key old_bucket) then + begin + Array.unsafe_set h_data i (Cons { key = key ; next = old_bucket}); + h.size <- h.size + 1 ; + if h.size > Array.length h_data lsl 1 then Hash_set_gen.resize key_index h; + true + end + else false -let setup () = - begin - Format.pp_set_mark_tags Format.std_formatter true ; - Format.pp_set_mark_tags Format.err_formatter true; - Format.pp_set_formatter_tag_functions - Format.std_formatter color_functions; - Format.pp_set_formatter_tag_functions - Format.err_formatter color_functions - end -type level = - | Debug - | Info - | Warn - | Error +let mem (h : _ Hash_set_gen.t) key = + Hash_set_gen.small_bucket_mem eq_key key (Array.unsafe_get h.data (key_index h key)) -let int_of_level (x : level) = - match x with - | Debug -> 0 - | Info -> 1 - | Warn -> 2 - | Error -> 3 + -let log_level = ref Warn +end +module Bsb_config_types += struct +#1 "bsb_config_types.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) -let verbose () = - log_level := Debug -let dfprintf level fmt = - if int_of_level level >= int_of_level !log_level then - Format.fprintf fmt - else Format.ifprintf fmt -type 'a fmt = - Format.formatter -> ('a, Format.formatter, unit) format -> 'a -type 'a log = - ('a, Format.formatter, unit) format -> 'a +type dependency = + { + package_name : Bsb_pkg_types.t ; + package_install_path : string ; + } +type dependencies = dependency list -let debug fmt = dfprintf Debug Format.std_formatter fmt -let info fmt = dfprintf Info Format.std_formatter fmt -let warn fmt = dfprintf Warn Format.err_formatter fmt -let error fmt = dfprintf Error Format.err_formatter fmt +(* `string` is a path to the entrypoint *) +type entries_t = JsTarget of string | NativeTarget of string | BytecodeTarget of string +type compilation_kind_t = Js | Bytecode | Native -let info_args (args : string array) = - if int_of_level Info >= int_of_level !log_level then - begin - for i = 0 to Array.length args - 1 do - Format.pp_print_string Format.std_formatter (Array.unsafe_get args i) ; - Format.pp_print_string Format.std_formatter Ext_string.single_space; - done ; - Format.pp_print_newline Format.std_formatter () - end - else () - +type reason_react_jsx = + | Jsx_v2 + | Jsx_v3 + (* string option *) + +type refmt = string option + +type gentype_config = { + path : string (* resolved *) +} +type command = string + +type ppx = { + name : string; + args : string list +} +type t = + { + package_name : string ; + (* [captial-package] *) + namespace : string option; + (* CapitalPackage *) + external_includes : string list ; + bsc_flags : string list ; + ppx_files : ppx list ; + pp_file : string option; + bs_dependencies : dependencies; + bs_dev_dependencies : dependencies; + built_in_dependency : dependency option; + warning : Bsb_warning.t; + (*TODO: maybe we should always resolve bs-platform + so that we can calculate correct relative path in + [.merlin] + *) + refmt : refmt; + js_post_build_cmd : string option; + package_specs : Bsb_package_specs.t ; + file_groups : Bsb_file_groups.t; + files_to_install : Hash_set_string.t ; + generate_merlin : bool ; + reason_react_jsx : reason_react_jsx option; (* whether apply PPX transform or not*) + entries : entries_t list ; + generators : command Map_string.t ; + cut_generators : bool; (* note when used as a dev mode, we will always ignore it *) + gentype_config : gentype_config option; + number_of_dev_groups : int + } end module Bsb_real_path : sig @@ -10233,7 +10338,7 @@ val scan : root:string -> cut_generators:bool -> namespace:string option -> - bs_suffix:bool -> + bs_suffixes:string list -> ignored_dirs:Set_string.t -> Ext_json_types.t -> Bsb_file_groups.t * int @@ -10292,7 +10397,7 @@ type cxt = { cut_generators : bool; traverse : bool; namespace : string option; - bs_suffix : bool; + bs_suffixes : string list; ignored_dirs : Set_string.t; } @@ -10452,6 +10557,13 @@ let classify_suffix (x : string) : suffix_kind = if i >= 0 then Cmti i else Not_any +(** Attempt to delete any [.bs.[cm]?js] files for a given artifact. *) +let unlink_bs_suffixes context artifact = + List.iter + (fun suffix -> try_unlink (Filename.concat context.cwd (artifact ^ suffix))) + context.bs_suffixes + + (* This is the only place where we do some removal during scanning, configurably. *) let prune_staled_bs_js_files (context : cxt) (cur_sources : _ Map_string.t) : @@ -10482,12 +10594,7 @@ let prune_staled_bs_js_files (context : cxt) (cur_sources : _ Map_string.t) : if cmd <> "" then Ext_pervasives.try_it (fun _ -> Sys.command (cmd ^ " -cmt-rm " ^ filepath)) - | Cmj _ -> - (* remove .bs.js *) - if context.bs_suffix then - try_unlink - (Filename.concat context.cwd - (String.sub x 0 j ^ Literals.suffix_bs_js)) + | Cmj _ -> unlink_bs_suffixes context (String.sub x 0 j) | _ -> () ); try_unlink filepath ) else () @@ -10647,8 +10754,8 @@ and parse_sources (cxt : cxt) (sources : Ext_json_types.t) = | _ -> parsing_single_source cxt sources -let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffix ~ignored_dirs x : - t * int = +let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffixes ~ignored_dirs x + : t * int = Bsb_dir_index.reset (); let output = parse_sources @@ -10660,7 +10767,7 @@ let scan ~toplevel ~root ~cut_generators ~namespace ~bs_suffix ~ignored_dirs x : root; cut_generators; namespace; - bs_suffix; + bs_suffixes; traverse = false; } x @@ -11199,13 +11306,32 @@ let extract_main_entries (map : json_map) = +let deprecated_extract_bs_suffix_exn (map : json_map) = + match Map_string.find_opt map Bsb_build_schemas.suffix with + | None -> None + | Some (Str { str } as config) -> + if str = Literals.suffix_js then Some false + else if str = Literals.suffix_bs_js then Some true + else + Bsb_exception.config_error config + "DEPRECATED: This form of 'suffix' only supports either `.js` or \ + `.bs.js`. Use 'suffix' under 'package-specs' instead." + | Some config -> + Bsb_exception.config_error config + "DEPRECATED: This form of 'suffix' only supports a string" + + +let package_specs_from_obj_map (map : json_map) = + let deprecated_bs_suffix = deprecated_extract_bs_suffix_exn map in + match Map_string.find_opt map Bsb_build_schemas.package_specs with + | Some x -> Bsb_package_specs.from_json ?deprecated_bs_suffix x + | None -> Bsb_package_specs.default_package_specs ?deprecated_bs_suffix () + + let package_specs_from_bsconfig () = let json = Ext_json_parse.parse_json_from_file Literals.bsconfig_json in match json with - | Obj { map } -> ( - match Map_string.find_opt map Bsb_build_schemas.package_specs with - | Some x -> Bsb_package_specs.from_json x - | None -> Bsb_package_specs.default_package_specs ) + | Obj { map } -> package_specs_from_obj_map map | _ -> assert false @@ -11273,17 +11399,6 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) = | _ -> assert false ) -let extract_bs_suffix_exn (map : json_map) = - match Map_string.find_opt map Bsb_build_schemas.suffix with - | None -> false - | Some (Str { str } as config) -> - if str = Literals.suffix_js then false - else if str = Literals.suffix_bs_js then true - else Bsb_exception.config_error config "expect .bs.js or .js string here" - | Some config -> - Bsb_exception.config_error config "expect .bs.js or .js string here" - - let extract_gentype_config (map : json_map) cwd : Bsb_config_types.gentype_config option = match Map_string.find_opt map Bsb_build_schemas.gentypeconfig with @@ -11489,13 +11604,11 @@ let interpret_json ~toplevel_package_specs ~(per_proj_dir : string) : let package_name, namespace = extract_package_name_and_namespace map in let refmt = extract_refmt map per_proj_dir in let gentype_config = extract_gentype_config map per_proj_dir in - let bs_suffix = extract_bs_suffix_exn map in (* The default situation is empty *) let built_in_package = check_stdlib map per_proj_dir in - let package_specs = - match Map_string.find_opt map Bsb_build_schemas.package_specs with - | Some x -> Bsb_package_specs.from_json x - | None -> Bsb_package_specs.default_package_specs + let package_specs = package_specs_from_obj_map map in + let bs_suffixes = + Bsb_package_specs.extract_in_source_bs_suffixes package_specs in let pp_flags : string option = extract_string map Bsb_build_schemas.pp_flags (fun p -> @@ -11525,12 +11638,11 @@ let interpret_json ~toplevel_package_specs ~(per_proj_dir : string) : in let groups, number_of_dev_groups = Bsb_parse_sources.scan ~ignored_dirs:(extract_ignored_dirs map) - ~toplevel ~root:per_proj_dir ~cut_generators ~bs_suffix ~namespace - sources + ~toplevel ~root:per_proj_dir ~cut_generators ~bs_suffixes + ~namespace sources in { gentype_config; - bs_suffix; package_name; namespace; warning = extract_warning map; @@ -12517,7 +12629,6 @@ val make_custom_rules : has_ppx:bool -> has_pp:bool -> has_builtin:bool -> - bs_suffix:bool -> reason_react_jsx:Bsb_config_types.reason_react_jsx option -> digest:string -> refmt:string option -> @@ -12627,7 +12738,7 @@ type builtin = { } let make_custom_rules ~(has_gentype : bool) ~(has_postbuild : bool) - ~(has_ppx : bool) ~(has_pp : bool) ~(has_builtin : bool) ~(bs_suffix : bool) + ~(has_ppx : bool) ~(has_pp : bool) ~(has_builtin : bool) ~(reason_react_jsx : Bsb_config_types.reason_react_jsx option) ~(digest : string) ~(refmt : string option) (* set refmt path when needed *) @@ -12638,7 +12749,6 @@ let make_custom_rules ~(has_gentype : bool) ~(has_postbuild : bool) let mk_ml_cmj_cmd ~read_cmi ~is_dev ~postbuild : string = Buffer.clear buf; Buffer.add_string buf "$bsc -nostdlib $g_pkg_flg -color always"; - if bs_suffix then Buffer.add_string buf " -bs-suffix"; if read_cmi then Buffer.add_string buf " -bs-read-cmi"; if is_dev then Buffer.add_string buf " $g_dev_incls"; Buffer.add_string buf " $g_lib_incls"; @@ -12985,7 +13095,6 @@ module Bsb_ninja_file_groups : sig val handle_files_per_dir : out_channel -> - bs_suffix:bool -> rules:Bsb_ninja_rule.builtin -> package_specs:Bsb_package_specs.t -> js_post_build_cmd:string option -> @@ -13043,7 +13152,7 @@ let make_common_shadows package_specs dirname dir_index : key = Bsb_ninja_global_vars.g_pkg_flg; op = Append - (Bsb_package_specs.package_flag_of_package_specs package_specs dirname); + (Bsb_package_specs.flags_of_package_specs package_specs dirname); } :: ( if Bsb_dir_index.is_lib_dir dir_index then [] @@ -13058,7 +13167,7 @@ let make_common_shadows package_specs dirname dir_index : let emit_module_build (rules : Bsb_ninja_rule.builtin) (package_specs : Bsb_package_specs.t) (group_dir_index : Bsb_dir_index.t) oc - ~bs_suffix js_post_build_cmd namespace (module_info : Bsb_db.module_info) = + js_post_build_cmd namespace (module_info : Bsb_db.module_info) = let has_intf_file = module_info.info = Ml_mli in let is_re = module_info.is_re in let filename_sans_extension = module_info.name_sans_extension in @@ -13088,7 +13197,7 @@ let emit_module_build (rules : Bsb_ninja_rule.builtin) let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in let output_js = - Bsb_package_specs.get_list_of_output_js package_specs bs_suffix + Bsb_package_specs.get_list_of_output_js package_specs output_filename_sans_extension in let common_shadows = @@ -13153,8 +13262,8 @@ let emit_module_build (rules : Bsb_ninja_rule.builtin) ~order_only_deps:[ output_d ] ~rule -let handle_files_per_dir oc ~bs_suffix ~(rules : Bsb_ninja_rule.builtin) - ~package_specs ~js_post_build_cmd ~(files_to_install : Hash_set_string.t) +let handle_files_per_dir oc ~(rules : Bsb_ninja_rule.builtin) ~package_specs + ~js_post_build_cmd ~(files_to_install : Hash_set_string.t) ~(namespace : string option) (group : Bsb_file_groups.file_group) : unit = handle_generators oc group rules.customs; let installable = @@ -13166,8 +13275,8 @@ let handle_files_per_dir oc ~bs_suffix ~(rules : Bsb_ninja_rule.builtin) Map_string.iter group.sources (fun module_name module_info -> if installable module_name then Hash_set_string.add files_to_install module_info.name_sans_extension; - emit_module_build rules package_specs group.dir_index oc ~bs_suffix - js_post_build_cmd namespace module_info) + emit_module_build rules package_specs group.dir_index oc js_post_build_cmd + namespace module_info) (* pseuduo targets per directory *) @@ -13276,7 +13385,6 @@ let output_static_resources (static_resources : string list) copy_rule oc = let output_ninja_and_namespace_map ~per_proj_dir ~toplevel ({ - bs_suffix; package_name; external_includes; bsc_flags; @@ -13401,7 +13509,7 @@ let output_ninja_and_namespace_map ~per_proj_dir ~toplevel ~has_postbuild:(js_post_build_cmd <> None) ~has_ppx:(ppx_files <> []) ~has_pp:(pp_file <> None) ~has_builtin:(built_in_dependency <> None) - ~reason_react_jsx ~bs_suffix ~digest generators + ~reason_react_jsx ~digest generators in emit_bsc_lib_includes bs_dependencies bsc_lib_dirs external_includes namespace @@ -13409,9 +13517,8 @@ let output_ninja_and_namespace_map ~per_proj_dir ~toplevel output_static_resources static_resources rules.copy_resources oc; (* Generate build statement for each file *) Ext_list.iter bs_file_groups (fun files_per_dir -> - Bsb_ninja_file_groups.handle_files_per_dir oc ~bs_suffix ~rules - ~js_post_build_cmd ~package_specs ~files_to_install ~namespace - files_per_dir); + Bsb_ninja_file_groups.handle_files_per_dir oc ~rules ~js_post_build_cmd + ~package_specs ~files_to_install ~namespace files_per_dir); Ext_option.iter namespace (fun ns -> let namespace_dir = per_proj_dir // Bsb_config.lib_bs in diff --git a/lib/4.06.1/unstable/bspack.ml b/lib/4.06.1/unstable/bspack.ml index f8364f8c28..cfb97c8535 100644 --- a/lib/4.06.1/unstable/bspack.ml +++ b/lib/4.06.1/unstable/bspack.ml @@ -9966,7 +9966,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -10104,8 +10108,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" @@ -11234,15 +11243,13 @@ module Js_config : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* val get_packages_info : unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) (** return [package_name] and [path] when in script mode: *) -(* val get_current_package_name_and_path : Js_packages_info.module_system -> - Js_packages_info.info_query *) +(* val get_current_package_name_and_path : Js_package_info.module_system -> + Js_package_info.info_query *) (* val set_package_name : string -> unit val get_package_name : unit -> string option *) @@ -11283,7 +11290,6 @@ val syntax_only : bool ref val binary_ast : bool ref val simple_binary_ast : bool ref -val bs_suffix : bool ref val debug : bool ref val cmi_only : bool ref @@ -11340,8 +11346,6 @@ let set_diagnose b = diagnose := b let ( // ) = Filename.concat -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx_ml = ref false let no_builtin_ppx_mli = ref false diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index f0098931d5..2d4dba222b 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -14151,15 +14151,13 @@ module Js_config : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* val get_packages_info : unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) (** return [package_name] and [path] when in script mode: *) -(* val get_current_package_name_and_path : Js_packages_info.module_system -> - Js_packages_info.info_query *) +(* val get_current_package_name_and_path : Js_package_info.module_system -> + Js_package_info.info_query *) (* val set_package_name : string -> unit val get_package_name : unit -> string option *) @@ -14200,7 +14198,6 @@ val syntax_only : bool ref val binary_ast : bool ref val simple_binary_ast : bool ref -val bs_suffix : bool ref val debug : bool ref val cmi_only : bool ref @@ -14257,8 +14254,6 @@ let set_diagnose b = diagnose := b let ( // ) = Filename.concat -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx_ml = ref false let no_builtin_ppx_mli = ref false @@ -14306,7 +14301,7 @@ end module Bs_warnings : sig #1 "bs_warnings.mli" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -14324,29 +14319,27 @@ module Bs_warnings : sig * 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. *) - -type t = - | Unsafe_poly_variant_type +type t = Unsafe_poly_variant_type val prerr_bs_ffi_warning : Location.t -> t -> unit +val warn_deprecated_bs_suffix_flag : unit -> unit -val warn_missing_primitive : Location.t -> string -> unit +val warn_missing_primitive : Location.t -> string -> unit -val warn_literal_overflow : Location.t -> unit +val warn_literal_overflow : Location.t -> unit -val error_unescaped_delimiter : - Location.t -> string -> unit +val error_unescaped_delimiter : Location.t -> string -> unit end = struct #1 "bs_warnings.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -14364,117 +14357,106 @@ end = struct * 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. *) - - type t = | Unsafe_poly_variant_type - (* for users write code like this: - {[ external f : [`a of int ] -> string = ""]} - Here users forget about `[@bs.string]` or `[@bs.int]` - *) + (** for users write code like this: + {[ external f : [ `a of int ] -> string = "" ]} + Here users forget about `[@bs.string]` or `[@bs.int]` *) let to_string t = match t with - | Unsafe_poly_variant_type - -> - "Here a OCaml polymorphic variant type passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]` " + | Unsafe_poly_variant_type -> + "Here a OCaml polymorphic variant type passed into JS, probably you \ + forgot annotations like `[@bs.int]` or `[@bs.string]` " + let warning_formatter = Format.err_formatter -let print_string_warning (loc : Location.t) x = - if loc.loc_ghost then - Format.fprintf warning_formatter "File %s@." !Location.input_name - else - Location.print warning_formatter loc ; - Format.fprintf warning_formatter "@{Warning@}: %s@." x +let print_string_warning (loc : Location.t) ?(kind = "Warning") x = + if loc.loc_ghost then + Format.fprintf warning_formatter "File %s@." !Location.input_name + else Location.print warning_formatter loc; + Format.fprintf warning_formatter "@{%s@}: %s@." kind x -let prerr_bs_ffi_warning loc x = - Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) -let unimplemented_primitive = "Unimplemented primitive used:" -type error = +let prerr_bs_ffi_warning loc x = + Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) + + +let unimplemented_primitive = "Unimplemented primitive used:" +type error = | Uninterpreted_delimiters of string - | Unimplemented_primitive of string -exception Error of Location.t * error + | Unimplemented_primitive of string +exception Error of Location.t * error let pp_error fmt x = - match x with - | Unimplemented_primitive str -> - Format.pp_print_string fmt unimplemented_primitive; - Format.pp_print_string fmt str - - | Uninterpreted_delimiters str -> - Format.pp_print_string fmt "Uninterpreted delimiters" ; - Format.pp_print_string fmt str + match x with + | Unimplemented_primitive str -> + Format.pp_print_string fmt unimplemented_primitive; + Format.pp_print_string fmt str + | Uninterpreted_delimiters str -> + Format.pp_print_string fmt "Uninterpreted delimiters"; + Format.pp_print_string fmt str +let () = + Location.register_error_of_exn (function + | Error (loc, err) -> Some (Location.error_of_printer loc pp_error err) + | _ -> None) -let () = - Location.register_error_of_exn (function - | Error (loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) +let warn_deprecated_bs_suffix_flag () = + if not !Clflags.bs_quiet then ( + print_string_warning Location.none ~kind:"DEPRECATED" + "`-bs-suffix` used; consider using third field of `-bs-package-output` \ + instead"; + Format.pp_print_flush warning_formatter () ) +let warn_missing_primitive loc txt = + if (not !Js_config.no_warn_unimplemented_external) && not !Clflags.bs_quiet + then ( + print_string_warning loc (unimplemented_primitive ^ txt ^ " \n"); + Format.pp_print_flush warning_formatter () ) -let warn_missing_primitive loc txt = - if not !Js_config.no_warn_unimplemented_external && not !Clflags.bs_quiet then - begin - print_string_warning loc ( unimplemented_primitive ^ txt ^ " \n" ); - Format.pp_print_flush warning_formatter () - end -let warn_literal_overflow loc = - if not !Clflags.bs_quiet then - begin - print_string_warning loc +let warn_literal_overflow loc = + if not !Clflags.bs_quiet then ( + print_string_warning loc "Integer literal exceeds the range of representable integers of type int"; - Format.pp_print_flush warning_formatter () - end - + Format.pp_print_flush warning_formatter () ) -let error_unescaped_delimiter loc txt = - raise (Error(loc, Uninterpreted_delimiters txt)) +let error_unescaped_delimiter loc txt = + raise (Error (loc, Uninterpreted_delimiters txt)) +(** Note the standard way of reporting error in compiler: + val Location.register_error_of_exn : (exn -> Location.error option) -> unit + val Location.error_of_printer : Location.t -> (Format.formatter -> error -> + unit) -> error -> Location.error + Define an error type + type error exception Error of Location.t * error -(** - Note the standard way of reporting error in compiler: - - val Location.register_error_of_exn : (exn -> Location.error option) -> unit - val Location.error_of_printer : Location.t -> - (Format.formatter -> error -> unit) -> error -> Location.error - - Define an error type + Provide a printer to error - type error - exception Error of Location.t * error - - Provide a printer to error - - {[ - let () = - Location.register_error_of_exn - (function - | Error(loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) - ]} -*) + {[ + let () = + Location.register_error_of_exn (function + | Error (loc, err) -> + Some (Location.error_of_printer loc pp_error err) + | _ -> None) + ]} *) end module Ext_util : sig @@ -15178,7 +15160,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -15316,8 +15302,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" @@ -75486,14 +75477,18 @@ val make : ?ns:string -> string -> string val try_split_module_name : string -> (string * string) option -val change_ext_ns_suffix : string -> string -> string +val replace_namespace_with_extension : name:string -> ext:string -> string +(** [replace_namespace_with_extension ~name ~ext] removes the part of [name] + after [ns_sep_char], if any; and appends [ext]. +*) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -val js_name_of_modulename : string -> file_kind -> string +val js_filename_of_modulename : + name:string -> ext:string -> leading_case -> string (** Predicts the JavaScript filename for a given (possibly namespaced) module- - name; i.e. [js_name_of_modulename "AA-Ns" Little_bs] would produce - ["aA.bs.js"]. *) + name; i.e. [js_filename_of_modulename ~name:"AA-Ns" ~ext:".js" Lower] would + produce ["aA.bs.js"]. *) val is_valid_npm_package_name : string -> bool @@ -75556,7 +75551,7 @@ let rec rindex_rec s i = #1933 when removing ns suffix, don't pass the bound of basename FIXME: micro-optimizaiton *) -let change_ext_ns_suffix name ext = +let replace_namespace_with_extension ~name ~ext = let i = rindex_rec name (String.length name - 1) in if i < 0 then name ^ ext else String.sub name 0 i ^ ext @@ -75568,18 +75563,15 @@ let try_split_module_name name = else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -let js_name_of_modulename s little = - match little with - | Little_js -> - change_ext_ns_suffix (Ext_string.uncapitalize_ascii s) Literals.suffix_js - | Little_bs -> - change_ext_ns_suffix - (Ext_string.uncapitalize_ascii s) - Literals.suffix_bs_js - | Upper_js -> change_ext_ns_suffix s Literals.suffix_js - | Upper_bs -> change_ext_ns_suffix s Literals.suffix_bs_js +let js_filename_of_modulename ~name ~ext (leading_case : leading_case) = + match leading_case with + | Lower -> + replace_namespace_with_extension + ~name:(Ext_string.uncapitalize_ascii name) + ~ext + | Upper -> replace_namespace_with_extension ~name ~ext (** https://docs.npmjs.com/files/package.json @@ -90378,8 +90370,8 @@ end = struct #1 "ext_arg.ml" let bad_argf fmt = Format.ksprintf (fun x -> raise (Arg.Bad x ) ) fmt end -module Js_packages_info : sig -#1 "js_packages_info.mli" +module Js_package_info : sig +#1 "js_package_info.mli" (* Copyright (C) 2017 Authors of BuckleScript * * This program is free software: you can redistribute it and/or modify @@ -90410,7 +90402,11 @@ val runtime_dir_of_module_system : module_system -> string val runtime_package_path : module_system -> string -> string -type package_info = { module_system : module_system; path : string } +type location_descriptor = { + module_system : module_system; + path : string; + extension : string; +} type t @@ -90418,32 +90414,38 @@ val is_runtime_package : t -> bool val same_package_by_name : t -> t -> bool -val iter : t -> (package_info -> unit) -> unit +val iter : t -> (location_descriptor -> unit) -> unit val empty : t val from_name : string -> t val is_empty : t -> bool -val dump_packages_info : Format.formatter -> t -> unit +val dump_package_info : Format.formatter -> t -> unit + +val deprecated_set_bs_extension : unit -> unit -val add_npm_package_path : t -> string -> t -(** used by command line option e.g [-bs-package-output commonjs:xx/path] *) +val append_location_descriptor_of_string : t -> string -> t +(** used by command line option e.g [-bs-package-output commonjs:xx/path:ext] *) -type package_found_info = { rel_path : string; pkg_rel_path : string } +type package_paths = { + rel_path : string; + pkg_rel_path : string; + extension : string; +} -type info_query = +type query_result = | Package_script | Package_not_found - | Package_found of package_found_info + | Package_found of package_paths val get_output_dir : t -> package_dir:string -> module_system -> string (* Note here we compare the package info by order in theory, we can compare it by set semantics *) -val query_package_infos : t -> module_system -> info_query +val query_package_location_by_module_system : t -> module_system -> query_result end = struct -#1 "js_packages_info.ml" +#1 "js_package_info.ml" (* Copyright (C) 2017 Authors of BuckleScript * * This program is free software: you can redistribute it and/or modify @@ -90487,10 +90489,16 @@ let compatible (dep : module_system) (query : module_system) = | Es6_global -> dep = Es6_global || dep = Es6 -type package_info = { module_system : module_system; path : string } +type location_descriptor = { + module_system : module_system; + path : string; + extension : string; +} type package_name = Pkg_empty | Pkg_runtime | Pkg_normal of string +let deprecated_use_bs_extension = ref false + let runtime_package_name = "bs-platform" let ( // ) = Filename.concat @@ -90506,23 +90514,22 @@ let runtime_package_path (ms : module_system) js_file = runtime_package_name // "lib" // runtime_dir_of_module_system ms // js_file -type t = { name : package_name; module_systems : package_info list } +type t = { name : package_name; locations : location_descriptor list } let same_package_by_name (x : t) (y : t) = x.name = y.name let is_runtime_package (x : t) = x.name = Pkg_runtime -let iter (x : t) cb = Ext_list.iter x.module_systems cb +let iter (x : t) = Ext_list.iter x.locations (* TODO: not allowing user to provide such specific package name For empty package, [-bs-package-output] does not make sense it is only allowed to generate commonjs file in the same directory *) -let empty : t = { name = Pkg_empty; module_systems = [] } +let empty : t = { name = Pkg_empty; locations = [] } let from_name (name : string) = - if name = runtime_package_name then - { name = Pkg_runtime; module_systems = [] } - else { name = Pkg_normal name; module_systems = [] } + if name = runtime_package_name then { name = Pkg_runtime; locations = [] } + else { name = Pkg_normal name; locations = [] } let is_empty (x : t) = x.name = Pkg_empty @@ -90542,9 +90549,11 @@ let module_system_of_string package_name : module_system option = | _ -> None -let dump_package_info (fmt : Format.formatter) - ({ module_system = ms; path = name } : package_info) = - Format.fprintf fmt "@[%s:@ %s@]" (string_of_module_system ms) name +let dump_location_descriptor (fmt : Format.formatter) + { module_system = ms; path; extension } = + Format.fprintf fmt "@[%s:@ %s:@ %s@]" + (string_of_module_system ms) + path extension let dump_package_name fmt (x : package_name) = @@ -90554,52 +90563,53 @@ let dump_package_name fmt (x : package_name) = | Pkg_runtime -> Format.pp_print_string fmt runtime_package_name -let dump_packages_info (fmt : Format.formatter) - ({ name; module_systems = ls } : t) = +let dump_package_info (fmt : Format.formatter) ({ name; locations } : t) = Format.fprintf fmt "@[%a;@ @[%a@]@]" dump_package_name name (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.pp_print_space fmt ()) - dump_package_info) - ls + dump_location_descriptor) + locations -type package_found_info = { rel_path : string; pkg_rel_path : string } -type info_query = +type package_paths = { + rel_path : string; + pkg_rel_path : string; + extension : string; +} +type query_result = | Package_script | Package_not_found - | Package_found of package_found_info + | Package_found of package_paths (* Note that package-name has to be exactly the same as npm package name, otherwise the path resolution will be wrong *) -let query_package_infos ({ name; module_systems } : t) - (module_system : module_system) : info_query = +let query_package_location_by_module_system ({ name; locations } : t) + (module_system : module_system) : query_result = match name with | Pkg_empty -> Package_script | Pkg_normal name -> ( match - Ext_list.find_first module_systems (fun k -> + Ext_list.find_first locations (fun k -> compatible k.module_system module_system) with - | Some k -> - let rel_path = k.path in + | Some { path = rel_path; extension; module_system = _ms } -> let pkg_rel_path = name // rel_path in - Package_found { rel_path; pkg_rel_path } + Package_found { rel_path; pkg_rel_path; extension } | None -> Package_not_found ) | Pkg_runtime -> ( match - Ext_list.find_first module_systems (fun k -> + Ext_list.find_first locations (fun k -> compatible k.module_system module_system) with - | Some k -> - let rel_path = k.path in + | Some { path = rel_path; extension; module_system = _ms } -> let pkg_rel_path = runtime_package_name // rel_path in - Package_found { rel_path; pkg_rel_path } + Package_found { rel_path; pkg_rel_path; extension } | None -> Package_not_found ) let get_js_path (x : t) module_system = match - Ext_list.find_first x.module_systems (fun k -> + Ext_list.find_first x.locations (fun k -> compatible k.module_system module_system) with | Some k -> k.path @@ -90611,31 +90621,43 @@ let get_output_dir (info : t) ~package_dir module_system = Filename.concat package_dir (get_js_path info module_system) -let add_npm_package_path (packages_info : t) (s : string) : t = - if is_empty packages_info then - Ext_arg.bad_argf "please set package name first using -bs-package-name " - else - let module_system, path = - match Ext_string.split ~keep_empty:false s ':' with - | [ module_system; path ] -> - ( ( match module_system_of_string module_system with - | Some x -> x - | None -> Ext_arg.bad_argf "invalid module system %s" module_system - ), - path ) - | [ path ] -> (NodeJS, path) - | module_system :: path -> - ( ( match module_system_of_string module_system with - | Some x -> x - | None -> Ext_arg.bad_argf "invalid module system %s" module_system - ), - String.concat ":" path ) - | _ -> Ext_arg.bad_argf "invalid npm package path: %s" s - in - { - packages_info with - module_systems = { module_system; path } :: packages_info.module_systems; - } +let deprecated_set_bs_extension () = + Bs_warnings.warn_deprecated_bs_suffix_flag (); + deprecated_use_bs_extension := true + + +let deprecated_get_default_extension () = + if !deprecated_use_bs_extension then Literals.suffix_bs_js + else Literals.suffix_js + + +(* FIXME: The deprecated -bs-suffix will only affect -bs-package-output flags + passed *after* it. *) +let append_location_descriptor_of_string (packages_info : t) (s : string) : t = + let module_system, path, extension = + match Ext_string.split ~keep_empty:false s ':' with + | [ module_system; path; extension ] -> (module_system, path, extension) + (* Note that, for most users, the default values for [module_system] and + [extension] come not from here, but from [bsb], which always invokes this + with a fully-populated [-bs-package-output]. + + If you're changing the default, make sure both places match! *) + | [ module_system; path ] -> + (module_system, path, deprecated_get_default_extension ()) + | [ path ] -> ("NodeJS", path, deprecated_get_default_extension ()) + | _ -> Ext_arg.bad_argf "invalid value for -bs-package-output: %s" s + in + let module_system = + match module_system_of_string module_system with + | Some x -> x + | None -> + Ext_arg.bad_argf "invalid module system in -bs-package-output: %s" + module_system + in + { + packages_info with + locations = { module_system; path; extension } :: packages_info.locations; + } (* support es6 modules instead @@ -93476,24 +93498,22 @@ type cmj_value = { type effect = string option -type cmj_case = Ext_namespace.file_kind - type t val mk : values:cmj_value Map_string.t -> effect:effect -> - npm_package_path:Js_packages_info.t -> - cmj_case:cmj_case -> + package_info:Js_package_info.t -> + leading_case:Ext_namespace.leading_case -> t val query_by_name : t -> string -> arity * Lam.t option val is_pure : t -> bool -val get_npm_package_path : t -> Js_packages_info.t +val get_package_info : t -> Js_package_info.t -val get_cmj_case : t -> cmj_case +val get_leading_case : t -> Ext_namespace.leading_case val single_na : arity @@ -93546,29 +93566,27 @@ type effect = string option (* we don't force people to use package *) let single_na = Single Lam_arity.na -type cmj_case = Ext_namespace.file_kind - type keyed_cmj_values = (string * cmj_value) array type t = { values : keyed_cmj_values; pure : bool; - npm_package_path : Js_packages_info.t; - cmj_case : cmj_case; + package_info : Js_package_info.t; + leading_case : Ext_namespace.leading_case; } let empty_values = [||] -let mk ~values ~effect ~npm_package_path ~cmj_case : t = +let mk ~values ~effect ~package_info ~leading_case : t = { values = Map_string.to_sorted_array values; pure = effect = None; - npm_package_path; - cmj_case; + package_info; + leading_case; } -let cmj_magic_number = "BUCKLE20171012" +let cmj_magic_number = "BUCKLE20200410" let cmj_magic_number_length = String.length cmj_magic_number let digest_length = 16 (*16 chars *) @@ -93686,26 +93704,24 @@ let query_by_name (cmj_table : t) name = let is_pure (cmj_table : t) = cmj_table.pure -let get_npm_package_path (cmj_table : t) = cmj_table.npm_package_path +let get_package_info (cmj_table : t) = cmj_table.package_info -let get_cmj_case (cmj_table : t) = cmj_table.cmj_case +let get_leading_case (cmj_table : t) = cmj_table.leading_case (* start dumping *) let f fmt = Printf.fprintf stdout fmt -let pp_cmj_case (cmj_case : cmj_case) : unit = - match cmj_case with - | Little_js -> f "case : little, .js\n" - | Little_bs -> f "case : little, .bs.js\n" - | Upper_js -> f "case: upper, .js\n" - | Upper_bs -> f "case: upper, .bs.js\n" +let pp_leading_case (leading_case : Ext_namespace.leading_case) : unit = + match leading_case with + | Upper -> f "case: upper\n" + | Lower -> f "case: lower\n" -let pp_cmj ({ values; pure; npm_package_path; cmj_case } : t) = +let pp_cmj ({ values; pure; package_info; leading_case } : t) = f "package info: %s\n" - (Format.asprintf "%a" Js_packages_info.dump_packages_info npm_package_path); - pp_cmj_case cmj_case; + (Format.asprintf "%a" Js_package_info.dump_package_info package_info); + pp_leading_case leading_case; f "effect: %s\n" (if pure then "pure" else "not pure"); Ext_array.iter values (fun (k, { arity; persistent_closed_lambda }) -> @@ -102787,6 +102803,7 @@ val imports : Ext_pp.t -> (Ident.t * string) list -> Ext_pp_scope.t + end = struct #1 "js_dump_import_export.ml" (* Copyright (C) 2017 Authors of BuckleScript @@ -103671,8 +103688,8 @@ let find_package_json_dir cwd = let package_dir = lazy (find_package_json_dir (Lazy.force cwd)) end -module Js_packages_state : sig -#1 "js_packages_state.mli" +module Js_current_package_info : sig +#1 "js_current_package_info.mli" (* Copyright (C) 2017 Authors of BuckleScript * * This program is free software: you can redistribute it and/or modify @@ -103701,12 +103718,12 @@ val set_package_name : string -> unit val set_package_map : string -> unit -val get_packages_info : unit -> Js_packages_info.t +val get_packages_info : unit -> Js_package_info.t -val update_npm_package_path : string -> unit +val append_location_descriptor_of_string : string -> unit end = struct -#1 "js_packages_state.ml" +#1 "js_current_package_info.ml" (* Copyright (C) 2017 Authors of BuckleScript * * This program is free software: you can redistribute it and/or modify @@ -103731,11 +103748,11 @@ end = struct * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let packages_info = ref Js_packages_info.empty +let packages_info = ref Js_package_info.empty let set_package_name name = - if Js_packages_info.is_empty !packages_info then - packages_info := Js_packages_info.from_name name + if Js_package_info.is_empty !packages_info then + packages_info := Js_package_info.from_name name else Ext_arg.bad_argf "duplicated flag for -bs-package-name" @@ -103744,9 +103761,11 @@ let set_package_map module_name = Clflags.open_modules := module_name :: !Clflags.open_modules -let update_npm_package_path s = - packages_info := Js_packages_info.add_npm_package_path !packages_info s - +let append_location_descriptor_of_string s = + if Js_package_info.is_empty !packages_info then + Ext_arg.bad_argf "please set package name first using -bs-package-name or -bs-ns" + else + packages_info := Js_package_info.append_location_descriptor_of_string !packages_info s let get_packages_info () = !packages_info @@ -104119,7 +104138,7 @@ let find_cmj_exn file : cmj_load_info = Bs_exception.error (Cmj_not_found file) | v -> { cmj_path = "BROWSER"; cmj_table = v } - (* see {!Js_packages_info.string_of_module_id} *) ) + (* see {!Js_package_info.string_of_module_id} *) ) | exception Not_found -> Bs_exception.error (Cmj_not_found file) @@ -109246,15 +109265,18 @@ val query_external_id_info : Ident.t -> string -> ident_info val is_pure_module : Lam_module_ident.t -> bool val get_package_path_from_cmj : - Lam_module_ident.t -> string * Js_packages_info.t * Js_cmj_format.cmj_case + Lam_module_ident.t -> string * Js_package_info.t * Ext_namespace.leading_case -(* The second argument is mostly from [runtime] modules will change the input - [hard_dependencies] [get_required_modules extra hard_dependencies] [extra] - maybe removed if it is pure and not in [hard_dependencies] *) val get_required_modules : Lam_module_ident.Hash_set.t -> Lam_module_ident.Hash_set.t -> Lam_module_ident.t list +(** The second argument is mostly from [runtime] modules + + will change the input [hard_dependencies] + + [get_required_modules extra hard_dependencies] - [extra] maybe removed if it + is pure and not in [hard_dependencies] *) end = struct #1 "lam_compile_env.ml" @@ -109355,8 +109377,8 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) = match Lam_module_ident.Hash.find_opt cached_tbl id with | Some (Ml { cmj_table; cmj_path }) -> ( cmj_path, - Js_cmj_format.get_npm_package_path cmj_table, - Js_cmj_format.get_cmj_case cmj_table ) + Js_cmj_format.get_package_info cmj_table, + Js_cmj_format.get_leading_case cmj_table ) | Some (External | Runtime _) -> assert false (* called by {!Js_name_of_module_id.string_of_module_id} can not be @@ -109371,8 +109393,8 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) = in id +> Ml cmj_load_info; ( cmj_load_info.cmj_path, - Js_cmj_format.get_npm_package_path cmj_table, - Js_cmj_format.get_cmj_case cmj_table ) ) + Js_cmj_format.get_package_info cmj_table, + Js_cmj_format.get_leading_case cmj_table ) ) let add = Lam_module_ident.Hash_set.add @@ -109437,7 +109459,8 @@ module Js_name_of_module_id : sig val string_of_module_id : Lam_module_ident.t -> output_dir:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> string (** generate the mdoule path so that it can be spliced here: @@ -109490,29 +109513,30 @@ let fix_path_for_windows : string -> string = let get_runtime_module_path (dep_module_id : Lam_module_ident.t) - (current_package_info : Js_packages_info.t) module_system = - let current_info_query = - Js_packages_info.query_package_infos current_package_info module_system + (current_package_info : Js_package_info.t) module_system = + let loc = + Js_package_info.query_package_location_by_module_system current_package_info + module_system in let js_file = - Ext_namespace.js_name_of_modulename dep_module_id.id.name Little_js + Ext_namespace.js_filename_of_modulename ~name:dep_module_id.id.name + ~ext:".js" Lower in - match current_info_query with + match loc with | Package_not_found -> assert false - | Package_script -> - Js_packages_info.runtime_package_path module_system js_file + | Package_script -> Js_package_info.runtime_package_path module_system js_file | Package_found pkg -> ( let dep_path = - "lib" // Js_packages_info.runtime_dir_of_module_system module_system + "lib" // Js_package_info.runtime_dir_of_module_system module_system in - if Js_packages_info.is_runtime_package current_package_info then + if Js_package_info.is_runtime_package current_package_info then Ext_path.node_rebase_file ~from:pkg.rel_path ~to_:dep_path js_file (* TODO: we assume that both [x] and [path] could only be relative path which is guaranteed by [-bs-package-output] *) else match module_system with | NodeJS | Es6 -> - Js_packages_info.runtime_package_path module_system js_file + Js_package_info.runtime_package_path module_system js_file (* Note we did a post-processing when working on Windows *) | Es6_global -> (* lib/ocaml/xx.cmj -- @@ -109522,7 +109546,7 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t) (* assert false *) Ext_path.rel_normalized_absolute_path ~from: - (Js_packages_info.get_output_dir current_package_info + (Js_package_info.get_output_dir current_package_info ~package_dir:(Lazy.force Ext_path.package_dir) module_system) (Lazy.force runtime_package_path // dep_path // js_file) ) @@ -109530,9 +109554,9 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t) (* [output_dir] is decided by the command line argument *) let string_of_module_id (dep_module_id : Lam_module_ident.t) - ~(output_dir : string) (module_system : Js_packages_info.module_system) : - string = - let current_package_info = Js_packages_state.get_packages_info () in + ~(output_dir : string) ~(ext : string) + (module_system : Js_package_info.module_system) : string = + let current_package_info = Js_current_package_info.get_packages_info () in fix_path_for_windows ( match dep_module_id.kind with | External name -> name (* the literal string for external package *) @@ -109546,34 +109570,39 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t) | Runtime -> get_runtime_module_path dep_module_id current_package_info module_system | Ml -> ( - let current_info_query = - Js_packages_info.query_package_infos current_package_info - module_system - in + let query = Js_package_info.query_package_location_by_module_system in + let current_loc = query current_package_info module_system in match Lam_compile_env.get_package_path_from_cmj dep_module_id with - | cmj_path, dep_package_info, little -> ( - let js_file = - Ext_namespace.js_name_of_modulename dep_module_id.id.name little - in - let dep_info_query = - Js_packages_info.query_package_infos dep_package_info - module_system - in - match (dep_info_query, current_info_query) with + | cmj_path, dep_package_info, case -> ( + let dep_loc = query dep_package_info module_system in + match (dep_loc, current_loc) with | Package_not_found, _ -> Bs_exception.error (Missing_ml_dependency dep_module_id.id.name) | Package_script, Package_found _ -> + let js_file = + Ext_namespace.js_filename_of_modulename + (* FIXME: Unsure how to infer a useful file-extension here. *) + ~name:dep_module_id.id.name ~ext:"" case + in Bs_exception.error (Dependency_script_module_dependent_not js_file) | (Package_script | Package_found _), Package_not_found -> assert false - | Package_found pkg, Package_script -> + | Package_found dep_pkg, Package_script -> + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext:dep_pkg.extension case + in - pkg.pkg_rel_path // js_file + dep_pkg.pkg_rel_path // js_file | Package_found dep_pkg, Package_found cur_pkg -> ( + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext:dep_pkg.extension case + in if - Js_packages_info.same_package_by_name current_package_info + Js_package_info.same_package_by_name current_package_info dep_package_info then Ext_path.node_rebase_file ~from:cur_pkg.rel_path @@ -109595,13 +109624,17 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t) (* assert false *) Ext_path.rel_normalized_absolute_path ~from: - (Js_packages_info.get_output_dir current_package_info + (Js_package_info.get_output_dir current_package_info ~package_dir:(Lazy.force Ext_path.package_dir) module_system) ( Filename.dirname (Filename.dirname (Filename.dirname cmj_path)) // dep_pkg.rel_path // js_file ) ) | Package_script, Package_script -> ( + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext case + in match Config_util.find_opt js_file with | Some file -> let basename = Filename.basename file in @@ -109623,7 +109656,7 @@ let string_of_module_id_in_browser (x : Lam_module_ident.t) = let string_of_module_id (id : Lam_module_ident.t) ~output_dir:(_ : string) - (_module_system : Js_packages_info.module_system) = + ~ext:(_ : string) (_module_system : Js_package_info.module_system) = string_of_module_id_in_browser id @@ -109659,14 +109692,16 @@ val dump_program : J.program -> out_channel -> unit val pp_deps_program : output_prefix:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> J.deps_program -> Ext_pp.t -> unit val dump_deps_program : output_prefix:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> J.deps_program -> out_channel -> unit @@ -109728,24 +109763,25 @@ let dump_program (x : J.program) oc = ignore (program (P.from_channel oc) Ext_pp_scope.empty x) -let node_program ~output_dir f (x : J.deps_program) = +let node_program ~output_dir ~ext f (x : J.deps_program) = P.string f L.strict_directive; P.newline f; let cxt = Js_dump_import_export.requires L.require Ext_pp_scope.empty f (Ext_list.map x.modules (fun x -> ( Lam_module_ident.id x, - Js_name_of_module_id.string_of_module_id x ~output_dir NodeJS ))) + Js_name_of_module_id.string_of_module_id x ~output_dir ~ext NodeJS + ))) in program f cxt x.program -let es6_program ~output_dir fmt f (x : J.deps_program) = +let es6_program ~output_dir ~ext fmt f (x : J.deps_program) = let cxt = Js_dump_import_export.imports Ext_pp_scope.empty f (Ext_list.map x.modules (fun x -> ( Lam_module_ident.id x, - Js_name_of_module_id.string_of_module_id x ~output_dir fmt ))) + Js_name_of_module_id.string_of_module_id x ~output_dir ~ext fmt ))) in let () = P.force_newline f in let cxt = Js_dump.statement_list true cxt f x.program.block in @@ -109760,7 +109796,7 @@ let es6_program ~output_dir fmt f (x : J.deps_program) = Linguist::FileBlob.new('jscomp/test/test_u.js').generated? ]} *) -let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) +let pp_deps_program ~output_prefix ~ext (kind : Js_package_info.module_system) (program : J.deps_program) (f : Ext_pp.t) = if not !Js_config.no_version_header then ( P.string f Bs_version.header; @@ -109771,8 +109807,8 @@ let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) let output_dir = Filename.dirname output_prefix in ignore ( match kind with - | Es6 | Es6_global -> es6_program ~output_dir kind f program - | NodeJS -> node_program ~output_dir f program ); + | Es6 | Es6_global -> es6_program ~output_dir ~ext kind f program + | NodeJS -> node_program ~output_dir ~ext f program ); P.newline f; P.string f ( match program.side_effect with @@ -109782,8 +109818,8 @@ let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) P.flush f () -let dump_deps_program ~output_prefix kind x (oc : out_channel) = - pp_deps_program ~output_prefix kind x (P.from_channel oc) +let dump_deps_program ~output_prefix ~ext kind x (oc : out_channel) = + pp_deps_program ~output_prefix ~ext kind x (P.from_channel oc) end module Jsoo_common : sig @@ -128344,7 +128380,7 @@ val export_to_cmj : Lam_stats.t -> Js_cmj_format.effect -> Lam.t Map_ident.t -> - Js_cmj_format.cmj_case -> + Ext_namespace.leading_case -> Js_cmj_format.t end = struct @@ -128456,15 +128492,15 @@ let get_dependent_module_effect (meta : Lam_stats.t) backend, we compile to js for the inliner, we try to seriaize it -- relies on other optimizations to make this happen {[ exports.Make = function () {.....} ]} TODO: check that we don't do this in browser environment *) -let export_to_cmj (meta : Lam_stats.t) effect export_map cmj_case : - Js_cmj_format.t = +let export_to_cmj (meta : Lam_stats.t) effect export_map + (leading_case : Ext_namespace.leading_case) : Js_cmj_format.t = let values = values_of_export meta export_map in (* FIXME: make sure [-o] would not change its case *) (* FIXME: add test for ns/non-ns *) Js_cmj_format.mk ~values ~effect - ~npm_package_path:(Js_packages_state.get_packages_info ()) - ~cmj_case + ~package_info:(Js_current_package_info.get_packages_info ()) + ~leading_case end module Lam_compile_main : sig @@ -128532,13 +128568,9 @@ end = struct module E = Js_exp_make module S = Js_stmt_make -let get_cmj_case output_prefix : Ext_namespace.file_kind = - let little = Ext_char.is_lower_case (Filename.basename output_prefix).[0] in - match (little, !Js_config.bs_suffix) with - | true, true -> Little_bs - | true, false -> Little_js - | false, true -> Upper_bs - | false, false -> Upper_js +let get_leading_case output_prefix : Ext_namespace.leading_case = + if Ext_char.is_lower_case (Filename.basename output_prefix).[0] then Lower + else Upper let compile_group (meta : Lam_stats.t) (x : Lam_group.t) : Js_output.t = @@ -128718,7 +128750,7 @@ let compile (output_prefix : string) (lam : Lambda.lambda) = in let v : Js_cmj_format.t = Lam_stats_export.export_to_cmj meta effect coerced_input.export_map - (get_cmj_case output_prefix) + (get_leading_case output_prefix) in if not @@ !Clflags.dont_write_files then Js_cmj_format.to_file ~check_exists:(not !Js_config.force_cmj) @@ -128731,20 +128763,21 @@ let ( // ) = Filename.concat let lambda_as_module (lambda_output : J.deps_program) (output_prefix : string) : unit = - let basename = - Ext_namespace.change_ext_ns_suffix - (Filename.basename output_prefix) - ( if !Js_config.bs_suffix then Literals.suffix_bs_js - else Literals.suffix_js ) - in - let package_info = Js_packages_state.get_packages_info () in - if Js_packages_info.is_empty package_info && !Js_config.js_stdout then - Js_dump_program.dump_deps_program ~output_prefix NodeJS lambda_output stdout + let package_info = Js_current_package_info.get_packages_info () in + if Js_package_info.is_empty package_info && !Js_config.js_stdout then + Js_dump_program.dump_deps_program ~ext:".js" ~output_prefix NodeJS + lambda_output stdout else - Js_packages_info.iter package_info (fun { module_system; path = _path } -> + Js_package_info.iter package_info + (fun { module_system; path = _path; extension } -> + let basename = + Ext_namespace.replace_namespace_with_extension + ~name:(Filename.basename output_prefix) + ~ext:extension + in let output_chan chan = - Js_dump_program.dump_deps_program ~output_prefix module_system - lambda_output chan + Js_dump_program.dump_deps_program ~output_prefix ~ext:extension + module_system lambda_output chan in if not @@ !Clflags.dont_write_files then Ext_pervasives.with_file_as_chan @@ -132291,7 +132324,7 @@ let implementation ~use_super_errors ?(react_ppx_version = V3) prefix impl str : let buffer = Buffer.create 1000 in let () = Js_dump_program.pp_deps_program (* does not matter here *) - ~output_prefix:"" NodeJS + ~output_prefix:"" ~ext:".js" NodeJS (Lam_compile_main.compile "" lam) (Ext_pp.from_buffer buffer) in diff --git a/lib/4.06.1/unstable/js_compiler.ml.d b/lib/4.06.1/unstable/js_compiler.ml.d index 823a5525ff..00ac81fae7 100644 --- a/lib/4.06.1/unstable/js_compiler.ml.d +++ b/lib/4.06.1/unstable/js_compiler.ml.d @@ -1 +1 @@ -../lib/4.06.1/unstable/js_compiler.ml: ../ocaml/bytecomp/lambda.ml ../ocaml/bytecomp/lambda.mli ../ocaml/bytecomp/matching.ml ../ocaml/bytecomp/matching.mli ../ocaml/bytecomp/printlambda.ml ../ocaml/bytecomp/printlambda.mli ../ocaml/bytecomp/switch.ml ../ocaml/bytecomp/switch.mli ../ocaml/bytecomp/translattribute.ml ../ocaml/bytecomp/translattribute.mli ../ocaml/bytecomp/translclass.ml ../ocaml/bytecomp/translclass.mli ../ocaml/bytecomp/translcore.ml ../ocaml/bytecomp/translcore.mli ../ocaml/bytecomp/translmod.ml ../ocaml/bytecomp/translmod.mli ../ocaml/bytecomp/translobj.ml ../ocaml/bytecomp/translobj.mli ../ocaml/driver/compenv.ml ../ocaml/driver/compenv.mli ../ocaml/driver/compmisc.ml ../ocaml/driver/compmisc.mli ../ocaml/parsing/ast_helper.ml ../ocaml/parsing/ast_helper.mli ../ocaml/parsing/ast_iterator.ml ../ocaml/parsing/ast_iterator.mli ../ocaml/parsing/ast_mapper.ml ../ocaml/parsing/ast_mapper.mli ../ocaml/parsing/asttypes.mli ../ocaml/parsing/attr_helper.ml ../ocaml/parsing/attr_helper.mli ../ocaml/parsing/builtin_attributes.ml ../ocaml/parsing/builtin_attributes.mli ../ocaml/parsing/docstrings.ml ../ocaml/parsing/docstrings.mli ../ocaml/parsing/lexer.ml ../ocaml/parsing/lexer.mli ../ocaml/parsing/location.ml ../ocaml/parsing/location.mli ../ocaml/parsing/longident.ml ../ocaml/parsing/longident.mli ../ocaml/parsing/parse.ml ../ocaml/parsing/parse.mli ../ocaml/parsing/parser.ml ../ocaml/parsing/parser.mli ../ocaml/parsing/parsetree.mli ../ocaml/parsing/syntaxerr.ml ../ocaml/parsing/syntaxerr.mli ../ocaml/typing/annot.mli ../ocaml/typing/btype.ml ../ocaml/typing/btype.mli ../ocaml/typing/cmi_format.ml ../ocaml/typing/cmi_format.mli ../ocaml/typing/cmt_format.ml ../ocaml/typing/cmt_format.mli ../ocaml/typing/ctype.ml ../ocaml/typing/ctype.mli ../ocaml/typing/datarepr.ml ../ocaml/typing/datarepr.mli ../ocaml/typing/env.ml ../ocaml/typing/env.mli ../ocaml/typing/ident.ml ../ocaml/typing/ident.mli ../ocaml/typing/includeclass.ml ../ocaml/typing/includeclass.mli ../ocaml/typing/includecore.ml ../ocaml/typing/includecore.mli ../ocaml/typing/includemod.ml ../ocaml/typing/includemod.mli ../ocaml/typing/mtype.ml ../ocaml/typing/mtype.mli ../ocaml/typing/oprint.ml ../ocaml/typing/oprint.mli ../ocaml/typing/outcometree.mli ../ocaml/typing/parmatch.ml ../ocaml/typing/parmatch.mli ../ocaml/typing/path.ml ../ocaml/typing/path.mli ../ocaml/typing/predef.ml ../ocaml/typing/predef.mli ../ocaml/typing/primitive.ml ../ocaml/typing/primitive.mli ../ocaml/typing/printtyp.ml ../ocaml/typing/printtyp.mli ../ocaml/typing/stypes.ml ../ocaml/typing/stypes.mli ../ocaml/typing/subst.ml ../ocaml/typing/subst.mli ../ocaml/typing/tast_mapper.ml ../ocaml/typing/tast_mapper.mli ../ocaml/typing/typeclass.ml ../ocaml/typing/typeclass.mli ../ocaml/typing/typecore.ml ../ocaml/typing/typecore.mli ../ocaml/typing/typedecl.ml ../ocaml/typing/typedecl.mli ../ocaml/typing/typedtree.ml ../ocaml/typing/typedtree.mli ../ocaml/typing/typedtreeIter.ml ../ocaml/typing/typedtreeIter.mli ../ocaml/typing/typemod.ml ../ocaml/typing/typemod.mli ../ocaml/typing/typeopt.ml ../ocaml/typing/typeopt.mli ../ocaml/typing/types.ml ../ocaml/typing/types.mli ../ocaml/typing/typetexp.ml ../ocaml/typing/typetexp.mli ../ocaml/typing/untypeast.ml ../ocaml/typing/untypeast.mli ../ocaml/utils/arg_helper.ml ../ocaml/utils/arg_helper.mli ../ocaml/utils/ccomp.ml ../ocaml/utils/ccomp.mli ../ocaml/utils/clflags.ml ../ocaml/utils/clflags.mli ../ocaml/utils/consistbl.ml ../ocaml/utils/consistbl.mli ../ocaml/utils/identifiable.ml ../ocaml/utils/identifiable.mli ../ocaml/utils/misc.ml ../ocaml/utils/misc.mli ../ocaml/utils/numbers.ml ../ocaml/utils/numbers.mli ../ocaml/utils/profile.ml ../ocaml/utils/profile.mli ../ocaml/utils/tbl.ml ../ocaml/utils/tbl.mli ../ocaml/utils/terminfo.ml ../ocaml/utils/terminfo.mli ../ocaml/utils/warnings.ml ../ocaml/utils/warnings.mli ./common/bs_loc.ml ./common/bs_loc.mli ./common/bs_version.ml ./common/bs_version.mli ./common/bs_warnings.ml ./common/bs_warnings.mli ./common/ext_log.ml ./common/ext_log.mli ./common/js_config.ml ./common/js_config.mli ./common/lam_methname.ml ./common/lam_methname.mli ./core/bs_conditional_initial.ml ./core/bs_conditional_initial.mli ./core/classify_function.ml ./core/classify_function.mli ./core/config_util.ml ./core/config_util.mli ./core/config_whole_compiler.ml ./core/config_whole_compiler.mli ./core/j.ml ./core/js_analyzer.ml ./core/js_analyzer.mli ./core/js_arr.ml ./core/js_arr.mli ./core/js_ast_util.ml ./core/js_ast_util.mli ./core/js_block_runtime.ml ./core/js_block_runtime.mli ./core/js_call_info.ml ./core/js_call_info.mli ./core/js_closure.ml ./core/js_closure.mli ./core/js_cmj_datasets.ml ./core/js_cmj_datasets.mli ./core/js_cmj_format.ml ./core/js_cmj_format.mli ./core/js_cmj_load.ml ./core/js_cmj_load.mli ./core/js_dump.ml ./core/js_dump.mli ./core/js_dump_import_export.ml ./core/js_dump_import_export.mli ./core/js_dump_lit.ml ./core/js_dump_program.ml ./core/js_dump_program.mli ./core/js_dump_property.ml ./core/js_dump_property.mli ./core/js_dump_string.ml ./core/js_dump_string.mli ./core/js_exp_make.ml ./core/js_exp_make.mli ./core/js_fold.ml ./core/js_fold_basic.ml ./core/js_fold_basic.mli ./core/js_fun_env.ml ./core/js_fun_env.mli ./core/js_long.ml ./core/js_long.mli ./core/js_map.ml ./core/js_name_of_module_id.ml ./core/js_name_of_module_id.mli ./core/js_number.ml ./core/js_number.mli ./core/js_of_lam_array.ml ./core/js_of_lam_array.mli ./core/js_of_lam_block.ml ./core/js_of_lam_block.mli ./core/js_of_lam_exception.ml ./core/js_of_lam_exception.mli ./core/js_of_lam_option.ml ./core/js_of_lam_option.mli ./core/js_of_lam_polyvar.ml ./core/js_of_lam_polyvar.mli ./core/js_of_lam_string.ml ./core/js_of_lam_string.mli ./core/js_of_lam_tuple.ml ./core/js_of_lam_tuple.mli ./core/js_of_lam_variant.ml ./core/js_of_lam_variant.mli ./core/js_op.ml ./core/js_op_util.ml ./core/js_op_util.mli ./core/js_output.ml ./core/js_output.mli ./core/js_packages_info.ml ./core/js_packages_info.mli ./core/js_packages_state.ml ./core/js_packages_state.mli ./core/js_pass_debug.ml ./core/js_pass_debug.mli ./core/js_pass_flatten.ml ./core/js_pass_flatten.mli ./core/js_pass_flatten_and_mark_dead.ml ./core/js_pass_flatten_and_mark_dead.mli ./core/js_pass_scope.ml ./core/js_pass_scope.mli ./core/js_pass_tailcall_inline.ml ./core/js_pass_tailcall_inline.mli ./core/js_raw_exp_info.ml ./core/js_shake.ml ./core/js_shake.mli ./core/js_stmt_make.ml ./core/js_stmt_make.mli ./core/lam.ml ./core/lam.mli ./core/lam_analysis.ml ./core/lam_analysis.mli ./core/lam_arity.ml ./core/lam_arity.mli ./core/lam_arity_analysis.ml ./core/lam_arity_analysis.mli ./core/lam_beta_reduce.ml ./core/lam_beta_reduce.mli ./core/lam_beta_reduce_util.ml ./core/lam_beta_reduce_util.mli ./core/lam_bounded_vars.ml ./core/lam_bounded_vars.mli ./core/lam_closure.ml ./core/lam_closure.mli ./core/lam_coercion.ml ./core/lam_coercion.mli ./core/lam_compat.ml ./core/lam_compat.mli ./core/lam_compile.ml ./core/lam_compile.mli ./core/lam_compile_const.ml ./core/lam_compile_const.mli ./core/lam_compile_context.ml ./core/lam_compile_context.mli ./core/lam_compile_env.ml ./core/lam_compile_env.mli ./core/lam_compile_external_call.ml ./core/lam_compile_external_call.mli ./core/lam_compile_external_obj.ml ./core/lam_compile_external_obj.mli ./core/lam_compile_main.ml ./core/lam_compile_main.mli ./core/lam_compile_primitive.ml ./core/lam_compile_primitive.mli ./core/lam_compile_util.ml ./core/lam_compile_util.mli ./core/lam_constant.ml ./core/lam_constant.mli ./core/lam_constant_convert.ml ./core/lam_constant_convert.mli ./core/lam_convert.ml ./core/lam_convert.mli ./core/lam_dce.ml ./core/lam_dce.mli ./core/lam_dispatch_primitive.ml ./core/lam_dispatch_primitive.mli ./core/lam_eta_conversion.ml ./core/lam_eta_conversion.mli ./core/lam_exit_code.ml ./core/lam_exit_code.mli ./core/lam_exit_count.ml ./core/lam_exit_count.mli ./core/lam_free_variables.ml ./core/lam_free_variables.mli ./core/lam_group.ml ./core/lam_group.mli ./core/lam_hit.ml ./core/lam_hit.mli ./core/lam_id_kind.ml ./core/lam_id_kind.mli ./core/lam_inline_util.ml ./core/lam_inline_util.mli ./core/lam_iter.ml ./core/lam_iter.mli ./core/lam_module_ident.ml ./core/lam_module_ident.mli ./core/lam_pass_alpha_conversion.ml ./core/lam_pass_alpha_conversion.mli ./core/lam_pass_collect.ml ./core/lam_pass_collect.mli ./core/lam_pass_count.ml ./core/lam_pass_count.mli ./core/lam_pass_deep_flatten.ml ./core/lam_pass_deep_flatten.mli ./core/lam_pass_eliminate_ref.ml ./core/lam_pass_eliminate_ref.mli ./core/lam_pass_exits.ml ./core/lam_pass_exits.mli ./core/lam_pass_lets_dce.ml ./core/lam_pass_lets_dce.mli ./core/lam_pass_remove_alias.ml ./core/lam_pass_remove_alias.mli ./core/lam_pointer_info.ml ./core/lam_pointer_info.mli ./core/lam_primitive.ml ./core/lam_primitive.mli ./core/lam_print.ml ./core/lam_print.mli ./core/lam_scc.ml ./core/lam_scc.mli ./core/lam_stats.ml ./core/lam_stats.mli ./core/lam_stats_export.ml ./core/lam_stats_export.mli ./core/lam_subst.ml ./core/lam_subst.mli ./core/lam_tag_info.ml ./core/lam_util.ml ./core/lam_util.mli ./core/lam_var_stats.ml ./core/lam_var_stats.mli ./core/matching_polyfill.ml ./core/matching_polyfill.mli ./core/primitive_compat.ml ./core/primitive_compat.mli ./core/record_attributes_check.ml ./depends/bs_exception.ml ./depends/bs_exception.mli ./ext/bsc_warnings.ml ./ext/ext_arg.ml ./ext/ext_arg.mli ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_fmt.ml ./ext/ext_ident.ml ./ext/ext_ident.mli ./ext/ext_int.ml ./ext/ext_int.mli ./ext/ext_json_parse.ml ./ext/ext_json_parse.mli ./ext/ext_json_types.ml ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_modulename.ml ./ext/ext_modulename.mli ./ext/ext_namespace.ml ./ext/ext_namespace.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_path.ml ./ext/ext_path.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_position.ml ./ext/ext_position.mli ./ext/ext_pp.ml ./ext/ext_pp.mli ./ext/ext_pp_scope.ml ./ext/ext_pp_scope.mli ./ext/ext_ref.ml ./ext/ext_ref.mli ./ext/ext_scc.ml ./ext/ext_scc.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_sys.ml ./ext/ext_sys.mli ./ext/ext_utf8.ml ./ext/ext_utf8.mli ./ext/ext_util.ml ./ext/ext_util.mli ./ext/hash.ml ./ext/hash.mli ./ext/hash_gen.ml ./ext/hash_ident.ml ./ext/hash_ident.mli ./ext/hash_int.ml ./ext/hash_int.mli ./ext/hash_set.ml ./ext/hash_set.mli ./ext/hash_set_gen.ml ./ext/hash_set_ident.ml ./ext/hash_set_ident.mli ./ext/hash_set_ident_mask.ml ./ext/hash_set_ident_mask.mli ./ext/hash_set_poly.ml ./ext/hash_set_poly.mli ./ext/hash_set_string.ml ./ext/hash_set_string.mli ./ext/hash_string.ml ./ext/hash_string.mli ./ext/int_vec_util.ml ./ext/int_vec_util.mli ./ext/int_vec_vec.ml ./ext/int_vec_vec.mli ./ext/js_reserved_map.ml ./ext/js_reserved_map.mli ./ext/js_runtime_modules.ml ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/map_ident.ml ./ext/map_ident.mli ./ext/map_int.ml ./ext/map_int.mli ./ext/map_string.ml ./ext/map_string.mli ./ext/ordered_hash_map_gen.ml ./ext/ordered_hash_map_local_ident.ml ./ext/ordered_hash_map_local_ident.mli ./ext/set_gen.ml ./ext/set_ident.ml ./ext/set_ident.mli ./ext/set_string.ml ./ext/set_string.mli ./ext/vec.ml ./ext/vec.mli ./ext/vec_gen.ml ./ext/vec_int.ml ./ext/vec_int.mli ./main/jsoo_common.ml ./main/jsoo_common.mli ./main/jsoo_main.ml ./main/jsoo_main.mli ./outcome_printer/outcome_printer_ns.ml ./outcome_printer/outcome_printer_ns.mli ./stubs/bs_hash_stubs.ml ./super_errors/super_env.ml ./super_errors/super_location.ml ./super_errors/super_main.ml ./super_errors/super_misc.ml ./super_errors/super_misc.mli ./super_errors/super_pparse.ml ./super_errors/super_reason_react.ml ./super_errors/super_reason_react.mli ./super_errors/super_typecore.ml ./super_errors/super_typemod.ml ./super_errors/super_typetexp.ml ./super_errors/super_warnings.ml ./syntax/ast_attributes.ml ./syntax/ast_attributes.mli ./syntax/ast_bs_open.ml ./syntax/ast_bs_open.mli ./syntax/ast_comb.ml ./syntax/ast_comb.mli ./syntax/ast_compatible.ml ./syntax/ast_compatible.mli ./syntax/ast_core_type.ml ./syntax/ast_core_type.mli ./syntax/ast_core_type_class_type.ml ./syntax/ast_core_type_class_type.mli ./syntax/ast_derive.ml ./syntax/ast_derive.mli ./syntax/ast_derive_abstract.ml ./syntax/ast_derive_abstract.mli ./syntax/ast_derive_js_mapper.ml ./syntax/ast_derive_js_mapper.mli ./syntax/ast_derive_projector.ml ./syntax/ast_derive_projector.mli ./syntax/ast_derive_util.ml ./syntax/ast_derive_util.mli ./syntax/ast_exp.ml ./syntax/ast_exp.mli ./syntax/ast_exp_apply.ml ./syntax/ast_exp_apply.mli ./syntax/ast_exp_extension.ml ./syntax/ast_exp_extension.mli ./syntax/ast_external.ml ./syntax/ast_external.mli ./syntax/ast_external_mk.ml ./syntax/ast_external_mk.mli ./syntax/ast_external_process.ml ./syntax/ast_external_process.mli ./syntax/ast_literal.ml ./syntax/ast_literal.mli ./syntax/ast_open_cxt.ml ./syntax/ast_open_cxt.mli ./syntax/ast_pat.ml ./syntax/ast_pat.mli ./syntax/ast_payload.ml ./syntax/ast_payload.mli ./syntax/ast_polyvar.ml ./syntax/ast_polyvar.mli ./syntax/ast_raw.ml ./syntax/ast_raw.mli ./syntax/ast_reason_pp.ml ./syntax/ast_reason_pp.mli ./syntax/ast_signature.ml ./syntax/ast_signature.mli ./syntax/ast_structure.ml ./syntax/ast_structure.mli ./syntax/ast_tdcls.ml ./syntax/ast_tdcls.mli ./syntax/ast_tuple_pattern_flatten.ml ./syntax/ast_tuple_pattern_flatten.mli ./syntax/ast_utf8_string.ml ./syntax/ast_utf8_string.mli ./syntax/ast_utf8_string_interp.ml ./syntax/ast_utf8_string_interp.mli ./syntax/ast_util.ml ./syntax/ast_util.mli ./syntax/bs_ast_invariant.ml ./syntax/bs_ast_invariant.mli ./syntax/bs_ast_mapper.ml ./syntax/bs_ast_mapper.mli ./syntax/bs_builtin_ppx.ml ./syntax/bs_builtin_ppx.mli ./syntax/bs_syntaxerr.ml ./syntax/bs_syntaxerr.mli ./syntax/external_arg_spec.ml ./syntax/external_arg_spec.mli ./syntax/external_ffi_types.ml ./syntax/external_ffi_types.mli ./syntax/reactjs_jsx_ppx_v2.ml ./syntax/reactjs_jsx_ppx_v3.ml \ No newline at end of file +../lib/4.06.1/unstable/js_compiler.ml: ../ocaml/bytecomp/lambda.ml ../ocaml/bytecomp/lambda.mli ../ocaml/bytecomp/matching.ml ../ocaml/bytecomp/matching.mli ../ocaml/bytecomp/printlambda.ml ../ocaml/bytecomp/printlambda.mli ../ocaml/bytecomp/switch.ml ../ocaml/bytecomp/switch.mli ../ocaml/bytecomp/translattribute.ml ../ocaml/bytecomp/translattribute.mli ../ocaml/bytecomp/translclass.ml ../ocaml/bytecomp/translclass.mli ../ocaml/bytecomp/translcore.ml ../ocaml/bytecomp/translcore.mli ../ocaml/bytecomp/translmod.ml ../ocaml/bytecomp/translmod.mli ../ocaml/bytecomp/translobj.ml ../ocaml/bytecomp/translobj.mli ../ocaml/driver/compenv.ml ../ocaml/driver/compenv.mli ../ocaml/driver/compmisc.ml ../ocaml/driver/compmisc.mli ../ocaml/parsing/ast_helper.ml ../ocaml/parsing/ast_helper.mli ../ocaml/parsing/ast_iterator.ml ../ocaml/parsing/ast_iterator.mli ../ocaml/parsing/ast_mapper.ml ../ocaml/parsing/ast_mapper.mli ../ocaml/parsing/asttypes.mli ../ocaml/parsing/attr_helper.ml ../ocaml/parsing/attr_helper.mli ../ocaml/parsing/builtin_attributes.ml ../ocaml/parsing/builtin_attributes.mli ../ocaml/parsing/docstrings.ml ../ocaml/parsing/docstrings.mli ../ocaml/parsing/lexer.ml ../ocaml/parsing/lexer.mli ../ocaml/parsing/location.ml ../ocaml/parsing/location.mli ../ocaml/parsing/longident.ml ../ocaml/parsing/longident.mli ../ocaml/parsing/parse.ml ../ocaml/parsing/parse.mli ../ocaml/parsing/parser.ml ../ocaml/parsing/parser.mli ../ocaml/parsing/parsetree.mli ../ocaml/parsing/syntaxerr.ml ../ocaml/parsing/syntaxerr.mli ../ocaml/typing/annot.mli ../ocaml/typing/btype.ml ../ocaml/typing/btype.mli ../ocaml/typing/cmi_format.ml ../ocaml/typing/cmi_format.mli ../ocaml/typing/cmt_format.ml ../ocaml/typing/cmt_format.mli ../ocaml/typing/ctype.ml ../ocaml/typing/ctype.mli ../ocaml/typing/datarepr.ml ../ocaml/typing/datarepr.mli ../ocaml/typing/env.ml ../ocaml/typing/env.mli ../ocaml/typing/ident.ml ../ocaml/typing/ident.mli ../ocaml/typing/includeclass.ml ../ocaml/typing/includeclass.mli ../ocaml/typing/includecore.ml ../ocaml/typing/includecore.mli ../ocaml/typing/includemod.ml ../ocaml/typing/includemod.mli ../ocaml/typing/mtype.ml ../ocaml/typing/mtype.mli ../ocaml/typing/oprint.ml ../ocaml/typing/oprint.mli ../ocaml/typing/outcometree.mli ../ocaml/typing/parmatch.ml ../ocaml/typing/parmatch.mli ../ocaml/typing/path.ml ../ocaml/typing/path.mli ../ocaml/typing/predef.ml ../ocaml/typing/predef.mli ../ocaml/typing/primitive.ml ../ocaml/typing/primitive.mli ../ocaml/typing/printtyp.ml ../ocaml/typing/printtyp.mli ../ocaml/typing/stypes.ml ../ocaml/typing/stypes.mli ../ocaml/typing/subst.ml ../ocaml/typing/subst.mli ../ocaml/typing/tast_mapper.ml ../ocaml/typing/tast_mapper.mli ../ocaml/typing/typeclass.ml ../ocaml/typing/typeclass.mli ../ocaml/typing/typecore.ml ../ocaml/typing/typecore.mli ../ocaml/typing/typedecl.ml ../ocaml/typing/typedecl.mli ../ocaml/typing/typedtree.ml ../ocaml/typing/typedtree.mli ../ocaml/typing/typedtreeIter.ml ../ocaml/typing/typedtreeIter.mli ../ocaml/typing/typemod.ml ../ocaml/typing/typemod.mli ../ocaml/typing/typeopt.ml ../ocaml/typing/typeopt.mli ../ocaml/typing/types.ml ../ocaml/typing/types.mli ../ocaml/typing/typetexp.ml ../ocaml/typing/typetexp.mli ../ocaml/typing/untypeast.ml ../ocaml/typing/untypeast.mli ../ocaml/utils/arg_helper.ml ../ocaml/utils/arg_helper.mli ../ocaml/utils/ccomp.ml ../ocaml/utils/ccomp.mli ../ocaml/utils/clflags.ml ../ocaml/utils/clflags.mli ../ocaml/utils/consistbl.ml ../ocaml/utils/consistbl.mli ../ocaml/utils/identifiable.ml ../ocaml/utils/identifiable.mli ../ocaml/utils/misc.ml ../ocaml/utils/misc.mli ../ocaml/utils/numbers.ml ../ocaml/utils/numbers.mli ../ocaml/utils/profile.ml ../ocaml/utils/profile.mli ../ocaml/utils/tbl.ml ../ocaml/utils/tbl.mli ../ocaml/utils/terminfo.ml ../ocaml/utils/terminfo.mli ../ocaml/utils/warnings.ml ../ocaml/utils/warnings.mli ./common/bs_loc.ml ./common/bs_loc.mli ./common/bs_version.ml ./common/bs_version.mli ./common/bs_warnings.ml ./common/bs_warnings.mli ./common/ext_log.ml ./common/ext_log.mli ./common/js_config.ml ./common/js_config.mli ./common/lam_methname.ml ./common/lam_methname.mli ./core/bs_conditional_initial.ml ./core/bs_conditional_initial.mli ./core/classify_function.ml ./core/classify_function.mli ./core/config_util.ml ./core/config_util.mli ./core/config_whole_compiler.ml ./core/config_whole_compiler.mli ./core/j.ml ./core/js_analyzer.ml ./core/js_analyzer.mli ./core/js_arr.ml ./core/js_arr.mli ./core/js_ast_util.ml ./core/js_ast_util.mli ./core/js_block_runtime.ml ./core/js_block_runtime.mli ./core/js_call_info.ml ./core/js_call_info.mli ./core/js_closure.ml ./core/js_closure.mli ./core/js_cmj_datasets.ml ./core/js_cmj_datasets.mli ./core/js_cmj_format.ml ./core/js_cmj_format.mli ./core/js_cmj_load.ml ./core/js_cmj_load.mli ./core/js_current_package_info.ml ./core/js_current_package_info.mli ./core/js_dump.ml ./core/js_dump.mli ./core/js_dump_import_export.ml ./core/js_dump_import_export.mli ./core/js_dump_lit.ml ./core/js_dump_program.ml ./core/js_dump_program.mli ./core/js_dump_property.ml ./core/js_dump_property.mli ./core/js_dump_string.ml ./core/js_dump_string.mli ./core/js_exp_make.ml ./core/js_exp_make.mli ./core/js_fold.ml ./core/js_fold_basic.ml ./core/js_fold_basic.mli ./core/js_fun_env.ml ./core/js_fun_env.mli ./core/js_long.ml ./core/js_long.mli ./core/js_map.ml ./core/js_name_of_module_id.ml ./core/js_name_of_module_id.mli ./core/js_number.ml ./core/js_number.mli ./core/js_of_lam_array.ml ./core/js_of_lam_array.mli ./core/js_of_lam_block.ml ./core/js_of_lam_block.mli ./core/js_of_lam_exception.ml ./core/js_of_lam_exception.mli ./core/js_of_lam_option.ml ./core/js_of_lam_option.mli ./core/js_of_lam_polyvar.ml ./core/js_of_lam_polyvar.mli ./core/js_of_lam_string.ml ./core/js_of_lam_string.mli ./core/js_of_lam_tuple.ml ./core/js_of_lam_tuple.mli ./core/js_of_lam_variant.ml ./core/js_of_lam_variant.mli ./core/js_op.ml ./core/js_op_util.ml ./core/js_op_util.mli ./core/js_output.ml ./core/js_output.mli ./core/js_package_info.ml ./core/js_package_info.mli ./core/js_pass_debug.ml ./core/js_pass_debug.mli ./core/js_pass_flatten.ml ./core/js_pass_flatten.mli ./core/js_pass_flatten_and_mark_dead.ml ./core/js_pass_flatten_and_mark_dead.mli ./core/js_pass_scope.ml ./core/js_pass_scope.mli ./core/js_pass_tailcall_inline.ml ./core/js_pass_tailcall_inline.mli ./core/js_raw_exp_info.ml ./core/js_shake.ml ./core/js_shake.mli ./core/js_stmt_make.ml ./core/js_stmt_make.mli ./core/lam.ml ./core/lam.mli ./core/lam_analysis.ml ./core/lam_analysis.mli ./core/lam_arity.ml ./core/lam_arity.mli ./core/lam_arity_analysis.ml ./core/lam_arity_analysis.mli ./core/lam_beta_reduce.ml ./core/lam_beta_reduce.mli ./core/lam_beta_reduce_util.ml ./core/lam_beta_reduce_util.mli ./core/lam_bounded_vars.ml ./core/lam_bounded_vars.mli ./core/lam_closure.ml ./core/lam_closure.mli ./core/lam_coercion.ml ./core/lam_coercion.mli ./core/lam_compat.ml ./core/lam_compat.mli ./core/lam_compile.ml ./core/lam_compile.mli ./core/lam_compile_const.ml ./core/lam_compile_const.mli ./core/lam_compile_context.ml ./core/lam_compile_context.mli ./core/lam_compile_env.ml ./core/lam_compile_env.mli ./core/lam_compile_external_call.ml ./core/lam_compile_external_call.mli ./core/lam_compile_external_obj.ml ./core/lam_compile_external_obj.mli ./core/lam_compile_main.ml ./core/lam_compile_main.mli ./core/lam_compile_primitive.ml ./core/lam_compile_primitive.mli ./core/lam_compile_util.ml ./core/lam_compile_util.mli ./core/lam_constant.ml ./core/lam_constant.mli ./core/lam_constant_convert.ml ./core/lam_constant_convert.mli ./core/lam_convert.ml ./core/lam_convert.mli ./core/lam_dce.ml ./core/lam_dce.mli ./core/lam_dispatch_primitive.ml ./core/lam_dispatch_primitive.mli ./core/lam_eta_conversion.ml ./core/lam_eta_conversion.mli ./core/lam_exit_code.ml ./core/lam_exit_code.mli ./core/lam_exit_count.ml ./core/lam_exit_count.mli ./core/lam_free_variables.ml ./core/lam_free_variables.mli ./core/lam_group.ml ./core/lam_group.mli ./core/lam_hit.ml ./core/lam_hit.mli ./core/lam_id_kind.ml ./core/lam_id_kind.mli ./core/lam_inline_util.ml ./core/lam_inline_util.mli ./core/lam_iter.ml ./core/lam_iter.mli ./core/lam_module_ident.ml ./core/lam_module_ident.mli ./core/lam_pass_alpha_conversion.ml ./core/lam_pass_alpha_conversion.mli ./core/lam_pass_collect.ml ./core/lam_pass_collect.mli ./core/lam_pass_count.ml ./core/lam_pass_count.mli ./core/lam_pass_deep_flatten.ml ./core/lam_pass_deep_flatten.mli ./core/lam_pass_eliminate_ref.ml ./core/lam_pass_eliminate_ref.mli ./core/lam_pass_exits.ml ./core/lam_pass_exits.mli ./core/lam_pass_lets_dce.ml ./core/lam_pass_lets_dce.mli ./core/lam_pass_remove_alias.ml ./core/lam_pass_remove_alias.mli ./core/lam_pointer_info.ml ./core/lam_pointer_info.mli ./core/lam_primitive.ml ./core/lam_primitive.mli ./core/lam_print.ml ./core/lam_print.mli ./core/lam_scc.ml ./core/lam_scc.mli ./core/lam_stats.ml ./core/lam_stats.mli ./core/lam_stats_export.ml ./core/lam_stats_export.mli ./core/lam_subst.ml ./core/lam_subst.mli ./core/lam_tag_info.ml ./core/lam_util.ml ./core/lam_util.mli ./core/lam_var_stats.ml ./core/lam_var_stats.mli ./core/matching_polyfill.ml ./core/matching_polyfill.mli ./core/primitive_compat.ml ./core/primitive_compat.mli ./core/record_attributes_check.ml ./depends/bs_exception.ml ./depends/bs_exception.mli ./ext/bsc_warnings.ml ./ext/ext_arg.ml ./ext/ext_arg.mli ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_fmt.ml ./ext/ext_ident.ml ./ext/ext_ident.mli ./ext/ext_int.ml ./ext/ext_int.mli ./ext/ext_json_parse.ml ./ext/ext_json_parse.mli ./ext/ext_json_types.ml ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_modulename.ml ./ext/ext_modulename.mli ./ext/ext_namespace.ml ./ext/ext_namespace.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_path.ml ./ext/ext_path.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_position.ml ./ext/ext_position.mli ./ext/ext_pp.ml ./ext/ext_pp.mli ./ext/ext_pp_scope.ml ./ext/ext_pp_scope.mli ./ext/ext_ref.ml ./ext/ext_ref.mli ./ext/ext_scc.ml ./ext/ext_scc.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_sys.ml ./ext/ext_sys.mli ./ext/ext_utf8.ml ./ext/ext_utf8.mli ./ext/ext_util.ml ./ext/ext_util.mli ./ext/hash.ml ./ext/hash.mli ./ext/hash_gen.ml ./ext/hash_ident.ml ./ext/hash_ident.mli ./ext/hash_int.ml ./ext/hash_int.mli ./ext/hash_set.ml ./ext/hash_set.mli ./ext/hash_set_gen.ml ./ext/hash_set_ident.ml ./ext/hash_set_ident.mli ./ext/hash_set_ident_mask.ml ./ext/hash_set_ident_mask.mli ./ext/hash_set_poly.ml ./ext/hash_set_poly.mli ./ext/hash_set_string.ml ./ext/hash_set_string.mli ./ext/hash_string.ml ./ext/hash_string.mli ./ext/int_vec_util.ml ./ext/int_vec_util.mli ./ext/int_vec_vec.ml ./ext/int_vec_vec.mli ./ext/js_reserved_map.ml ./ext/js_reserved_map.mli ./ext/js_runtime_modules.ml ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/map_ident.ml ./ext/map_ident.mli ./ext/map_int.ml ./ext/map_int.mli ./ext/map_string.ml ./ext/map_string.mli ./ext/ordered_hash_map_gen.ml ./ext/ordered_hash_map_local_ident.ml ./ext/ordered_hash_map_local_ident.mli ./ext/set_gen.ml ./ext/set_ident.ml ./ext/set_ident.mli ./ext/set_string.ml ./ext/set_string.mli ./ext/vec.ml ./ext/vec.mli ./ext/vec_gen.ml ./ext/vec_int.ml ./ext/vec_int.mli ./main/jsoo_common.ml ./main/jsoo_common.mli ./main/jsoo_main.ml ./main/jsoo_main.mli ./outcome_printer/outcome_printer_ns.ml ./outcome_printer/outcome_printer_ns.mli ./stubs/bs_hash_stubs.ml ./super_errors/super_env.ml ./super_errors/super_location.ml ./super_errors/super_main.ml ./super_errors/super_misc.ml ./super_errors/super_misc.mli ./super_errors/super_pparse.ml ./super_errors/super_reason_react.ml ./super_errors/super_reason_react.mli ./super_errors/super_typecore.ml ./super_errors/super_typemod.ml ./super_errors/super_typetexp.ml ./super_errors/super_warnings.ml ./syntax/ast_attributes.ml ./syntax/ast_attributes.mli ./syntax/ast_bs_open.ml ./syntax/ast_bs_open.mli ./syntax/ast_comb.ml ./syntax/ast_comb.mli ./syntax/ast_compatible.ml ./syntax/ast_compatible.mli ./syntax/ast_core_type.ml ./syntax/ast_core_type.mli ./syntax/ast_core_type_class_type.ml ./syntax/ast_core_type_class_type.mli ./syntax/ast_derive.ml ./syntax/ast_derive.mli ./syntax/ast_derive_abstract.ml ./syntax/ast_derive_abstract.mli ./syntax/ast_derive_js_mapper.ml ./syntax/ast_derive_js_mapper.mli ./syntax/ast_derive_projector.ml ./syntax/ast_derive_projector.mli ./syntax/ast_derive_util.ml ./syntax/ast_derive_util.mli ./syntax/ast_exp.ml ./syntax/ast_exp.mli ./syntax/ast_exp_apply.ml ./syntax/ast_exp_apply.mli ./syntax/ast_exp_extension.ml ./syntax/ast_exp_extension.mli ./syntax/ast_external.ml ./syntax/ast_external.mli ./syntax/ast_external_mk.ml ./syntax/ast_external_mk.mli ./syntax/ast_external_process.ml ./syntax/ast_external_process.mli ./syntax/ast_literal.ml ./syntax/ast_literal.mli ./syntax/ast_open_cxt.ml ./syntax/ast_open_cxt.mli ./syntax/ast_pat.ml ./syntax/ast_pat.mli ./syntax/ast_payload.ml ./syntax/ast_payload.mli ./syntax/ast_polyvar.ml ./syntax/ast_polyvar.mli ./syntax/ast_raw.ml ./syntax/ast_raw.mli ./syntax/ast_reason_pp.ml ./syntax/ast_reason_pp.mli ./syntax/ast_signature.ml ./syntax/ast_signature.mli ./syntax/ast_structure.ml ./syntax/ast_structure.mli ./syntax/ast_tdcls.ml ./syntax/ast_tdcls.mli ./syntax/ast_tuple_pattern_flatten.ml ./syntax/ast_tuple_pattern_flatten.mli ./syntax/ast_utf8_string.ml ./syntax/ast_utf8_string.mli ./syntax/ast_utf8_string_interp.ml ./syntax/ast_utf8_string_interp.mli ./syntax/ast_util.ml ./syntax/ast_util.mli ./syntax/bs_ast_invariant.ml ./syntax/bs_ast_invariant.mli ./syntax/bs_ast_mapper.ml ./syntax/bs_ast_mapper.mli ./syntax/bs_builtin_ppx.ml ./syntax/bs_builtin_ppx.mli ./syntax/bs_syntaxerr.ml ./syntax/bs_syntaxerr.mli ./syntax/external_arg_spec.ml ./syntax/external_arg_spec.mli ./syntax/external_ffi_types.ml ./syntax/external_ffi_types.mli ./syntax/reactjs_jsx_ppx_v2.ml ./syntax/reactjs_jsx_ppx_v3.ml \ No newline at end of file diff --git a/lib/4.06.1/unstable/js_refmt_compiler.ml b/lib/4.06.1/unstable/js_refmt_compiler.ml index 0dc16208b5..acae7cf6f8 100644 --- a/lib/4.06.1/unstable/js_refmt_compiler.ml +++ b/lib/4.06.1/unstable/js_refmt_compiler.ml @@ -14151,15 +14151,13 @@ module Js_config : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* val get_packages_info : unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) (** return [package_name] and [path] when in script mode: *) -(* val get_current_package_name_and_path : Js_packages_info.module_system -> - Js_packages_info.info_query *) +(* val get_current_package_name_and_path : Js_package_info.module_system -> + Js_package_info.info_query *) (* val set_package_name : string -> unit val get_package_name : unit -> string option *) @@ -14200,7 +14198,6 @@ val syntax_only : bool ref val binary_ast : bool ref val simple_binary_ast : bool ref -val bs_suffix : bool ref val debug : bool ref val cmi_only : bool ref @@ -14257,8 +14254,6 @@ let set_diagnose b = diagnose := b let ( // ) = Filename.concat -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx_ml = ref false let no_builtin_ppx_mli = ref false @@ -14306,7 +14301,7 @@ end module Bs_warnings : sig #1 "bs_warnings.mli" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -14324,29 +14319,27 @@ module Bs_warnings : sig * 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. *) - -type t = - | Unsafe_poly_variant_type +type t = Unsafe_poly_variant_type val prerr_bs_ffi_warning : Location.t -> t -> unit +val warn_deprecated_bs_suffix_flag : unit -> unit -val warn_missing_primitive : Location.t -> string -> unit +val warn_missing_primitive : Location.t -> string -> unit -val warn_literal_overflow : Location.t -> unit +val warn_literal_overflow : Location.t -> unit -val error_unescaped_delimiter : - Location.t -> string -> unit +val error_unescaped_delimiter : Location.t -> string -> unit end = struct #1 "bs_warnings.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -14364,117 +14357,106 @@ end = struct * 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. *) - - type t = | Unsafe_poly_variant_type - (* for users write code like this: - {[ external f : [`a of int ] -> string = ""]} - Here users forget about `[@bs.string]` or `[@bs.int]` - *) + (** for users write code like this: + {[ external f : [ `a of int ] -> string = "" ]} + Here users forget about `[@bs.string]` or `[@bs.int]` *) let to_string t = match t with - | Unsafe_poly_variant_type - -> - "Here a OCaml polymorphic variant type passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]` " + | Unsafe_poly_variant_type -> + "Here a OCaml polymorphic variant type passed into JS, probably you \ + forgot annotations like `[@bs.int]` or `[@bs.string]` " + let warning_formatter = Format.err_formatter -let print_string_warning (loc : Location.t) x = - if loc.loc_ghost then - Format.fprintf warning_formatter "File %s@." !Location.input_name - else - Location.print warning_formatter loc ; - Format.fprintf warning_formatter "@{Warning@}: %s@." x +let print_string_warning (loc : Location.t) ?(kind = "Warning") x = + if loc.loc_ghost then + Format.fprintf warning_formatter "File %s@." !Location.input_name + else Location.print warning_formatter loc; + Format.fprintf warning_formatter "@{%s@}: %s@." kind x -let prerr_bs_ffi_warning loc x = - Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) -let unimplemented_primitive = "Unimplemented primitive used:" -type error = +let prerr_bs_ffi_warning loc x = + Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) + + +let unimplemented_primitive = "Unimplemented primitive used:" +type error = | Uninterpreted_delimiters of string - | Unimplemented_primitive of string -exception Error of Location.t * error + | Unimplemented_primitive of string +exception Error of Location.t * error let pp_error fmt x = - match x with - | Unimplemented_primitive str -> - Format.pp_print_string fmt unimplemented_primitive; - Format.pp_print_string fmt str - - | Uninterpreted_delimiters str -> - Format.pp_print_string fmt "Uninterpreted delimiters" ; - Format.pp_print_string fmt str + match x with + | Unimplemented_primitive str -> + Format.pp_print_string fmt unimplemented_primitive; + Format.pp_print_string fmt str + | Uninterpreted_delimiters str -> + Format.pp_print_string fmt "Uninterpreted delimiters"; + Format.pp_print_string fmt str +let () = + Location.register_error_of_exn (function + | Error (loc, err) -> Some (Location.error_of_printer loc pp_error err) + | _ -> None) -let () = - Location.register_error_of_exn (function - | Error (loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) +let warn_deprecated_bs_suffix_flag () = + if not !Clflags.bs_quiet then ( + print_string_warning Location.none ~kind:"DEPRECATED" + "`-bs-suffix` used; consider using third field of `-bs-package-output` \ + instead"; + Format.pp_print_flush warning_formatter () ) +let warn_missing_primitive loc txt = + if (not !Js_config.no_warn_unimplemented_external) && not !Clflags.bs_quiet + then ( + print_string_warning loc (unimplemented_primitive ^ txt ^ " \n"); + Format.pp_print_flush warning_formatter () ) -let warn_missing_primitive loc txt = - if not !Js_config.no_warn_unimplemented_external && not !Clflags.bs_quiet then - begin - print_string_warning loc ( unimplemented_primitive ^ txt ^ " \n" ); - Format.pp_print_flush warning_formatter () - end -let warn_literal_overflow loc = - if not !Clflags.bs_quiet then - begin - print_string_warning loc +let warn_literal_overflow loc = + if not !Clflags.bs_quiet then ( + print_string_warning loc "Integer literal exceeds the range of representable integers of type int"; - Format.pp_print_flush warning_formatter () - end - + Format.pp_print_flush warning_formatter () ) -let error_unescaped_delimiter loc txt = - raise (Error(loc, Uninterpreted_delimiters txt)) +let error_unescaped_delimiter loc txt = + raise (Error (loc, Uninterpreted_delimiters txt)) +(** Note the standard way of reporting error in compiler: + val Location.register_error_of_exn : (exn -> Location.error option) -> unit + val Location.error_of_printer : Location.t -> (Format.formatter -> error -> + unit) -> error -> Location.error + Define an error type + type error exception Error of Location.t * error -(** - Note the standard way of reporting error in compiler: - - val Location.register_error_of_exn : (exn -> Location.error option) -> unit - val Location.error_of_printer : Location.t -> - (Format.formatter -> error -> unit) -> error -> Location.error - - Define an error type + Provide a printer to error - type error - exception Error of Location.t * error - - Provide a printer to error - - {[ - let () = - Location.register_error_of_exn - (function - | Error(loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) - ]} -*) + {[ + let () = + Location.register_error_of_exn (function + | Error (loc, err) -> + Some (Location.error_of_printer loc pp_error err) + | _ -> None) + ]} *) end module Ext_util : sig @@ -15178,7 +15160,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -15316,8 +15302,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" @@ -75486,14 +75477,18 @@ val make : ?ns:string -> string -> string val try_split_module_name : string -> (string * string) option -val change_ext_ns_suffix : string -> string -> string +val replace_namespace_with_extension : name:string -> ext:string -> string +(** [replace_namespace_with_extension ~name ~ext] removes the part of [name] + after [ns_sep_char], if any; and appends [ext]. +*) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -val js_name_of_modulename : string -> file_kind -> string +val js_filename_of_modulename : + name:string -> ext:string -> leading_case -> string (** Predicts the JavaScript filename for a given (possibly namespaced) module- - name; i.e. [js_name_of_modulename "AA-Ns" Little_bs] would produce - ["aA.bs.js"]. *) + name; i.e. [js_filename_of_modulename ~name:"AA-Ns" ~ext:".js" Lower] would + produce ["aA.bs.js"]. *) val is_valid_npm_package_name : string -> bool @@ -75556,7 +75551,7 @@ let rec rindex_rec s i = #1933 when removing ns suffix, don't pass the bound of basename FIXME: micro-optimizaiton *) -let change_ext_ns_suffix name ext = +let replace_namespace_with_extension ~name ~ext = let i = rindex_rec name (String.length name - 1) in if i < 0 then name ^ ext else String.sub name 0 i ^ ext @@ -75568,18 +75563,15 @@ let try_split_module_name name = else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -let js_name_of_modulename s little = - match little with - | Little_js -> - change_ext_ns_suffix (Ext_string.uncapitalize_ascii s) Literals.suffix_js - | Little_bs -> - change_ext_ns_suffix - (Ext_string.uncapitalize_ascii s) - Literals.suffix_bs_js - | Upper_js -> change_ext_ns_suffix s Literals.suffix_js - | Upper_bs -> change_ext_ns_suffix s Literals.suffix_bs_js +let js_filename_of_modulename ~name ~ext (leading_case : leading_case) = + match leading_case with + | Lower -> + replace_namespace_with_extension + ~name:(Ext_string.uncapitalize_ascii name) + ~ext + | Upper -> replace_namespace_with_extension ~name ~ext (** https://docs.npmjs.com/files/package.json @@ -90378,8 +90370,8 @@ end = struct #1 "ext_arg.ml" let bad_argf fmt = Format.ksprintf (fun x -> raise (Arg.Bad x ) ) fmt end -module Js_packages_info : sig -#1 "js_packages_info.mli" +module Js_package_info : sig +#1 "js_package_info.mli" (* Copyright (C) 2017 Authors of BuckleScript * * This program is free software: you can redistribute it and/or modify @@ -90410,7 +90402,11 @@ val runtime_dir_of_module_system : module_system -> string val runtime_package_path : module_system -> string -> string -type package_info = { module_system : module_system; path : string } +type location_descriptor = { + module_system : module_system; + path : string; + extension : string; +} type t @@ -90418,32 +90414,38 @@ val is_runtime_package : t -> bool val same_package_by_name : t -> t -> bool -val iter : t -> (package_info -> unit) -> unit +val iter : t -> (location_descriptor -> unit) -> unit val empty : t val from_name : string -> t val is_empty : t -> bool -val dump_packages_info : Format.formatter -> t -> unit +val dump_package_info : Format.formatter -> t -> unit + +val deprecated_set_bs_extension : unit -> unit -val add_npm_package_path : t -> string -> t -(** used by command line option e.g [-bs-package-output commonjs:xx/path] *) +val append_location_descriptor_of_string : t -> string -> t +(** used by command line option e.g [-bs-package-output commonjs:xx/path:ext] *) -type package_found_info = { rel_path : string; pkg_rel_path : string } +type package_paths = { + rel_path : string; + pkg_rel_path : string; + extension : string; +} -type info_query = +type query_result = | Package_script | Package_not_found - | Package_found of package_found_info + | Package_found of package_paths val get_output_dir : t -> package_dir:string -> module_system -> string (* Note here we compare the package info by order in theory, we can compare it by set semantics *) -val query_package_infos : t -> module_system -> info_query +val query_package_location_by_module_system : t -> module_system -> query_result end = struct -#1 "js_packages_info.ml" +#1 "js_package_info.ml" (* Copyright (C) 2017 Authors of BuckleScript * * This program is free software: you can redistribute it and/or modify @@ -90487,10 +90489,16 @@ let compatible (dep : module_system) (query : module_system) = | Es6_global -> dep = Es6_global || dep = Es6 -type package_info = { module_system : module_system; path : string } +type location_descriptor = { + module_system : module_system; + path : string; + extension : string; +} type package_name = Pkg_empty | Pkg_runtime | Pkg_normal of string +let deprecated_use_bs_extension = ref false + let runtime_package_name = "bs-platform" let ( // ) = Filename.concat @@ -90506,23 +90514,22 @@ let runtime_package_path (ms : module_system) js_file = runtime_package_name // "lib" // runtime_dir_of_module_system ms // js_file -type t = { name : package_name; module_systems : package_info list } +type t = { name : package_name; locations : location_descriptor list } let same_package_by_name (x : t) (y : t) = x.name = y.name let is_runtime_package (x : t) = x.name = Pkg_runtime -let iter (x : t) cb = Ext_list.iter x.module_systems cb +let iter (x : t) = Ext_list.iter x.locations (* TODO: not allowing user to provide such specific package name For empty package, [-bs-package-output] does not make sense it is only allowed to generate commonjs file in the same directory *) -let empty : t = { name = Pkg_empty; module_systems = [] } +let empty : t = { name = Pkg_empty; locations = [] } let from_name (name : string) = - if name = runtime_package_name then - { name = Pkg_runtime; module_systems = [] } - else { name = Pkg_normal name; module_systems = [] } + if name = runtime_package_name then { name = Pkg_runtime; locations = [] } + else { name = Pkg_normal name; locations = [] } let is_empty (x : t) = x.name = Pkg_empty @@ -90542,9 +90549,11 @@ let module_system_of_string package_name : module_system option = | _ -> None -let dump_package_info (fmt : Format.formatter) - ({ module_system = ms; path = name } : package_info) = - Format.fprintf fmt "@[%s:@ %s@]" (string_of_module_system ms) name +let dump_location_descriptor (fmt : Format.formatter) + { module_system = ms; path; extension } = + Format.fprintf fmt "@[%s:@ %s:@ %s@]" + (string_of_module_system ms) + path extension let dump_package_name fmt (x : package_name) = @@ -90554,52 +90563,53 @@ let dump_package_name fmt (x : package_name) = | Pkg_runtime -> Format.pp_print_string fmt runtime_package_name -let dump_packages_info (fmt : Format.formatter) - ({ name; module_systems = ls } : t) = +let dump_package_info (fmt : Format.formatter) ({ name; locations } : t) = Format.fprintf fmt "@[%a;@ @[%a@]@]" dump_package_name name (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.pp_print_space fmt ()) - dump_package_info) - ls + dump_location_descriptor) + locations -type package_found_info = { rel_path : string; pkg_rel_path : string } -type info_query = +type package_paths = { + rel_path : string; + pkg_rel_path : string; + extension : string; +} +type query_result = | Package_script | Package_not_found - | Package_found of package_found_info + | Package_found of package_paths (* Note that package-name has to be exactly the same as npm package name, otherwise the path resolution will be wrong *) -let query_package_infos ({ name; module_systems } : t) - (module_system : module_system) : info_query = +let query_package_location_by_module_system ({ name; locations } : t) + (module_system : module_system) : query_result = match name with | Pkg_empty -> Package_script | Pkg_normal name -> ( match - Ext_list.find_first module_systems (fun k -> + Ext_list.find_first locations (fun k -> compatible k.module_system module_system) with - | Some k -> - let rel_path = k.path in + | Some { path = rel_path; extension; module_system = _ms } -> let pkg_rel_path = name // rel_path in - Package_found { rel_path; pkg_rel_path } + Package_found { rel_path; pkg_rel_path; extension } | None -> Package_not_found ) | Pkg_runtime -> ( match - Ext_list.find_first module_systems (fun k -> + Ext_list.find_first locations (fun k -> compatible k.module_system module_system) with - | Some k -> - let rel_path = k.path in + | Some { path = rel_path; extension; module_system = _ms } -> let pkg_rel_path = runtime_package_name // rel_path in - Package_found { rel_path; pkg_rel_path } + Package_found { rel_path; pkg_rel_path; extension } | None -> Package_not_found ) let get_js_path (x : t) module_system = match - Ext_list.find_first x.module_systems (fun k -> + Ext_list.find_first x.locations (fun k -> compatible k.module_system module_system) with | Some k -> k.path @@ -90611,31 +90621,43 @@ let get_output_dir (info : t) ~package_dir module_system = Filename.concat package_dir (get_js_path info module_system) -let add_npm_package_path (packages_info : t) (s : string) : t = - if is_empty packages_info then - Ext_arg.bad_argf "please set package name first using -bs-package-name " - else - let module_system, path = - match Ext_string.split ~keep_empty:false s ':' with - | [ module_system; path ] -> - ( ( match module_system_of_string module_system with - | Some x -> x - | None -> Ext_arg.bad_argf "invalid module system %s" module_system - ), - path ) - | [ path ] -> (NodeJS, path) - | module_system :: path -> - ( ( match module_system_of_string module_system with - | Some x -> x - | None -> Ext_arg.bad_argf "invalid module system %s" module_system - ), - String.concat ":" path ) - | _ -> Ext_arg.bad_argf "invalid npm package path: %s" s - in - { - packages_info with - module_systems = { module_system; path } :: packages_info.module_systems; - } +let deprecated_set_bs_extension () = + Bs_warnings.warn_deprecated_bs_suffix_flag (); + deprecated_use_bs_extension := true + + +let deprecated_get_default_extension () = + if !deprecated_use_bs_extension then Literals.suffix_bs_js + else Literals.suffix_js + + +(* FIXME: The deprecated -bs-suffix will only affect -bs-package-output flags + passed *after* it. *) +let append_location_descriptor_of_string (packages_info : t) (s : string) : t = + let module_system, path, extension = + match Ext_string.split ~keep_empty:false s ':' with + | [ module_system; path; extension ] -> (module_system, path, extension) + (* Note that, for most users, the default values for [module_system] and + [extension] come not from here, but from [bsb], which always invokes this + with a fully-populated [-bs-package-output]. + + If you're changing the default, make sure both places match! *) + | [ module_system; path ] -> + (module_system, path, deprecated_get_default_extension ()) + | [ path ] -> ("NodeJS", path, deprecated_get_default_extension ()) + | _ -> Ext_arg.bad_argf "invalid value for -bs-package-output: %s" s + in + let module_system = + match module_system_of_string module_system with + | Some x -> x + | None -> + Ext_arg.bad_argf "invalid module system in -bs-package-output: %s" + module_system + in + { + packages_info with + locations = { module_system; path; extension } :: packages_info.locations; + } (* support es6 modules instead @@ -93476,24 +93498,22 @@ type cmj_value = { type effect = string option -type cmj_case = Ext_namespace.file_kind - type t val mk : values:cmj_value Map_string.t -> effect:effect -> - npm_package_path:Js_packages_info.t -> - cmj_case:cmj_case -> + package_info:Js_package_info.t -> + leading_case:Ext_namespace.leading_case -> t val query_by_name : t -> string -> arity * Lam.t option val is_pure : t -> bool -val get_npm_package_path : t -> Js_packages_info.t +val get_package_info : t -> Js_package_info.t -val get_cmj_case : t -> cmj_case +val get_leading_case : t -> Ext_namespace.leading_case val single_na : arity @@ -93546,29 +93566,27 @@ type effect = string option (* we don't force people to use package *) let single_na = Single Lam_arity.na -type cmj_case = Ext_namespace.file_kind - type keyed_cmj_values = (string * cmj_value) array type t = { values : keyed_cmj_values; pure : bool; - npm_package_path : Js_packages_info.t; - cmj_case : cmj_case; + package_info : Js_package_info.t; + leading_case : Ext_namespace.leading_case; } let empty_values = [||] -let mk ~values ~effect ~npm_package_path ~cmj_case : t = +let mk ~values ~effect ~package_info ~leading_case : t = { values = Map_string.to_sorted_array values; pure = effect = None; - npm_package_path; - cmj_case; + package_info; + leading_case; } -let cmj_magic_number = "BUCKLE20171012" +let cmj_magic_number = "BUCKLE20200410" let cmj_magic_number_length = String.length cmj_magic_number let digest_length = 16 (*16 chars *) @@ -93686,26 +93704,24 @@ let query_by_name (cmj_table : t) name = let is_pure (cmj_table : t) = cmj_table.pure -let get_npm_package_path (cmj_table : t) = cmj_table.npm_package_path +let get_package_info (cmj_table : t) = cmj_table.package_info -let get_cmj_case (cmj_table : t) = cmj_table.cmj_case +let get_leading_case (cmj_table : t) = cmj_table.leading_case (* start dumping *) let f fmt = Printf.fprintf stdout fmt -let pp_cmj_case (cmj_case : cmj_case) : unit = - match cmj_case with - | Little_js -> f "case : little, .js\n" - | Little_bs -> f "case : little, .bs.js\n" - | Upper_js -> f "case: upper, .js\n" - | Upper_bs -> f "case: upper, .bs.js\n" +let pp_leading_case (leading_case : Ext_namespace.leading_case) : unit = + match leading_case with + | Upper -> f "case: upper\n" + | Lower -> f "case: lower\n" -let pp_cmj ({ values; pure; npm_package_path; cmj_case } : t) = +let pp_cmj ({ values; pure; package_info; leading_case } : t) = f "package info: %s\n" - (Format.asprintf "%a" Js_packages_info.dump_packages_info npm_package_path); - pp_cmj_case cmj_case; + (Format.asprintf "%a" Js_package_info.dump_package_info package_info); + pp_leading_case leading_case; f "effect: %s\n" (if pure then "pure" else "not pure"); Ext_array.iter values (fun (k, { arity; persistent_closed_lambda }) -> @@ -102787,6 +102803,7 @@ val imports : Ext_pp.t -> (Ident.t * string) list -> Ext_pp_scope.t + end = struct #1 "js_dump_import_export.ml" (* Copyright (C) 2017 Authors of BuckleScript @@ -103671,8 +103688,8 @@ let find_package_json_dir cwd = let package_dir = lazy (find_package_json_dir (Lazy.force cwd)) end -module Js_packages_state : sig -#1 "js_packages_state.mli" +module Js_current_package_info : sig +#1 "js_current_package_info.mli" (* Copyright (C) 2017 Authors of BuckleScript * * This program is free software: you can redistribute it and/or modify @@ -103701,12 +103718,12 @@ val set_package_name : string -> unit val set_package_map : string -> unit -val get_packages_info : unit -> Js_packages_info.t +val get_packages_info : unit -> Js_package_info.t -val update_npm_package_path : string -> unit +val append_location_descriptor_of_string : string -> unit end = struct -#1 "js_packages_state.ml" +#1 "js_current_package_info.ml" (* Copyright (C) 2017 Authors of BuckleScript * * This program is free software: you can redistribute it and/or modify @@ -103731,11 +103748,11 @@ end = struct * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let packages_info = ref Js_packages_info.empty +let packages_info = ref Js_package_info.empty let set_package_name name = - if Js_packages_info.is_empty !packages_info then - packages_info := Js_packages_info.from_name name + if Js_package_info.is_empty !packages_info then + packages_info := Js_package_info.from_name name else Ext_arg.bad_argf "duplicated flag for -bs-package-name" @@ -103744,9 +103761,11 @@ let set_package_map module_name = Clflags.open_modules := module_name :: !Clflags.open_modules -let update_npm_package_path s = - packages_info := Js_packages_info.add_npm_package_path !packages_info s - +let append_location_descriptor_of_string s = + if Js_package_info.is_empty !packages_info then + Ext_arg.bad_argf "please set package name first using -bs-package-name or -bs-ns" + else + packages_info := Js_package_info.append_location_descriptor_of_string !packages_info s let get_packages_info () = !packages_info @@ -104119,7 +104138,7 @@ let find_cmj_exn file : cmj_load_info = Bs_exception.error (Cmj_not_found file) | v -> { cmj_path = "BROWSER"; cmj_table = v } - (* see {!Js_packages_info.string_of_module_id} *) ) + (* see {!Js_package_info.string_of_module_id} *) ) | exception Not_found -> Bs_exception.error (Cmj_not_found file) @@ -109246,15 +109265,18 @@ val query_external_id_info : Ident.t -> string -> ident_info val is_pure_module : Lam_module_ident.t -> bool val get_package_path_from_cmj : - Lam_module_ident.t -> string * Js_packages_info.t * Js_cmj_format.cmj_case + Lam_module_ident.t -> string * Js_package_info.t * Ext_namespace.leading_case -(* The second argument is mostly from [runtime] modules will change the input - [hard_dependencies] [get_required_modules extra hard_dependencies] [extra] - maybe removed if it is pure and not in [hard_dependencies] *) val get_required_modules : Lam_module_ident.Hash_set.t -> Lam_module_ident.Hash_set.t -> Lam_module_ident.t list +(** The second argument is mostly from [runtime] modules + + will change the input [hard_dependencies] + + [get_required_modules extra hard_dependencies] - [extra] maybe removed if it + is pure and not in [hard_dependencies] *) end = struct #1 "lam_compile_env.ml" @@ -109355,8 +109377,8 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) = match Lam_module_ident.Hash.find_opt cached_tbl id with | Some (Ml { cmj_table; cmj_path }) -> ( cmj_path, - Js_cmj_format.get_npm_package_path cmj_table, - Js_cmj_format.get_cmj_case cmj_table ) + Js_cmj_format.get_package_info cmj_table, + Js_cmj_format.get_leading_case cmj_table ) | Some (External | Runtime _) -> assert false (* called by {!Js_name_of_module_id.string_of_module_id} can not be @@ -109371,8 +109393,8 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) = in id +> Ml cmj_load_info; ( cmj_load_info.cmj_path, - Js_cmj_format.get_npm_package_path cmj_table, - Js_cmj_format.get_cmj_case cmj_table ) ) + Js_cmj_format.get_package_info cmj_table, + Js_cmj_format.get_leading_case cmj_table ) ) let add = Lam_module_ident.Hash_set.add @@ -109437,7 +109459,8 @@ module Js_name_of_module_id : sig val string_of_module_id : Lam_module_ident.t -> output_dir:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> string (** generate the mdoule path so that it can be spliced here: @@ -109490,29 +109513,30 @@ let fix_path_for_windows : string -> string = let get_runtime_module_path (dep_module_id : Lam_module_ident.t) - (current_package_info : Js_packages_info.t) module_system = - let current_info_query = - Js_packages_info.query_package_infos current_package_info module_system + (current_package_info : Js_package_info.t) module_system = + let loc = + Js_package_info.query_package_location_by_module_system current_package_info + module_system in let js_file = - Ext_namespace.js_name_of_modulename dep_module_id.id.name Little_js + Ext_namespace.js_filename_of_modulename ~name:dep_module_id.id.name + ~ext:".js" Lower in - match current_info_query with + match loc with | Package_not_found -> assert false - | Package_script -> - Js_packages_info.runtime_package_path module_system js_file + | Package_script -> Js_package_info.runtime_package_path module_system js_file | Package_found pkg -> ( let dep_path = - "lib" // Js_packages_info.runtime_dir_of_module_system module_system + "lib" // Js_package_info.runtime_dir_of_module_system module_system in - if Js_packages_info.is_runtime_package current_package_info then + if Js_package_info.is_runtime_package current_package_info then Ext_path.node_rebase_file ~from:pkg.rel_path ~to_:dep_path js_file (* TODO: we assume that both [x] and [path] could only be relative path which is guaranteed by [-bs-package-output] *) else match module_system with | NodeJS | Es6 -> - Js_packages_info.runtime_package_path module_system js_file + Js_package_info.runtime_package_path module_system js_file (* Note we did a post-processing when working on Windows *) | Es6_global -> (* lib/ocaml/xx.cmj -- @@ -109522,7 +109546,7 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t) (* assert false *) Ext_path.rel_normalized_absolute_path ~from: - (Js_packages_info.get_output_dir current_package_info + (Js_package_info.get_output_dir current_package_info ~package_dir:(Lazy.force Ext_path.package_dir) module_system) (Lazy.force runtime_package_path // dep_path // js_file) ) @@ -109530,9 +109554,9 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t) (* [output_dir] is decided by the command line argument *) let string_of_module_id (dep_module_id : Lam_module_ident.t) - ~(output_dir : string) (module_system : Js_packages_info.module_system) : - string = - let current_package_info = Js_packages_state.get_packages_info () in + ~(output_dir : string) ~(ext : string) + (module_system : Js_package_info.module_system) : string = + let current_package_info = Js_current_package_info.get_packages_info () in fix_path_for_windows ( match dep_module_id.kind with | External name -> name (* the literal string for external package *) @@ -109546,34 +109570,39 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t) | Runtime -> get_runtime_module_path dep_module_id current_package_info module_system | Ml -> ( - let current_info_query = - Js_packages_info.query_package_infos current_package_info - module_system - in + let query = Js_package_info.query_package_location_by_module_system in + let current_loc = query current_package_info module_system in match Lam_compile_env.get_package_path_from_cmj dep_module_id with - | cmj_path, dep_package_info, little -> ( - let js_file = - Ext_namespace.js_name_of_modulename dep_module_id.id.name little - in - let dep_info_query = - Js_packages_info.query_package_infos dep_package_info - module_system - in - match (dep_info_query, current_info_query) with + | cmj_path, dep_package_info, case -> ( + let dep_loc = query dep_package_info module_system in + match (dep_loc, current_loc) with | Package_not_found, _ -> Bs_exception.error (Missing_ml_dependency dep_module_id.id.name) | Package_script, Package_found _ -> + let js_file = + Ext_namespace.js_filename_of_modulename + (* FIXME: Unsure how to infer a useful file-extension here. *) + ~name:dep_module_id.id.name ~ext:"" case + in Bs_exception.error (Dependency_script_module_dependent_not js_file) | (Package_script | Package_found _), Package_not_found -> assert false - | Package_found pkg, Package_script -> + | Package_found dep_pkg, Package_script -> + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext:dep_pkg.extension case + in - pkg.pkg_rel_path // js_file + dep_pkg.pkg_rel_path // js_file | Package_found dep_pkg, Package_found cur_pkg -> ( + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext:dep_pkg.extension case + in if - Js_packages_info.same_package_by_name current_package_info + Js_package_info.same_package_by_name current_package_info dep_package_info then Ext_path.node_rebase_file ~from:cur_pkg.rel_path @@ -109595,13 +109624,17 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t) (* assert false *) Ext_path.rel_normalized_absolute_path ~from: - (Js_packages_info.get_output_dir current_package_info + (Js_package_info.get_output_dir current_package_info ~package_dir:(Lazy.force Ext_path.package_dir) module_system) ( Filename.dirname (Filename.dirname (Filename.dirname cmj_path)) // dep_pkg.rel_path // js_file ) ) | Package_script, Package_script -> ( + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext case + in match Config_util.find_opt js_file with | Some file -> let basename = Filename.basename file in @@ -109623,7 +109656,7 @@ let string_of_module_id_in_browser (x : Lam_module_ident.t) = let string_of_module_id (id : Lam_module_ident.t) ~output_dir:(_ : string) - (_module_system : Js_packages_info.module_system) = + ~ext:(_ : string) (_module_system : Js_package_info.module_system) = string_of_module_id_in_browser id @@ -109659,14 +109692,16 @@ val dump_program : J.program -> out_channel -> unit val pp_deps_program : output_prefix:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> J.deps_program -> Ext_pp.t -> unit val dump_deps_program : output_prefix:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> J.deps_program -> out_channel -> unit @@ -109728,24 +109763,25 @@ let dump_program (x : J.program) oc = ignore (program (P.from_channel oc) Ext_pp_scope.empty x) -let node_program ~output_dir f (x : J.deps_program) = +let node_program ~output_dir ~ext f (x : J.deps_program) = P.string f L.strict_directive; P.newline f; let cxt = Js_dump_import_export.requires L.require Ext_pp_scope.empty f (Ext_list.map x.modules (fun x -> ( Lam_module_ident.id x, - Js_name_of_module_id.string_of_module_id x ~output_dir NodeJS ))) + Js_name_of_module_id.string_of_module_id x ~output_dir ~ext NodeJS + ))) in program f cxt x.program -let es6_program ~output_dir fmt f (x : J.deps_program) = +let es6_program ~output_dir ~ext fmt f (x : J.deps_program) = let cxt = Js_dump_import_export.imports Ext_pp_scope.empty f (Ext_list.map x.modules (fun x -> ( Lam_module_ident.id x, - Js_name_of_module_id.string_of_module_id x ~output_dir fmt ))) + Js_name_of_module_id.string_of_module_id x ~output_dir ~ext fmt ))) in let () = P.force_newline f in let cxt = Js_dump.statement_list true cxt f x.program.block in @@ -109760,7 +109796,7 @@ let es6_program ~output_dir fmt f (x : J.deps_program) = Linguist::FileBlob.new('jscomp/test/test_u.js').generated? ]} *) -let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) +let pp_deps_program ~output_prefix ~ext (kind : Js_package_info.module_system) (program : J.deps_program) (f : Ext_pp.t) = if not !Js_config.no_version_header then ( P.string f Bs_version.header; @@ -109771,8 +109807,8 @@ let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) let output_dir = Filename.dirname output_prefix in ignore ( match kind with - | Es6 | Es6_global -> es6_program ~output_dir kind f program - | NodeJS -> node_program ~output_dir f program ); + | Es6 | Es6_global -> es6_program ~output_dir ~ext kind f program + | NodeJS -> node_program ~output_dir ~ext f program ); P.newline f; P.string f ( match program.side_effect with @@ -109782,8 +109818,8 @@ let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) P.flush f () -let dump_deps_program ~output_prefix kind x (oc : out_channel) = - pp_deps_program ~output_prefix kind x (P.from_channel oc) +let dump_deps_program ~output_prefix ~ext kind x (oc : out_channel) = + pp_deps_program ~output_prefix ~ext kind x (P.from_channel oc) end module Jsoo_common : sig @@ -128344,7 +128380,7 @@ val export_to_cmj : Lam_stats.t -> Js_cmj_format.effect -> Lam.t Map_ident.t -> - Js_cmj_format.cmj_case -> + Ext_namespace.leading_case -> Js_cmj_format.t end = struct @@ -128456,15 +128492,15 @@ let get_dependent_module_effect (meta : Lam_stats.t) backend, we compile to js for the inliner, we try to seriaize it -- relies on other optimizations to make this happen {[ exports.Make = function () {.....} ]} TODO: check that we don't do this in browser environment *) -let export_to_cmj (meta : Lam_stats.t) effect export_map cmj_case : - Js_cmj_format.t = +let export_to_cmj (meta : Lam_stats.t) effect export_map + (leading_case : Ext_namespace.leading_case) : Js_cmj_format.t = let values = values_of_export meta export_map in (* FIXME: make sure [-o] would not change its case *) (* FIXME: add test for ns/non-ns *) Js_cmj_format.mk ~values ~effect - ~npm_package_path:(Js_packages_state.get_packages_info ()) - ~cmj_case + ~package_info:(Js_current_package_info.get_packages_info ()) + ~leading_case end module Lam_compile_main : sig @@ -128532,13 +128568,9 @@ end = struct module E = Js_exp_make module S = Js_stmt_make -let get_cmj_case output_prefix : Ext_namespace.file_kind = - let little = Ext_char.is_lower_case (Filename.basename output_prefix).[0] in - match (little, !Js_config.bs_suffix) with - | true, true -> Little_bs - | true, false -> Little_js - | false, true -> Upper_bs - | false, false -> Upper_js +let get_leading_case output_prefix : Ext_namespace.leading_case = + if Ext_char.is_lower_case (Filename.basename output_prefix).[0] then Lower + else Upper let compile_group (meta : Lam_stats.t) (x : Lam_group.t) : Js_output.t = @@ -128718,7 +128750,7 @@ let compile (output_prefix : string) (lam : Lambda.lambda) = in let v : Js_cmj_format.t = Lam_stats_export.export_to_cmj meta effect coerced_input.export_map - (get_cmj_case output_prefix) + (get_leading_case output_prefix) in if not @@ !Clflags.dont_write_files then Js_cmj_format.to_file ~check_exists:(not !Js_config.force_cmj) @@ -128731,20 +128763,21 @@ let ( // ) = Filename.concat let lambda_as_module (lambda_output : J.deps_program) (output_prefix : string) : unit = - let basename = - Ext_namespace.change_ext_ns_suffix - (Filename.basename output_prefix) - ( if !Js_config.bs_suffix then Literals.suffix_bs_js - else Literals.suffix_js ) - in - let package_info = Js_packages_state.get_packages_info () in - if Js_packages_info.is_empty package_info && !Js_config.js_stdout then - Js_dump_program.dump_deps_program ~output_prefix NodeJS lambda_output stdout + let package_info = Js_current_package_info.get_packages_info () in + if Js_package_info.is_empty package_info && !Js_config.js_stdout then + Js_dump_program.dump_deps_program ~ext:".js" ~output_prefix NodeJS + lambda_output stdout else - Js_packages_info.iter package_info (fun { module_system; path = _path } -> + Js_package_info.iter package_info + (fun { module_system; path = _path; extension } -> + let basename = + Ext_namespace.replace_namespace_with_extension + ~name:(Filename.basename output_prefix) + ~ext:extension + in let output_chan chan = - Js_dump_program.dump_deps_program ~output_prefix module_system - lambda_output chan + Js_dump_program.dump_deps_program ~output_prefix ~ext:extension + module_system lambda_output chan in if not @@ !Clflags.dont_write_files then Ext_pervasives.with_file_as_chan @@ -291997,7 +292030,7 @@ let implementation ?prefix ~use_super_errors ?(react_ppx_version = V3) impl str let buffer = Buffer.create 1000 in let () = Js_dump_program.pp_deps_program (* does not matter here *) - ~output_prefix:"" NodeJS + ~output_prefix:"" ~ext:".js" NodeJS (Lam_compile_main.compile "" lam) (Ext_pp.from_buffer buffer) in diff --git a/lib/4.06.1/unstable/js_refmt_compiler.ml.d b/lib/4.06.1/unstable/js_refmt_compiler.ml.d index 8cfbe01640..9c4811b52f 100644 --- a/lib/4.06.1/unstable/js_refmt_compiler.ml.d +++ b/lib/4.06.1/unstable/js_refmt_compiler.ml.d @@ -1 +1 @@ -../lib/4.06.1/unstable/js_refmt_compiler.ml: ../ocaml/bytecomp/lambda.ml ../ocaml/bytecomp/lambda.mli ../ocaml/bytecomp/matching.ml ../ocaml/bytecomp/matching.mli ../ocaml/bytecomp/printlambda.ml ../ocaml/bytecomp/printlambda.mli ../ocaml/bytecomp/switch.ml ../ocaml/bytecomp/switch.mli ../ocaml/bytecomp/translattribute.ml ../ocaml/bytecomp/translattribute.mli ../ocaml/bytecomp/translclass.ml ../ocaml/bytecomp/translclass.mli ../ocaml/bytecomp/translcore.ml ../ocaml/bytecomp/translcore.mli ../ocaml/bytecomp/translmod.ml ../ocaml/bytecomp/translmod.mli ../ocaml/bytecomp/translobj.ml ../ocaml/bytecomp/translobj.mli ../ocaml/driver/compenv.ml ../ocaml/driver/compenv.mli ../ocaml/driver/compmisc.ml ../ocaml/driver/compmisc.mli ../ocaml/parsing/ast_helper.ml ../ocaml/parsing/ast_helper.mli ../ocaml/parsing/ast_iterator.ml ../ocaml/parsing/ast_iterator.mli ../ocaml/parsing/ast_mapper.ml ../ocaml/parsing/ast_mapper.mli ../ocaml/parsing/asttypes.mli ../ocaml/parsing/attr_helper.ml ../ocaml/parsing/attr_helper.mli ../ocaml/parsing/builtin_attributes.ml ../ocaml/parsing/builtin_attributes.mli ../ocaml/parsing/docstrings.ml ../ocaml/parsing/docstrings.mli ../ocaml/parsing/lexer.ml ../ocaml/parsing/lexer.mli ../ocaml/parsing/location.ml ../ocaml/parsing/location.mli ../ocaml/parsing/longident.ml ../ocaml/parsing/longident.mli ../ocaml/parsing/parse.ml ../ocaml/parsing/parse.mli ../ocaml/parsing/parser.ml ../ocaml/parsing/parser.mli ../ocaml/parsing/parsetree.mli ../ocaml/parsing/pprintast.ml ../ocaml/parsing/pprintast.mli ../ocaml/parsing/syntaxerr.ml ../ocaml/parsing/syntaxerr.mli ../ocaml/typing/annot.mli ../ocaml/typing/btype.ml ../ocaml/typing/btype.mli ../ocaml/typing/cmi_format.ml ../ocaml/typing/cmi_format.mli ../ocaml/typing/cmt_format.ml ../ocaml/typing/cmt_format.mli ../ocaml/typing/ctype.ml ../ocaml/typing/ctype.mli ../ocaml/typing/datarepr.ml ../ocaml/typing/datarepr.mli ../ocaml/typing/env.ml ../ocaml/typing/env.mli ../ocaml/typing/ident.ml ../ocaml/typing/ident.mli ../ocaml/typing/includeclass.ml ../ocaml/typing/includeclass.mli ../ocaml/typing/includecore.ml ../ocaml/typing/includecore.mli ../ocaml/typing/includemod.ml ../ocaml/typing/includemod.mli ../ocaml/typing/mtype.ml ../ocaml/typing/mtype.mli ../ocaml/typing/oprint.ml ../ocaml/typing/oprint.mli ../ocaml/typing/outcometree.mli ../ocaml/typing/parmatch.ml ../ocaml/typing/parmatch.mli ../ocaml/typing/path.ml ../ocaml/typing/path.mli ../ocaml/typing/predef.ml ../ocaml/typing/predef.mli ../ocaml/typing/primitive.ml ../ocaml/typing/primitive.mli ../ocaml/typing/printtyp.ml ../ocaml/typing/printtyp.mli ../ocaml/typing/stypes.ml ../ocaml/typing/stypes.mli ../ocaml/typing/subst.ml ../ocaml/typing/subst.mli ../ocaml/typing/tast_mapper.ml ../ocaml/typing/tast_mapper.mli ../ocaml/typing/typeclass.ml ../ocaml/typing/typeclass.mli ../ocaml/typing/typecore.ml ../ocaml/typing/typecore.mli ../ocaml/typing/typedecl.ml ../ocaml/typing/typedecl.mli ../ocaml/typing/typedtree.ml ../ocaml/typing/typedtree.mli ../ocaml/typing/typedtreeIter.ml ../ocaml/typing/typedtreeIter.mli ../ocaml/typing/typemod.ml ../ocaml/typing/typemod.mli ../ocaml/typing/typeopt.ml ../ocaml/typing/typeopt.mli ../ocaml/typing/types.ml ../ocaml/typing/types.mli ../ocaml/typing/typetexp.ml ../ocaml/typing/typetexp.mli ../ocaml/typing/untypeast.ml ../ocaml/typing/untypeast.mli ../ocaml/utils/arg_helper.ml ../ocaml/utils/arg_helper.mli ../ocaml/utils/ccomp.ml ../ocaml/utils/ccomp.mli ../ocaml/utils/clflags.ml ../ocaml/utils/clflags.mli ../ocaml/utils/consistbl.ml ../ocaml/utils/consistbl.mli ../ocaml/utils/identifiable.ml ../ocaml/utils/identifiable.mli ../ocaml/utils/misc.ml ../ocaml/utils/misc.mli ../ocaml/utils/numbers.ml ../ocaml/utils/numbers.mli ../ocaml/utils/profile.ml ../ocaml/utils/profile.mli ../ocaml/utils/tbl.ml ../ocaml/utils/tbl.mli ../ocaml/utils/terminfo.ml ../ocaml/utils/terminfo.mli ../ocaml/utils/warnings.ml ../ocaml/utils/warnings.mli ./common/bs_loc.ml ./common/bs_loc.mli ./common/bs_version.ml ./common/bs_version.mli ./common/bs_warnings.ml ./common/bs_warnings.mli ./common/ext_log.ml ./common/ext_log.mli ./common/js_config.ml ./common/js_config.mli ./common/lam_methname.ml ./common/lam_methname.mli ./core/bs_conditional_initial.ml ./core/bs_conditional_initial.mli ./core/classify_function.ml ./core/classify_function.mli ./core/config_util.ml ./core/config_util.mli ./core/config_whole_compiler.ml ./core/config_whole_compiler.mli ./core/j.ml ./core/js_analyzer.ml ./core/js_analyzer.mli ./core/js_arr.ml ./core/js_arr.mli ./core/js_ast_util.ml ./core/js_ast_util.mli ./core/js_block_runtime.ml ./core/js_block_runtime.mli ./core/js_call_info.ml ./core/js_call_info.mli ./core/js_closure.ml ./core/js_closure.mli ./core/js_cmj_datasets.ml ./core/js_cmj_datasets.mli ./core/js_cmj_format.ml ./core/js_cmj_format.mli ./core/js_cmj_load.ml ./core/js_cmj_load.mli ./core/js_dump.ml ./core/js_dump.mli ./core/js_dump_import_export.ml ./core/js_dump_import_export.mli ./core/js_dump_lit.ml ./core/js_dump_program.ml ./core/js_dump_program.mli ./core/js_dump_property.ml ./core/js_dump_property.mli ./core/js_dump_string.ml ./core/js_dump_string.mli ./core/js_exp_make.ml ./core/js_exp_make.mli ./core/js_fold.ml ./core/js_fold_basic.ml ./core/js_fold_basic.mli ./core/js_fun_env.ml ./core/js_fun_env.mli ./core/js_long.ml ./core/js_long.mli ./core/js_map.ml ./core/js_name_of_module_id.ml ./core/js_name_of_module_id.mli ./core/js_number.ml ./core/js_number.mli ./core/js_of_lam_array.ml ./core/js_of_lam_array.mli ./core/js_of_lam_block.ml ./core/js_of_lam_block.mli ./core/js_of_lam_exception.ml ./core/js_of_lam_exception.mli ./core/js_of_lam_option.ml ./core/js_of_lam_option.mli ./core/js_of_lam_polyvar.ml ./core/js_of_lam_polyvar.mli ./core/js_of_lam_string.ml ./core/js_of_lam_string.mli ./core/js_of_lam_tuple.ml ./core/js_of_lam_tuple.mli ./core/js_of_lam_variant.ml ./core/js_of_lam_variant.mli ./core/js_op.ml ./core/js_op_util.ml ./core/js_op_util.mli ./core/js_output.ml ./core/js_output.mli ./core/js_packages_info.ml ./core/js_packages_info.mli ./core/js_packages_state.ml ./core/js_packages_state.mli ./core/js_pass_debug.ml ./core/js_pass_debug.mli ./core/js_pass_flatten.ml ./core/js_pass_flatten.mli ./core/js_pass_flatten_and_mark_dead.ml ./core/js_pass_flatten_and_mark_dead.mli ./core/js_pass_scope.ml ./core/js_pass_scope.mli ./core/js_pass_tailcall_inline.ml ./core/js_pass_tailcall_inline.mli ./core/js_raw_exp_info.ml ./core/js_shake.ml ./core/js_shake.mli ./core/js_stmt_make.ml ./core/js_stmt_make.mli ./core/lam.ml ./core/lam.mli ./core/lam_analysis.ml ./core/lam_analysis.mli ./core/lam_arity.ml ./core/lam_arity.mli ./core/lam_arity_analysis.ml ./core/lam_arity_analysis.mli ./core/lam_beta_reduce.ml ./core/lam_beta_reduce.mli ./core/lam_beta_reduce_util.ml ./core/lam_beta_reduce_util.mli ./core/lam_bounded_vars.ml ./core/lam_bounded_vars.mli ./core/lam_closure.ml ./core/lam_closure.mli ./core/lam_coercion.ml ./core/lam_coercion.mli ./core/lam_compat.ml ./core/lam_compat.mli ./core/lam_compile.ml ./core/lam_compile.mli ./core/lam_compile_const.ml ./core/lam_compile_const.mli ./core/lam_compile_context.ml ./core/lam_compile_context.mli ./core/lam_compile_env.ml ./core/lam_compile_env.mli ./core/lam_compile_external_call.ml ./core/lam_compile_external_call.mli ./core/lam_compile_external_obj.ml ./core/lam_compile_external_obj.mli ./core/lam_compile_main.ml ./core/lam_compile_main.mli ./core/lam_compile_primitive.ml ./core/lam_compile_primitive.mli ./core/lam_compile_util.ml ./core/lam_compile_util.mli ./core/lam_constant.ml ./core/lam_constant.mli ./core/lam_constant_convert.ml ./core/lam_constant_convert.mli ./core/lam_convert.ml ./core/lam_convert.mli ./core/lam_dce.ml ./core/lam_dce.mli ./core/lam_dispatch_primitive.ml ./core/lam_dispatch_primitive.mli ./core/lam_eta_conversion.ml ./core/lam_eta_conversion.mli ./core/lam_exit_code.ml ./core/lam_exit_code.mli ./core/lam_exit_count.ml ./core/lam_exit_count.mli ./core/lam_free_variables.ml ./core/lam_free_variables.mli ./core/lam_group.ml ./core/lam_group.mli ./core/lam_hit.ml ./core/lam_hit.mli ./core/lam_id_kind.ml ./core/lam_id_kind.mli ./core/lam_inline_util.ml ./core/lam_inline_util.mli ./core/lam_iter.ml ./core/lam_iter.mli ./core/lam_module_ident.ml ./core/lam_module_ident.mli ./core/lam_pass_alpha_conversion.ml ./core/lam_pass_alpha_conversion.mli ./core/lam_pass_collect.ml ./core/lam_pass_collect.mli ./core/lam_pass_count.ml ./core/lam_pass_count.mli ./core/lam_pass_deep_flatten.ml ./core/lam_pass_deep_flatten.mli ./core/lam_pass_eliminate_ref.ml ./core/lam_pass_eliminate_ref.mli ./core/lam_pass_exits.ml ./core/lam_pass_exits.mli ./core/lam_pass_lets_dce.ml ./core/lam_pass_lets_dce.mli ./core/lam_pass_remove_alias.ml ./core/lam_pass_remove_alias.mli ./core/lam_pointer_info.ml ./core/lam_pointer_info.mli ./core/lam_primitive.ml ./core/lam_primitive.mli ./core/lam_print.ml ./core/lam_print.mli ./core/lam_scc.ml ./core/lam_scc.mli ./core/lam_stats.ml ./core/lam_stats.mli ./core/lam_stats_export.ml ./core/lam_stats_export.mli ./core/lam_subst.ml ./core/lam_subst.mli ./core/lam_tag_info.ml ./core/lam_util.ml ./core/lam_util.mli ./core/lam_var_stats.ml ./core/lam_var_stats.mli ./core/matching_polyfill.ml ./core/matching_polyfill.mli ./core/primitive_compat.ml ./core/primitive_compat.mli ./core/record_attributes_check.ml ./depends/bs_exception.ml ./depends/bs_exception.mli ./ext/bsc_warnings.ml ./ext/ext_arg.ml ./ext/ext_arg.mli ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_fmt.ml ./ext/ext_ident.ml ./ext/ext_ident.mli ./ext/ext_int.ml ./ext/ext_int.mli ./ext/ext_json_parse.ml ./ext/ext_json_parse.mli ./ext/ext_json_types.ml ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_modulename.ml ./ext/ext_modulename.mli ./ext/ext_namespace.ml ./ext/ext_namespace.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_path.ml ./ext/ext_path.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_position.ml ./ext/ext_position.mli ./ext/ext_pp.ml ./ext/ext_pp.mli ./ext/ext_pp_scope.ml ./ext/ext_pp_scope.mli ./ext/ext_ref.ml ./ext/ext_ref.mli ./ext/ext_scc.ml ./ext/ext_scc.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_sys.ml ./ext/ext_sys.mli ./ext/ext_utf8.ml ./ext/ext_utf8.mli ./ext/ext_util.ml ./ext/ext_util.mli ./ext/hash.ml ./ext/hash.mli ./ext/hash_gen.ml ./ext/hash_ident.ml ./ext/hash_ident.mli ./ext/hash_int.ml ./ext/hash_int.mli ./ext/hash_set.ml ./ext/hash_set.mli ./ext/hash_set_gen.ml ./ext/hash_set_ident.ml ./ext/hash_set_ident.mli ./ext/hash_set_ident_mask.ml ./ext/hash_set_ident_mask.mli ./ext/hash_set_poly.ml ./ext/hash_set_poly.mli ./ext/hash_set_string.ml ./ext/hash_set_string.mli ./ext/hash_string.ml ./ext/hash_string.mli ./ext/int_vec_util.ml ./ext/int_vec_util.mli ./ext/int_vec_vec.ml ./ext/int_vec_vec.mli ./ext/js_reserved_map.ml ./ext/js_reserved_map.mli ./ext/js_runtime_modules.ml ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/map_ident.ml ./ext/map_ident.mli ./ext/map_int.ml ./ext/map_int.mli ./ext/map_string.ml ./ext/map_string.mli ./ext/ordered_hash_map_gen.ml ./ext/ordered_hash_map_local_ident.ml ./ext/ordered_hash_map_local_ident.mli ./ext/set_gen.ml ./ext/set_ident.ml ./ext/set_ident.mli ./ext/set_string.ml ./ext/set_string.mli ./ext/vec.ml ./ext/vec.mli ./ext/vec_gen.ml ./ext/vec_int.ml ./ext/vec_int.mli ./main/jsoo_common.ml ./main/jsoo_common.mli ./main/jsoo_refmt_main.ml ./main/jsoo_refmt_main.mli ./main/refmt_api.ml ./outcome_printer/outcome_printer_ns.ml ./outcome_printer/outcome_printer_ns.mli ./stubs/bs_hash_stubs.ml ./super_errors/super_env.ml ./super_errors/super_location.ml ./super_errors/super_main.ml ./super_errors/super_misc.ml ./super_errors/super_misc.mli ./super_errors/super_pparse.ml ./super_errors/super_reason_react.ml ./super_errors/super_reason_react.mli ./super_errors/super_typecore.ml ./super_errors/super_typemod.ml ./super_errors/super_typetexp.ml ./super_errors/super_warnings.ml ./syntax/ast_attributes.ml ./syntax/ast_attributes.mli ./syntax/ast_bs_open.ml ./syntax/ast_bs_open.mli ./syntax/ast_comb.ml ./syntax/ast_comb.mli ./syntax/ast_compatible.ml ./syntax/ast_compatible.mli ./syntax/ast_core_type.ml ./syntax/ast_core_type.mli ./syntax/ast_core_type_class_type.ml ./syntax/ast_core_type_class_type.mli ./syntax/ast_derive.ml ./syntax/ast_derive.mli ./syntax/ast_derive_abstract.ml ./syntax/ast_derive_abstract.mli ./syntax/ast_derive_js_mapper.ml ./syntax/ast_derive_js_mapper.mli ./syntax/ast_derive_projector.ml ./syntax/ast_derive_projector.mli ./syntax/ast_derive_util.ml ./syntax/ast_derive_util.mli ./syntax/ast_exp.ml ./syntax/ast_exp.mli ./syntax/ast_exp_apply.ml ./syntax/ast_exp_apply.mli ./syntax/ast_exp_extension.ml ./syntax/ast_exp_extension.mli ./syntax/ast_external.ml ./syntax/ast_external.mli ./syntax/ast_external_mk.ml ./syntax/ast_external_mk.mli ./syntax/ast_external_process.ml ./syntax/ast_external_process.mli ./syntax/ast_literal.ml ./syntax/ast_literal.mli ./syntax/ast_open_cxt.ml ./syntax/ast_open_cxt.mli ./syntax/ast_pat.ml ./syntax/ast_pat.mli ./syntax/ast_payload.ml ./syntax/ast_payload.mli ./syntax/ast_polyvar.ml ./syntax/ast_polyvar.mli ./syntax/ast_raw.ml ./syntax/ast_raw.mli ./syntax/ast_reason_pp.ml ./syntax/ast_reason_pp.mli ./syntax/ast_signature.ml ./syntax/ast_signature.mli ./syntax/ast_structure.ml ./syntax/ast_structure.mli ./syntax/ast_tdcls.ml ./syntax/ast_tdcls.mli ./syntax/ast_tuple_pattern_flatten.ml ./syntax/ast_tuple_pattern_flatten.mli ./syntax/ast_utf8_string.ml ./syntax/ast_utf8_string.mli ./syntax/ast_utf8_string_interp.ml ./syntax/ast_utf8_string_interp.mli ./syntax/ast_util.ml ./syntax/ast_util.mli ./syntax/bs_ast_invariant.ml ./syntax/bs_ast_invariant.mli ./syntax/bs_ast_mapper.ml ./syntax/bs_ast_mapper.mli ./syntax/bs_builtin_ppx.ml ./syntax/bs_builtin_ppx.mli ./syntax/bs_syntaxerr.ml ./syntax/bs_syntaxerr.mli ./syntax/external_arg_spec.ml ./syntax/external_arg_spec.mli ./syntax/external_ffi_types.ml ./syntax/external_ffi_types.mli ./syntax/reactjs_jsx_ppx_v2.ml ./syntax/reactjs_jsx_ppx_v3.ml \ No newline at end of file +../lib/4.06.1/unstable/js_refmt_compiler.ml: ../ocaml/bytecomp/lambda.ml ../ocaml/bytecomp/lambda.mli ../ocaml/bytecomp/matching.ml ../ocaml/bytecomp/matching.mli ../ocaml/bytecomp/printlambda.ml ../ocaml/bytecomp/printlambda.mli ../ocaml/bytecomp/switch.ml ../ocaml/bytecomp/switch.mli ../ocaml/bytecomp/translattribute.ml ../ocaml/bytecomp/translattribute.mli ../ocaml/bytecomp/translclass.ml ../ocaml/bytecomp/translclass.mli ../ocaml/bytecomp/translcore.ml ../ocaml/bytecomp/translcore.mli ../ocaml/bytecomp/translmod.ml ../ocaml/bytecomp/translmod.mli ../ocaml/bytecomp/translobj.ml ../ocaml/bytecomp/translobj.mli ../ocaml/driver/compenv.ml ../ocaml/driver/compenv.mli ../ocaml/driver/compmisc.ml ../ocaml/driver/compmisc.mli ../ocaml/parsing/ast_helper.ml ../ocaml/parsing/ast_helper.mli ../ocaml/parsing/ast_iterator.ml ../ocaml/parsing/ast_iterator.mli ../ocaml/parsing/ast_mapper.ml ../ocaml/parsing/ast_mapper.mli ../ocaml/parsing/asttypes.mli ../ocaml/parsing/attr_helper.ml ../ocaml/parsing/attr_helper.mli ../ocaml/parsing/builtin_attributes.ml ../ocaml/parsing/builtin_attributes.mli ../ocaml/parsing/docstrings.ml ../ocaml/parsing/docstrings.mli ../ocaml/parsing/lexer.ml ../ocaml/parsing/lexer.mli ../ocaml/parsing/location.ml ../ocaml/parsing/location.mli ../ocaml/parsing/longident.ml ../ocaml/parsing/longident.mli ../ocaml/parsing/parse.ml ../ocaml/parsing/parse.mli ../ocaml/parsing/parser.ml ../ocaml/parsing/parser.mli ../ocaml/parsing/parsetree.mli ../ocaml/parsing/pprintast.ml ../ocaml/parsing/pprintast.mli ../ocaml/parsing/syntaxerr.ml ../ocaml/parsing/syntaxerr.mli ../ocaml/typing/annot.mli ../ocaml/typing/btype.ml ../ocaml/typing/btype.mli ../ocaml/typing/cmi_format.ml ../ocaml/typing/cmi_format.mli ../ocaml/typing/cmt_format.ml ../ocaml/typing/cmt_format.mli ../ocaml/typing/ctype.ml ../ocaml/typing/ctype.mli ../ocaml/typing/datarepr.ml ../ocaml/typing/datarepr.mli ../ocaml/typing/env.ml ../ocaml/typing/env.mli ../ocaml/typing/ident.ml ../ocaml/typing/ident.mli ../ocaml/typing/includeclass.ml ../ocaml/typing/includeclass.mli ../ocaml/typing/includecore.ml ../ocaml/typing/includecore.mli ../ocaml/typing/includemod.ml ../ocaml/typing/includemod.mli ../ocaml/typing/mtype.ml ../ocaml/typing/mtype.mli ../ocaml/typing/oprint.ml ../ocaml/typing/oprint.mli ../ocaml/typing/outcometree.mli ../ocaml/typing/parmatch.ml ../ocaml/typing/parmatch.mli ../ocaml/typing/path.ml ../ocaml/typing/path.mli ../ocaml/typing/predef.ml ../ocaml/typing/predef.mli ../ocaml/typing/primitive.ml ../ocaml/typing/primitive.mli ../ocaml/typing/printtyp.ml ../ocaml/typing/printtyp.mli ../ocaml/typing/stypes.ml ../ocaml/typing/stypes.mli ../ocaml/typing/subst.ml ../ocaml/typing/subst.mli ../ocaml/typing/tast_mapper.ml ../ocaml/typing/tast_mapper.mli ../ocaml/typing/typeclass.ml ../ocaml/typing/typeclass.mli ../ocaml/typing/typecore.ml ../ocaml/typing/typecore.mli ../ocaml/typing/typedecl.ml ../ocaml/typing/typedecl.mli ../ocaml/typing/typedtree.ml ../ocaml/typing/typedtree.mli ../ocaml/typing/typedtreeIter.ml ../ocaml/typing/typedtreeIter.mli ../ocaml/typing/typemod.ml ../ocaml/typing/typemod.mli ../ocaml/typing/typeopt.ml ../ocaml/typing/typeopt.mli ../ocaml/typing/types.ml ../ocaml/typing/types.mli ../ocaml/typing/typetexp.ml ../ocaml/typing/typetexp.mli ../ocaml/typing/untypeast.ml ../ocaml/typing/untypeast.mli ../ocaml/utils/arg_helper.ml ../ocaml/utils/arg_helper.mli ../ocaml/utils/ccomp.ml ../ocaml/utils/ccomp.mli ../ocaml/utils/clflags.ml ../ocaml/utils/clflags.mli ../ocaml/utils/consistbl.ml ../ocaml/utils/consistbl.mli ../ocaml/utils/identifiable.ml ../ocaml/utils/identifiable.mli ../ocaml/utils/misc.ml ../ocaml/utils/misc.mli ../ocaml/utils/numbers.ml ../ocaml/utils/numbers.mli ../ocaml/utils/profile.ml ../ocaml/utils/profile.mli ../ocaml/utils/tbl.ml ../ocaml/utils/tbl.mli ../ocaml/utils/terminfo.ml ../ocaml/utils/terminfo.mli ../ocaml/utils/warnings.ml ../ocaml/utils/warnings.mli ./common/bs_loc.ml ./common/bs_loc.mli ./common/bs_version.ml ./common/bs_version.mli ./common/bs_warnings.ml ./common/bs_warnings.mli ./common/ext_log.ml ./common/ext_log.mli ./common/js_config.ml ./common/js_config.mli ./common/lam_methname.ml ./common/lam_methname.mli ./core/bs_conditional_initial.ml ./core/bs_conditional_initial.mli ./core/classify_function.ml ./core/classify_function.mli ./core/config_util.ml ./core/config_util.mli ./core/config_whole_compiler.ml ./core/config_whole_compiler.mli ./core/j.ml ./core/js_analyzer.ml ./core/js_analyzer.mli ./core/js_arr.ml ./core/js_arr.mli ./core/js_ast_util.ml ./core/js_ast_util.mli ./core/js_block_runtime.ml ./core/js_block_runtime.mli ./core/js_call_info.ml ./core/js_call_info.mli ./core/js_closure.ml ./core/js_closure.mli ./core/js_cmj_datasets.ml ./core/js_cmj_datasets.mli ./core/js_cmj_format.ml ./core/js_cmj_format.mli ./core/js_cmj_load.ml ./core/js_cmj_load.mli ./core/js_current_package_info.ml ./core/js_current_package_info.mli ./core/js_dump.ml ./core/js_dump.mli ./core/js_dump_import_export.ml ./core/js_dump_import_export.mli ./core/js_dump_lit.ml ./core/js_dump_program.ml ./core/js_dump_program.mli ./core/js_dump_property.ml ./core/js_dump_property.mli ./core/js_dump_string.ml ./core/js_dump_string.mli ./core/js_exp_make.ml ./core/js_exp_make.mli ./core/js_fold.ml ./core/js_fold_basic.ml ./core/js_fold_basic.mli ./core/js_fun_env.ml ./core/js_fun_env.mli ./core/js_long.ml ./core/js_long.mli ./core/js_map.ml ./core/js_name_of_module_id.ml ./core/js_name_of_module_id.mli ./core/js_number.ml ./core/js_number.mli ./core/js_of_lam_array.ml ./core/js_of_lam_array.mli ./core/js_of_lam_block.ml ./core/js_of_lam_block.mli ./core/js_of_lam_exception.ml ./core/js_of_lam_exception.mli ./core/js_of_lam_option.ml ./core/js_of_lam_option.mli ./core/js_of_lam_polyvar.ml ./core/js_of_lam_polyvar.mli ./core/js_of_lam_string.ml ./core/js_of_lam_string.mli ./core/js_of_lam_tuple.ml ./core/js_of_lam_tuple.mli ./core/js_of_lam_variant.ml ./core/js_of_lam_variant.mli ./core/js_op.ml ./core/js_op_util.ml ./core/js_op_util.mli ./core/js_output.ml ./core/js_output.mli ./core/js_package_info.ml ./core/js_package_info.mli ./core/js_pass_debug.ml ./core/js_pass_debug.mli ./core/js_pass_flatten.ml ./core/js_pass_flatten.mli ./core/js_pass_flatten_and_mark_dead.ml ./core/js_pass_flatten_and_mark_dead.mli ./core/js_pass_scope.ml ./core/js_pass_scope.mli ./core/js_pass_tailcall_inline.ml ./core/js_pass_tailcall_inline.mli ./core/js_raw_exp_info.ml ./core/js_shake.ml ./core/js_shake.mli ./core/js_stmt_make.ml ./core/js_stmt_make.mli ./core/lam.ml ./core/lam.mli ./core/lam_analysis.ml ./core/lam_analysis.mli ./core/lam_arity.ml ./core/lam_arity.mli ./core/lam_arity_analysis.ml ./core/lam_arity_analysis.mli ./core/lam_beta_reduce.ml ./core/lam_beta_reduce.mli ./core/lam_beta_reduce_util.ml ./core/lam_beta_reduce_util.mli ./core/lam_bounded_vars.ml ./core/lam_bounded_vars.mli ./core/lam_closure.ml ./core/lam_closure.mli ./core/lam_coercion.ml ./core/lam_coercion.mli ./core/lam_compat.ml ./core/lam_compat.mli ./core/lam_compile.ml ./core/lam_compile.mli ./core/lam_compile_const.ml ./core/lam_compile_const.mli ./core/lam_compile_context.ml ./core/lam_compile_context.mli ./core/lam_compile_env.ml ./core/lam_compile_env.mli ./core/lam_compile_external_call.ml ./core/lam_compile_external_call.mli ./core/lam_compile_external_obj.ml ./core/lam_compile_external_obj.mli ./core/lam_compile_main.ml ./core/lam_compile_main.mli ./core/lam_compile_primitive.ml ./core/lam_compile_primitive.mli ./core/lam_compile_util.ml ./core/lam_compile_util.mli ./core/lam_constant.ml ./core/lam_constant.mli ./core/lam_constant_convert.ml ./core/lam_constant_convert.mli ./core/lam_convert.ml ./core/lam_convert.mli ./core/lam_dce.ml ./core/lam_dce.mli ./core/lam_dispatch_primitive.ml ./core/lam_dispatch_primitive.mli ./core/lam_eta_conversion.ml ./core/lam_eta_conversion.mli ./core/lam_exit_code.ml ./core/lam_exit_code.mli ./core/lam_exit_count.ml ./core/lam_exit_count.mli ./core/lam_free_variables.ml ./core/lam_free_variables.mli ./core/lam_group.ml ./core/lam_group.mli ./core/lam_hit.ml ./core/lam_hit.mli ./core/lam_id_kind.ml ./core/lam_id_kind.mli ./core/lam_inline_util.ml ./core/lam_inline_util.mli ./core/lam_iter.ml ./core/lam_iter.mli ./core/lam_module_ident.ml ./core/lam_module_ident.mli ./core/lam_pass_alpha_conversion.ml ./core/lam_pass_alpha_conversion.mli ./core/lam_pass_collect.ml ./core/lam_pass_collect.mli ./core/lam_pass_count.ml ./core/lam_pass_count.mli ./core/lam_pass_deep_flatten.ml ./core/lam_pass_deep_flatten.mli ./core/lam_pass_eliminate_ref.ml ./core/lam_pass_eliminate_ref.mli ./core/lam_pass_exits.ml ./core/lam_pass_exits.mli ./core/lam_pass_lets_dce.ml ./core/lam_pass_lets_dce.mli ./core/lam_pass_remove_alias.ml ./core/lam_pass_remove_alias.mli ./core/lam_pointer_info.ml ./core/lam_pointer_info.mli ./core/lam_primitive.ml ./core/lam_primitive.mli ./core/lam_print.ml ./core/lam_print.mli ./core/lam_scc.ml ./core/lam_scc.mli ./core/lam_stats.ml ./core/lam_stats.mli ./core/lam_stats_export.ml ./core/lam_stats_export.mli ./core/lam_subst.ml ./core/lam_subst.mli ./core/lam_tag_info.ml ./core/lam_util.ml ./core/lam_util.mli ./core/lam_var_stats.ml ./core/lam_var_stats.mli ./core/matching_polyfill.ml ./core/matching_polyfill.mli ./core/primitive_compat.ml ./core/primitive_compat.mli ./core/record_attributes_check.ml ./depends/bs_exception.ml ./depends/bs_exception.mli ./ext/bsc_warnings.ml ./ext/ext_arg.ml ./ext/ext_arg.mli ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_fmt.ml ./ext/ext_ident.ml ./ext/ext_ident.mli ./ext/ext_int.ml ./ext/ext_int.mli ./ext/ext_json_parse.ml ./ext/ext_json_parse.mli ./ext/ext_json_types.ml ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_modulename.ml ./ext/ext_modulename.mli ./ext/ext_namespace.ml ./ext/ext_namespace.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_path.ml ./ext/ext_path.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_position.ml ./ext/ext_position.mli ./ext/ext_pp.ml ./ext/ext_pp.mli ./ext/ext_pp_scope.ml ./ext/ext_pp_scope.mli ./ext/ext_ref.ml ./ext/ext_ref.mli ./ext/ext_scc.ml ./ext/ext_scc.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_sys.ml ./ext/ext_sys.mli ./ext/ext_utf8.ml ./ext/ext_utf8.mli ./ext/ext_util.ml ./ext/ext_util.mli ./ext/hash.ml ./ext/hash.mli ./ext/hash_gen.ml ./ext/hash_ident.ml ./ext/hash_ident.mli ./ext/hash_int.ml ./ext/hash_int.mli ./ext/hash_set.ml ./ext/hash_set.mli ./ext/hash_set_gen.ml ./ext/hash_set_ident.ml ./ext/hash_set_ident.mli ./ext/hash_set_ident_mask.ml ./ext/hash_set_ident_mask.mli ./ext/hash_set_poly.ml ./ext/hash_set_poly.mli ./ext/hash_set_string.ml ./ext/hash_set_string.mli ./ext/hash_string.ml ./ext/hash_string.mli ./ext/int_vec_util.ml ./ext/int_vec_util.mli ./ext/int_vec_vec.ml ./ext/int_vec_vec.mli ./ext/js_reserved_map.ml ./ext/js_reserved_map.mli ./ext/js_runtime_modules.ml ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/map_ident.ml ./ext/map_ident.mli ./ext/map_int.ml ./ext/map_int.mli ./ext/map_string.ml ./ext/map_string.mli ./ext/ordered_hash_map_gen.ml ./ext/ordered_hash_map_local_ident.ml ./ext/ordered_hash_map_local_ident.mli ./ext/set_gen.ml ./ext/set_ident.ml ./ext/set_ident.mli ./ext/set_string.ml ./ext/set_string.mli ./ext/vec.ml ./ext/vec.mli ./ext/vec_gen.ml ./ext/vec_int.ml ./ext/vec_int.mli ./main/jsoo_common.ml ./main/jsoo_common.mli ./main/jsoo_refmt_main.ml ./main/jsoo_refmt_main.mli ./main/refmt_api.ml ./outcome_printer/outcome_printer_ns.ml ./outcome_printer/outcome_printer_ns.mli ./stubs/bs_hash_stubs.ml ./super_errors/super_env.ml ./super_errors/super_location.ml ./super_errors/super_main.ml ./super_errors/super_misc.ml ./super_errors/super_misc.mli ./super_errors/super_pparse.ml ./super_errors/super_reason_react.ml ./super_errors/super_reason_react.mli ./super_errors/super_typecore.ml ./super_errors/super_typemod.ml ./super_errors/super_typetexp.ml ./super_errors/super_warnings.ml ./syntax/ast_attributes.ml ./syntax/ast_attributes.mli ./syntax/ast_bs_open.ml ./syntax/ast_bs_open.mli ./syntax/ast_comb.ml ./syntax/ast_comb.mli ./syntax/ast_compatible.ml ./syntax/ast_compatible.mli ./syntax/ast_core_type.ml ./syntax/ast_core_type.mli ./syntax/ast_core_type_class_type.ml ./syntax/ast_core_type_class_type.mli ./syntax/ast_derive.ml ./syntax/ast_derive.mli ./syntax/ast_derive_abstract.ml ./syntax/ast_derive_abstract.mli ./syntax/ast_derive_js_mapper.ml ./syntax/ast_derive_js_mapper.mli ./syntax/ast_derive_projector.ml ./syntax/ast_derive_projector.mli ./syntax/ast_derive_util.ml ./syntax/ast_derive_util.mli ./syntax/ast_exp.ml ./syntax/ast_exp.mli ./syntax/ast_exp_apply.ml ./syntax/ast_exp_apply.mli ./syntax/ast_exp_extension.ml ./syntax/ast_exp_extension.mli ./syntax/ast_external.ml ./syntax/ast_external.mli ./syntax/ast_external_mk.ml ./syntax/ast_external_mk.mli ./syntax/ast_external_process.ml ./syntax/ast_external_process.mli ./syntax/ast_literal.ml ./syntax/ast_literal.mli ./syntax/ast_open_cxt.ml ./syntax/ast_open_cxt.mli ./syntax/ast_pat.ml ./syntax/ast_pat.mli ./syntax/ast_payload.ml ./syntax/ast_payload.mli ./syntax/ast_polyvar.ml ./syntax/ast_polyvar.mli ./syntax/ast_raw.ml ./syntax/ast_raw.mli ./syntax/ast_reason_pp.ml ./syntax/ast_reason_pp.mli ./syntax/ast_signature.ml ./syntax/ast_signature.mli ./syntax/ast_structure.ml ./syntax/ast_structure.mli ./syntax/ast_tdcls.ml ./syntax/ast_tdcls.mli ./syntax/ast_tuple_pattern_flatten.ml ./syntax/ast_tuple_pattern_flatten.mli ./syntax/ast_utf8_string.ml ./syntax/ast_utf8_string.mli ./syntax/ast_utf8_string_interp.ml ./syntax/ast_utf8_string_interp.mli ./syntax/ast_util.ml ./syntax/ast_util.mli ./syntax/bs_ast_invariant.ml ./syntax/bs_ast_invariant.mli ./syntax/bs_ast_mapper.ml ./syntax/bs_ast_mapper.mli ./syntax/bs_builtin_ppx.ml ./syntax/bs_builtin_ppx.mli ./syntax/bs_syntaxerr.ml ./syntax/bs_syntaxerr.mli ./syntax/external_arg_spec.ml ./syntax/external_arg_spec.mli ./syntax/external_ffi_types.ml ./syntax/external_ffi_types.mli ./syntax/reactjs_jsx_ppx_v2.ml ./syntax/reactjs_jsx_ppx_v3.ml \ No newline at end of file diff --git a/lib/4.06.1/unstable/native_ppx.ml b/lib/4.06.1/unstable/native_ppx.ml index 5eeadfbca8..3df6616a8f 100644 --- a/lib/4.06.1/unstable/native_ppx.ml +++ b/lib/4.06.1/unstable/native_ppx.ml @@ -14129,15 +14129,13 @@ module Js_config : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* val get_packages_info : unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) (** return [package_name] and [path] when in script mode: *) -(* val get_current_package_name_and_path : Js_packages_info.module_system -> - Js_packages_info.info_query *) +(* val get_current_package_name_and_path : Js_package_info.module_system -> + Js_package_info.info_query *) (* val set_package_name : string -> unit val get_package_name : unit -> string option *) @@ -14178,7 +14176,6 @@ val syntax_only : bool ref val binary_ast : bool ref val simple_binary_ast : bool ref -val bs_suffix : bool ref val debug : bool ref val cmi_only : bool ref @@ -14235,8 +14232,6 @@ let set_diagnose b = diagnose := b let ( // ) = Filename.concat -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx_ml = ref false let no_builtin_ppx_mli = ref false @@ -14284,7 +14279,7 @@ end module Bs_warnings : sig #1 "bs_warnings.mli" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -14302,29 +14297,27 @@ module Bs_warnings : sig * 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. *) - -type t = - | Unsafe_poly_variant_type +type t = Unsafe_poly_variant_type val prerr_bs_ffi_warning : Location.t -> t -> unit +val warn_deprecated_bs_suffix_flag : unit -> unit -val warn_missing_primitive : Location.t -> string -> unit +val warn_missing_primitive : Location.t -> string -> unit -val warn_literal_overflow : Location.t -> unit +val warn_literal_overflow : Location.t -> unit -val error_unescaped_delimiter : - Location.t -> string -> unit +val error_unescaped_delimiter : Location.t -> string -> unit end = struct #1 "bs_warnings.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * 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, either version 3 of the License, or @@ -14342,117 +14335,106 @@ end = struct * 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. *) - - type t = | Unsafe_poly_variant_type - (* for users write code like this: - {[ external f : [`a of int ] -> string = ""]} - Here users forget about `[@bs.string]` or `[@bs.int]` - *) + (** for users write code like this: + {[ external f : [ `a of int ] -> string = "" ]} + Here users forget about `[@bs.string]` or `[@bs.int]` *) let to_string t = match t with - | Unsafe_poly_variant_type - -> - "Here a OCaml polymorphic variant type passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]` " + | Unsafe_poly_variant_type -> + "Here a OCaml polymorphic variant type passed into JS, probably you \ + forgot annotations like `[@bs.int]` or `[@bs.string]` " + let warning_formatter = Format.err_formatter -let print_string_warning (loc : Location.t) x = - if loc.loc_ghost then - Format.fprintf warning_formatter "File %s@." !Location.input_name - else - Location.print warning_formatter loc ; - Format.fprintf warning_formatter "@{Warning@}: %s@." x +let print_string_warning (loc : Location.t) ?(kind = "Warning") x = + if loc.loc_ghost then + Format.fprintf warning_formatter "File %s@." !Location.input_name + else Location.print warning_formatter loc; + Format.fprintf warning_formatter "@{%s@}: %s@." kind x -let prerr_bs_ffi_warning loc x = - Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) -let unimplemented_primitive = "Unimplemented primitive used:" -type error = +let prerr_bs_ffi_warning loc x = + Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) + + +let unimplemented_primitive = "Unimplemented primitive used:" +type error = | Uninterpreted_delimiters of string - | Unimplemented_primitive of string -exception Error of Location.t * error + | Unimplemented_primitive of string +exception Error of Location.t * error let pp_error fmt x = - match x with - | Unimplemented_primitive str -> - Format.pp_print_string fmt unimplemented_primitive; - Format.pp_print_string fmt str - - | Uninterpreted_delimiters str -> - Format.pp_print_string fmt "Uninterpreted delimiters" ; - Format.pp_print_string fmt str + match x with + | Unimplemented_primitive str -> + Format.pp_print_string fmt unimplemented_primitive; + Format.pp_print_string fmt str + | Uninterpreted_delimiters str -> + Format.pp_print_string fmt "Uninterpreted delimiters"; + Format.pp_print_string fmt str +let () = + Location.register_error_of_exn (function + | Error (loc, err) -> Some (Location.error_of_printer loc pp_error err) + | _ -> None) -let () = - Location.register_error_of_exn (function - | Error (loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) +let warn_deprecated_bs_suffix_flag () = + if not !Clflags.bs_quiet then ( + print_string_warning Location.none ~kind:"DEPRECATED" + "`-bs-suffix` used; consider using third field of `-bs-package-output` \ + instead"; + Format.pp_print_flush warning_formatter () ) +let warn_missing_primitive loc txt = + if (not !Js_config.no_warn_unimplemented_external) && not !Clflags.bs_quiet + then ( + print_string_warning loc (unimplemented_primitive ^ txt ^ " \n"); + Format.pp_print_flush warning_formatter () ) -let warn_missing_primitive loc txt = - if not !Js_config.no_warn_unimplemented_external && not !Clflags.bs_quiet then - begin - print_string_warning loc ( unimplemented_primitive ^ txt ^ " \n" ); - Format.pp_print_flush warning_formatter () - end -let warn_literal_overflow loc = - if not !Clflags.bs_quiet then - begin - print_string_warning loc +let warn_literal_overflow loc = + if not !Clflags.bs_quiet then ( + print_string_warning loc "Integer literal exceeds the range of representable integers of type int"; - Format.pp_print_flush warning_formatter () - end - + Format.pp_print_flush warning_formatter () ) -let error_unescaped_delimiter loc txt = - raise (Error(loc, Uninterpreted_delimiters txt)) +let error_unescaped_delimiter loc txt = + raise (Error (loc, Uninterpreted_delimiters txt)) +(** Note the standard way of reporting error in compiler: + val Location.register_error_of_exn : (exn -> Location.error option) -> unit + val Location.error_of_printer : Location.t -> (Format.formatter -> error -> + unit) -> error -> Location.error + Define an error type + type error exception Error of Location.t * error -(** - Note the standard way of reporting error in compiler: - - val Location.register_error_of_exn : (exn -> Location.error option) -> unit - val Location.error_of_printer : Location.t -> - (Format.formatter -> error -> unit) -> error -> Location.error - - Define an error type + Provide a printer to error - type error - exception Error of Location.t * error - - Provide a printer to error - - {[ - let () = - Location.register_error_of_exn - (function - | Error(loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) - ]} -*) + {[ + let () = + Location.register_error_of_exn (function + | Error (loc, err) -> + Some (Location.error_of_printer loc pp_error err) + | _ -> None) + ]} *) end module Ext_util : sig @@ -15156,7 +15138,11 @@ val suffix_rei : string val suffix_d : string val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string (* val suffix_re_js : string *) val suffix_gen_js : string val suffix_gen_tsx: string @@ -15294,8 +15280,13 @@ let suffix_reast = ".reast" let suffix_reiast = ".reiast" let suffix_mliast_simple = ".mliast_simple" let suffix_d = ".d" + let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" (* let suffix_re_js = ".re.js" *) let suffix_gen_js = ".gen.js" let suffix_gen_tsx = ".gen.tsx" diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index d12741bee0..df3fcb9908 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -7015,15 +7015,13 @@ module Js_config : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* val get_packages_info : unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) (** return [package_name] and [path] when in script mode: *) -(* val get_current_package_name_and_path : Js_packages_info.module_system -> - Js_packages_info.info_query *) +(* val get_current_package_name_and_path : Js_package_info.module_system -> + Js_package_info.info_query *) (* val set_package_name : string -> unit val get_package_name : unit -> string option *) @@ -7064,7 +7062,6 @@ val syntax_only : bool ref val binary_ast : bool ref val simple_binary_ast : bool ref -val bs_suffix : bool ref val debug : bool ref val cmi_only : bool ref @@ -7121,8 +7118,6 @@ let set_diagnose b = diagnose := b let ( // ) = Filename.concat -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx_ml = ref false let no_builtin_ppx_mli = ref false @@ -61182,283 +61177,6 @@ let add_int_4 (b : t ) (x : int ) = -end -module Literals : sig -#1 "literals.mli" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) - - - - - - -val js_array_ctor : string -val js_type_number : string -val js_type_string : string -val js_type_object : string -val js_type_boolean : string -val js_undefined : string -val js_prop_length : string - -val param : string -val partial_arg : string -val prim : string - -(**temporary varaible used in {!Js_ast_util} *) -val tmp : string - -val create : string -val runtime : string -val stdlib : string -val imul : string - -val setter_suffix : string -val setter_suffix_len : int - - -val debugger : string - -val unsafe_downgrade : string -val fn_run : string -val method_run : string -val fn_method : string -val fn_mk : string - -(** callback actually, not exposed to user yet *) -(* val js_fn_runmethod : string *) - -val bs_deriving : string -val bs_deriving_dot : string -val bs_type : string - -(** nodejs *) - -val node_modules : string -val node_modules_length : int -val package_json : string -val bsconfig_json : string -val build_ninja : string - -(* Name of the library file created for each external dependency. *) -val library_file : string - -val suffix_a : string -val suffix_cmj : string -val suffix_cmo : string -val suffix_cma : string -val suffix_cmi : string -val suffix_cmx : string -val suffix_cmxa : string -val suffix_ml : string -val suffix_mlast : string -val suffix_mlast_simple : string -val suffix_mliast : string -val suffix_reast : string -val suffix_reiast : string - -val suffix_mliast_simple : string -val suffix_mlmap : string -val suffix_mll : string -val suffix_re : string -val suffix_rei : string - -val suffix_d : string -val suffix_js : string -val suffix_bs_js : string -(* val suffix_re_js : string *) -val suffix_gen_js : string -val suffix_gen_tsx: string - -val suffix_tsx : string - -val suffix_mli : string -val suffix_cmt : string -val suffix_cmti : string - -val commonjs : string - -val es6 : string -val es6_global : string - -val unused_attribute : string -val dash_nostdlib : string - -val reactjs_jsx_ppx_2_exe : string -val reactjs_jsx_ppx_3_exe : string - -val native : string -val bytecode : string -val js : string - -val node_sep : string -val node_parent : string -val node_current : string -val gentype_import : string - -val bsbuild_cache : string - -val sourcedirs_meta : string - -end = struct -#1 "literals.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) - - - - - - - -let js_array_ctor = "Array" -let js_type_number = "number" -let js_type_string = "string" -let js_type_object = "object" -let js_type_boolean = "boolean" -let js_undefined = "undefined" -let js_prop_length = "length" - -let prim = "prim" -let param = "param" -let partial_arg = "partial_arg" -let tmp = "tmp" - -let create = "create" (* {!Caml_exceptions.create}*) - -let runtime = "runtime" (* runtime directory *) - -let stdlib = "stdlib" - -let imul = "imul" (* signed int32 mul *) - -let setter_suffix = "#=" -let setter_suffix_len = String.length setter_suffix - -let debugger = "debugger" -let unsafe_downgrade = "unsafe_downgrade" -let fn_run = "fn_run" -let method_run = "method_run" - -let fn_method = "fn_method" -let fn_mk = "fn_mk" -(*let js_fn_runmethod = "js_fn_runmethod"*) - -let bs_deriving = "bs.deriving" -let bs_deriving_dot = "bs.deriving." -let bs_type = "bs.type" - - -(** nodejs *) -let node_modules = "node_modules" -let node_modules_length = String.length "node_modules" -let package_json = "package.json" -let bsconfig_json = "bsconfig.json" -let build_ninja = "build.ninja" - -(* Name of the library file created for each external dependency. *) -let library_file = "lib" - -let suffix_a = ".a" -let suffix_cmj = ".cmj" -let suffix_cmo = ".cmo" -let suffix_cma = ".cma" -let suffix_cmi = ".cmi" -let suffix_cmx = ".cmx" -let suffix_cmxa = ".cmxa" -let suffix_mll = ".mll" -let suffix_ml = ".ml" -let suffix_mli = ".mli" -let suffix_re = ".re" -let suffix_rei = ".rei" -let suffix_mlmap = ".mlmap" - -let suffix_cmt = ".cmt" -let suffix_cmti = ".cmti" -let suffix_mlast = ".mlast" -let suffix_mlast_simple = ".mlast_simple" -let suffix_mliast = ".mliast" -let suffix_reast = ".reast" -let suffix_reiast = ".reiast" -let suffix_mliast_simple = ".mliast_simple" -let suffix_d = ".d" -let suffix_js = ".js" -let suffix_bs_js = ".bs.js" -(* let suffix_re_js = ".re.js" *) -let suffix_gen_js = ".gen.js" -let suffix_gen_tsx = ".gen.tsx" -let suffix_tsx = ".tsx" - -let commonjs = "commonjs" - -let es6 = "es6" -let es6_global = "es6-global" - -let unused_attribute = "Unused attribute " -let dash_nostdlib = "-nostdlib" - -let reactjs_jsx_ppx_2_exe = "reactjs_jsx_ppx_2.exe" -let reactjs_jsx_ppx_3_exe = "reactjs_jsx_ppx_3.exe" - -let native = "native" -let bytecode = "bytecode" -let js = "js" - - - -(** Used when produce node compatible paths *) -let node_sep = "/" -let node_parent = ".." -let node_current = "." - -let gentype_import = "genType.import" - -let bsbuild_cache = ".bsbuild" - -let sourcedirs_meta = ".sourcedirs.json" - end module Ext_namespace : sig #1 "ext_namespace.mli" @@ -61492,14 +61210,18 @@ val make : ?ns:string -> string -> string val try_split_module_name : string -> (string * string) option -val change_ext_ns_suffix : string -> string -> string +val replace_namespace_with_extension : name:string -> ext:string -> string +(** [replace_namespace_with_extension ~name ~ext] removes the part of [name] + after [ns_sep_char], if any; and appends [ext]. +*) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -val js_name_of_modulename : string -> file_kind -> string +val js_filename_of_modulename : + name:string -> ext:string -> leading_case -> string (** Predicts the JavaScript filename for a given (possibly namespaced) module- - name; i.e. [js_name_of_modulename "AA-Ns" Little_bs] would produce - ["aA.bs.js"]. *) + name; i.e. [js_filename_of_modulename ~name:"AA-Ns" ~ext:".js" Lower] would + produce ["aA.bs.js"]. *) val is_valid_npm_package_name : string -> bool @@ -61562,7 +61284,7 @@ let rec rindex_rec s i = #1933 when removing ns suffix, don't pass the bound of basename FIXME: micro-optimizaiton *) -let change_ext_ns_suffix name ext = +let replace_namespace_with_extension ~name ~ext = let i = rindex_rec name (String.length name - 1) in if i < 0 then name ^ ext else String.sub name 0 i ^ ext @@ -61574,18 +61296,15 @@ let try_split_module_name name = else Some (String.sub name (i + 1) (len - i - 1), String.sub name 0 i) -type file_kind = Upper_js | Upper_bs | Little_js | Little_bs +type leading_case = Upper | Lower -let js_name_of_modulename s little = - match little with - | Little_js -> - change_ext_ns_suffix (Ext_string.uncapitalize_ascii s) Literals.suffix_js - | Little_bs -> - change_ext_ns_suffix - (Ext_string.uncapitalize_ascii s) - Literals.suffix_bs_js - | Upper_js -> change_ext_ns_suffix s Literals.suffix_js - | Upper_bs -> change_ext_ns_suffix s Literals.suffix_bs_js +let js_filename_of_modulename ~name ~ext (leading_case : leading_case) = + match leading_case with + | Lower -> + replace_namespace_with_extension + ~name:(Ext_string.uncapitalize_ascii name) + ~ext + | Upper -> replace_namespace_with_extension ~name ~ext (** https://docs.npmjs.com/files/package.json @@ -64025,6 +63744,845 @@ let bt () = Printf.eprintf "File \"%s\", line %d, characters %d-%d\n" bt.filename bt.line_number bt.start_char bt.end_char ) +end +module Ext_arg : sig +#1 "ext_arg.mli" +val bad_argf : ('a, unit, string, 'b) format4 -> 'a + +end = struct +#1 "ext_arg.ml" +let bad_argf fmt = Format.ksprintf (fun x -> raise (Arg.Bad x ) ) fmt +end +module Bs_warnings : sig +#1 "bs_warnings.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + +type t = Unsafe_poly_variant_type + +val prerr_bs_ffi_warning : Location.t -> t -> unit + +val warn_deprecated_bs_suffix_flag : unit -> unit + +val warn_missing_primitive : Location.t -> string -> unit + +val warn_literal_overflow : Location.t -> unit + +val error_unescaped_delimiter : Location.t -> string -> unit + +end = struct +#1 "bs_warnings.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + +type t = + | Unsafe_poly_variant_type + (** for users write code like this: + + {[ external f : [ `a of int ] -> string = "" ]} + + Here users forget about `[@bs.string]` or `[@bs.int]` *) + +let to_string t = + match t with + | Unsafe_poly_variant_type -> + "Here a OCaml polymorphic variant type passed into JS, probably you \ + forgot annotations like `[@bs.int]` or `[@bs.string]` " + + +let warning_formatter = Format.err_formatter + +let print_string_warning (loc : Location.t) ?(kind = "Warning") x = + if loc.loc_ghost then + Format.fprintf warning_formatter "File %s@." !Location.input_name + else Location.print warning_formatter loc; + Format.fprintf warning_formatter "@{%s@}: %s@." kind x + + +let prerr_bs_ffi_warning loc x = + Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) + + +let unimplemented_primitive = "Unimplemented primitive used:" +type error = + | Uninterpreted_delimiters of string + | Unimplemented_primitive of string +exception Error of Location.t * error + +let pp_error fmt x = + match x with + | Unimplemented_primitive str -> + Format.pp_print_string fmt unimplemented_primitive; + Format.pp_print_string fmt str + | Uninterpreted_delimiters str -> + Format.pp_print_string fmt "Uninterpreted delimiters"; + Format.pp_print_string fmt str + + +let () = + Location.register_error_of_exn (function + | Error (loc, err) -> Some (Location.error_of_printer loc pp_error err) + | _ -> None) + + +let warn_deprecated_bs_suffix_flag () = + if not !Clflags.bs_quiet then ( + print_string_warning Location.none ~kind:"DEPRECATED" + "`-bs-suffix` used; consider using third field of `-bs-package-output` \ + instead"; + Format.pp_print_flush warning_formatter () ) + + +let warn_missing_primitive loc txt = + if (not !Js_config.no_warn_unimplemented_external) && not !Clflags.bs_quiet + then ( + print_string_warning loc (unimplemented_primitive ^ txt ^ " \n"); + Format.pp_print_flush warning_formatter () ) + + +let warn_literal_overflow loc = + if not !Clflags.bs_quiet then ( + print_string_warning loc + "Integer literal exceeds the range of representable integers of type int"; + Format.pp_print_flush warning_formatter () ) + + +let error_unescaped_delimiter loc txt = + raise (Error (loc, Uninterpreted_delimiters txt)) + + +(** Note the standard way of reporting error in compiler: + + val Location.register_error_of_exn : (exn -> Location.error option) -> unit + val Location.error_of_printer : Location.t -> (Format.formatter -> error -> + unit) -> error -> Location.error + + Define an error type + + type error exception Error of Location.t * error + + Provide a printer to error + + {[ + let () = + Location.register_error_of_exn (function + | Error (loc, err) -> + Some (Location.error_of_printer loc pp_error err) + | _ -> None) + ]} *) + +end +module Literals : sig +#1 "literals.mli" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + + + + + + +val js_array_ctor : string +val js_type_number : string +val js_type_string : string +val js_type_object : string +val js_type_boolean : string +val js_undefined : string +val js_prop_length : string + +val param : string +val partial_arg : string +val prim : string + +(**temporary varaible used in {!Js_ast_util} *) +val tmp : string + +val create : string +val runtime : string +val stdlib : string +val imul : string + +val setter_suffix : string +val setter_suffix_len : int + + +val debugger : string + +val unsafe_downgrade : string +val fn_run : string +val method_run : string +val fn_method : string +val fn_mk : string + +(** callback actually, not exposed to user yet *) +(* val js_fn_runmethod : string *) + +val bs_deriving : string +val bs_deriving_dot : string +val bs_type : string + +(** nodejs *) + +val node_modules : string +val node_modules_length : int +val package_json : string +val bsconfig_json : string +val build_ninja : string + +(* Name of the library file created for each external dependency. *) +val library_file : string + +val suffix_a : string +val suffix_cmj : string +val suffix_cmo : string +val suffix_cma : string +val suffix_cmi : string +val suffix_cmx : string +val suffix_cmxa : string +val suffix_ml : string +val suffix_mlast : string +val suffix_mlast_simple : string +val suffix_mliast : string +val suffix_reast : string +val suffix_reiast : string + +val suffix_mliast_simple : string +val suffix_mlmap : string +val suffix_mll : string +val suffix_re : string +val suffix_rei : string + +val suffix_d : string +val suffix_js : string +val suffix_mjs : string +val suffix_cjs : string +val suffix_bs_js : string +val suffix_bs_mjs : string +val suffix_bs_cjs : string +(* val suffix_re_js : string *) +val suffix_gen_js : string +val suffix_gen_tsx: string + +val suffix_tsx : string + +val suffix_mli : string +val suffix_cmt : string +val suffix_cmti : string + +val commonjs : string + +val es6 : string +val es6_global : string + +val unused_attribute : string +val dash_nostdlib : string + +val reactjs_jsx_ppx_2_exe : string +val reactjs_jsx_ppx_3_exe : string + +val native : string +val bytecode : string +val js : string + +val node_sep : string +val node_parent : string +val node_current : string +val gentype_import : string + +val bsbuild_cache : string + +val sourcedirs_meta : string + +end = struct +#1 "literals.ml" +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + + + + + + + +let js_array_ctor = "Array" +let js_type_number = "number" +let js_type_string = "string" +let js_type_object = "object" +let js_type_boolean = "boolean" +let js_undefined = "undefined" +let js_prop_length = "length" + +let prim = "prim" +let param = "param" +let partial_arg = "partial_arg" +let tmp = "tmp" + +let create = "create" (* {!Caml_exceptions.create}*) + +let runtime = "runtime" (* runtime directory *) + +let stdlib = "stdlib" + +let imul = "imul" (* signed int32 mul *) + +let setter_suffix = "#=" +let setter_suffix_len = String.length setter_suffix + +let debugger = "debugger" +let unsafe_downgrade = "unsafe_downgrade" +let fn_run = "fn_run" +let method_run = "method_run" + +let fn_method = "fn_method" +let fn_mk = "fn_mk" +(*let js_fn_runmethod = "js_fn_runmethod"*) + +let bs_deriving = "bs.deriving" +let bs_deriving_dot = "bs.deriving." +let bs_type = "bs.type" + + +(** nodejs *) +let node_modules = "node_modules" +let node_modules_length = String.length "node_modules" +let package_json = "package.json" +let bsconfig_json = "bsconfig.json" +let build_ninja = "build.ninja" + +(* Name of the library file created for each external dependency. *) +let library_file = "lib" + +let suffix_a = ".a" +let suffix_cmj = ".cmj" +let suffix_cmo = ".cmo" +let suffix_cma = ".cma" +let suffix_cmi = ".cmi" +let suffix_cmx = ".cmx" +let suffix_cmxa = ".cmxa" +let suffix_mll = ".mll" +let suffix_ml = ".ml" +let suffix_mli = ".mli" +let suffix_re = ".re" +let suffix_rei = ".rei" +let suffix_mlmap = ".mlmap" + +let suffix_cmt = ".cmt" +let suffix_cmti = ".cmti" +let suffix_mlast = ".mlast" +let suffix_mlast_simple = ".mlast_simple" +let suffix_mliast = ".mliast" +let suffix_reast = ".reast" +let suffix_reiast = ".reiast" +let suffix_mliast_simple = ".mliast_simple" +let suffix_d = ".d" + +let suffix_js = ".js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" +let suffix_bs_js = ".bs.js" +let suffix_bs_mjs = ".bs.mjs" +let suffix_bs_cjs = ".bs.cjs" +(* let suffix_re_js = ".re.js" *) +let suffix_gen_js = ".gen.js" +let suffix_gen_tsx = ".gen.tsx" +let suffix_tsx = ".tsx" + +let commonjs = "commonjs" + +let es6 = "es6" +let es6_global = "es6-global" + +let unused_attribute = "Unused attribute " +let dash_nostdlib = "-nostdlib" + +let reactjs_jsx_ppx_2_exe = "reactjs_jsx_ppx_2.exe" +let reactjs_jsx_ppx_3_exe = "reactjs_jsx_ppx_3.exe" + +let native = "native" +let bytecode = "bytecode" +let js = "js" + + + +(** Used when produce node compatible paths *) +let node_sep = "/" +let node_parent = ".." +let node_current = "." + +let gentype_import = "genType.import" + +let bsbuild_cache = ".bsbuild" + +let sourcedirs_meta = ".sourcedirs.json" + +end +module Js_package_info : sig +#1 "js_package_info.mli" +(* Copyright (C) 2017 Authors of BuckleScript + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + +type module_system = NodeJS | Es6 | Es6_global + +val runtime_dir_of_module_system : module_system -> string + +val runtime_package_path : module_system -> string -> string + +type location_descriptor = { + module_system : module_system; + path : string; + extension : string; +} + +type t + +val is_runtime_package : t -> bool + +val same_package_by_name : t -> t -> bool + +val iter : t -> (location_descriptor -> unit) -> unit + +val empty : t +val from_name : string -> t +val is_empty : t -> bool + +val dump_package_info : Format.formatter -> t -> unit + +val deprecated_set_bs_extension : unit -> unit + +val append_location_descriptor_of_string : t -> string -> t +(** used by command line option e.g [-bs-package-output commonjs:xx/path:ext] *) + +type package_paths = { + rel_path : string; + pkg_rel_path : string; + extension : string; +} + +type query_result = + | Package_script + | Package_not_found + | Package_found of package_paths + +val get_output_dir : t -> package_dir:string -> module_system -> string + +(* Note here we compare the package info by order in theory, we can compare it + by set semantics *) +val query_package_location_by_module_system : t -> module_system -> query_result + +end = struct +#1 "js_package_info.ml" +(* Copyright (C) 2017 Authors of BuckleScript + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + +[@@@ocaml.warning "+9"] + +type path = string + +type module_system = + | NodeJS + | Es6 + (* ignore node_modules, just calcluating relative path *) + | Es6_global + +(* ocamlopt could not optimize such simple case... *) +let compatible (dep : module_system) (query : module_system) = + match query with + | NodeJS -> dep = NodeJS + | Es6 -> dep = Es6 + (* As a dependency Leaf Node, it is the same either [global] or [not] *) + | Es6_global -> dep = Es6_global || dep = Es6 + + +type location_descriptor = { + module_system : module_system; + path : string; + extension : string; +} + +type package_name = Pkg_empty | Pkg_runtime | Pkg_normal of string + +let deprecated_use_bs_extension = ref false + +let runtime_package_name = "bs-platform" + +let ( // ) = Filename.concat + +(* in runtime lib, [es6] and [es6-global] are treated the same way *) +let runtime_dir_of_module_system (ms : module_system) = + match ms with + | NodeJS -> "js" + | Es6 | Es6_global -> "es6" + + +let runtime_package_path (ms : module_system) js_file = + runtime_package_name // "lib" // runtime_dir_of_module_system ms // js_file + + +type t = { name : package_name; locations : location_descriptor list } + +let same_package_by_name (x : t) (y : t) = x.name = y.name + +let is_runtime_package (x : t) = x.name = Pkg_runtime + +let iter (x : t) = Ext_list.iter x.locations + +(* TODO: not allowing user to provide such specific package name For empty + package, [-bs-package-output] does not make sense it is only allowed to + generate commonjs file in the same directory *) +let empty : t = { name = Pkg_empty; locations = [] } + +let from_name (name : string) = + if name = runtime_package_name then { name = Pkg_runtime; locations = [] } + else { name = Pkg_normal name; locations = [] } + + +let is_empty (x : t) = x.name = Pkg_empty + +let string_of_module_system (ms : module_system) = + match ms with + | NodeJS -> "NodeJS" + | Es6 -> "Es6" + | Es6_global -> "Es6_global" + + +let module_system_of_string package_name : module_system option = + match package_name with + | "commonjs" -> Some NodeJS + | "es6" -> Some Es6 + | "es6-global" -> Some Es6_global + | _ -> None + + +let dump_location_descriptor (fmt : Format.formatter) + { module_system = ms; path; extension } = + Format.fprintf fmt "@[%s:@ %s:@ %s@]" + (string_of_module_system ms) + path extension + + +let dump_package_name fmt (x : package_name) = + match x with + | Pkg_empty -> Format.fprintf fmt "@empty_pkg@" + | Pkg_normal s -> Format.pp_print_string fmt s + | Pkg_runtime -> Format.pp_print_string fmt runtime_package_name + + +let dump_package_info (fmt : Format.formatter) ({ name; locations } : t) = + Format.fprintf fmt "@[%a;@ @[%a@]@]" dump_package_name name + (Format.pp_print_list + ~pp_sep:(fun fmt () -> Format.pp_print_space fmt ()) + dump_location_descriptor) + locations + + +type package_paths = { + rel_path : string; + pkg_rel_path : string; + extension : string; +} +type query_result = + | Package_script + | Package_not_found + | Package_found of package_paths + +(* Note that package-name has to be exactly the same as npm package name, + otherwise the path resolution will be wrong *) +let query_package_location_by_module_system ({ name; locations } : t) + (module_system : module_system) : query_result = + match name with + | Pkg_empty -> Package_script + | Pkg_normal name -> ( + match + Ext_list.find_first locations (fun k -> + compatible k.module_system module_system) + with + | Some { path = rel_path; extension; module_system = _ms } -> + let pkg_rel_path = name // rel_path in + Package_found { rel_path; pkg_rel_path; extension } + | None -> Package_not_found ) + | Pkg_runtime -> ( + match + Ext_list.find_first locations (fun k -> + compatible k.module_system module_system) + with + | Some { path = rel_path; extension; module_system = _ms } -> + let pkg_rel_path = runtime_package_name // rel_path in + Package_found { rel_path; pkg_rel_path; extension } + | None -> Package_not_found ) + + +let get_js_path (x : t) module_system = + match + Ext_list.find_first x.locations (fun k -> + compatible k.module_system module_system) + with + | Some k -> k.path + | None -> assert false + + +(* for a single pass compilation, [output_dir] can be cached *) +let get_output_dir (info : t) ~package_dir module_system = + Filename.concat package_dir (get_js_path info module_system) + + +let deprecated_set_bs_extension () = + Bs_warnings.warn_deprecated_bs_suffix_flag (); + deprecated_use_bs_extension := true + + +let deprecated_get_default_extension () = + if !deprecated_use_bs_extension then Literals.suffix_bs_js + else Literals.suffix_js + + +(* FIXME: The deprecated -bs-suffix will only affect -bs-package-output flags + passed *after* it. *) +let append_location_descriptor_of_string (packages_info : t) (s : string) : t = + let module_system, path, extension = + match Ext_string.split ~keep_empty:false s ':' with + | [ module_system; path; extension ] -> (module_system, path, extension) + (* Note that, for most users, the default values for [module_system] and + [extension] come not from here, but from [bsb], which always invokes this + with a fully-populated [-bs-package-output]. + + If you're changing the default, make sure both places match! *) + | [ module_system; path ] -> + (module_system, path, deprecated_get_default_extension ()) + | [ path ] -> ("NodeJS", path, deprecated_get_default_extension ()) + | _ -> Ext_arg.bad_argf "invalid value for -bs-package-output: %s" s + in + let module_system = + match module_system_of_string module_system with + | Some x -> x + | None -> + Ext_arg.bad_argf "invalid module system in -bs-package-output: %s" + module_system + in + { + packages_info with + locations = { module_system; path; extension } :: packages_info.locations; + } + +(* support es6 modules instead + + TODO: enrich ast to support import export + http://www.ecma-international.org/ecma-262/6.0/#sec-imports For every module, + we need [Ident.t] for accessing and [filename] for import, they are not + necessarily the same. + + Es6 modules is not the same with commonjs, we use commonjs currently (play + better with node) + + FIXME: the module order matters? *) + +end +module Js_current_package_info : sig +#1 "js_current_package_info.mli" +(* Copyright (C) 2017 Authors of BuckleScript + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + +val set_package_name : string -> unit + +val set_package_map : string -> unit + +val get_packages_info : unit -> Js_package_info.t + +val append_location_descriptor_of_string : string -> unit + +end = struct +#1 "js_current_package_info.ml" +(* Copyright (C) 2017 Authors of BuckleScript + * + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a 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. *) + +let packages_info = ref Js_package_info.empty + +let set_package_name name = + if Js_package_info.is_empty !packages_info then + packages_info := Js_package_info.from_name name + else Ext_arg.bad_argf "duplicated flag for -bs-package-name" + + +let set_package_map module_name = + Clflags.dont_record_crc_unit := Some module_name; + Clflags.open_modules := module_name :: !Clflags.open_modules + + +let append_location_descriptor_of_string s = + if Js_package_info.is_empty !packages_info then + Ext_arg.bad_argf "please set package name first using -bs-package-name or -bs-ns" + else + packages_info := Js_package_info.append_location_descriptor_of_string !packages_info s + +let get_packages_info () = !packages_info + end module Bs_exception : sig #1 "bs_exception.mli" @@ -83560,286 +84118,6 @@ let inline_int_primitive i : string list = (Lam_constant.Const_int32 (Int32.of_int i))) ] end -module Ext_arg : sig -#1 "ext_arg.mli" -val bad_argf : ('a, unit, string, 'b) format4 -> 'a - -end = struct -#1 "ext_arg.ml" -let bad_argf fmt = Format.ksprintf (fun x -> raise (Arg.Bad x ) ) fmt -end -module Js_packages_info : sig -#1 "js_packages_info.mli" -(* Copyright (C) 2017 Authors of BuckleScript - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) - -type module_system = NodeJS | Es6 | Es6_global - -val runtime_dir_of_module_system : module_system -> string - -val runtime_package_path : module_system -> string -> string - -type package_info = { module_system : module_system; path : string } - -type t - -val is_runtime_package : t -> bool - -val same_package_by_name : t -> t -> bool - -val iter : t -> (package_info -> unit) -> unit - -val empty : t -val from_name : string -> t -val is_empty : t -> bool - -val dump_packages_info : Format.formatter -> t -> unit - -val add_npm_package_path : t -> string -> t -(** used by command line option e.g [-bs-package-output commonjs:xx/path] *) - -type package_found_info = { rel_path : string; pkg_rel_path : string } - -type info_query = - | Package_script - | Package_not_found - | Package_found of package_found_info - -val get_output_dir : t -> package_dir:string -> module_system -> string - -(* Note here we compare the package info by order in theory, we can compare it - by set semantics *) -val query_package_infos : t -> module_system -> info_query - -end = struct -#1 "js_packages_info.ml" -(* Copyright (C) 2017 Authors of BuckleScript - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) - -[@@@ocaml.warning "+9"] - -type path = string - -type module_system = - | NodeJS - | Es6 - (* ignore node_modules, just calcluating relative path *) - | Es6_global - -(* ocamlopt could not optimize such simple case... *) -let compatible (dep : module_system) (query : module_system) = - match query with - | NodeJS -> dep = NodeJS - | Es6 -> dep = Es6 - (* As a dependency Leaf Node, it is the same either [global] or [not] *) - | Es6_global -> dep = Es6_global || dep = Es6 - - -type package_info = { module_system : module_system; path : string } - -type package_name = Pkg_empty | Pkg_runtime | Pkg_normal of string - -let runtime_package_name = "bs-platform" - -let ( // ) = Filename.concat - -(* in runtime lib, [es6] and [es6-global] are treated the same way *) -let runtime_dir_of_module_system (ms : module_system) = - match ms with - | NodeJS -> "js" - | Es6 | Es6_global -> "es6" - - -let runtime_package_path (ms : module_system) js_file = - runtime_package_name // "lib" // runtime_dir_of_module_system ms // js_file - - -type t = { name : package_name; module_systems : package_info list } - -let same_package_by_name (x : t) (y : t) = x.name = y.name - -let is_runtime_package (x : t) = x.name = Pkg_runtime - -let iter (x : t) cb = Ext_list.iter x.module_systems cb - -(* TODO: not allowing user to provide such specific package name For empty - package, [-bs-package-output] does not make sense it is only allowed to - generate commonjs file in the same directory *) -let empty : t = { name = Pkg_empty; module_systems = [] } - -let from_name (name : string) = - if name = runtime_package_name then - { name = Pkg_runtime; module_systems = [] } - else { name = Pkg_normal name; module_systems = [] } - - -let is_empty (x : t) = x.name = Pkg_empty - -let string_of_module_system (ms : module_system) = - match ms with - | NodeJS -> "NodeJS" - | Es6 -> "Es6" - | Es6_global -> "Es6_global" - - -let module_system_of_string package_name : module_system option = - match package_name with - | "commonjs" -> Some NodeJS - | "es6" -> Some Es6 - | "es6-global" -> Some Es6_global - | _ -> None - - -let dump_package_info (fmt : Format.formatter) - ({ module_system = ms; path = name } : package_info) = - Format.fprintf fmt "@[%s:@ %s@]" (string_of_module_system ms) name - - -let dump_package_name fmt (x : package_name) = - match x with - | Pkg_empty -> Format.fprintf fmt "@empty_pkg@" - | Pkg_normal s -> Format.pp_print_string fmt s - | Pkg_runtime -> Format.pp_print_string fmt runtime_package_name - - -let dump_packages_info (fmt : Format.formatter) - ({ name; module_systems = ls } : t) = - Format.fprintf fmt "@[%a;@ @[%a@]@]" dump_package_name name - (Format.pp_print_list - ~pp_sep:(fun fmt () -> Format.pp_print_space fmt ()) - dump_package_info) - ls - - -type package_found_info = { rel_path : string; pkg_rel_path : string } -type info_query = - | Package_script - | Package_not_found - | Package_found of package_found_info - -(* Note that package-name has to be exactly the same as npm package name, - otherwise the path resolution will be wrong *) -let query_package_infos ({ name; module_systems } : t) - (module_system : module_system) : info_query = - match name with - | Pkg_empty -> Package_script - | Pkg_normal name -> ( - match - Ext_list.find_first module_systems (fun k -> - compatible k.module_system module_system) - with - | Some k -> - let rel_path = k.path in - let pkg_rel_path = name // rel_path in - Package_found { rel_path; pkg_rel_path } - | None -> Package_not_found ) - | Pkg_runtime -> ( - match - Ext_list.find_first module_systems (fun k -> - compatible k.module_system module_system) - with - | Some k -> - let rel_path = k.path in - let pkg_rel_path = runtime_package_name // rel_path in - Package_found { rel_path; pkg_rel_path } - | None -> Package_not_found ) - - -let get_js_path (x : t) module_system = - match - Ext_list.find_first x.module_systems (fun k -> - compatible k.module_system module_system) - with - | Some k -> k.path - | None -> assert false - - -(* for a single pass compilation, [output_dir] can be cached *) -let get_output_dir (info : t) ~package_dir module_system = - Filename.concat package_dir (get_js_path info module_system) - - -let add_npm_package_path (packages_info : t) (s : string) : t = - if is_empty packages_info then - Ext_arg.bad_argf "please set package name first using -bs-package-name " - else - let module_system, path = - match Ext_string.split ~keep_empty:false s ':' with - | [ module_system; path ] -> - ( ( match module_system_of_string module_system with - | Some x -> x - | None -> Ext_arg.bad_argf "invalid module system %s" module_system - ), - path ) - | [ path ] -> (NodeJS, path) - | module_system :: path -> - ( ( match module_system_of_string module_system with - | Some x -> x - | None -> Ext_arg.bad_argf "invalid module system %s" module_system - ), - String.concat ":" path ) - | _ -> Ext_arg.bad_argf "invalid npm package path: %s" s - in - { - packages_info with - module_systems = { module_system; path } :: packages_info.module_systems; - } - -(* support es6 modules instead - - TODO: enrich ast to support import export - http://www.ecma-international.org/ecma-262/6.0/#sec-imports For every module, - we need [Ident.t] for accessing and [filename] for import, they are not - necessarily the same. - - Es6 modules is not the same with commonjs, we use commonjs currently (play - better with node) - - FIXME: the module order matters? *) - -end module Lam_compat : sig #1 "lam_compat.mli" (* Copyright (C) 2018 Authors of BuckleScript @@ -86717,24 +86995,22 @@ type cmj_value = { type effect = string option -type cmj_case = Ext_namespace.file_kind - type t val mk : values:cmj_value Map_string.t -> effect:effect -> - npm_package_path:Js_packages_info.t -> - cmj_case:cmj_case -> + package_info:Js_package_info.t -> + leading_case:Ext_namespace.leading_case -> t val query_by_name : t -> string -> arity * Lam.t option val is_pure : t -> bool -val get_npm_package_path : t -> Js_packages_info.t +val get_package_info : t -> Js_package_info.t -val get_cmj_case : t -> cmj_case +val get_leading_case : t -> Ext_namespace.leading_case val single_na : arity @@ -86787,29 +87063,27 @@ type effect = string option (* we don't force people to use package *) let single_na = Single Lam_arity.na -type cmj_case = Ext_namespace.file_kind - type keyed_cmj_values = (string * cmj_value) array type t = { values : keyed_cmj_values; pure : bool; - npm_package_path : Js_packages_info.t; - cmj_case : cmj_case; + package_info : Js_package_info.t; + leading_case : Ext_namespace.leading_case; } let empty_values = [||] -let mk ~values ~effect ~npm_package_path ~cmj_case : t = +let mk ~values ~effect ~package_info ~leading_case : t = { values = Map_string.to_sorted_array values; pure = effect = None; - npm_package_path; - cmj_case; + package_info; + leading_case; } -let cmj_magic_number = "BUCKLE20171012" +let cmj_magic_number = "BUCKLE20200410" let cmj_magic_number_length = String.length cmj_magic_number let digest_length = 16 (*16 chars *) @@ -86927,26 +87201,24 @@ let query_by_name (cmj_table : t) name = let is_pure (cmj_table : t) = cmj_table.pure -let get_npm_package_path (cmj_table : t) = cmj_table.npm_package_path +let get_package_info (cmj_table : t) = cmj_table.package_info -let get_cmj_case (cmj_table : t) = cmj_table.cmj_case +let get_leading_case (cmj_table : t) = cmj_table.leading_case (* start dumping *) let f fmt = Printf.fprintf stdout fmt -let pp_cmj_case (cmj_case : cmj_case) : unit = - match cmj_case with - | Little_js -> f "case : little, .js\n" - | Little_bs -> f "case : little, .bs.js\n" - | Upper_js -> f "case: upper, .js\n" - | Upper_bs -> f "case: upper, .bs.js\n" +let pp_leading_case (leading_case : Ext_namespace.leading_case) : unit = + match leading_case with + | Upper -> f "case: upper\n" + | Lower -> f "case: lower\n" -let pp_cmj ({ values; pure; npm_package_path; cmj_case } : t) = +let pp_cmj ({ values; pure; package_info; leading_case } : t) = f "package info: %s\n" - (Format.asprintf "%a" Js_packages_info.dump_packages_info npm_package_path); - pp_cmj_case cmj_case; + (Format.asprintf "%a" Js_package_info.dump_package_info package_info); + pp_leading_case leading_case; f "effect: %s\n" (if pure then "pure" else "not pure"); Ext_array.iter values (fun (k, { arity; persistent_closed_lambda }) -> @@ -98356,15 +98628,18 @@ val query_external_id_info : Ident.t -> string -> ident_info val is_pure_module : Lam_module_ident.t -> bool val get_package_path_from_cmj : - Lam_module_ident.t -> string * Js_packages_info.t * Js_cmj_format.cmj_case + Lam_module_ident.t -> string * Js_package_info.t * Ext_namespace.leading_case -(* The second argument is mostly from [runtime] modules will change the input - [hard_dependencies] [get_required_modules extra hard_dependencies] [extra] - maybe removed if it is pure and not in [hard_dependencies] *) val get_required_modules : Lam_module_ident.Hash_set.t -> Lam_module_ident.Hash_set.t -> Lam_module_ident.t list +(** The second argument is mostly from [runtime] modules + + will change the input [hard_dependencies] + + [get_required_modules extra hard_dependencies] - [extra] maybe removed if it + is pure and not in [hard_dependencies] *) end = struct #1 "lam_compile_env.ml" @@ -98465,8 +98740,8 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) = match Lam_module_ident.Hash.find_opt cached_tbl id with | Some (Ml { cmj_table; cmj_path }) -> ( cmj_path, - Js_cmj_format.get_npm_package_path cmj_table, - Js_cmj_format.get_cmj_case cmj_table ) + Js_cmj_format.get_package_info cmj_table, + Js_cmj_format.get_leading_case cmj_table ) | Some (External | Runtime _) -> assert false (* called by {!Js_name_of_module_id.string_of_module_id} can not be @@ -98481,8 +98756,8 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) = in id +> Ml cmj_load_info; ( cmj_load_info.cmj_path, - Js_cmj_format.get_npm_package_path cmj_table, - Js_cmj_format.get_cmj_case cmj_table ) ) + Js_cmj_format.get_package_info cmj_table, + Js_cmj_format.get_leading_case cmj_table ) ) let add = Lam_module_ident.Hash_set.add @@ -101334,207 +101609,25 @@ module Js_dump_import_export : sig -val exports : - Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t - -val es6_export : - Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t - -val requires : - string -> Ext_pp_scope.t -> - Ext_pp.t -> (Ident.t * string) list -> - Ext_pp_scope.t - -val imports : - Ext_pp_scope.t -> - Ext_pp.t -> - (Ident.t * string) list -> - Ext_pp_scope.t -end = struct -#1 "js_dump_import_export.ml" -(* Copyright (C) 2017 Authors of BuckleScript - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) - -module P = Ext_pp -module L = Js_dump_lit -let default_export = "default" -let esModule = "__esModule", "true" -(** Exports printer *) -(** Print exports in Google module format, CommonJS format *) -let exports cxt f (idents : Ident.t list) = - let outer_cxt, reversed_list = - Ext_list.fold_left idents (cxt, []) (fun (cxt, acc) id -> - let id_name = id.name in - let s = Ext_ident.convert id_name in - let str,cxt = Ext_pp_scope.str_of_ident cxt id in - cxt, ( - if id_name = default_export then - (* TODO check how it will affect AMDJS*) - esModule :: (default_export, str) :: (s,str)::acc - else (s,str) :: acc )) - in - P.newline f ; - Ext_list.rev_iter reversed_list (fun (s,export) -> - P.group f 0 @@ (fun _ -> - P.string f L.exports; - P.string f L.dot; - P.string f s; - P.space f ; - P.string f L.eq; - P.space f; - P.string f export; - P.string f L.semi;); - P.newline f; - ) ; - outer_cxt - - -(** Print module in ES6 format, it is ES6, trailing comma is valid ES6 code *) -let es6_export cxt f (idents : Ident.t list) = - let outer_cxt, reversed_list = - Ext_list.fold_left idents (cxt, []) (fun (cxt, acc) id -> - let id_name = id.name in - let s = Ext_ident.convert id_name in - let str,cxt = Ext_pp_scope.str_of_ident cxt id in - cxt, ( - if id_name = default_export then - (default_export,str)::(s,str)::acc - else - (s,str) :: acc )) - in - P.newline f ; - P.string f L.export ; - P.space f ; - P.brace_vgroup f 1 begin fun _ -> - Ext_list.rev_iter reversed_list (fun (s,export) -> - P.group f 0 @@ (fun _ -> - P.string f export; - P.space f ; - if not @@ Ext_string.equal export s then begin - P.string f L.as_ ; - P.space f; - P.string f s - end ; - P.string f L.comma ;); - P.newline f; - ) ; - end; - outer_cxt - - -(** Node or Google module style imports *) -let requires require_lit cxt f (modules : (Ident.t * string) list ) = - P.newline f ; - (* the context used to print the following program *) - let outer_cxt, reversed_list = - Ext_list.fold_left modules (cxt, []) - (fun (cxt, acc) (id,s) -> - let str, cxt = Ext_pp_scope.str_of_ident cxt id in - cxt, ((str,s) :: acc)) - in - P.force_newline f ; - Ext_list.rev_iter reversed_list (fun (s,file) -> - P.string f L.var; - P.space f ; - P.string f s ; - P.space f ; - P.string f L.eq; - P.space f; - P.string f require_lit; - P.paren_group f 0 @@ (fun _ -> - Js_dump_string.pp_string f file ); - P.string f L.semi; - P.newline f ; - ) ; - outer_cxt - -(** ES6 module style imports *) -let imports cxt f (modules : (Ident.t * string) list ) = - P.newline f ; - (* the context used to print the following program *) - let outer_cxt, reversed_list = - Ext_list.fold_left modules (cxt, []) - (fun (cxt, acc) (id,s) -> - let str, cxt = Ext_pp_scope.str_of_ident cxt id in - cxt, ((str,s) :: acc)) - in - P.force_newline f ; - Ext_list.rev_iter reversed_list (fun (s,file) -> - - P.string f L.import; - P.space f ; - P.string f L.star ; - P.space f ; (* import * as xx from 'xx*) - P.string f L.as_ ; - P.space f ; - P.string f s ; - P.space f ; - P.string f L.from; - P.space f; - Js_dump_string.pp_string f file ; - P.string f L.semi ; - P.newline f ; - ) ; - outer_cxt - -end -module Js_packages_state : sig -#1 "js_packages_state.mli" -(* Copyright (C) 2017 Authors of BuckleScript - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) - -val set_package_name : string -> unit - -val set_package_map : string -> unit - -val get_packages_info : unit -> Js_packages_info.t +val exports : + Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t + +val es6_export : + Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t + +val requires : + string -> Ext_pp_scope.t -> + Ext_pp.t -> (Ident.t * string) list -> + Ext_pp_scope.t -val update_npm_package_path : string -> unit +val imports : + Ext_pp_scope.t -> + Ext_pp.t -> + (Ident.t * string) list -> + Ext_pp_scope.t end = struct -#1 "js_packages_state.ml" +#1 "js_dump_import_export.ml" (* Copyright (C) 2017 Authors of BuckleScript * * This program is free software: you can redistribute it and/or modify @@ -101559,24 +101652,127 @@ end = struct * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let packages_info = ref Js_packages_info.empty - -let set_package_name name = - if Js_packages_info.is_empty !packages_info then - packages_info := Js_packages_info.from_name name - else Ext_arg.bad_argf "duplicated flag for -bs-package-name" - +module P = Ext_pp +module L = Js_dump_lit +let default_export = "default" +let esModule = "__esModule", "true" +(** Exports printer *) +(** Print exports in Google module format, CommonJS format *) +let exports cxt f (idents : Ident.t list) = + let outer_cxt, reversed_list = + Ext_list.fold_left idents (cxt, []) (fun (cxt, acc) id -> + let id_name = id.name in + let s = Ext_ident.convert id_name in + let str,cxt = Ext_pp_scope.str_of_ident cxt id in + cxt, ( + if id_name = default_export then + (* TODO check how it will affect AMDJS*) + esModule :: (default_export, str) :: (s,str)::acc + else (s,str) :: acc )) + in + P.newline f ; + Ext_list.rev_iter reversed_list (fun (s,export) -> + P.group f 0 @@ (fun _ -> + P.string f L.exports; + P.string f L.dot; + P.string f s; + P.space f ; + P.string f L.eq; + P.space f; + P.string f export; + P.string f L.semi;); + P.newline f; + ) ; + outer_cxt -let set_package_map module_name = - Clflags.dont_record_crc_unit := Some module_name; - Clflags.open_modules := module_name :: !Clflags.open_modules +(** Print module in ES6 format, it is ES6, trailing comma is valid ES6 code *) +let es6_export cxt f (idents : Ident.t list) = + let outer_cxt, reversed_list = + Ext_list.fold_left idents (cxt, []) (fun (cxt, acc) id -> + let id_name = id.name in + let s = Ext_ident.convert id_name in + let str,cxt = Ext_pp_scope.str_of_ident cxt id in + cxt, ( + if id_name = default_export then + (default_export,str)::(s,str)::acc + else + (s,str) :: acc )) + in + P.newline f ; + P.string f L.export ; + P.space f ; + P.brace_vgroup f 1 begin fun _ -> + Ext_list.rev_iter reversed_list (fun (s,export) -> + P.group f 0 @@ (fun _ -> + P.string f export; + P.space f ; + if not @@ Ext_string.equal export s then begin + P.string f L.as_ ; + P.space f; + P.string f s + end ; + P.string f L.comma ;); + P.newline f; + ) ; + end; + outer_cxt + -let update_npm_package_path s = - packages_info := Js_packages_info.add_npm_package_path !packages_info s +(** Node or Google module style imports *) +let requires require_lit cxt f (modules : (Ident.t * string) list ) = + P.newline f ; + (* the context used to print the following program *) + let outer_cxt, reversed_list = + Ext_list.fold_left modules (cxt, []) + (fun (cxt, acc) (id,s) -> + let str, cxt = Ext_pp_scope.str_of_ident cxt id in + cxt, ((str,s) :: acc)) + in + P.force_newline f ; + Ext_list.rev_iter reversed_list (fun (s,file) -> + P.string f L.var; + P.space f ; + P.string f s ; + P.space f ; + P.string f L.eq; + P.space f; + P.string f require_lit; + P.paren_group f 0 @@ (fun _ -> + Js_dump_string.pp_string f file ); + P.string f L.semi; + P.newline f ; + ) ; + outer_cxt +(** ES6 module style imports *) +let imports cxt f (modules : (Ident.t * string) list ) = + P.newline f ; + (* the context used to print the following program *) + let outer_cxt, reversed_list = + Ext_list.fold_left modules (cxt, []) + (fun (cxt, acc) (id,s) -> + let str, cxt = Ext_pp_scope.str_of_ident cxt id in + cxt, ((str,s) :: acc)) + in + P.force_newline f ; + Ext_list.rev_iter reversed_list (fun (s,file) -> -let get_packages_info () = !packages_info + P.string f L.import; + P.space f ; + P.string f L.star ; + P.space f ; (* import * as xx from 'xx*) + P.string f L.as_ ; + P.space f ; + P.string f s ; + P.space f ; + P.string f L.from; + P.space f; + Js_dump_string.pp_string f file ; + P.string f L.semi ; + P.newline f ; + ) ; + outer_cxt end module Js_name_of_module_id : sig @@ -101608,7 +101804,8 @@ module Js_name_of_module_id : sig val string_of_module_id : Lam_module_ident.t -> output_dir:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> string (** generate the mdoule path so that it can be spliced here: @@ -101661,29 +101858,30 @@ let fix_path_for_windows : string -> string = let get_runtime_module_path (dep_module_id : Lam_module_ident.t) - (current_package_info : Js_packages_info.t) module_system = - let current_info_query = - Js_packages_info.query_package_infos current_package_info module_system + (current_package_info : Js_package_info.t) module_system = + let loc = + Js_package_info.query_package_location_by_module_system current_package_info + module_system in let js_file = - Ext_namespace.js_name_of_modulename dep_module_id.id.name Little_js + Ext_namespace.js_filename_of_modulename ~name:dep_module_id.id.name + ~ext:".js" Lower in - match current_info_query with + match loc with | Package_not_found -> assert false - | Package_script -> - Js_packages_info.runtime_package_path module_system js_file + | Package_script -> Js_package_info.runtime_package_path module_system js_file | Package_found pkg -> ( let dep_path = - "lib" // Js_packages_info.runtime_dir_of_module_system module_system + "lib" // Js_package_info.runtime_dir_of_module_system module_system in - if Js_packages_info.is_runtime_package current_package_info then + if Js_package_info.is_runtime_package current_package_info then Ext_path.node_rebase_file ~from:pkg.rel_path ~to_:dep_path js_file (* TODO: we assume that both [x] and [path] could only be relative path which is guaranteed by [-bs-package-output] *) else match module_system with | NodeJS | Es6 -> - Js_packages_info.runtime_package_path module_system js_file + Js_package_info.runtime_package_path module_system js_file (* Note we did a post-processing when working on Windows *) | Es6_global -> (* lib/ocaml/xx.cmj -- @@ -101693,7 +101891,7 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t) (* assert false *) Ext_path.rel_normalized_absolute_path ~from: - (Js_packages_info.get_output_dir current_package_info + (Js_package_info.get_output_dir current_package_info ~package_dir:(Lazy.force Ext_path.package_dir) module_system) (Lazy.force runtime_package_path // dep_path // js_file) ) @@ -101701,9 +101899,9 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t) (* [output_dir] is decided by the command line argument *) let string_of_module_id (dep_module_id : Lam_module_ident.t) - ~(output_dir : string) (module_system : Js_packages_info.module_system) : - string = - let current_package_info = Js_packages_state.get_packages_info () in + ~(output_dir : string) ~(ext : string) + (module_system : Js_package_info.module_system) : string = + let current_package_info = Js_current_package_info.get_packages_info () in fix_path_for_windows ( match dep_module_id.kind with | External name -> name (* the literal string for external package *) @@ -101717,34 +101915,39 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t) | Runtime -> get_runtime_module_path dep_module_id current_package_info module_system | Ml -> ( - let current_info_query = - Js_packages_info.query_package_infos current_package_info - module_system - in + let query = Js_package_info.query_package_location_by_module_system in + let current_loc = query current_package_info module_system in match Lam_compile_env.get_package_path_from_cmj dep_module_id with - | cmj_path, dep_package_info, little -> ( - let js_file = - Ext_namespace.js_name_of_modulename dep_module_id.id.name little - in - let dep_info_query = - Js_packages_info.query_package_infos dep_package_info - module_system - in - match (dep_info_query, current_info_query) with + | cmj_path, dep_package_info, case -> ( + let dep_loc = query dep_package_info module_system in + match (dep_loc, current_loc) with | Package_not_found, _ -> Bs_exception.error (Missing_ml_dependency dep_module_id.id.name) | Package_script, Package_found _ -> + let js_file = + Ext_namespace.js_filename_of_modulename + (* FIXME: Unsure how to infer a useful file-extension here. *) + ~name:dep_module_id.id.name ~ext:"" case + in Bs_exception.error (Dependency_script_module_dependent_not js_file) | (Package_script | Package_found _), Package_not_found -> assert false - | Package_found pkg, Package_script -> + | Package_found dep_pkg, Package_script -> + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext:dep_pkg.extension case + in - pkg.pkg_rel_path // js_file + dep_pkg.pkg_rel_path // js_file | Package_found dep_pkg, Package_found cur_pkg -> ( + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext:dep_pkg.extension case + in if - Js_packages_info.same_package_by_name current_package_info + Js_package_info.same_package_by_name current_package_info dep_package_info then Ext_path.node_rebase_file ~from:cur_pkg.rel_path @@ -101766,13 +101969,17 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t) (* assert false *) Ext_path.rel_normalized_absolute_path ~from: - (Js_packages_info.get_output_dir current_package_info + (Js_package_info.get_output_dir current_package_info ~package_dir:(Lazy.force Ext_path.package_dir) module_system) ( Filename.dirname (Filename.dirname (Filename.dirname cmj_path)) // dep_pkg.rel_path // js_file ) ) | Package_script, Package_script -> ( + let js_file = + Ext_namespace.js_filename_of_modulename + ~name:dep_module_id.id.name ~ext case + in match Config_util.find_opt js_file with | Some file -> let basename = Filename.basename file in @@ -101819,14 +102026,16 @@ val dump_program : J.program -> out_channel -> unit val pp_deps_program : output_prefix:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> J.deps_program -> Ext_pp.t -> unit val dump_deps_program : output_prefix:string -> - Js_packages_info.module_system -> + ext:string -> + Js_package_info.module_system -> J.deps_program -> out_channel -> unit @@ -101888,24 +102097,25 @@ let dump_program (x : J.program) oc = ignore (program (P.from_channel oc) Ext_pp_scope.empty x) -let node_program ~output_dir f (x : J.deps_program) = +let node_program ~output_dir ~ext f (x : J.deps_program) = P.string f L.strict_directive; P.newline f; let cxt = Js_dump_import_export.requires L.require Ext_pp_scope.empty f (Ext_list.map x.modules (fun x -> ( Lam_module_ident.id x, - Js_name_of_module_id.string_of_module_id x ~output_dir NodeJS ))) + Js_name_of_module_id.string_of_module_id x ~output_dir ~ext NodeJS + ))) in program f cxt x.program -let es6_program ~output_dir fmt f (x : J.deps_program) = +let es6_program ~output_dir ~ext fmt f (x : J.deps_program) = let cxt = Js_dump_import_export.imports Ext_pp_scope.empty f (Ext_list.map x.modules (fun x -> ( Lam_module_ident.id x, - Js_name_of_module_id.string_of_module_id x ~output_dir fmt ))) + Js_name_of_module_id.string_of_module_id x ~output_dir ~ext fmt ))) in let () = P.force_newline f in let cxt = Js_dump.statement_list true cxt f x.program.block in @@ -101920,7 +102130,7 @@ let es6_program ~output_dir fmt f (x : J.deps_program) = Linguist::FileBlob.new('jscomp/test/test_u.js').generated? ]} *) -let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) +let pp_deps_program ~output_prefix ~ext (kind : Js_package_info.module_system) (program : J.deps_program) (f : Ext_pp.t) = if not !Js_config.no_version_header then ( P.string f Bs_version.header; @@ -101931,8 +102141,8 @@ let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) let output_dir = Filename.dirname output_prefix in ignore ( match kind with - | Es6 | Es6_global -> es6_program ~output_dir kind f program - | NodeJS -> node_program ~output_dir f program ); + | Es6 | Es6_global -> es6_program ~output_dir ~ext kind f program + | NodeJS -> node_program ~output_dir ~ext f program ); P.newline f; P.string f ( match program.side_effect with @@ -101942,8 +102152,8 @@ let pp_deps_program ~output_prefix (kind : Js_packages_info.module_system) P.flush f () -let dump_deps_program ~output_prefix kind x (oc : out_channel) = - pp_deps_program ~output_prefix kind x (P.from_channel oc) +let dump_deps_program ~output_prefix ~ext kind x (oc : out_channel) = + pp_deps_program ~output_prefix ~ext kind x (P.from_channel oc) end module Js_fold_basic : sig @@ -110829,180 +111039,6 @@ let assemble_obj_args (labels : External_arg_spec.t list) (args : J.expression ) , var_v -end -module Bs_warnings : sig -#1 "bs_warnings.mli" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) - - -type t = - | Unsafe_poly_variant_type - -val prerr_bs_ffi_warning : Location.t -> t -> unit - - -val warn_missing_primitive : Location.t -> string -> unit - -val warn_literal_overflow : Location.t -> unit - -val error_unescaped_delimiter : - Location.t -> string -> unit - -end = struct -#1 "bs_warnings.ml" -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a 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. *) - - - -type t = - | Unsafe_poly_variant_type - (* for users write code like this: - {[ external f : [`a of int ] -> string = ""]} - Here users forget about `[@bs.string]` or `[@bs.int]` - *) - - - -let to_string t = - match t with - | Unsafe_poly_variant_type - -> - "Here a OCaml polymorphic variant type passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]` " - -let warning_formatter = Format.err_formatter - -let print_string_warning (loc : Location.t) x = - if loc.loc_ghost then - Format.fprintf warning_formatter "File %s@." !Location.input_name - else - Location.print warning_formatter loc ; - Format.fprintf warning_formatter "@{Warning@}: %s@." x - -let prerr_bs_ffi_warning loc x = - Location.prerr_warning loc (Warnings.Bs_ffi_warning (to_string x)) - -let unimplemented_primitive = "Unimplemented primitive used:" -type error = - | Uninterpreted_delimiters of string - | Unimplemented_primitive of string -exception Error of Location.t * error - -let pp_error fmt x = - match x with - | Unimplemented_primitive str -> - Format.pp_print_string fmt unimplemented_primitive; - Format.pp_print_string fmt str - - | Uninterpreted_delimiters str -> - Format.pp_print_string fmt "Uninterpreted delimiters" ; - Format.pp_print_string fmt str - - - -let () = - Location.register_error_of_exn (function - | Error (loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) - - - - -let warn_missing_primitive loc txt = - if not !Js_config.no_warn_unimplemented_external && not !Clflags.bs_quiet then - begin - print_string_warning loc ( unimplemented_primitive ^ txt ^ " \n" ); - Format.pp_print_flush warning_formatter () - end - -let warn_literal_overflow loc = - if not !Clflags.bs_quiet then - begin - print_string_warning loc - "Integer literal exceeds the range of representable integers of type int"; - Format.pp_print_flush warning_formatter () - end - - - -let error_unescaped_delimiter loc txt = - raise (Error(loc, Uninterpreted_delimiters txt)) - - - - - - -(** - Note the standard way of reporting error in compiler: - - val Location.register_error_of_exn : (exn -> Location.error option) -> unit - val Location.error_of_printer : Location.t -> - (Format.formatter -> error -> unit) -> error -> Location.error - - Define an error type - - type error - exception Error of Location.t * error - - Provide a printer to error - - {[ - let () = - Location.register_error_of_exn - (function - | Error(loc,err) -> - Some (Location.error_of_printer loc pp_error err) - | _ -> None - ) - ]} -*) - end module Js_of_lam_exception : sig #1 "js_of_lam_exception.mli" @@ -406149,7 +406185,7 @@ val export_to_cmj : Lam_stats.t -> Js_cmj_format.effect -> Lam.t Map_ident.t -> - Js_cmj_format.cmj_case -> + Ext_namespace.leading_case -> Js_cmj_format.t end = struct @@ -406261,15 +406297,15 @@ let get_dependent_module_effect (meta : Lam_stats.t) backend, we compile to js for the inliner, we try to seriaize it -- relies on other optimizations to make this happen {[ exports.Make = function () {.....} ]} TODO: check that we don't do this in browser environment *) -let export_to_cmj (meta : Lam_stats.t) effect export_map cmj_case : - Js_cmj_format.t = +let export_to_cmj (meta : Lam_stats.t) effect export_map + (leading_case : Ext_namespace.leading_case) : Js_cmj_format.t = let values = values_of_export meta export_map in (* FIXME: make sure [-o] would not change its case *) (* FIXME: add test for ns/non-ns *) Js_cmj_format.mk ~values ~effect - ~npm_package_path:(Js_packages_state.get_packages_info ()) - ~cmj_case + ~package_info:(Js_current_package_info.get_packages_info ()) + ~leading_case end module Lam_compile_main : sig @@ -406337,13 +406373,9 @@ end = struct module E = Js_exp_make module S = Js_stmt_make -let get_cmj_case output_prefix : Ext_namespace.file_kind = - let little = Ext_char.is_lower_case (Filename.basename output_prefix).[0] in - match (little, !Js_config.bs_suffix) with - | true, true -> Little_bs - | true, false -> Little_js - | false, true -> Upper_bs - | false, false -> Upper_js +let get_leading_case output_prefix : Ext_namespace.leading_case = + if Ext_char.is_lower_case (Filename.basename output_prefix).[0] then Lower + else Upper let compile_group (meta : Lam_stats.t) (x : Lam_group.t) : Js_output.t = @@ -406523,7 +406555,7 @@ let compile (output_prefix : string) (lam : Lambda.lambda) = in let v : Js_cmj_format.t = Lam_stats_export.export_to_cmj meta effect coerced_input.export_map - (get_cmj_case output_prefix) + (get_leading_case output_prefix) in if not @@ !Clflags.dont_write_files then Js_cmj_format.to_file ~check_exists:(not !Js_config.force_cmj) @@ -406536,20 +406568,21 @@ let ( // ) = Filename.concat let lambda_as_module (lambda_output : J.deps_program) (output_prefix : string) : unit = - let basename = - Ext_namespace.change_ext_ns_suffix - (Filename.basename output_prefix) - ( if !Js_config.bs_suffix then Literals.suffix_bs_js - else Literals.suffix_js ) - in - let package_info = Js_packages_state.get_packages_info () in - if Js_packages_info.is_empty package_info && !Js_config.js_stdout then - Js_dump_program.dump_deps_program ~output_prefix NodeJS lambda_output stdout + let package_info = Js_current_package_info.get_packages_info () in + if Js_package_info.is_empty package_info && !Js_config.js_stdout then + Js_dump_program.dump_deps_program ~ext:".js" ~output_prefix NodeJS + lambda_output stdout else - Js_packages_info.iter package_info (fun { module_system; path = _path } -> + Js_package_info.iter package_info + (fun { module_system; path = _path; extension } -> + let basename = + Ext_namespace.replace_namespace_with_extension + ~name:(Filename.basename output_prefix) + ~ext:extension + in let output_chan chan = - Js_dump_program.dump_deps_program ~output_prefix module_system - lambda_output chan + Js_dump_program.dump_deps_program ~output_prefix ~ext:extension + module_system lambda_output chan in if not @@ !Clflags.dont_write_files then Ext_pervasives.with_file_as_chan @@ -418671,7 +418704,10 @@ let buckle_script_flags : (string * Arg.spec * string) list = :: ( "-bs-gentype", Arg.String (fun s -> Clflags.bs_gentype := Some s), " Pass gentype command" ) - :: ("-bs-suffix", Arg.Set Js_config.bs_suffix, " Set suffix to .bs.js") + :: ( "-bs-suffix", + Arg.Unit Js_package_info.deprecated_set_bs_extension, + " (DEPRECATED) Set default suffix to .bs.js - use third compoment of \ + -bs-package-output instead" ) :: ( "-bs-no-implicit-include", Arg.Set Clflags.no_implicit_current_dir, " Don't include current dir implicitly" ) @@ -418724,19 +418760,19 @@ let buckle_script_flags : (string * Arg.spec * string) list = Arg.Clear Js_config.sort_imports, " No sort (see -bs-sort-imports)" ) :: ( "-bs-package-name", - Arg.String Js_packages_state.set_package_name, + Arg.String Js_current_package_info.set_package_name, " set package name, useful when you want to produce npm packages" ) :: ( "-bs-ns", - Arg.String Js_packages_state.set_package_map, + Arg.String Js_current_package_info.set_package_map, " set package map, not only set package name but also use it as a \ namespace" ) :: ( "-bs-no-version-header", Arg.Set Js_config.no_version_header, " Don't print version header" ) :: ( "-bs-package-output", - Arg.String Js_packages_state.update_npm_package_path, - " set npm-output-path: [opt_module]:path, for example: 'lib/cjs', \ - 'amdjs:lib/amdjs', 'es6:lib/es6' " ) + Arg.String Js_current_package_info.append_location_descriptor_of_string, + " set npm-output-path: [opt_module]:path:[ext], for example: 'lib/cjs', \ + 'amdjs:lib/amdjs', 'es6:lib/es6:mjs' " ) :: ( "-bs-no-warn-unimplemented-external", Arg.Set Js_config.no_warn_unimplemented_external, " disable warnings on unimplmented c externals" ) diff --git a/lib/4.06.1/whole_compiler.ml.d b/lib/4.06.1/whole_compiler.ml.d index d0c943e5a5..eb8bcb888f 100644 --- a/lib/4.06.1/whole_compiler.ml.d +++ b/lib/4.06.1/whole_compiler.ml.d @@ -1 +1 @@ -../lib/4.06.1/whole_compiler.ml: ../ocaml/bytecomp/lambda.ml ../ocaml/bytecomp/lambda.mli ../ocaml/bytecomp/matching.ml ../ocaml/bytecomp/matching.mli ../ocaml/bytecomp/printlambda.ml ../ocaml/bytecomp/printlambda.mli ../ocaml/bytecomp/switch.ml ../ocaml/bytecomp/switch.mli ../ocaml/bytecomp/translattribute.ml ../ocaml/bytecomp/translattribute.mli ../ocaml/bytecomp/translclass.ml ../ocaml/bytecomp/translclass.mli ../ocaml/bytecomp/translcore.ml ../ocaml/bytecomp/translcore.mli ../ocaml/bytecomp/translmod.ml ../ocaml/bytecomp/translmod.mli ../ocaml/bytecomp/translobj.ml ../ocaml/bytecomp/translobj.mli ../ocaml/driver/compenv.ml ../ocaml/driver/compenv.mli ../ocaml/driver/compmisc.ml ../ocaml/driver/compmisc.mli ../ocaml/driver/pparse.ml ../ocaml/driver/pparse.mli ../ocaml/parsing/ast_helper.ml ../ocaml/parsing/ast_helper.mli ../ocaml/parsing/ast_invariants.ml ../ocaml/parsing/ast_invariants.mli ../ocaml/parsing/ast_iterator.ml ../ocaml/parsing/ast_iterator.mli ../ocaml/parsing/ast_mapper.ml ../ocaml/parsing/ast_mapper.mli ../ocaml/parsing/asttypes.mli ../ocaml/parsing/attr_helper.ml ../ocaml/parsing/attr_helper.mli ../ocaml/parsing/builtin_attributes.ml ../ocaml/parsing/builtin_attributes.mli ../ocaml/parsing/depend.ml ../ocaml/parsing/depend.mli ../ocaml/parsing/docstrings.ml ../ocaml/parsing/docstrings.mli ../ocaml/parsing/lexer.ml ../ocaml/parsing/lexer.mli ../ocaml/parsing/location.ml ../ocaml/parsing/location.mli ../ocaml/parsing/longident.ml ../ocaml/parsing/longident.mli ../ocaml/parsing/parse.ml ../ocaml/parsing/parse.mli ../ocaml/parsing/parser.ml ../ocaml/parsing/parser.mli ../ocaml/parsing/parsetree.mli ../ocaml/parsing/pprintast.ml ../ocaml/parsing/pprintast.mli ../ocaml/parsing/printast.ml ../ocaml/parsing/printast.mli ../ocaml/parsing/syntaxerr.ml ../ocaml/parsing/syntaxerr.mli ../ocaml/typing/annot.mli ../ocaml/typing/btype.ml ../ocaml/typing/btype.mli ../ocaml/typing/cmi_format.ml ../ocaml/typing/cmi_format.mli ../ocaml/typing/cmt_format.ml ../ocaml/typing/cmt_format.mli ../ocaml/typing/ctype.ml ../ocaml/typing/ctype.mli ../ocaml/typing/datarepr.ml ../ocaml/typing/datarepr.mli ../ocaml/typing/env.ml ../ocaml/typing/env.mli ../ocaml/typing/ident.ml ../ocaml/typing/ident.mli ../ocaml/typing/includeclass.ml ../ocaml/typing/includeclass.mli ../ocaml/typing/includecore.ml ../ocaml/typing/includecore.mli ../ocaml/typing/includemod.ml ../ocaml/typing/includemod.mli ../ocaml/typing/mtype.ml ../ocaml/typing/mtype.mli ../ocaml/typing/oprint.ml ../ocaml/typing/oprint.mli ../ocaml/typing/outcometree.mli ../ocaml/typing/parmatch.ml ../ocaml/typing/parmatch.mli ../ocaml/typing/path.ml ../ocaml/typing/path.mli ../ocaml/typing/predef.ml ../ocaml/typing/predef.mli ../ocaml/typing/primitive.ml ../ocaml/typing/primitive.mli ../ocaml/typing/printtyp.ml ../ocaml/typing/printtyp.mli ../ocaml/typing/printtyped.ml ../ocaml/typing/printtyped.mli ../ocaml/typing/stypes.ml ../ocaml/typing/stypes.mli ../ocaml/typing/subst.ml ../ocaml/typing/subst.mli ../ocaml/typing/tast_mapper.ml ../ocaml/typing/tast_mapper.mli ../ocaml/typing/typeclass.ml ../ocaml/typing/typeclass.mli ../ocaml/typing/typecore.ml ../ocaml/typing/typecore.mli ../ocaml/typing/typedecl.ml ../ocaml/typing/typedecl.mli ../ocaml/typing/typedtree.ml ../ocaml/typing/typedtree.mli ../ocaml/typing/typedtreeIter.ml ../ocaml/typing/typedtreeIter.mli ../ocaml/typing/typemod.ml ../ocaml/typing/typemod.mli ../ocaml/typing/typeopt.ml ../ocaml/typing/typeopt.mli ../ocaml/typing/types.ml ../ocaml/typing/types.mli ../ocaml/typing/typetexp.ml ../ocaml/typing/typetexp.mli ../ocaml/typing/untypeast.ml ../ocaml/typing/untypeast.mli ../ocaml/utils/arg_helper.ml ../ocaml/utils/arg_helper.mli ../ocaml/utils/ccomp.ml ../ocaml/utils/ccomp.mli ../ocaml/utils/clflags.ml ../ocaml/utils/clflags.mli ../ocaml/utils/consistbl.ml ../ocaml/utils/consistbl.mli ../ocaml/utils/identifiable.ml ../ocaml/utils/identifiable.mli ../ocaml/utils/misc.ml ../ocaml/utils/misc.mli ../ocaml/utils/numbers.ml ../ocaml/utils/numbers.mli ../ocaml/utils/profile.ml ../ocaml/utils/profile.mli ../ocaml/utils/tbl.ml ../ocaml/utils/tbl.mli ../ocaml/utils/terminfo.ml ../ocaml/utils/terminfo.mli ../ocaml/utils/warnings.ml ../ocaml/utils/warnings.mli ./common/bs_loc.ml ./common/bs_loc.mli ./common/bs_version.ml ./common/bs_version.mli ./common/bs_warnings.ml ./common/bs_warnings.mli ./common/ext_log.ml ./common/ext_log.mli ./common/js_config.ml ./common/js_config.mli ./common/lam_methname.ml ./common/lam_methname.mli ./common/ml_binary.ml ./common/ml_binary.mli ./core/bs_conditional_initial.ml ./core/bs_conditional_initial.mli ./core/classify_function.ml ./core/classify_function.mli ./core/config_util.ml ./core/config_util.mli ./core/config_whole_compiler.ml ./core/config_whole_compiler.mli ./core/j.ml ./core/js_analyzer.ml ./core/js_analyzer.mli ./core/js_arr.ml ./core/js_arr.mli ./core/js_ast_util.ml ./core/js_ast_util.mli ./core/js_block_runtime.ml ./core/js_block_runtime.mli ./core/js_call_info.ml ./core/js_call_info.mli ./core/js_closure.ml ./core/js_closure.mli ./core/js_cmj_format.ml ./core/js_cmj_format.mli ./core/js_cmj_load.ml ./core/js_cmj_load.mli ./core/js_dump.ml ./core/js_dump.mli ./core/js_dump_import_export.ml ./core/js_dump_import_export.mli ./core/js_dump_lit.ml ./core/js_dump_program.ml ./core/js_dump_program.mli ./core/js_dump_property.ml ./core/js_dump_property.mli ./core/js_dump_string.ml ./core/js_dump_string.mli ./core/js_exp_make.ml ./core/js_exp_make.mli ./core/js_fold.ml ./core/js_fold_basic.ml ./core/js_fold_basic.mli ./core/js_fun_env.ml ./core/js_fun_env.mli ./core/js_implementation.ml ./core/js_implementation.mli ./core/js_long.ml ./core/js_long.mli ./core/js_map.ml ./core/js_name_of_module_id.ml ./core/js_name_of_module_id.mli ./core/js_number.ml ./core/js_number.mli ./core/js_of_lam_array.ml ./core/js_of_lam_array.mli ./core/js_of_lam_block.ml ./core/js_of_lam_block.mli ./core/js_of_lam_exception.ml ./core/js_of_lam_exception.mli ./core/js_of_lam_option.ml ./core/js_of_lam_option.mli ./core/js_of_lam_polyvar.ml ./core/js_of_lam_polyvar.mli ./core/js_of_lam_string.ml ./core/js_of_lam_string.mli ./core/js_of_lam_tuple.ml ./core/js_of_lam_tuple.mli ./core/js_of_lam_variant.ml ./core/js_of_lam_variant.mli ./core/js_op.ml ./core/js_op_util.ml ./core/js_op_util.mli ./core/js_output.ml ./core/js_output.mli ./core/js_packages_info.ml ./core/js_packages_info.mli ./core/js_packages_state.ml ./core/js_packages_state.mli ./core/js_pass_debug.ml ./core/js_pass_debug.mli ./core/js_pass_flatten.ml ./core/js_pass_flatten.mli ./core/js_pass_flatten_and_mark_dead.ml ./core/js_pass_flatten_and_mark_dead.mli ./core/js_pass_scope.ml ./core/js_pass_scope.mli ./core/js_pass_tailcall_inline.ml ./core/js_pass_tailcall_inline.mli ./core/js_raw_exp_info.ml ./core/js_shake.ml ./core/js_shake.mli ./core/js_stmt_make.ml ./core/js_stmt_make.mli ./core/lam.ml ./core/lam.mli ./core/lam_analysis.ml ./core/lam_analysis.mli ./core/lam_arity.ml ./core/lam_arity.mli ./core/lam_arity_analysis.ml ./core/lam_arity_analysis.mli ./core/lam_beta_reduce.ml ./core/lam_beta_reduce.mli ./core/lam_beta_reduce_util.ml ./core/lam_beta_reduce_util.mli ./core/lam_bounded_vars.ml ./core/lam_bounded_vars.mli ./core/lam_closure.ml ./core/lam_closure.mli ./core/lam_coercion.ml ./core/lam_coercion.mli ./core/lam_compat.ml ./core/lam_compat.mli ./core/lam_compile.ml ./core/lam_compile.mli ./core/lam_compile_const.ml ./core/lam_compile_const.mli ./core/lam_compile_context.ml ./core/lam_compile_context.mli ./core/lam_compile_env.ml ./core/lam_compile_env.mli ./core/lam_compile_external_call.ml ./core/lam_compile_external_call.mli ./core/lam_compile_external_obj.ml ./core/lam_compile_external_obj.mli ./core/lam_compile_main.ml ./core/lam_compile_main.mli ./core/lam_compile_primitive.ml ./core/lam_compile_primitive.mli ./core/lam_compile_util.ml ./core/lam_compile_util.mli ./core/lam_constant.ml ./core/lam_constant.mli ./core/lam_constant_convert.ml ./core/lam_constant_convert.mli ./core/lam_convert.ml ./core/lam_convert.mli ./core/lam_dce.ml ./core/lam_dce.mli ./core/lam_dispatch_primitive.ml ./core/lam_dispatch_primitive.mli ./core/lam_eta_conversion.ml ./core/lam_eta_conversion.mli ./core/lam_exit_code.ml ./core/lam_exit_code.mli ./core/lam_exit_count.ml ./core/lam_exit_count.mli ./core/lam_free_variables.ml ./core/lam_free_variables.mli ./core/lam_group.ml ./core/lam_group.mli ./core/lam_hit.ml ./core/lam_hit.mli ./core/lam_id_kind.ml ./core/lam_id_kind.mli ./core/lam_inline_util.ml ./core/lam_inline_util.mli ./core/lam_iter.ml ./core/lam_iter.mli ./core/lam_module_ident.ml ./core/lam_module_ident.mli ./core/lam_pass_alpha_conversion.ml ./core/lam_pass_alpha_conversion.mli ./core/lam_pass_collect.ml ./core/lam_pass_collect.mli ./core/lam_pass_count.ml ./core/lam_pass_count.mli ./core/lam_pass_deep_flatten.ml ./core/lam_pass_deep_flatten.mli ./core/lam_pass_eliminate_ref.ml ./core/lam_pass_eliminate_ref.mli ./core/lam_pass_exits.ml ./core/lam_pass_exits.mli ./core/lam_pass_lets_dce.ml ./core/lam_pass_lets_dce.mli ./core/lam_pass_remove_alias.ml ./core/lam_pass_remove_alias.mli ./core/lam_pointer_info.ml ./core/lam_pointer_info.mli ./core/lam_primitive.ml ./core/lam_primitive.mli ./core/lam_print.ml ./core/lam_print.mli ./core/lam_scc.ml ./core/lam_scc.mli ./core/lam_stats.ml ./core/lam_stats.mli ./core/lam_stats_export.ml ./core/lam_stats_export.mli ./core/lam_subst.ml ./core/lam_subst.mli ./core/lam_tag_info.ml ./core/lam_util.ml ./core/lam_util.mli ./core/lam_var_stats.ml ./core/lam_var_stats.mli ./core/matching_polyfill.ml ./core/matching_polyfill.mli ./core/ocaml_options.ml ./core/ocaml_options.mli ./core/primitive_compat.ml ./core/primitive_compat.mli ./core/record_attributes_check.ml ./depends/ast_extract.ml ./depends/ast_extract.mli ./depends/binary_ast.ml ./depends/binary_ast.mli ./depends/bs_exception.ml ./depends/bs_exception.mli ./ext/bsc_warnings.ml ./ext/ext_arg.ml ./ext/ext_arg.mli ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_digest.ml ./ext/ext_digest.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_fmt.ml ./ext/ext_format.ml ./ext/ext_format.mli ./ext/ext_ident.ml ./ext/ext_ident.mli ./ext/ext_int.ml ./ext/ext_int.mli ./ext/ext_io.ml ./ext/ext_io.mli ./ext/ext_json_parse.ml ./ext/ext_json_parse.mli ./ext/ext_json_types.ml ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_modulename.ml ./ext/ext_modulename.mli ./ext/ext_namespace.ml ./ext/ext_namespace.mli ./ext/ext_obj.ml ./ext/ext_obj.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_path.ml ./ext/ext_path.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_position.ml ./ext/ext_position.mli ./ext/ext_pp.ml ./ext/ext_pp.mli ./ext/ext_pp_scope.ml ./ext/ext_pp_scope.mli ./ext/ext_ref.ml ./ext/ext_ref.mli ./ext/ext_scc.ml ./ext/ext_scc.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_sys.ml ./ext/ext_sys.mli ./ext/ext_utf8.ml ./ext/ext_utf8.mli ./ext/ext_util.ml ./ext/ext_util.mli ./ext/hash.ml ./ext/hash.mli ./ext/hash_gen.ml ./ext/hash_ident.ml ./ext/hash_ident.mli ./ext/hash_int.ml ./ext/hash_int.mli ./ext/hash_set.ml ./ext/hash_set.mli ./ext/hash_set_gen.ml ./ext/hash_set_ident.ml ./ext/hash_set_ident.mli ./ext/hash_set_ident_mask.ml ./ext/hash_set_ident_mask.mli ./ext/hash_set_poly.ml ./ext/hash_set_poly.mli ./ext/hash_set_string.ml ./ext/hash_set_string.mli ./ext/hash_string.ml ./ext/hash_string.mli ./ext/int_vec_util.ml ./ext/int_vec_util.mli ./ext/int_vec_vec.ml ./ext/int_vec_vec.mli ./ext/js_reserved_map.ml ./ext/js_reserved_map.mli ./ext/js_runtime_modules.ml ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/map_ident.ml ./ext/map_ident.mli ./ext/map_int.ml ./ext/map_int.mli ./ext/map_string.ml ./ext/map_string.mli ./ext/ordered_hash_map_gen.ml ./ext/ordered_hash_map_local_ident.ml ./ext/ordered_hash_map_local_ident.mli ./ext/set_gen.ml ./ext/set_ident.ml ./ext/set_ident.mli ./ext/set_string.ml ./ext/set_string.mli ./ext/vec.ml ./ext/vec.mli ./ext/vec_gen.ml ./ext/vec_int.ml ./ext/vec_int.mli ./js_parser/declaration_parser.ml ./js_parser/enum_common.ml ./js_parser/enum_parser.ml ./js_parser/expression_parser.ml ./js_parser/file_key.ml ./js_parser/flow_ast.ml ./js_parser/flow_ast_utils.ml ./js_parser/flow_ast_utils.mli ./js_parser/flow_lexer.ml ./js_parser/flow_lexer.mli ./js_parser/jsx_parser.ml ./js_parser/lex_env.ml ./js_parser/lex_result.ml ./js_parser/loc.ml ./js_parser/loc.mli ./js_parser/object_parser.ml ./js_parser/parse_error.ml ./js_parser/parser_common.ml ./js_parser/parser_env.ml ./js_parser/parser_env.mli ./js_parser/parser_flow.ml ./js_parser/pattern_cover.ml ./js_parser/pattern_parser.ml ./js_parser/sedlexing.ml ./js_parser/sedlexing.mli ./js_parser/statement_parser.ml ./js_parser/token.ml ./js_parser/type_parser.ml ./js_parser/wtf8.ml ./js_parser/wtf8.mli ./main/js_main.ml ./main/js_main.mli ./outcome_printer/outcome_printer_ns.ml ./outcome_printer/outcome_printer_ns.mli ./outcome_printer/reason_outcome_printer_main.ml ./outcome_printer/reason_syntax_util.ml ./outcome_printer/reason_syntax_util.mli ./outcome_printer/tweaked_reason_oprint.ml ./stubs/bs_hash_stubs.ml ./super_errors/super_env.ml ./super_errors/super_location.ml ./super_errors/super_main.ml ./super_errors/super_misc.ml ./super_errors/super_misc.mli ./super_errors/super_pparse.ml ./super_errors/super_reason_react.ml ./super_errors/super_reason_react.mli ./super_errors/super_typecore.ml ./super_errors/super_typemod.ml ./super_errors/super_typetexp.ml ./super_errors/super_warnings.ml ./syntax/ast_attributes.ml ./syntax/ast_attributes.mli ./syntax/ast_bs_open.ml ./syntax/ast_bs_open.mli ./syntax/ast_comb.ml ./syntax/ast_comb.mli ./syntax/ast_compatible.ml ./syntax/ast_compatible.mli ./syntax/ast_core_type.ml ./syntax/ast_core_type.mli ./syntax/ast_core_type_class_type.ml ./syntax/ast_core_type_class_type.mli ./syntax/ast_derive.ml ./syntax/ast_derive.mli ./syntax/ast_derive_abstract.ml ./syntax/ast_derive_abstract.mli ./syntax/ast_derive_js_mapper.ml ./syntax/ast_derive_js_mapper.mli ./syntax/ast_derive_projector.ml ./syntax/ast_derive_projector.mli ./syntax/ast_derive_util.ml ./syntax/ast_derive_util.mli ./syntax/ast_exp.ml ./syntax/ast_exp.mli ./syntax/ast_exp_apply.ml ./syntax/ast_exp_apply.mli ./syntax/ast_exp_extension.ml ./syntax/ast_exp_extension.mli ./syntax/ast_external.ml ./syntax/ast_external.mli ./syntax/ast_external_mk.ml ./syntax/ast_external_mk.mli ./syntax/ast_external_process.ml ./syntax/ast_external_process.mli ./syntax/ast_literal.ml ./syntax/ast_literal.mli ./syntax/ast_open_cxt.ml ./syntax/ast_open_cxt.mli ./syntax/ast_pat.ml ./syntax/ast_pat.mli ./syntax/ast_payload.ml ./syntax/ast_payload.mli ./syntax/ast_polyvar.ml ./syntax/ast_polyvar.mli ./syntax/ast_raw.ml ./syntax/ast_raw.mli ./syntax/ast_reason_pp.ml ./syntax/ast_reason_pp.mli ./syntax/ast_signature.ml ./syntax/ast_signature.mli ./syntax/ast_structure.ml ./syntax/ast_structure.mli ./syntax/ast_tdcls.ml ./syntax/ast_tdcls.mli ./syntax/ast_tuple_pattern_flatten.ml ./syntax/ast_tuple_pattern_flatten.mli ./syntax/ast_utf8_string.ml ./syntax/ast_utf8_string.mli ./syntax/ast_utf8_string_interp.ml ./syntax/ast_utf8_string_interp.mli ./syntax/ast_util.ml ./syntax/ast_util.mli ./syntax/bs_ast_invariant.ml ./syntax/bs_ast_invariant.mli ./syntax/bs_ast_mapper.ml ./syntax/bs_ast_mapper.mli ./syntax/bs_builtin_ppx.ml ./syntax/bs_builtin_ppx.mli ./syntax/bs_syntaxerr.ml ./syntax/bs_syntaxerr.mli ./syntax/external_arg_spec.ml ./syntax/external_arg_spec.mli ./syntax/external_ffi_types.ml ./syntax/external_ffi_types.mli ./syntax/ppx_entry.ml ./syntax/reactjs_jsx_ppx_v2.ml ./syntax/reactjs_jsx_ppx_v3.ml \ No newline at end of file +../lib/4.06.1/whole_compiler.ml: ../ocaml/bytecomp/lambda.ml ../ocaml/bytecomp/lambda.mli ../ocaml/bytecomp/matching.ml ../ocaml/bytecomp/matching.mli ../ocaml/bytecomp/printlambda.ml ../ocaml/bytecomp/printlambda.mli ../ocaml/bytecomp/switch.ml ../ocaml/bytecomp/switch.mli ../ocaml/bytecomp/translattribute.ml ../ocaml/bytecomp/translattribute.mli ../ocaml/bytecomp/translclass.ml ../ocaml/bytecomp/translclass.mli ../ocaml/bytecomp/translcore.ml ../ocaml/bytecomp/translcore.mli ../ocaml/bytecomp/translmod.ml ../ocaml/bytecomp/translmod.mli ../ocaml/bytecomp/translobj.ml ../ocaml/bytecomp/translobj.mli ../ocaml/driver/compenv.ml ../ocaml/driver/compenv.mli ../ocaml/driver/compmisc.ml ../ocaml/driver/compmisc.mli ../ocaml/driver/pparse.ml ../ocaml/driver/pparse.mli ../ocaml/parsing/ast_helper.ml ../ocaml/parsing/ast_helper.mli ../ocaml/parsing/ast_invariants.ml ../ocaml/parsing/ast_invariants.mli ../ocaml/parsing/ast_iterator.ml ../ocaml/parsing/ast_iterator.mli ../ocaml/parsing/ast_mapper.ml ../ocaml/parsing/ast_mapper.mli ../ocaml/parsing/asttypes.mli ../ocaml/parsing/attr_helper.ml ../ocaml/parsing/attr_helper.mli ../ocaml/parsing/builtin_attributes.ml ../ocaml/parsing/builtin_attributes.mli ../ocaml/parsing/depend.ml ../ocaml/parsing/depend.mli ../ocaml/parsing/docstrings.ml ../ocaml/parsing/docstrings.mli ../ocaml/parsing/lexer.ml ../ocaml/parsing/lexer.mli ../ocaml/parsing/location.ml ../ocaml/parsing/location.mli ../ocaml/parsing/longident.ml ../ocaml/parsing/longident.mli ../ocaml/parsing/parse.ml ../ocaml/parsing/parse.mli ../ocaml/parsing/parser.ml ../ocaml/parsing/parser.mli ../ocaml/parsing/parsetree.mli ../ocaml/parsing/pprintast.ml ../ocaml/parsing/pprintast.mli ../ocaml/parsing/printast.ml ../ocaml/parsing/printast.mli ../ocaml/parsing/syntaxerr.ml ../ocaml/parsing/syntaxerr.mli ../ocaml/typing/annot.mli ../ocaml/typing/btype.ml ../ocaml/typing/btype.mli ../ocaml/typing/cmi_format.ml ../ocaml/typing/cmi_format.mli ../ocaml/typing/cmt_format.ml ../ocaml/typing/cmt_format.mli ../ocaml/typing/ctype.ml ../ocaml/typing/ctype.mli ../ocaml/typing/datarepr.ml ../ocaml/typing/datarepr.mli ../ocaml/typing/env.ml ../ocaml/typing/env.mli ../ocaml/typing/ident.ml ../ocaml/typing/ident.mli ../ocaml/typing/includeclass.ml ../ocaml/typing/includeclass.mli ../ocaml/typing/includecore.ml ../ocaml/typing/includecore.mli ../ocaml/typing/includemod.ml ../ocaml/typing/includemod.mli ../ocaml/typing/mtype.ml ../ocaml/typing/mtype.mli ../ocaml/typing/oprint.ml ../ocaml/typing/oprint.mli ../ocaml/typing/outcometree.mli ../ocaml/typing/parmatch.ml ../ocaml/typing/parmatch.mli ../ocaml/typing/path.ml ../ocaml/typing/path.mli ../ocaml/typing/predef.ml ../ocaml/typing/predef.mli ../ocaml/typing/primitive.ml ../ocaml/typing/primitive.mli ../ocaml/typing/printtyp.ml ../ocaml/typing/printtyp.mli ../ocaml/typing/printtyped.ml ../ocaml/typing/printtyped.mli ../ocaml/typing/stypes.ml ../ocaml/typing/stypes.mli ../ocaml/typing/subst.ml ../ocaml/typing/subst.mli ../ocaml/typing/tast_mapper.ml ../ocaml/typing/tast_mapper.mli ../ocaml/typing/typeclass.ml ../ocaml/typing/typeclass.mli ../ocaml/typing/typecore.ml ../ocaml/typing/typecore.mli ../ocaml/typing/typedecl.ml ../ocaml/typing/typedecl.mli ../ocaml/typing/typedtree.ml ../ocaml/typing/typedtree.mli ../ocaml/typing/typedtreeIter.ml ../ocaml/typing/typedtreeIter.mli ../ocaml/typing/typemod.ml ../ocaml/typing/typemod.mli ../ocaml/typing/typeopt.ml ../ocaml/typing/typeopt.mli ../ocaml/typing/types.ml ../ocaml/typing/types.mli ../ocaml/typing/typetexp.ml ../ocaml/typing/typetexp.mli ../ocaml/typing/untypeast.ml ../ocaml/typing/untypeast.mli ../ocaml/utils/arg_helper.ml ../ocaml/utils/arg_helper.mli ../ocaml/utils/ccomp.ml ../ocaml/utils/ccomp.mli ../ocaml/utils/clflags.ml ../ocaml/utils/clflags.mli ../ocaml/utils/consistbl.ml ../ocaml/utils/consistbl.mli ../ocaml/utils/identifiable.ml ../ocaml/utils/identifiable.mli ../ocaml/utils/misc.ml ../ocaml/utils/misc.mli ../ocaml/utils/numbers.ml ../ocaml/utils/numbers.mli ../ocaml/utils/profile.ml ../ocaml/utils/profile.mli ../ocaml/utils/tbl.ml ../ocaml/utils/tbl.mli ../ocaml/utils/terminfo.ml ../ocaml/utils/terminfo.mli ../ocaml/utils/warnings.ml ../ocaml/utils/warnings.mli ./common/bs_loc.ml ./common/bs_loc.mli ./common/bs_version.ml ./common/bs_version.mli ./common/bs_warnings.ml ./common/bs_warnings.mli ./common/ext_log.ml ./common/ext_log.mli ./common/js_config.ml ./common/js_config.mli ./common/lam_methname.ml ./common/lam_methname.mli ./common/ml_binary.ml ./common/ml_binary.mli ./core/bs_conditional_initial.ml ./core/bs_conditional_initial.mli ./core/classify_function.ml ./core/classify_function.mli ./core/config_util.ml ./core/config_util.mli ./core/config_whole_compiler.ml ./core/config_whole_compiler.mli ./core/j.ml ./core/js_analyzer.ml ./core/js_analyzer.mli ./core/js_arr.ml ./core/js_arr.mli ./core/js_ast_util.ml ./core/js_ast_util.mli ./core/js_block_runtime.ml ./core/js_block_runtime.mli ./core/js_call_info.ml ./core/js_call_info.mli ./core/js_closure.ml ./core/js_closure.mli ./core/js_cmj_format.ml ./core/js_cmj_format.mli ./core/js_cmj_load.ml ./core/js_cmj_load.mli ./core/js_current_package_info.ml ./core/js_current_package_info.mli ./core/js_dump.ml ./core/js_dump.mli ./core/js_dump_import_export.ml ./core/js_dump_import_export.mli ./core/js_dump_lit.ml ./core/js_dump_program.ml ./core/js_dump_program.mli ./core/js_dump_property.ml ./core/js_dump_property.mli ./core/js_dump_string.ml ./core/js_dump_string.mli ./core/js_exp_make.ml ./core/js_exp_make.mli ./core/js_fold.ml ./core/js_fold_basic.ml ./core/js_fold_basic.mli ./core/js_fun_env.ml ./core/js_fun_env.mli ./core/js_implementation.ml ./core/js_implementation.mli ./core/js_long.ml ./core/js_long.mli ./core/js_map.ml ./core/js_name_of_module_id.ml ./core/js_name_of_module_id.mli ./core/js_number.ml ./core/js_number.mli ./core/js_of_lam_array.ml ./core/js_of_lam_array.mli ./core/js_of_lam_block.ml ./core/js_of_lam_block.mli ./core/js_of_lam_exception.ml ./core/js_of_lam_exception.mli ./core/js_of_lam_option.ml ./core/js_of_lam_option.mli ./core/js_of_lam_polyvar.ml ./core/js_of_lam_polyvar.mli ./core/js_of_lam_string.ml ./core/js_of_lam_string.mli ./core/js_of_lam_tuple.ml ./core/js_of_lam_tuple.mli ./core/js_of_lam_variant.ml ./core/js_of_lam_variant.mli ./core/js_op.ml ./core/js_op_util.ml ./core/js_op_util.mli ./core/js_output.ml ./core/js_output.mli ./core/js_package_info.ml ./core/js_package_info.mli ./core/js_pass_debug.ml ./core/js_pass_debug.mli ./core/js_pass_flatten.ml ./core/js_pass_flatten.mli ./core/js_pass_flatten_and_mark_dead.ml ./core/js_pass_flatten_and_mark_dead.mli ./core/js_pass_scope.ml ./core/js_pass_scope.mli ./core/js_pass_tailcall_inline.ml ./core/js_pass_tailcall_inline.mli ./core/js_raw_exp_info.ml ./core/js_shake.ml ./core/js_shake.mli ./core/js_stmt_make.ml ./core/js_stmt_make.mli ./core/lam.ml ./core/lam.mli ./core/lam_analysis.ml ./core/lam_analysis.mli ./core/lam_arity.ml ./core/lam_arity.mli ./core/lam_arity_analysis.ml ./core/lam_arity_analysis.mli ./core/lam_beta_reduce.ml ./core/lam_beta_reduce.mli ./core/lam_beta_reduce_util.ml ./core/lam_beta_reduce_util.mli ./core/lam_bounded_vars.ml ./core/lam_bounded_vars.mli ./core/lam_closure.ml ./core/lam_closure.mli ./core/lam_coercion.ml ./core/lam_coercion.mli ./core/lam_compat.ml ./core/lam_compat.mli ./core/lam_compile.ml ./core/lam_compile.mli ./core/lam_compile_const.ml ./core/lam_compile_const.mli ./core/lam_compile_context.ml ./core/lam_compile_context.mli ./core/lam_compile_env.ml ./core/lam_compile_env.mli ./core/lam_compile_external_call.ml ./core/lam_compile_external_call.mli ./core/lam_compile_external_obj.ml ./core/lam_compile_external_obj.mli ./core/lam_compile_main.ml ./core/lam_compile_main.mli ./core/lam_compile_primitive.ml ./core/lam_compile_primitive.mli ./core/lam_compile_util.ml ./core/lam_compile_util.mli ./core/lam_constant.ml ./core/lam_constant.mli ./core/lam_constant_convert.ml ./core/lam_constant_convert.mli ./core/lam_convert.ml ./core/lam_convert.mli ./core/lam_dce.ml ./core/lam_dce.mli ./core/lam_dispatch_primitive.ml ./core/lam_dispatch_primitive.mli ./core/lam_eta_conversion.ml ./core/lam_eta_conversion.mli ./core/lam_exit_code.ml ./core/lam_exit_code.mli ./core/lam_exit_count.ml ./core/lam_exit_count.mli ./core/lam_free_variables.ml ./core/lam_free_variables.mli ./core/lam_group.ml ./core/lam_group.mli ./core/lam_hit.ml ./core/lam_hit.mli ./core/lam_id_kind.ml ./core/lam_id_kind.mli ./core/lam_inline_util.ml ./core/lam_inline_util.mli ./core/lam_iter.ml ./core/lam_iter.mli ./core/lam_module_ident.ml ./core/lam_module_ident.mli ./core/lam_pass_alpha_conversion.ml ./core/lam_pass_alpha_conversion.mli ./core/lam_pass_collect.ml ./core/lam_pass_collect.mli ./core/lam_pass_count.ml ./core/lam_pass_count.mli ./core/lam_pass_deep_flatten.ml ./core/lam_pass_deep_flatten.mli ./core/lam_pass_eliminate_ref.ml ./core/lam_pass_eliminate_ref.mli ./core/lam_pass_exits.ml ./core/lam_pass_exits.mli ./core/lam_pass_lets_dce.ml ./core/lam_pass_lets_dce.mli ./core/lam_pass_remove_alias.ml ./core/lam_pass_remove_alias.mli ./core/lam_pointer_info.ml ./core/lam_pointer_info.mli ./core/lam_primitive.ml ./core/lam_primitive.mli ./core/lam_print.ml ./core/lam_print.mli ./core/lam_scc.ml ./core/lam_scc.mli ./core/lam_stats.ml ./core/lam_stats.mli ./core/lam_stats_export.ml ./core/lam_stats_export.mli ./core/lam_subst.ml ./core/lam_subst.mli ./core/lam_tag_info.ml ./core/lam_util.ml ./core/lam_util.mli ./core/lam_var_stats.ml ./core/lam_var_stats.mli ./core/matching_polyfill.ml ./core/matching_polyfill.mli ./core/ocaml_options.ml ./core/ocaml_options.mli ./core/primitive_compat.ml ./core/primitive_compat.mli ./core/record_attributes_check.ml ./depends/ast_extract.ml ./depends/ast_extract.mli ./depends/binary_ast.ml ./depends/binary_ast.mli ./depends/bs_exception.ml ./depends/bs_exception.mli ./ext/bsc_warnings.ml ./ext/ext_arg.ml ./ext/ext_arg.mli ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_digest.ml ./ext/ext_digest.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_fmt.ml ./ext/ext_format.ml ./ext/ext_format.mli ./ext/ext_ident.ml ./ext/ext_ident.mli ./ext/ext_int.ml ./ext/ext_int.mli ./ext/ext_io.ml ./ext/ext_io.mli ./ext/ext_json_parse.ml ./ext/ext_json_parse.mli ./ext/ext_json_types.ml ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_modulename.ml ./ext/ext_modulename.mli ./ext/ext_namespace.ml ./ext/ext_namespace.mli ./ext/ext_obj.ml ./ext/ext_obj.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_path.ml ./ext/ext_path.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_position.ml ./ext/ext_position.mli ./ext/ext_pp.ml ./ext/ext_pp.mli ./ext/ext_pp_scope.ml ./ext/ext_pp_scope.mli ./ext/ext_ref.ml ./ext/ext_ref.mli ./ext/ext_scc.ml ./ext/ext_scc.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_sys.ml ./ext/ext_sys.mli ./ext/ext_utf8.ml ./ext/ext_utf8.mli ./ext/ext_util.ml ./ext/ext_util.mli ./ext/hash.ml ./ext/hash.mli ./ext/hash_gen.ml ./ext/hash_ident.ml ./ext/hash_ident.mli ./ext/hash_int.ml ./ext/hash_int.mli ./ext/hash_set.ml ./ext/hash_set.mli ./ext/hash_set_gen.ml ./ext/hash_set_ident.ml ./ext/hash_set_ident.mli ./ext/hash_set_ident_mask.ml ./ext/hash_set_ident_mask.mli ./ext/hash_set_poly.ml ./ext/hash_set_poly.mli ./ext/hash_set_string.ml ./ext/hash_set_string.mli ./ext/hash_string.ml ./ext/hash_string.mli ./ext/int_vec_util.ml ./ext/int_vec_util.mli ./ext/int_vec_vec.ml ./ext/int_vec_vec.mli ./ext/js_reserved_map.ml ./ext/js_reserved_map.mli ./ext/js_runtime_modules.ml ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/map_ident.ml ./ext/map_ident.mli ./ext/map_int.ml ./ext/map_int.mli ./ext/map_string.ml ./ext/map_string.mli ./ext/ordered_hash_map_gen.ml ./ext/ordered_hash_map_local_ident.ml ./ext/ordered_hash_map_local_ident.mli ./ext/set_gen.ml ./ext/set_ident.ml ./ext/set_ident.mli ./ext/set_string.ml ./ext/set_string.mli ./ext/vec.ml ./ext/vec.mli ./ext/vec_gen.ml ./ext/vec_int.ml ./ext/vec_int.mli ./js_parser/declaration_parser.ml ./js_parser/enum_common.ml ./js_parser/enum_parser.ml ./js_parser/expression_parser.ml ./js_parser/file_key.ml ./js_parser/flow_ast.ml ./js_parser/flow_ast_utils.ml ./js_parser/flow_ast_utils.mli ./js_parser/flow_lexer.ml ./js_parser/flow_lexer.mli ./js_parser/jsx_parser.ml ./js_parser/lex_env.ml ./js_parser/lex_result.ml ./js_parser/loc.ml ./js_parser/loc.mli ./js_parser/object_parser.ml ./js_parser/parse_error.ml ./js_parser/parser_common.ml ./js_parser/parser_env.ml ./js_parser/parser_env.mli ./js_parser/parser_flow.ml ./js_parser/pattern_cover.ml ./js_parser/pattern_parser.ml ./js_parser/sedlexing.ml ./js_parser/sedlexing.mli ./js_parser/statement_parser.ml ./js_parser/token.ml ./js_parser/type_parser.ml ./js_parser/wtf8.ml ./js_parser/wtf8.mli ./main/js_main.ml ./main/js_main.mli ./outcome_printer/outcome_printer_ns.ml ./outcome_printer/outcome_printer_ns.mli ./outcome_printer/reason_outcome_printer_main.ml ./outcome_printer/reason_syntax_util.ml ./outcome_printer/reason_syntax_util.mli ./outcome_printer/tweaked_reason_oprint.ml ./stubs/bs_hash_stubs.ml ./super_errors/super_env.ml ./super_errors/super_location.ml ./super_errors/super_main.ml ./super_errors/super_misc.ml ./super_errors/super_misc.mli ./super_errors/super_pparse.ml ./super_errors/super_reason_react.ml ./super_errors/super_reason_react.mli ./super_errors/super_typecore.ml ./super_errors/super_typemod.ml ./super_errors/super_typetexp.ml ./super_errors/super_warnings.ml ./syntax/ast_attributes.ml ./syntax/ast_attributes.mli ./syntax/ast_bs_open.ml ./syntax/ast_bs_open.mli ./syntax/ast_comb.ml ./syntax/ast_comb.mli ./syntax/ast_compatible.ml ./syntax/ast_compatible.mli ./syntax/ast_core_type.ml ./syntax/ast_core_type.mli ./syntax/ast_core_type_class_type.ml ./syntax/ast_core_type_class_type.mli ./syntax/ast_derive.ml ./syntax/ast_derive.mli ./syntax/ast_derive_abstract.ml ./syntax/ast_derive_abstract.mli ./syntax/ast_derive_js_mapper.ml ./syntax/ast_derive_js_mapper.mli ./syntax/ast_derive_projector.ml ./syntax/ast_derive_projector.mli ./syntax/ast_derive_util.ml ./syntax/ast_derive_util.mli ./syntax/ast_exp.ml ./syntax/ast_exp.mli ./syntax/ast_exp_apply.ml ./syntax/ast_exp_apply.mli ./syntax/ast_exp_extension.ml ./syntax/ast_exp_extension.mli ./syntax/ast_external.ml ./syntax/ast_external.mli ./syntax/ast_external_mk.ml ./syntax/ast_external_mk.mli ./syntax/ast_external_process.ml ./syntax/ast_external_process.mli ./syntax/ast_literal.ml ./syntax/ast_literal.mli ./syntax/ast_open_cxt.ml ./syntax/ast_open_cxt.mli ./syntax/ast_pat.ml ./syntax/ast_pat.mli ./syntax/ast_payload.ml ./syntax/ast_payload.mli ./syntax/ast_polyvar.ml ./syntax/ast_polyvar.mli ./syntax/ast_raw.ml ./syntax/ast_raw.mli ./syntax/ast_reason_pp.ml ./syntax/ast_reason_pp.mli ./syntax/ast_signature.ml ./syntax/ast_signature.mli ./syntax/ast_structure.ml ./syntax/ast_structure.mli ./syntax/ast_tdcls.ml ./syntax/ast_tdcls.mli ./syntax/ast_tuple_pattern_flatten.ml ./syntax/ast_tuple_pattern_flatten.mli ./syntax/ast_utf8_string.ml ./syntax/ast_utf8_string.mli ./syntax/ast_utf8_string_interp.ml ./syntax/ast_utf8_string_interp.mli ./syntax/ast_util.ml ./syntax/ast_util.mli ./syntax/bs_ast_invariant.ml ./syntax/bs_ast_invariant.mli ./syntax/bs_ast_mapper.ml ./syntax/bs_ast_mapper.mli ./syntax/bs_builtin_ppx.ml ./syntax/bs_builtin_ppx.mli ./syntax/bs_syntaxerr.ml ./syntax/bs_syntaxerr.mli ./syntax/external_arg_spec.ml ./syntax/external_arg_spec.mli ./syntax/external_ffi_types.ml ./syntax/external_ffi_types.mli ./syntax/ppx_entry.ml ./syntax/reactjs_jsx_ppx_v2.ml ./syntax/reactjs_jsx_ppx_v3.ml \ No newline at end of file