diff --git a/analysis/src/Cmt.ml b/analysis/src/Cmt.ml index a433d12908..ac1d5ae595 100644 --- a/analysis/src/Cmt.ml +++ b/analysis/src/Cmt.ml @@ -51,3 +51,17 @@ let fullsFromModule ~package ~moduleName = let loadFullCmtFromPath ~path = let uri = Uri.fromPath path in fullFromUri ~uri + +let loadCmtInfosFromPath ~path = + let uri = Uri.fromPath path in + match Packages.getPackage ~uri with + | None -> None + | Some package -> ( + let moduleName = + BuildSystem.namespacedName package.namespace (FindFiles.getName path) + in + match Hashtbl.find_opt package.pathsForModule moduleName with + | Some paths -> + let cmt = getCmtPath ~uri paths in + Shared.tryReadCmt cmt + | None -> None) diff --git a/compiler/bsb/bsb_package_specs.ml b/compiler/bsb/bsb_package_specs.ml index 0a5efe8664..eaf4ccee02 100644 --- a/compiler/bsb/bsb_package_specs.ml +++ b/compiler/bsb/bsb_package_specs.ml @@ -50,7 +50,7 @@ let supported_format (x : string) loc : Ext_module_system.t = {loc with Lexing.pos_cnum = loc.Lexing.pos_cnum + String.length x} in let loc = {Warnings.loc_start = loc; loc_end; loc_ghost = false} in - Location.deprecated loc + Location.deprecated ~can_be_automigrated:false loc (Printf.sprintf "Option \"%s\" is deprecated. Use \"%s\" instead." x Literals.esmodule) in diff --git a/compiler/ext/ext_list.ml b/compiler/ext/ext_list.ml index 7066f301ba..e7681aee30 100644 --- a/compiler/ext/ext_list.ml +++ b/compiler/ext/ext_list.ml @@ -774,3 +774,7 @@ let filter lst p = | x :: l -> if p x then find (x :: accu) l ~p else find accu l ~p in find [] lst ~p + +let is_empty = function + | [] -> true + | _ :: _ -> false diff --git a/compiler/ext/ext_list.mli b/compiler/ext/ext_list.mli index 61a07c7b38..c5e65149e9 100644 --- a/compiler/ext/ext_list.mli +++ b/compiler/ext/ext_list.mli @@ -231,3 +231,5 @@ val filter : 'a list -> ('a -> bool) -> 'a list val array_list_filter_map : 'a array -> 'b list -> ('a -> 'b -> 'c option) -> 'c list + +val is_empty : 'a list -> bool diff --git a/compiler/ext/warnings.ml b/compiler/ext/warnings.ml index 1ef517acc4..f25b91b4f8 100644 --- a/compiler/ext/warnings.ml +++ b/compiler/ext/warnings.ml @@ -31,7 +31,7 @@ type top_level_unit_help = FunctionCall | Other type t = | Comment_start (* 1 *) | Comment_not_end (* 2 *) - | Deprecated of string * loc * loc (* 3 *) + | Deprecated of string * loc * loc * bool (* 3 *) | Fragile_match of string (* 4 *) | Partial_application (* 5 *) | Method_override of string list (* 7 *) @@ -299,7 +299,7 @@ let () = reset () let message = function | Comment_start -> "this is the start of a comment." | Comment_not_end -> "this is not the end of a comment." - | Deprecated (s, _, _) -> + | Deprecated (s, _, _, can_be_automigrated) -> (* Reduce \r\n to \n: - Prevents any \r characters being printed on Unix when processing Windows sources @@ -307,6 +307,14 @@ let message = function testsuite *) "deprecated: " ^ Misc.normalise_eol s + ^ + if can_be_automigrated then + "\n\n\ + \ This can be automatically migrated by the ReScript migration tool. \ + Run `rescript-tools migrate-all ` to run all automatic \ + migrations available in your project, or `rescript-tools migrate \ + ` to migrate a single file." + else "" | Fragile_match "" -> "this pattern-matching is fragile." | Fragile_match s -> "this pattern-matching is fragile.\n\ @@ -533,7 +541,7 @@ let message = function you implement this before running the code." let sub_locs = function - | Deprecated (_, def, use) -> + | Deprecated (_, def, use, _) -> [(def, "Definition"); (use, "Expected signature")] | _ -> [] diff --git a/compiler/ext/warnings.mli b/compiler/ext/warnings.mli index 59971b94be..ba1a03ceec 100644 --- a/compiler/ext/warnings.mli +++ b/compiler/ext/warnings.mli @@ -24,7 +24,7 @@ type top_level_unit_help = FunctionCall | Other type t = | Comment_start (* 1 *) | Comment_not_end (* 2 *) - | Deprecated of string * loc * loc (* 3 *) + | Deprecated of string * loc * loc * bool (* 3 *) | Fragile_match of string (* 4 *) | Partial_application (* 5 *) | Method_override of string list (* 7 *) diff --git a/compiler/ml/builtin_attributes.ml b/compiler/ml/builtin_attributes.ml index 5d110eda75..a4d073104b 100644 --- a/compiler/ml/builtin_attributes.ml +++ b/compiler/ml/builtin_attributes.ml @@ -79,10 +79,64 @@ let rec deprecated_of_attrs = function Some (string_of_opt_payload p) | _ :: tl -> deprecated_of_attrs tl -let check_deprecated loc attrs s = - match deprecated_of_attrs attrs with +let rec deprecated_of_attrs_with_migrate = function + | [] -> None + | ( {txt = "deprecated"; _}, + PStr [{pstr_desc = Pstr_eval ({pexp_desc = Pexp_record (fields, _)}, _)}] + ) + :: _ -> ( + let reason = + fields + |> List.find_map (fun field -> + match field with + | { + lid = {txt = Lident "reason"}; + x = {pexp_desc = Pexp_constant (Pconst_string (reason, _))}; + } -> + Some reason + | _ -> None) + in + let migration_template = + fields + |> List.find_map (fun field -> + match field with + | {lid = {txt = Lident "migrate"}; x = migration_template} -> + Some migration_template + | _ -> None) + in + let migration_in_pipe_chain_template = + fields + |> List.find_map (fun field -> + match field with + | { + lid = {txt = Lident "migrateInPipeChain"}; + x = migration_in_pipe_chain_template; + } -> + Some migration_in_pipe_chain_template + | _ -> None) + in + + (* TODO: Validate and error if expected shape mismatches *) + match reason with + | Some reason -> + Some (reason, migration_template, migration_in_pipe_chain_template) + | None -> None) + | ({txt = "ocaml.deprecated" | "deprecated"; _}, p) :: _ -> + Some (string_of_opt_payload p, None, None) + | _ :: tl -> deprecated_of_attrs_with_migrate tl + +let check_deprecated ?deprecated_context loc attrs s = + match deprecated_of_attrs_with_migrate attrs with | None -> () - | Some txt -> Location.deprecated loc (cat s txt) + | Some (txt, migration_template, migration_in_pipe_chain_template) -> + !Cmt_utils.record_deprecated_used + ?deprecated_context ?migration_template ?migration_in_pipe_chain_template + loc txt; + Location.deprecated + ~can_be_automigrated: + (Option.is_some migration_template + || Option.is_some migration_in_pipe_chain_template) + loc (cat s txt) let check_deprecated_inclusion ~def ~use loc attrs1 attrs2 s = match (deprecated_of_attrs attrs1, deprecated_of_attrs attrs2) with diff --git a/compiler/ml/builtin_attributes.mli b/compiler/ml/builtin_attributes.mli index fd898388c7..63bf762331 100644 --- a/compiler/ml/builtin_attributes.mli +++ b/compiler/ml/builtin_attributes.mli @@ -27,7 +27,12 @@ ocaml.boxed / ocaml.unboxed *) -val check_deprecated : Location.t -> Parsetree.attributes -> string -> unit +val check_deprecated : + ?deprecated_context:Cmt_utils.deprecated_used_context -> + Location.t -> + Parsetree.attributes -> + string -> + unit val check_deprecated_inclusion : def:Location.t -> use:Location.t -> diff --git a/compiler/ml/cmt_format.ml b/compiler/ml/cmt_format.ml index 907f2e7122..ff30fc0043 100644 --- a/compiler/ml/cmt_format.ml +++ b/compiler/ml/cmt_format.ml @@ -63,6 +63,7 @@ type cmt_infos = { cmt_imports : (string * Digest.t option) list; cmt_interface_digest : Digest.t option; cmt_use_summaries : bool; + cmt_extra_info: Cmt_utils.cmt_extra_info; } type error = @@ -154,15 +155,30 @@ let read_cmi filename = let saved_types = ref [] let value_deps = ref [] +let deprecated_used = ref [] let clear () = saved_types := []; - value_deps := [] + value_deps := []; + deprecated_used := [] let add_saved_type b = saved_types := b :: !saved_types let get_saved_types () = !saved_types let set_saved_types l = saved_types := l +let record_deprecated_used ?deprecated_context ?migration_template ?migration_in_pipe_chain_template source_loc deprecated_text = + deprecated_used := + { + Cmt_utils.source_loc; + deprecated_text; + migration_template; + migration_in_pipe_chain_template; + context = deprecated_context; + } + :: !deprecated_used + +let _ = Cmt_utils.record_deprecated_used := record_deprecated_used + let record_value_dependency vd1 vd2 = if vd1.Types.val_loc <> vd2.Types.val_loc then value_deps := (vd1, vd2) :: !value_deps @@ -197,8 +213,9 @@ let save_cmt filename modname binary_annots sourcefile initial_env cmi = cmt_imports = List.sort compare (Env.imports ()); cmt_interface_digest = this_crc; cmt_use_summaries = need_to_clear_env; + cmt_extra_info = {deprecated_used = !deprecated_used}; } in output_cmt oc cmt) end; clear () -#endif \ No newline at end of file +#endif diff --git a/compiler/ml/cmt_format.mli b/compiler/ml/cmt_format.mli index 1a84aa68d0..66589f088d 100644 --- a/compiler/ml/cmt_format.mli +++ b/compiler/ml/cmt_format.mli @@ -63,6 +63,7 @@ type cmt_infos = { cmt_imports: (string * Digest.t option) list; cmt_interface_digest: Digest.t option; cmt_use_summaries: bool; + cmt_extra_info: Cmt_utils.cmt_extra_info; } type error = Not_a_typedtree of string @@ -111,6 +112,14 @@ val set_saved_types : binary_part list -> unit val record_value_dependency : Types.value_description -> Types.value_description -> unit +val record_deprecated_used : + ?deprecated_context:Cmt_utils.deprecated_used_context -> + ?migration_template:Parsetree.expression -> + ?migration_in_pipe_chain_template:Parsetree.expression -> + Location.t -> + string -> + unit + (* val is_magic_number : string -> bool diff --git a/compiler/ml/cmt_utils.ml b/compiler/ml/cmt_utils.ml new file mode 100644 index 0000000000..3e08cd93b4 --- /dev/null +++ b/compiler/ml/cmt_utils.ml @@ -0,0 +1,31 @@ +type deprecated_used_context = FunctionCall | Reference + +type deprecated_used = { + source_loc: Location.t; + deprecated_text: string; + migration_template: Parsetree.expression option; + migration_in_pipe_chain_template: Parsetree.expression option; + context: deprecated_used_context option; +} + +type cmt_extra_info = {deprecated_used: deprecated_used list} + +let record_deprecated_used : + (?deprecated_context:deprecated_used_context -> + ?migration_template:Parsetree.expression -> + ?migration_in_pipe_chain_template:Parsetree.expression -> + Location.t -> + string -> + unit) + ref = + ref + (fun + ?deprecated_context + ?migration_template + ?migration_in_pipe_chain_template + _ + _ + -> + ignore deprecated_context; + ignore migration_template; + ignore migration_in_pipe_chain_template) diff --git a/compiler/ml/location.ml b/compiler/ml/location.ml index caa0f98c86..fa2e806db0 100644 --- a/compiler/ml/location.ml +++ b/compiler/ml/location.ml @@ -298,7 +298,8 @@ let raise_errorf ?(loc = none) ?(sub = []) ?(if_highlight = "") = pp_ksprintf ~before:print_phanton_error_prefix (fun msg -> raise (Error {loc; msg; sub; if_highlight})) -let deprecated ?(def = none) ?(use = none) loc msg = - prerr_warning loc (Warnings.Deprecated (msg, def, use)) +let deprecated ?(can_be_automigrated = false) ?(def = none) ?(use = none) loc + msg = + prerr_warning loc (Warnings.Deprecated (msg, def, use, can_be_automigrated)) let map_loc f {txt; loc} = {txt = f txt; loc} diff --git a/compiler/ml/location.mli b/compiler/ml/location.mli index bff4609205..76f4db2bd8 100644 --- a/compiler/ml/location.mli +++ b/compiler/ml/location.mli @@ -130,6 +130,7 @@ val default_error_reporter : val report_exception : formatter -> exn -> unit (** Reraise the exception if it is unknown. *) -val deprecated : ?def:t -> ?use:t -> t -> string -> unit +val deprecated : + ?can_be_automigrated:bool -> ?def:t -> ?use:t -> t -> string -> unit val map_loc : ('a -> 'b) -> 'a loc -> 'b loc diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index b5061ae69d..f0f7b09009 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -2243,9 +2243,9 @@ type lazy_args = (Asttypes.arg_label * (unit -> Typedtree.expression) option) list type targs = (Asttypes.arg_label * Typedtree.expression option) list -let rec type_exp ~context ?recarg env sexp = +let rec type_exp ?deprecated_context ~context ?recarg env sexp = (* We now delegate everything to type_expect *) - type_expect ~context ?recarg env sexp (newvar ()) + type_expect ?deprecated_context ~context ?recarg env sexp (newvar ()) (* Typing of an expression with an expected type. This provide better error messages, and allows controlled @@ -2253,7 +2253,8 @@ let rec type_exp ~context ?recarg env sexp = In the principal case, [type_expected'] may be at generic_level. *) -and type_expect ~context ?in_function ?recarg env sexp ty_expected = +and type_expect ~context ?deprecated_context ?in_function ?recarg env sexp + ty_expected = (* Special errors for braced identifiers passed to records *) let context = match sexp.pexp_desc with @@ -2268,14 +2269,15 @@ and type_expect ~context ?in_function ?recarg env sexp ty_expected = let previous_saved_types = Cmt_format.get_saved_types () in let exp = Builtin_attributes.warning_scope sexp.pexp_attributes (fun () -> - type_expect_ ~context ?in_function ?recarg env sexp ty_expected) + type_expect_ ?deprecated_context ~context ?in_function ?recarg env sexp + ty_expected) in Cmt_format.set_saved_types (Cmt_format.Partial_expression exp :: previous_saved_types); exp -and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected - = +and type_expect_ ?deprecated_context ~context ?in_function ?(recarg = Rejected) + env sexp ty_expected = let loc = sexp.pexp_loc in (* Record the expression type before unifying it with the expected type *) let rue exp = @@ -2292,7 +2294,14 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected in match sexp.pexp_desc with | Pexp_ident lid -> - let path, desc = Typetexp.find_value env lid.loc lid.txt in + let path, desc = + Typetexp.find_value + ?deprecated_context: + (match deprecated_context with + | None -> Some Reference + | v -> v) + env lid.loc lid.txt + in (if !Clflags.annotations then let dloc = desc.Types.val_loc in let annot = @@ -2428,7 +2437,9 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected assert (sargs <> []); begin_def (); (* one more level for non-returning functions *) - let funct = type_exp ~context:None env sfunct in + let funct = + type_exp ~deprecated_context:FunctionCall ~context:None env sfunct + in let ty = instance env funct.exp_type in end_def (); wrap_trace_gadt_instances env (lower_args env []) ty; diff --git a/compiler/ml/typetexp.ml b/compiler/ml/typetexp.ml index 31c29ea35f..9867baac11 100644 --- a/compiler/ml/typetexp.ml +++ b/compiler/ml/typetexp.ml @@ -120,7 +120,8 @@ let find_type env loc lid = env loc lid in let decl = Env.find_type path env in - Builtin_attributes.check_deprecated loc decl.type_attributes (Path.name path); + Builtin_attributes.check_deprecated ~deprecated_context:Cmt_utils.Reference + loc decl.type_attributes (Path.name path); (path, decl) let find_constructor = @@ -131,12 +132,13 @@ let find_all_constructors = let find_all_labels = find_component Env.lookup_all_labels (fun lid -> Unbound_label (lid, None)) -let find_value env loc lid = +let find_value ?deprecated_context env loc lid = Env.check_value_name (Longident.last lid) loc; let ((path, decl) as r) = find_component Env.lookup_value (fun lid -> Unbound_value lid) env loc lid in - Builtin_attributes.check_deprecated loc decl.val_attributes (Path.name path); + Builtin_attributes.check_deprecated ?deprecated_context loc + decl.val_attributes (Path.name path); r let lookup_module ?(load = false) env loc lid = diff --git a/compiler/ml/typetexp.mli b/compiler/ml/typetexp.mli index 19f7fa46b9..8f40096392 100644 --- a/compiler/ml/typetexp.mli +++ b/compiler/ml/typetexp.mli @@ -89,7 +89,11 @@ val find_all_labels : Longident.t -> (label_description * (unit -> unit)) list val find_value : - Env.t -> Location.t -> Longident.t -> Path.t * value_description + ?deprecated_context:Cmt_utils.deprecated_used_context -> + Env.t -> + Location.t -> + Longident.t -> + Path.t * value_description val find_module : Env.t -> Location.t -> Longident.t -> Path.t * module_declaration val lookup_module : ?load:bool -> Env.t -> Location.t -> Longident.t -> Path.t diff --git a/packages/@rescript/runtime/Js.res b/packages/@rescript/runtime/Js.res index 4bdfdf03d1..d8e48dd7b5 100644 --- a/packages/@rescript/runtime/Js.res +++ b/packages/@rescript/runtime/Js.res @@ -156,67 +156,164 @@ module Map = Js_map module WeakMap = Js_weakmap /** JS object type */ +@deprecated( + "This has been deprecated and will be removed in v13. Use the `{..}` type directly instead." +) type t<'a> = {..} as 'a /** JS global object reference */ @val +@deprecated({ + reason: "Use `globalThis` directly instead.", + migrate: globalThis(), +}) external globalThis: t<'a> = "globalThis" +@deprecated({ + reason: "Use `Null.t` directly instead.", + migrate: %replace.type(: Null.t), +}) @unboxed type null<+'a> = Js_null.t<'a> = Value('a) | @as(null) Null +@deprecated("This has been deprecated and will be removed in v13.") type undefined<+'a> = Js_undefined.t<'a> @unboxed +@deprecated({ + reason: "Use `Nullable.t` directly instead.", + migrate: %replace.type(: Nullable.t), +}) type nullable<+'a> = Js_null_undefined.t<'a> = Value('a) | @as(null) Null | @as(undefined) Undefined +@deprecated({ + reason: "Use `Nullable.t` directly instead.", + migrate: %replace.type(: Nullable.t), +}) type null_undefined<+'a> = nullable<'a> external toOption: nullable<'a> => option<'a> = "%nullable_to_opt" +@deprecated({ + reason: "Use `fromUndefined` instead.", + migrate: fromUndefined(), +}) let undefinedToOption: undefined<'a> => option<'a> = Primitive_option.fromUndefined +@deprecated({ + reason: "Use `Null.toOption` instead.", + migrate: Null.toOption(), +}) external nullToOption: null<'a> => option<'a> = "%null_to_opt" +@deprecated({ + reason: "Use `isNullable` directly instead.", + migrate: isNullable(), +}) external isNullable: nullable<'a> => bool = "%is_nullable" +@deprecated({ + reason: "Use `import` directly instead.", + migrate: import(), +}) external import: 'a => promise<'a> = "%import" /** The same as {!test} except that it is more permissive on the types of input */ +@deprecated({ + reason: "Use `testAny` directly instead.", + migrate: testAny(), +}) external testAny: 'a => bool = "%is_nullable" /** The promise type, defined here for interoperation across packages. */ +@deprecated( + "This is deprecated and will be removed in v13. Use the `promise` type directly instead." +) type promise<+'a, +'e> /** The same as empty in `Js.Null`. Compiles to `null`. */ +@deprecated({ + reason: "Use `null` instead.", + migrate: null(), +}) external null: null<'a> = "%null" /** The same as empty `Js.Undefined`. Compiles to `undefined`. */ +@deprecated({ + reason: "Use `undefined` instead.", + migrate: undefined(), +}) external undefined: undefined<'a> = "%undefined" /** `typeof x` will be compiled as `typeof x` in JS. Please consider functions in `Js.Types` for a type safe way of reflection. */ +@deprecated({ + reason: "Use `typeof` instead.", + migrate: typeof(), +}) external typeof: 'a => string = "%typeof" /** Equivalent to console.log any value. */ -@val @scope("console") +@deprecated({ + reason: "Use `Console.log` instead.", + migrate: Console.log(), +}) +@val +@scope("console") external log: 'a => unit = "log" -@val @scope("console") external log2: ('a, 'b) => unit = "log" -@val @scope("console") external log3: ('a, 'b, 'c) => unit = "log" +@deprecated({ + reason: "Use `Console.log2` instead.", + migrate: Console.log2(), +}) +@val +@scope("console") +external log2: ('a, 'b) => unit = "log" + +@deprecated({ + reason: "Use `Console.log3` instead.", + migrate: Console.log3(), +}) +@val +@scope("console") +external log3: ('a, 'b, 'c) => unit = "log" -@val @scope("console") external log4: ('a, 'b, 'c, 'd) => unit = "log" +@deprecated({ + reason: "Use `Console.log4` instead.", + migrate: Console.log4(), +}) +@val +@scope("console") +external log4: ('a, 'b, 'c, 'd) => unit = "log" /** A convenience function to console.log more than 4 arguments */ -@val @scope("console") @variadic +@deprecated({ + reason: "Use `Console.logMany` instead.", + migrate: Console.logMany(), +}) +@val +@scope("console") +@variadic external logMany: array<'a> => unit = "log" +@deprecated({ + reason: "Use `eqNull` directly instead.", + migrate: eqNull(), +}) external eqNull: ('a, null<'a>) => bool = "%equal_null" +@deprecated({ + reason: "Use `eqUndefined` directly instead.", + migrate: eqUndefined(), +}) external eqUndefined: ('a, undefined<'a>) => bool = "%equal_undefined" +@deprecated({ + reason: "Use `eqNullable` directly instead.", + migrate: eqNullable(), +}) external eqNullable: ('a, nullable<'a>) => bool = "%equal_nullable" /* ## Operators */ @@ -226,22 +323,38 @@ external eqNullable: ('a, nullable<'a>) => bool = "%equal_nullable" It is marked as unsafe, since it is impossible to give a proper semantics for comparision which applies to any type */ +@deprecated({ + reason: "Use `lt` instead.", + migrate: lt(), +}) external unsafe_lt: ('a, 'a) => bool = "%unsafe_lt" /** `unsafe_le(a, b)` will be compiled as `a <= b`. See also `Js.unsafe_lt`. */ +@deprecated({ + reason: "Use `le` instead.", + migrate: le(), +}) external unsafe_le: ('a, 'a) => bool = "%unsafe_le" /** `unsafe_gt(a, b)` will be compiled as `a > b`. See also `Js.unsafe_lt`. */ +@deprecated({ + reason: "Use `gt` instead.", + migrate: gt(), +}) external unsafe_gt: ('a, 'a) => bool = "%unsafe_gt" /** `unsafe_ge(a, b)` will be compiled as `a >= b`. See also `Js.unsafe_lt`. */ +@deprecated({ + reason: "Use `ge` instead.", + migrate: ge(), +}) external unsafe_ge: ('a, 'a) => bool = "%unsafe_ge" diff --git a/packages/@rescript/runtime/Js_OO.res b/packages/@rescript/runtime/Js_OO.res index aba40deefa..65f9cbc591 100644 --- a/packages/@rescript/runtime/Js_OO.res +++ b/packages/@rescript/runtime/Js_OO.res @@ -24,29 +24,52 @@ @@config({flags: ["-unboxed-types"]}) +@deprecated("This has been deprecated and will be removed in v13.") external unsafe_to_method: 'a => 'a = "%unsafe_to_method" module Callback = { + @deprecated("This has been deprecated and will be removed in v13.") type arity1<'a> = {@internal i1: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity2<'a> = {@internal i2: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity3<'a> = {@internal i3: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity4<'a> = {@internal i4: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity5<'a> = {@internal i5: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity6<'a> = {@internal i6: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity7<'a> = {@internal i7: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity8<'a> = {@internal i8: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity9<'a> = {@internal i9: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity10<'a> = {@internal i10: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity11<'a> = {@internal i11: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity12<'a> = {@internal i12: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity13<'a> = {@internal i13: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity14<'a> = {@internal i14: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity15<'a> = {@internal i15: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity16<'a> = {@internal i16: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity17<'a> = {@internal i17: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity18<'a> = {@internal i18: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity19<'a> = {@internal i19: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity20<'a> = {@internal i20: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity21<'a> = {@internal i21: 'a} + @deprecated("This has been deprecated and will be removed in v13.") type arity22<'a> = {@internal i22: 'a} } diff --git a/packages/@rescript/runtime/Js_array.res b/packages/@rescript/runtime/Js_array.res index 0d352afe7a..b0fd70e5d5 100644 --- a/packages/@rescript/runtime/Js_array.res +++ b/packages/@rescript/runtime/Js_array.res @@ -33,11 +33,19 @@ parameter in the function. /** The type used to describe a JavaScript array. */ +@deprecated({ + reason: "Use `array` directly instead.", + migrate: %replace.type(: array), +}) type t<'a> = array<'a> /** A type used to describe JavaScript objects that are like an array or are iterable. */ +@deprecated({ + reason: "Use `Array.arrayLike` instead.", + migrate: %replace.type(: Array.arrayLike), +}) type array_like<'a> = Js_array2.array_like<'a> /* commented out until bs has a plan for iterators @@ -55,6 +63,10 @@ Js.Array.from(strArr) == ["a", "b", "c", "d"] ``` */ @val +@deprecated({ + reason: "Use `Array.fromArrayLike` instead.", + migrate: Array.fromArrayLike(), +}) external from: array_like<'a> => array<'a> = "Array.from" /* ES2015 */ @@ -74,11 +86,20 @@ Js.Array.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0] ``` */ @val +@deprecated({ + reason: "Use `Array.fromArrayLikeWithMap` instead.", + migrate: Array.fromArrayLikeWithMap(), +}) external fromMap: (array_like<'a>, 'a => 'b) => array<'b> = "Array.from" /* ES2015 */ -@val external isArray: 'a => bool = "Array.isArray" +@deprecated({ + reason: "Use `Array.isArray` instead.", + migrate: Array.isArray(), +}) +@val +external isArray: 'a => bool = "Array.isArray" /* ES2015 */ /* Returns `true` if its argument is an array; `false` otherwise. This is a @@ -97,6 +118,10 @@ Js.Array.isArray("abcd") == false /** Returns the number of elements in the array. See [`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) on MDN. */ +@deprecated({ + reason: "Use `Array.length` instead.", + migrate: Array.length(), +}) external length: array<'a> => int = "%array_length" /* Mutator functions */ @@ -218,6 +243,10 @@ let empty: array = [] Js.Array.pop(empty) == None ``` */ +@deprecated({ + reason: "Use `Array.pop` instead.", + migrate: Array.pop(), +}) @send external pop: t<'a> => option<'a> = "pop" @@ -262,6 +291,10 @@ Js.Array.reverseInPlace(arr) == ["cat", "bee", "ant"] arr == ["cat", "bee", "ant"] ``` */ +@deprecated({ + reason: "Use `Array.reverse` instead.", + migrate: Array.reverse(), +}) @send external reverseInPlace: t<'a> => 'this = "reverse" @@ -279,6 +312,10 @@ let empty: array = [] Js.Array.shift(empty) == None ``` */ +@deprecated({ + reason: "Use `Array.shift` instead.", + migrate: Array.shift(), +}) @send external shift: t<'a> => option<'a> = "shift" @@ -297,6 +334,9 @@ Js.Array.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30] numbers == [1, 10, 2, 20, 3, 30] ``` */ +@deprecated( + "This has been deprecated and will be removed in v13. Use functions from the `Array` module instead." +) @send external sortInPlace: t<'a> => 'this = "sort" @@ -527,7 +567,7 @@ Js.Array.indexOfFrom("b", ~from=2, ["a", "b", "a", "c", "a"]) == -1 external indexOfFrom: (t<'a>, 'a, ~from: int) => int = "indexOf" let indexOfFrom = (arg1, ~from, obj) => indexOfFrom(obj, arg1, ~from) -@send @deprecated("please use joinWith instead") +@send @deprecated({reason: "Use `Array.join` instead.", migrate: Array.join()}) external join: t<'a> => string = "join" /** @@ -611,6 +651,10 @@ Returns a copy of the entire array. Same as `Js.Array.Slice(~start=0, [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) on MDN. */ +@deprecated({ + reason: "Use `Array.copy` instead.", + migrate: Array.copy(), +}) @send external copy: t<'a> => 'this = "slice" @@ -642,6 +686,10 @@ Js.Array.toString([3.5, 4.6, 7.8]) == "3.5,4.6,7.8" Js.Array.toString(["a", "b", "c"]) == "a,b,c" ``` */ +@deprecated({ + reason: "Use `Array.toString` instead.", + migrate: Array.toString(), +}) @send external toString: t<'a> => string = "toString" @@ -661,6 +709,10 @@ Js.Array.toLocaleString([Js.Date.make()]) // returns "2020-3-19 10:52:11" for locale de_DE.utf8 ``` */ +@deprecated({ + reason: "Use `Array.toLocaleString` instead.", + migrate: Array.toLocaleString(), +}) @send external toLocaleString: t<'a> => string = "toLocaleString" @@ -1059,6 +1111,10 @@ Js.Array.unsafe_get(arr, 3) == 103 Js.Array.unsafe_get(arr, 4) // returns undefined ``` */ +@deprecated({ + reason: "Use `Array.getUnsafe` instead.", + migrate: Array.getUnsafe(), +}) external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" /** @@ -1083,4 +1139,8 @@ Js.Array.unsafe_set(arr, -1, 66) // you don't want to know. ``` */ +@deprecated({ + reason: "Use `Array.setUnsafe` instead.", + migrate: Array.setUnsafe(), +}) external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" diff --git a/packages/@rescript/runtime/Js_array2.res b/packages/@rescript/runtime/Js_array2.res index 04215f24cf..4688cebcd7 100644 --- a/packages/@rescript/runtime/Js_array2.res +++ b/packages/@rescript/runtime/Js_array2.res @@ -54,11 +54,19 @@ let result = { /** The type used to describe a JavaScript array. */ +@deprecated({ + reason: "Use `array` directly instead.", + migrate: %replace.type(: array), +}) type t<'a> = array<'a> /** A type used to describe JavaScript objects that are like an array or are iterable. */ +@deprecated({ + reason: "Use `Array.arrayLike` directly instead.", + migrate: %replace.type(: Array.arrayLike), +}) type array_like<'a> = Stdlib_Array.arrayLike<'a> /* commented out until bs has a plan for iterators @@ -77,6 +85,10 @@ let strArr = Js.String.castToArrayLike("abcd") Js.Array2.from(strArr) == ["a", "b", "c", "d"] ``` */ +@deprecated({ + reason: "Use `Array.fromArrayLike` instead.", + migrate: Array.fromArrayLike(), +}) @val external from: array_like<'a> => array<'a> = "Array.from" @@ -96,6 +108,10 @@ let code = s => Js.String.charCodeAt(0, s) Js.Array2.fromMap(strArr, code) == [97.0, 98.0, 99.0, 100.0] ``` */ +@deprecated({ + reason: "Use `Array.fromArrayLikeWithMap` instead.", + migrate: Array.fromArrayLikeWithMap(), +}) @val external fromMap: (array_like<'a>, 'a => 'b) => array<'b> = "Array.from" @@ -112,6 +128,10 @@ Js.Array2.isArray(list{5, 2, 3, 1, 4}) == true Js.Array2.isArray("abcd") == false ``` */ +@deprecated({ + reason: "Use `Array.isArray` instead.", + migrate: Array.isArray(), +}) @val external isArray: 'a => bool = "Array.isArray" @@ -120,6 +140,10 @@ Returns the number of elements in the array. See [`Array.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) on MDN. */ +@deprecated({ + reason: "Use `Array.length` instead.", + migrate: Array.length(), +}) external length: array<'a> => int = "%array_length" /* Mutator functions */ @@ -139,6 +163,10 @@ Js.Array2.copyWithin(arr, ~to_=2) == [100, 101, 100, 101, 102] arr == [100, 101, 100, 101, 102] ``` */ +@deprecated({ + reason: "Use `Array.copyAllWithin` instead.", + migrate: Array.copyAllWithin(~target=%insert.labelledArgument("to_")), +}) @send external copyWithin: (t<'a>, ~to_: int) => t<'a> = "copyWithin" @@ -159,6 +187,13 @@ Js.Array2.copyWithinFrom(arr, ~from=2, ~to_=0) == [102, 103, 104, 103, 104] arr == [102, 103, 104, 103, 104] ``` */ +@deprecated({ + reason: "Use `Array.copyWithinToEnd` instead.", + migrate: Array.copyWithinToEnd( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("from"), + ), +}) @send external copyWithinFrom: (t<'a>, ~to_: int, ~from: int) => t<'a> = "copyWithin" @@ -179,6 +214,13 @@ Js.Array2.copyWithinFromRange(arr, ~start=2, ~end_=5, ~to_=1) == [100, 102, 103, arr == [100, 102, 103, 104, 104, 105] ``` */ +@deprecated({ + reason: "Use `Array.copyWithin` instead.", + migrate: Array.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~end=%insert.labelledArgument("end_"), + ), +}) @send external copyWithinFromRange: (t<'a>, ~to_: int, ~start: int, ~end_: int) => t<'a> = "copyWithin" @@ -201,6 +243,10 @@ Js.Array2.fillInPlace(arr, 99) == [99, 99, 99, 99, 99] arr == [99, 99, 99, 99, 99] ``` */ +@deprecated({ + reason: "Use `Array.fillAll` instead.", + migrate: Array.fillAll(), +}) @send external fillInPlace: (t<'a>, 'a) => t<'a> = "fill" @@ -221,6 +267,10 @@ Js.Array2.fillFromInPlace(arr, 99, ~from=2) == [100, 101, 99, 99, 99] arr == [100, 101, 99, 99, 99] ``` */ +@deprecated({ + reason: "Use `Array.fillToEnd` instead.", + migrate: Array.fillToEnd(~start=%insert.labelledArgument("from")), +}) @send external fillFromInPlace: (t<'a>, 'a, ~from: int) => t<'a> = "fill" @@ -242,6 +292,10 @@ Js.Array2.fillRangeInPlace(arr, 99, ~start=1, ~end_=4) == [100, 99, 99, 99, 104] arr == [100, 99, 99, 99, 104] ``` */ +@deprecated({ + reason: "Use `Array.fill` instead.", + migrate: Array.fill(~end=%insert.labelledArgument("end_")), +}) @send external fillRangeInPlace: (t<'a>, 'a, ~start: int, ~end_: int) => t<'a> = "fill" @@ -265,6 +319,10 @@ let empty: array = [] Js.Array2.pop(empty) == None ``` */ +@deprecated({ + reason: "Use `Array.pop` instead.", + migrate: Array.pop(), +}) @send external pop: t<'a> => option<'a> = "pop" @@ -282,6 +340,10 @@ Js.Array2.push(arr, "dog") == 4 arr == ["ant", "bee", "cat", "dog"] ``` */ +@deprecated({ + reason: "Use `Array.push` instead. Note: `Array.push` returns `unit`, not the array length.", + migrate: Array.push(), +}) @send external push: (t<'a>, 'a) => int = "push" @@ -300,7 +362,12 @@ Js.Array2.pushMany(arr, ["dog", "elk"]) == 5 arr == ["ant", "bee", "cat", "dog", "elk"] ``` */ -@send @variadic +@deprecated({ + reason: "Use `Array.pushMany` instead. Note: `Array.pushMany` returns `unit`, not the array length.", + migrate: Array.pushMany(), +}) +@send +@variadic external pushMany: (t<'a>, array<'a>) => int = "push" /** @@ -317,6 +384,10 @@ Js.Array2.reverseInPlace(arr) == ["cat", "bee", "ant"] arr == ["cat", "bee", "ant"] ``` */ +@deprecated({ + reason: "Use `Array.reverse` instead.", + migrate: Array.reverse(), +}) @send external reverseInPlace: t<'a> => t<'a> = "reverse" @@ -338,6 +409,10 @@ let empty: array = [] Js.Array2.shift(empty) == None ``` */ +@deprecated({ + reason: "Use `Array.shift` instead.", + migrate: Array.shift(), +}) @send external shift: t<'a> => option<'a> = "shift" @@ -361,6 +436,12 @@ Js.Array2.sortInPlace(numbers) == [1, 10, 2, 20, 3, 30] numbers == [1, 10, 2, 20, 3, 30] ``` */ +@deprecated({ + reason: "Use `Array.toSorted` instead.", + migrate: Array.toSorted((_a, _b) => + %todo_("This needs a comparator function. Use `String.compare` for strings, etc.") + ), +}) @send external sortInPlace: t<'a> => t<'a> = "sort" @@ -394,6 +475,10 @@ let reverseNumeric = (n1, n2) => n2 - n1 Js.Array2.sortInPlaceWith(numbers, reverseNumeric) == [30, 20, 10, 3, 2, 1] ``` */ +@deprecated({ + reason: "Use `Array.sort` instead.", + migrate: Array.sort(), +}) @send external sortInPlaceWith: (t<'a>, ('a, 'a) => int) => t<'a> = "sort" @@ -420,7 +505,16 @@ Js.Array2.spliceInPlace(arr3, ~pos=9, ~remove=2, ~add=["x", "y", "z"]) == [] arr3 == ["a", "b", "c", "d", "e", "f", "x", "y", "z"] ``` */ -@send @variadic +@send +@variadic +@deprecated({ + reason: "Use `Array.splice` instead.", + migrate: Array.splice( + ~start=%insert.labelledArgument("pos"), + ~remove=%insert.labelledArgument("remove"), + ~insert=%insert.labelledArgument("add"), + ), +}) external spliceInPlace: (t<'a>, ~pos: int, ~remove: int, ~add: array<'a>) => t<'a> = "splice" /** @@ -439,6 +533,10 @@ arr == ["a", "b", "c", "d"] ``` */ @send +@deprecated({ + reason: "Use `Array.removeInPlace` instead.", + migrate: Array.removeInPlace(%insert.labelledArgument("pos")), +}) external removeFromInPlace: (t<'a>, ~pos: int) => t<'a> = "splice" /** @@ -457,6 +555,14 @@ arr == ["a", "b", "f"] ``` */ @send +@deprecated({ + reason: "Use `Array.splice` instead.", + migrate: Array.splice( + ~start=%insert.labelledArgument("pos"), + ~remove=%insert.labelledArgument("count"), + ~insert=[], + ), +}) external removeCountInPlace: (t<'a>, ~pos: int, ~count: int) => t<'a> = "splice" /** @@ -473,6 +579,10 @@ Js.Array2.unshift(arr, "a") == 4 arr == ["a", "b", "c", "d"] ``` */ +@deprecated({ + reason: "Use `Array.unshift` instead.", + migrate: Array.unshift(), +}) @send external unshift: (t<'a>, 'a) => int = "unshift" @@ -491,7 +601,12 @@ Js.Array2.unshiftMany(arr, ["a", "b", "c"]) == 5 arr == ["a", "b", "c", "d", "e"] ``` */ -@send @variadic +@deprecated({ + reason: "Use `Array.unshiftMany` instead.", + migrate: Array.unshiftMany(), +}) +@send +@variadic external unshiftMany: (t<'a>, array<'a>) => int = "unshift" /* Accessor functions @@ -511,6 +626,10 @@ on MDN. Js.Array2.concat(["a", "b"], ["c", "d", "e"]) == ["a", "b", "c", "d", "e"] ``` */ +@deprecated({ + reason: "Use `Array.concat` instead.", + migrate: Array.concat(), +}) @send external concat: (t<'a>, t<'a>) => t<'a> = "concat" @@ -535,7 +654,12 @@ Js.Array2.concatMany(["a", "b", "c"], [["d", "e"], ["f", "g", "h"]]) == [ ] ``` */ -@send @variadic +@deprecated({ + reason: "Use `Array.concatMany` instead.", + migrate: Array.concatMany(), +}) +@send +@variadic external concatMany: (t<'a>, array>) => t<'a> = "concat" /** @@ -550,6 +674,10 @@ Js.Array2.includes(["a", "b", "c"], "b") == true Js.Array2.includes(["a", "b", "c"], "x") == false ``` */ +@deprecated({ + reason: "Use `Array.includes` instead.", + migrate: Array.includes(), +}) @send external includes: (t<'a>, 'a) => bool = "includes" @@ -566,6 +694,10 @@ Js.Array2.indexOf([100, 101, 102, 103], 102) == 2 Js.Array2.indexOf([100, 101, 102, 103], 999) == -1 ``` */ +@deprecated({ + reason: "Use `Array.indexOf` instead.", + migrate: Array.indexOf(), +}) @send external indexOf: (t<'a>, 'a) => int = "indexOf" @@ -583,6 +715,10 @@ Js.Array2.indexOfFrom(["a", "b", "a", "c", "a"], "a", ~from=3) == 4 Js.Array2.indexOfFrom(["a", "b", "a", "c", "a"], "b", ~from=2) == -1 ``` */ +@deprecated({ + reason: "Use `Array.indexOfFrom` instead.", + migrate: Array.indexOfFrom(%insert.labelledArgument("from")), +}) @send external indexOfFrom: (t<'a>, 'a, ~from: int) => int = "indexOf" @@ -602,6 +738,10 @@ Js.Array2.joinWith([2020, 9, 4], "/") == "2020/9/4" Js.Array2.joinWith([2.5, 3.6, 3e-2], ";") == "2.5;3.6;0.03" ``` */ +@deprecated({ + reason: "Use `Array.joinUnsafe` instead.", + migrate: Array.joinUnsafe(), +}) @send external joinWith: (t<'a>, string) => string = "join" @@ -618,6 +758,10 @@ Js.Array2.lastIndexOf(["a", "b", "a", "c"], "a") == 2 Js.Array2.lastIndexOf(["a", "b", "a", "c"], "x") == -1 ``` */ +@deprecated({ + reason: "Use `Array.lastIndexOf` instead.", + migrate: Array.lastIndexOf(), +}) @send external lastIndexOf: (t<'a>, 'a) => int = "lastIndexOf" @@ -635,6 +779,10 @@ Js.Array2.lastIndexOfFrom(["a", "b", "a", "c", "a", "d"], "a", ~from=3) == 2 Js.Array2.lastIndexOfFrom(["a", "b", "a", "c", "a", "d"], "c", ~from=2) == -1 ``` */ +@deprecated({ + reason: "Use `Array.lastIndexOfFrom` instead.", + migrate: Array.lastIndexOfFrom(%insert.labelledArgument("from")), +}) @send external lastIndexOfFrom: (t<'a>, 'a, ~from: int) => int = "lastIndexOf" @@ -654,6 +802,10 @@ Js.Array2.slice(arr, ~start=-3, ~end_=-1) == [104, 105] Js.Array2.slice(arr, ~start=9, ~end_=10) == [] ``` */ +@deprecated({ + reason: "Use `Array.slice` instead.", + migrate: Array.slice(~end=%insert.labelledArgument("end_")), +}) @send external slice: (t<'a>, ~start: int, ~end_: int) => t<'a> = "slice" @@ -663,6 +815,10 @@ Returns a copy of the entire array. Same as `Js.Array2.Slice(arr, ~start=0, [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) on MDN. */ +@deprecated({ + reason: "Use `Array.copy` instead.", + migrate: Array.copy(), +}) @send external copy: t<'a> => t<'a> = "slice" @@ -671,6 +827,10 @@ Returns a shallow copy of the given array from the given index to the end. See [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) on MDN. */ +@deprecated({ + reason: "Use `Array.slice` instead.", + migrate: Array.slice(~start=%insert.unlabelledArgument(1)), +}) @send external sliceFrom: (t<'a>, int) => t<'a> = "slice" @@ -688,6 +848,10 @@ Js.Array2.toString([3.5, 4.6, 7.8]) == "3.5,4.6,7.8" Js.Array2.toString(["a", "b", "c"]) == "a,b,c" ``` */ +@deprecated({ + reason: "Use `Array.toString` instead.", + migrate: Array.toString(), +}) @send external toString: t<'a> => string = "toString" @@ -707,6 +871,10 @@ Js.Array2.toLocaleString([Js.Date.make()]) // returns "2020-3-19 10:52:11" for locale de_DE.utf8 ``` */ +@deprecated({ + reason: "Use `Array.toLocaleString` instead.", + migrate: Array.toLocaleString(), +}) @send external toLocaleString: t<'a> => string = "toLocaleString" @@ -732,6 +900,10 @@ Js.Array2.every([6, 22, 8, 4], isEven) == true Js.Array2.every([6, 22, 7, 4], isEven) == false ``` */ +@deprecated({ + reason: "Use `Array.every` instead.", + migrate: Array.every(), +}) @send external every: (t<'a>, 'a => bool) => bool = "every" @@ -754,6 +926,10 @@ Js.Array2.everyi([6, -3, 5, 8], evenIndexPositive) == true Js.Array2.everyi([6, 3, -5, 8], evenIndexPositive) == false ``` */ +@deprecated({ + reason: "Use `Array.everyWithIndex` instead.", + migrate: Array.everyWithIndex(), +}) @send external everyi: (t<'a>, ('a, int) => bool) => bool = "every" @@ -771,6 +947,10 @@ let nonEmpty = s => s != "" Js.Array2.filter(["abc", "", "", "def", "ghi"], nonEmpty) == ["abc", "def", "ghi"] ``` */ +@deprecated({ + reason: "Use `Array.filter` instead.", + migrate: Array.filter(), +}) @send external filter: (t<'a>, 'a => bool) => t<'a> = "filter" @@ -792,6 +972,10 @@ let positiveOddElement = (item, index) => mod(index, 2) == 1 && item > 0 Js.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8] ``` */ +@deprecated({ + reason: "Use `Array.filterWithIndex` instead.", + migrate: Array.filterWithIndex(), +}) @send external filteri: (t<'a>, ('a, int) => bool) => t<'a> = "filter" @@ -809,6 +993,10 @@ Js.Array2.find([33, 22, -55, 77, -44], x => x < 0) == Some(-55) Js.Array2.find([33, 22, 55, 77, 44], x => x < 0) == None ``` */ +@deprecated({ + reason: "Use `Array.find` instead.", + migrate: Array.find(), +}) @send external find: (t<'a>, 'a => bool) => option<'a> = "find" @@ -831,6 +1019,10 @@ Js.Array2.findi([66, -33, 55, 88, 22], positiveOddElement) == Some(88) Js.Array2.findi([66, -33, 55, -88, 22], positiveOddElement) == None ``` */ +@deprecated({ + reason: "Use `Array.findWithIndex` instead.", + migrate: Array.findWithIndex(), +}) @send external findi: (t<'a>, ('a, int) => bool) => option<'a> = "find" @@ -849,6 +1041,10 @@ Js.Array2.findIndex([33, 22, -55, 77, -44], x => x < 0) == 2 Js.Array2.findIndex([33, 22, 55, 77, 44], x => x < 0) == -1 ``` */ +@deprecated({ + reason: "Use `Array.findIndex` instead.", + migrate: Array.findIndex(), +}) @send external findIndex: (t<'a>, 'a => bool) => int = "findIndex" @@ -871,6 +1067,10 @@ Js.Array2.findIndexi([66, -33, 55, 88, 22], positiveOddElement) == 3 Js.Array2.findIndexi([66, -33, 55, -88, 22], positiveOddElement) == -1 ``` */ +@deprecated({ + reason: "Use `Array.findIndexWithIndex` instead.", + migrate: Array.findIndexWithIndex(), +}) @send external findIndexi: (t<'a>, ('a, int) => bool) => int = "findIndex" @@ -892,6 +1092,10 @@ on MDN. Js.Array2.forEach(["a", "b", "c"], x => Js.log(x)) == () ``` */ +@deprecated({ + reason: "Use `Array.forEach` instead.", + migrate: Array.forEach(), +}) @send external forEach: (t<'a>, 'a => unit) => unit = "forEach" @@ -912,6 +1116,10 @@ on MDN. Js.Array2.forEachi(["a", "b", "c"], (item, index) => Js.log2(index + 1, item)) == () ``` */ +@deprecated({ + reason: "Use `Array.forEachWithIndex` instead.", + migrate: Array.forEachWithIndex(), +}) @send external forEachi: (t<'a>, ('a, int) => unit) => unit = "forEach" @@ -933,6 +1141,10 @@ Js.Array2.map([12, 4, 8], x => x * x) == [144, 16, 64] Js.Array2.map(["animal", "vegetable", "mineral"], Js.String.length) == [6, 9, 7] ``` */ +@deprecated({ + reason: "Use `Array.map` instead.", + migrate: Array.map(), +}) @send external map: (t<'a>, 'a => 'b) => t<'b> = "map" @@ -952,6 +1164,10 @@ let product = (item, index) => item * index Js.Array2.mapi([10, 11, 12], product) == [0, 11, 24] ``` */ +@deprecated({ + reason: "Use `Array.mapWithIndex` instead.", + migrate: Array.mapWithIndex(), +}) @send external mapi: (t<'a>, ('a, int) => 'b) => t<'b> = "map" @@ -986,6 +1202,10 @@ Js.Array2.reduce( Js.Array2.reduce([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 2.0 // 4.0 / (2.0 / 1.0) ``` */ +@deprecated({ + reason: "Use `Array.reduce` instead.", + migrate: Array.reduce(%insert.unlabelledArgument(2), %insert.unlabelledArgument(1)), +}) @send external reduce: (t<'a>, ('b, 'a) => 'b, 'b) => 'b = "reduce" @@ -1022,6 +1242,10 @@ Js.Array2.reducei([2, 5, 1, 4, 3], sumOfEvens, 0) == 6 ``` */ @send +@deprecated({ + reason: "Use `Array.reduceWithIndex` instead.", + migrate: Array.reduceWithIndex(%insert.unlabelledArgument(2), %insert.unlabelledArgument(1)), +}) external reducei: (t<'a>, ('b, 'a, int) => 'b, 'b) => 'b = "reduce" /** @@ -1054,6 +1278,10 @@ Js.Array2.reduceRight([2.0, 4.0], (acc, item) => item /. acc, 1.0) == 0.5 // 2.0 ``` */ @send +@deprecated({ + reason: "Use `Array.reduceRight` instead.", + migrate: Array.reduceRight(%insert.unlabelledArgument(2), %insert.unlabelledArgument(1)), +}) external reduceRight: (t<'a>, ('b, 'a) => 'b, 'b) => 'b = "reduceRight" /** @@ -1091,6 +1319,10 @@ Js.Array2.reduceRighti([2, 5, 1, 4, 3], sumOfEvens, 0) == 6 ``` */ @send +@deprecated({ + reason: "Use `Array.reduceRightWithIndex` instead.", + migrate: Array.reduceRightWithIndex(%insert.unlabelledArgument(2), %insert.unlabelledArgument(1)), +}) external reduceRighti: (t<'a>, ('b, 'a, int) => 'b, 'b) => 'b = "reduceRight" /** @@ -1106,6 +1338,10 @@ Js.Array2.some([3, 7, 5, 2, 9], isEven) == true Js.Array2.some([3, 7, 5, 1, 9], isEven) == false ``` */ +@deprecated({ + reason: "Use `Array.some` instead.", + migrate: Array.some(), +}) @send external some: (t<'a>, 'a => bool) => bool = "some" @@ -1129,6 +1365,10 @@ Js.Array2.somei(["ab", "cd", "ef", "gh"], sameLength) == true Js.Array2.somei(["a", "bc", "def", "gh"], sameLength) == false ``` */ +@deprecated({ + reason: "Use `Array.someWithIndex` instead.", + migrate: Array.someWithIndex(), +}) @send external somei: (t<'a>, ('a, int) => bool) => bool = "some" @@ -1148,6 +1388,10 @@ Js.Array2.unsafe_get(arr, 3) == 103 Js.Array2.unsafe_get(arr, 4) // returns undefined ``` */ +@deprecated({ + reason: "Use `Array.getUnsafe` instead.", + migrate: Array.getUnsafe(), +}) external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" /** @@ -1173,4 +1417,8 @@ Js.Array2.unsafe_set(arr, -1, 66) // you don't want to know. ``` */ +@deprecated({ + reason: "Use `Array.setUnsafe` instead.", + migrate: Array.setUnsafe(), +}) external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" diff --git a/packages/@rescript/runtime/Js_bigint.res b/packages/@rescript/runtime/Js_bigint.res index e19daff867..0a28b8307f 100644 --- a/packages/@rescript/runtime/Js_bigint.res +++ b/packages/@rescript/runtime/Js_bigint.res @@ -30,6 +30,10 @@ try { } ``` */ +@deprecated({ + reason: "Use `fromStringOrThrow` instead", + migrate: BigInt.fromStringOrThrow(), +}) @val external fromStringExn: string => bigint = "BigInt" @@ -44,13 +48,45 @@ external \"/": (bigint, bigint) => bigint = "%divbigint" external mod: (bigint, bigint) => bigint = "%modbigint" external \"**": (bigint, bigint) => bigint = "%powbigint" +@deprecated({ + reason: "Use `&` operator or `BigInt.bitwiseAnd` instead.", + migrate: %insert.unlabelledArgument(0) & %insert.unlabelledArgument(1), + migrateInPipeChain: BigInt.bitwiseAnd(), +}) external land: (bigint, bigint) => bigint = "%andbigint" + +@deprecated({ + reason: "Use `bitwiseOr` instead.", + migrate: BigInt.bitwiseOr(), +}) external lor: (bigint, bigint) => bigint = "%orbigint" + +@deprecated({ + reason: "Use `^` operator or `BigInt.bitwiseXor` instead.", + migrate: %insert.unlabelledArgument(0) ^ %insert.unlabelledArgument(1), + migrateInPipeChain: BigInt.bitwiseXor(), +}) external lxor: (bigint, bigint) => bigint = "%xorbigint" +@deprecated({ + reason: "Use `~` operator or `BigInt.bitwiseNot` instead.", + migrate: ~(%insert.unlabelledArgument(0)), + migrateInPipeChain: BigInt.bitwiseNot(), +}) let lnot = x => lxor(x, -1n) +@deprecated({ + reason: "Use `<<` operator or `BigInt.shiftLeft` instead.", + migrate: %insert.unlabelledArgument(0) << %insert.unlabelledArgument(1), + migrateInPipeChain: BigInt.shiftLeft(), +}) external lsl: (bigint, bigint) => bigint = "%lslbigint" + +@deprecated({ + reason: "Use `>>` operator or `BigInt.shiftRight` instead.", + migrate: %insert.unlabelledArgument(0) >> %insert.unlabelledArgument(1), + migrateInPipeChain: BigInt.shiftRight(), +}) external asr: (bigint, bigint) => bigint = "%asrbigint" /** @@ -64,6 +100,10 @@ See [`toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen Js.BigInt.toString(123n)->Js.log ``` */ +@deprecated({ + reason: "Use `BigInt.toString` instead.", + migrate: BigInt.toString(), +}) @send external toString: bigint => string = "toString" @@ -77,5 +117,9 @@ Returns a string with a language-sensitive representation of this BigInt value. Js.BigInt.toString(123n)->Js.log ``` */ +@deprecated({ + reason: "Use `BigInt.toLocaleString` instead.", + migrate: BigInt.toLocaleString(), +}) @send external toLocaleString: bigint => string = "toLocaleString" diff --git a/packages/@rescript/runtime/Js_console.res b/packages/@rescript/runtime/Js_console.res index 9e0eda90c7..594ff1bb61 100644 --- a/packages/@rescript/runtime/Js_console.res +++ b/packages/@rescript/runtime/Js_console.res @@ -1,29 +1,195 @@ -@val @scope("console") external log: 'a => unit = "log" -@val @scope("console") external log2: ('a, 'b) => unit = "log" -@val @scope("console") external log3: ('a, 'b, 'c) => unit = "log" -@val @scope("console") external log4: ('a, 'b, 'c, 'd) => unit = "log" -@val @scope("console") @variadic external logMany: array<'a> => unit = "log" - -@val @scope("console") external info: 'a => unit = "info" -@val @scope("console") external info2: ('a, 'b) => unit = "info" -@val @scope("console") external info3: ('a, 'b, 'c) => unit = "info" -@val @scope("console") external info4: ('a, 'b, 'c, 'd) => unit = "info" -@val @scope("console") @variadic external infoMany: array<'a> => unit = "info" - -@val @scope("console") external warn: 'a => unit = "warn" -@val @scope("console") external warn2: ('a, 'b) => unit = "warn" -@val @scope("console") external warn3: ('a, 'b, 'c) => unit = "warn" -@val @scope("console") external warn4: ('a, 'b, 'c, 'd) => unit = "warn" -@val @scope("console") @variadic external warnMany: array<'a> => unit = "warn" - -@val @scope("console") external error: 'a => unit = "error" -@val @scope("console") external error2: ('a, 'b) => unit = "error" -@val @scope("console") external error3: ('a, 'b, 'c) => unit = "error" -@val @scope("console") external error4: ('a, 'b, 'c, 'd) => unit = "error" -@val @scope("console") @variadic external errorMany: array<'a> => unit = "error" - -@val @scope("console") external trace: unit => unit = "trace" - -@val @scope("console") external timeStart: string => unit = "time" - -@val @scope("console") external timeEnd: string => unit = "timeEnd" +@deprecated({ + reason: "Use `Console.log` instead.", + migrate: Console.log(), +}) +@val +@scope("console") +external log: 'a => unit = "log" + +@deprecated({ + reason: "Use `Console.log2` instead.", + migrate: Console.log2(), +}) +@val +@scope("console") +external log2: ('a, 'b) => unit = "log" + +@deprecated({ + reason: "Use `Console.log3` instead.", + migrate: Console.log3(), +}) +@val +@scope("console") +external log3: ('a, 'b, 'c) => unit = "log" + +@deprecated({ + reason: "Use `Console.log4` instead.", + migrate: Console.log4(), +}) +@val +@scope("console") +external log4: ('a, 'b, 'c, 'd) => unit = "log" + +@deprecated({ + reason: "Use `Console.logMany` instead.", + migrate: Console.logMany(), +}) +@val +@scope("console") +@variadic +external logMany: array<'a> => unit = "log" + +@deprecated({ + reason: "Use `Console.info` instead.", + migrate: Console.info(), +}) +@val +@scope("console") +external info: 'a => unit = "info" + +@deprecated({ + reason: "Use `Console.info2` instead.", + migrate: Console.info2(), +}) +@val +@scope("console") +external info2: ('a, 'b) => unit = "info" + +@deprecated({ + reason: "Use `Console.info3` instead.", + migrate: Console.info3(), +}) +@val +@scope("console") +external info3: ('a, 'b, 'c) => unit = "info" + +@deprecated({ + reason: "Use `Console.info4` instead.", + migrate: Console.info4(), +}) +@val +@scope("console") +external info4: ('a, 'b, 'c, 'd) => unit = "info" + +@deprecated({ + reason: "Use `Console.infoMany` instead.", + migrate: Console.infoMany(), +}) +@val +@scope("console") +@variadic +external infoMany: array<'a> => unit = "info" + +@deprecated({ + reason: "Use `Console.warn` instead.", + migrate: Console.warn(), +}) +@val +@scope("console") +external warn: 'a => unit = "warn" + +@deprecated({ + reason: "Use `Console.warn2` instead.", + migrate: Console.warn2(), +}) +@val +@scope("console") +external warn2: ('a, 'b) => unit = "warn" + +@deprecated({ + reason: "Use `Console.warn3` instead.", + migrate: Console.warn3(), +}) +@val +@scope("console") +external warn3: ('a, 'b, 'c) => unit = "warn" + +@deprecated({ + reason: "Use `Console.warn4` instead.", + migrate: Console.warn4(), +}) +@val +@scope("console") +external warn4: ('a, 'b, 'c, 'd) => unit = "warn" + +@deprecated({ + reason: "Use `Console.warnMany` instead.", + migrate: Console.warnMany(), +}) +@val +@scope("console") +@variadic +external warnMany: array<'a> => unit = "warn" + +@deprecated({ + reason: "Use `Console.error` instead.", + migrate: Console.error(), +}) +@val +@scope("console") +external error: 'a => unit = "error" + +@deprecated({ + reason: "Use `Console.error2` instead.", + migrate: Console.error2(), +}) +@val +@scope("console") +external error2: ('a, 'b) => unit = "error" + +@deprecated({ + reason: "Use `Console.error3` instead.", + migrate: Console.error3(), +}) +@val +@scope("console") +external error3: ('a, 'b, 'c) => unit = "error" + +@deprecated({ + reason: "Use `Console.error4` instead.", + migrate: Console.error4(), +}) +@val +@scope("console") +external error4: ('a, 'b, 'c, 'd) => unit = "error" + +@deprecated({ + reason: "Use `Console.errorMany` instead.", + migrate: Console.errorMany(), +}) +@val +@scope("console") +@variadic +external errorMany: array<'a> => unit = "error" + +@deprecated({ + reason: "Use `Console.trace` instead.", + migrate: Console.trace(), +}) +@val +@scope("console") +external trace: unit => unit = "trace" + +@deprecated({ + reason: "Use `Console.time` instead.", + migrate: Console.time(), +}) +@val +@scope("console") +external timeStart: string => unit = "time" + +@deprecated({ + reason: "Use `Console.timeEnd` instead.", + migrate: Console.timeEnd(), +}) +@val +@scope("console") +external timeEnd: string => unit = "timeEnd" + +@deprecated({ + reason: "Use `Console.table` instead.", + migrate: Console.table(), +}) +@val +@scope("console") +external table: 'a => unit = "table" diff --git a/packages/@rescript/runtime/Js_date.res b/packages/@rescript/runtime/Js_date.res index 73eb494d38..50a7c23f57 100644 --- a/packages/@rescript/runtime/Js_date.res +++ b/packages/@rescript/runtime/Js_date.res @@ -29,6 +29,10 @@ on MDN.) JavaScript stores dates as the number of milliseconds since the UNIX *epoch*, midnight 1 January 1970, UTC. */ +@deprecated({ + reason: "Use `Date.t` instead.", + migrate: %replace.type(: Date.t), +}) type t = Stdlib_Date.t /** @@ -42,6 +46,10 @@ on MDN.) Js.Date.valueOf(exampleDate) == 123456654321.0 ``` */ +@deprecated({ + reason: "Use `Date.getTime` instead.", + migrate: Date.getTime(), +}) @send external valueOf: t => float = "valueOf" @@ -56,6 +64,10 @@ on MDN. let now = Js.Date.make() ``` */ +@deprecated({ + reason: "Use `Date.make` instead.", + migrate: Date.make(), +}) @new external make: unit => t = "Date" @@ -71,6 +83,10 @@ on MDN. Js.Date.fromFloat(123456654321.0) == exampleDate ``` */ +@deprecated({ + reason: "Use `Date.fromTime` instead.", + migrate: Date.fromTime(), +}) @new external fromFloat: float => t = "Date" @@ -89,6 +105,10 @@ Js.Date.fromString("1973-11-29T21:30:54.321Z00:00") == exampleDate Js.Date.fromString("Thor, 32 Lok -19 60:70:80 XYZ") // returns NaN ``` */ +@deprecated({ + reason: "Use `Date.fromString` instead.", + migrate: Date.fromString(), +}) @new external fromString: string => t = "Date" @@ -105,6 +125,14 @@ on MDN. let november1 = Js.Date.makeWithYM(~year=2020.0, ~month=10.0, ()) ``` */ +@deprecated({ + reason: "Use `Date.makeWithYM` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.makeWithYM( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ), +}) @new external makeWithYM: (~year: float, ~month: float, unit) => t = "Date" @@ -115,6 +143,15 @@ year in the current time zone. Fractional parts of arguments are ignored. See Constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) on MDN. */ +@deprecated({ + reason: "Use `Date.makeWithYMD` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.makeWithYMD( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ), +}) @new external makeWithYMD: (~year: float, ~month: float, ~date: float, unit) => t = "Date" @@ -125,6 +162,16 @@ Fractional parts of arguments are ignored. See [`Date()` Constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) on MDN. Fractional parts of the arguments are ignored. */ +@deprecated({ + reason: "Use `Date.makeWithYMDH` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.makeWithYMDH( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ), +}) @new external makeWithYMDH: (~year: float, ~month: float, ~date: float, ~hours: float, unit) => t = "Date" @@ -136,6 +183,17 @@ Fractional parts of arguments are ignored. See [`Date()` Constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) on MDN. */ +@deprecated({ + reason: "Use `Date.makeWithYMDHM` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.makeWithYMDHM( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ), +}) @new external makeWithYMDHM: ( ~year: float, @@ -167,6 +225,18 @@ Js.Date.makeWithYMDHMS( ) == exampleDate ``` */ +@deprecated({ + reason: "Use `Date.makeWithYMDHMS` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.makeWithYMDHMS( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ), +}) @new external makeWithYMDHMS: ( ~year: float, @@ -191,6 +261,14 @@ on MDN. let november1 = Js.Date.utcWithYM(~year=2020.0, ~month=10.0, ()) ``` */ +@deprecated({ + reason: "Use `Date.UTC.makeWithYM` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.UTC.makeWithYM( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ), +}) @val("Date.UTC") external utcWithYM: (~year: float, ~month: float, unit) => float = "" @@ -201,6 +279,15 @@ of arguments are ignored. See [`Date.UTC`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC) on MDN. */ +@deprecated({ + reason: "Use `Date.UTC.makeWithYMD` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.UTC.makeWithYMD( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ), +}) @val("Date.UTC") external utcWithYMD: (~year: float, ~month: float, ~date: float, unit) => float = "" @@ -212,6 +299,16 @@ See [`Date.UTC`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC) on MDN. */ +@deprecated({ + reason: "Use `Date.UTC.makeWithYMDH` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.UTC.makeWithYMDH( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ), +}) @val("Date.UTC") external utcWithYMDH: (~year: float, ~month: float, ~date: float, ~hours: float, unit) => float = "" @@ -223,6 +320,17 @@ arguments are ignored. See [`Date.UTC`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC) on MDN. */ +@deprecated({ + reason: "Use `Date.UTC.makeWithYMDHM` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.UTC.makeWithYMDHM( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ), +}) @val("Date.UTC") external utcWithYMDHM: ( ~year: float, @@ -242,6 +350,18 @@ See [`Date.UTC`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC) on MDN. */ +@deprecated({ + reason: "Use `Date.UTC.makeWithYMDHMS` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.UTC.makeWithYMDHMS( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ), +}) @val("Date.UTC") external utcWithYMDHMS: ( ~year: float, @@ -254,10 +374,19 @@ external utcWithYMDHMS: ( ) => float = "" /** Returns the current time as number of milliseconds since Unix epoch. */ +@deprecated({ + reason: "Use `Date.now` instead.", + migrate: Date.now(), +}) @val("Date.now") external now: unit => float = "" -@new @deprecated("Please use `fromString` instead") external parse: string => t = "Date" +@new +@deprecated({ + reason: "Use `Date.fromString` instead.", + migrate: Date.fromString(), +}) +external parse: string => t = "Date" /** Returns a float with the number of milliseconds past the epoch represented by @@ -268,7 +397,12 @@ string. According to the documentation on MDN, its use is discouraged. Returns `NaN` if passed invalid date string. */ -@val("parse") @scope("Date") +@deprecated({ + reason: "Use `Date.fromString` + `Date.getTime` instead.", + migrate: Date.getTime(Date.fromString(%insert.unlabelledArgument(0))), +}) +@val("parse") +@scope("Date") external parseAsFloat: string => float = "" /** @@ -283,6 +417,10 @@ on MDN. Js.Date.getDate(exampleDate) == 29.0 ``` */ +@deprecated({ + reason: "Use `Date.getDate` instead.", + migrate: Date.getDate(), +}) @send external getDate: t => float = "getDate" @@ -298,6 +436,10 @@ on MDN. Js.Date.getDay(exampleDate) == 4.0 ``` */ +@deprecated({ + reason: "Use `Date.getDay` instead.", + migrate: Date.getDay(), +}) @send external getDay: t => float = "getDay" @@ -313,6 +455,10 @@ on MDN. Js.Date.getFullYear(exampleDate) == 1973.0 ``` */ +@deprecated({ + reason: "Use `Date.getFullYear` instead.", + migrate: Date.getFullYear(), +}) @send external getFullYear: t => float = "getFullYear" @@ -327,6 +473,10 @@ on MDN. Js.Date.getHours(exampleDate) == 22.0 // Vienna is in GMT+01:00 ``` */ +@deprecated({ + reason: "Use `Date.getHours` instead.", + migrate: Date.getHours(), +}) @send external getHours: t => float = "getHours" @@ -342,6 +492,10 @@ on MDN. Js.Date.getMilliseconds(exampleDate) == 321.0 ``` */ +@deprecated({ + reason: "Use `Date.getMilliseconds` instead.", + migrate: Date.getMilliseconds(), +}) @send external getMilliseconds: t => float = "getMilliseconds" @@ -357,6 +511,10 @@ on MDN. Js.Date.getMinutes(exampleDate) == 30.0 ``` */ +@deprecated({ + reason: "Use `Date.getMinutes` instead.", + migrate: Date.getMinutes(), +}) @send external getMinutes: t => float = "getMinutes" @@ -372,6 +530,10 @@ on MDN. Js.Date.getMonth(exampleDate) == 10.0 ``` */ +@deprecated({ + reason: "Use `Date.getMonth` instead.", + migrate: Date.getMonth(), +}) @send external getMonth: t => float = "getMonth" @@ -386,6 +548,10 @@ on MDN. Js.Date.getSeconds(exampleDate) == 54.0 ``` */ +@deprecated({ + reason: "Use `Date.getSeconds` instead.", + migrate: Date.getSeconds(), +}) @send external getSeconds: t => float = "getSeconds" @@ -400,6 +566,10 @@ on MDN. Js.Date.getTime(exampleDate) == 123456654321.0 ``` */ +@deprecated({ + reason: "Use `Date.getTime` instead.", + migrate: Date.getTime(), +}) @send external getTime: t => float = "getTime" @@ -414,6 +584,10 @@ on MDN. Js.Date.getTimezoneOffset(exampleDate) == -60.0 ``` */ +@deprecated({ + reason: "Use `Date.getTimezoneOffset` instead.", + migrate: Date.getTimezoneOffset(), +}) @send external getTimezoneOffset: t => float = "getTimezoneOffset" @@ -428,6 +602,10 @@ on MDN. Js.Date.getUTCDate(exampleDate) == 29.0 ``` */ +@deprecated({ + reason: "Use `Date.getUTCDate` instead.", + migrate: Date.getUTCDate(), +}) @send external getUTCDate: t => float = "getUTCDate" @@ -443,6 +621,10 @@ on MDN. Js.Date.getUTCDay(exampleDate) == 4.0 ``` */ +@deprecated({ + reason: "Use `Date.getUTCDay` instead.", + migrate: Date.getUTCDay(), +}) @send external getUTCDay: t => float = "getUTCDay" @@ -458,6 +640,10 @@ on MDN. Js.Date.getUTCFullYear(exampleDate) == 1973.0 ``` */ +@deprecated({ + reason: "Use `Date.getUTCFullYear` instead.", + migrate: Date.getUTCFullYear(), +}) @send external getUTCFullYear: t => float = "getUTCFullYear" @@ -472,6 +658,10 @@ on MDN. Js.Date.getUTCHours(exampleDate) == 21.0 ``` */ +@deprecated({ + reason: "Use `Date.getUTCHours` instead.", + migrate: Date.getUTCHours(), +}) @send external getUTCHours: t => float = "getUTCHours" @@ -486,6 +676,10 @@ on MDN. Js.Date.getUTCMilliseconds(exampleDate) == 321.0 ``` */ +@deprecated({ + reason: "Use `Date.getUTCMilliseconds` instead.", + migrate: Date.getUTCMilliseconds(), +}) @send external getUTCMilliseconds: t => float = "getUTCMilliseconds" @@ -500,6 +694,10 @@ on MDN. Js.Date.getUTCMinutes(exampleDate) == 30.0 ``` */ +@deprecated({ + reason: "Use `Date.getUTCMinutes` instead.", + migrate: Date.getUTCMinutes(), +}) @send external getUTCMinutes: t => float = "getUTCMinutes" @@ -515,6 +713,10 @@ on MDN. Js.Date.getUTCMonth(exampleDate) == 10.0 ``` */ +@deprecated({ + reason: "Use `Date.getUTCMonth` instead.", + migrate: Date.getUTCMonth(), +}) @send external getUTCMonth: t => float = "getUTCMonth" @@ -529,10 +731,15 @@ on MDN. Js.Date.getUTCSeconds(exampleDate) == 54.0 ``` */ +@deprecated({ + reason: "Use `Date.getUTCSeconds` instead.", + migrate: Date.getUTCSeconds(), +}) @send external getUTCSeconds: t => float = "getUTCSeconds" -@send @deprecated("Use `getFullYear` instead.") external getYear: t => float = "getYear" +@send @deprecated({reason: "Use `getFullYear` instead.", migrate: Date.getFullYear()}) +external getYear: t => float = "getYear" /** Sets the given `Date`’s day of month to the value in the second argument @@ -551,6 +758,10 @@ date1 == Js.Date.fromString("1973-11-15T21:30:54.321Z00:00") twoWeeksBefore == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setDate` instead.", + migrate: Date.setDate(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setDate: (t, float) => float = "setDate" @@ -570,6 +781,10 @@ date1 == Js.Date.fromString("1974-11-15T21:30:54.321Z00:00") nextYear == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setFullYear` instead.", + migrate: Date.setFullYear(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setFullYear: (t, float) => float = "setFullYear" @@ -590,6 +805,14 @@ date1 == Js.Date.fromString("1974-01-22T21:30:54.321Z00:00") future == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setFullYearM` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setFullYearM( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ), +}) @send external setFullYearM: (t, ~year: float, ~month: float, unit) => float = "setFullYear" @@ -611,6 +834,15 @@ future == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setFullYearMD` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setFullYearMD( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ), +}) external setFullYearMD: (t, ~year: float, ~month: float, ~date: float, unit) => float = "setFullYear" @@ -630,6 +862,10 @@ date1 == Js.Date.fromString("1973-11-29T22:30:54.321Z00:00") nextHour == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setHours` instead.", + migrate: Date.setHours(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setHours: (t, float) => float = "setHours" @@ -650,6 +886,14 @@ date1 == Js.Date.fromString("1973-11-29T22:46:54.321Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setHoursM` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setHoursM( + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ), +}) @send external setHoursM: (t, ~hours: float, ~minutes: float, unit) => float = "setHours" @@ -671,6 +915,15 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setHoursMS` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setHoursMS( + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ), +}) external setHoursMS: (t, ~hours: float, ~minutes: float, ~seconds: float, unit) => float = "setHours" @@ -699,6 +952,16 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setHoursMSMs` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setHoursMSMs( + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ~milliseconds=Float.toInt(%insert.labelledArgument("milliseconds")), + ), +}) external setHoursMSMs: ( t, ~hours: float, @@ -725,6 +988,10 @@ date1 == Js.Date.fromString("1973-11-29T21:30:54.494Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setMilliseconds` instead.", + migrate: Date.setMilliseconds(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setMilliseconds: (t, float) => float = "setMilliseconds" @@ -744,6 +1011,10 @@ date1 == Js.Date.fromString("1973-11-29T21:34:54.494Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setMinutes` instead.", + migrate: Date.setMinutes(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setMinutes: (t, float) => float = "setMinutes" @@ -765,6 +1036,14 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setMinutesS` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setMinutesS( + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ), +}) external setMinutesS: (t, ~minutes: float, ~seconds: float, unit) => float = "setMinutes" /** @@ -785,6 +1064,15 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setMinutesSMs` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setMinutesSMs( + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ~milliseconds=Float.toInt(%insert.labelledArgument("milliseconds")), + ), +}) external setMinutesSMs: (t, ~minutes: float, ~seconds: float, ~milliseconds: float, unit) => float = "setMinutes" @@ -804,6 +1092,10 @@ date1 == Js.Date.fromString("1973-12-29T21:34:56.789Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setMonth` instead.", + migrate: Date.setMonth(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setMonth: (t, float) => float = "setMonth" @@ -824,7 +1116,7 @@ date1 == Js.Date.fromString("1973-12-08T21:34:56.789Z00:00") futureTime == Js.Date.getTime(date1) ``` */ -@send +@deprecated("Use `Date.setMonth` then `Date.setDate`. No direct 1:1 migration available.") @send external setMonthD: (t, ~month: float, ~date: float, unit) => float = "setMonth" /** @@ -843,6 +1135,10 @@ date1 == Js.Date.fromString("1973-12-29T21:30:56.321Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setSeconds` instead.", + migrate: Date.setSeconds(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setSeconds: (t, float) => float = "setSeconds" @@ -864,6 +1160,14 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setSecondsMs` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setSecondsMs( + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ~milliseconds=Float.toInt(%insert.labelledArgument("milliseconds")), + ), +}) external setSecondsMs: (t, ~seconds: float, ~milliseconds: float, unit) => float = "setSeconds" /** @@ -883,7 +1187,7 @@ date1 == Js.Date.fromString("1976-04-19T12:37:12.101Z00:00") futureTime == Js.Date.getTime(date1) ``` */ -@send +@send @deprecated external setTime: (t, float) => float = "setTime" /** @@ -902,6 +1206,10 @@ date1 == Js.Date.fromString("1973-11-15T21:30:54.321Z00:00") twoWeeksBefore == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setUTCDate` instead.", + migrate: Date.setUTCDate(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setUTCDate: (t, float) => float = "setUTCDate" @@ -921,6 +1229,10 @@ date1 == Js.Date.fromString("1974-11-15T21:30:54.321Z00:00") nextYear == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setUTCFullYear` instead.", + migrate: Date.setUTCFullYear(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setUTCFullYear: (t, float) => float = "setUTCFullYear" @@ -941,6 +1253,14 @@ future == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setUTCFullYearM` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setUTCFullYearM( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ), +}) external setUTCFullYearM: (t, ~year: float, ~month: float, unit) => float = "setUTCFullYear" /** @@ -961,6 +1281,15 @@ future == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setUTCFullYearMD` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setUTCFullYearMD( + ~year=Float.toInt(%insert.labelledArgument("year")), + ~month=Float.toInt(%insert.labelledArgument("month")), + ~day=Float.toInt(%insert.labelledArgument("date")), + ), +}) external setUTCFullYearMD: (t, ~year: float, ~month: float, ~date: float, unit) => float = "setUTCFullYear" @@ -980,6 +1309,10 @@ date1 == Js.Date.fromString("1973-11-29T22:30:54.321Z00:00") nextHour == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setUTCHours` instead.", + migrate: Date.setUTCHours(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setUTCHours: (t, float) => float = "setUTCHours" @@ -1000,6 +1333,14 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setUTCHoursM` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setUTCHoursM( + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ), +}) external setUTCHoursM: (t, ~hours: float, ~minutes: float, unit) => float = "setUTCHours" /** @@ -1021,6 +1362,15 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setUTCHoursMS` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setUTCHoursMS( + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ), +}) external setUTCHoursMS: (t, ~hours: float, ~minutes: float, ~seconds: float, unit) => float = "setUTCHours" @@ -1049,6 +1399,16 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setUTCHoursMSMs` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setUTCHoursMSMs( + ~hours=Float.toInt(%insert.labelledArgument("hours")), + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ~milliseconds=Float.toInt(%insert.labelledArgument("milliseconds")), + ), +}) external setUTCHoursMSMs: ( t, ~hours: float, @@ -1074,6 +1434,10 @@ date1 == Js.Date.fromString("1973-11-29T21:30:54.494Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setUTCMilliseconds` instead.", + migrate: Date.setUTCMilliseconds(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setUTCMilliseconds: (t, float) => float = "setUTCMilliseconds" @@ -1093,6 +1457,10 @@ date1 == Js.Date.fromString("1973-11-29T21:34:54.494Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setUTCMinutes` instead.", + migrate: Date.setUTCMinutes(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setUTCMinutes: (t, float) => float = "setUTCMinutes" @@ -1113,6 +1481,14 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setUTCMinutesS` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setUTCMinutesS( + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ), +}) external setUTCMinutesS: (t, ~minutes: float, ~seconds: float, unit) => float = "setUTCMinutes" /** @@ -1139,6 +1515,15 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setUTCMinutesSMs` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setUTCMinutesSMs( + ~minutes=Float.toInt(%insert.labelledArgument("minutes")), + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ~milliseconds=Float.toInt(%insert.labelledArgument("milliseconds")), + ), +}) external setUTCMinutesSMs: ( t, ~minutes: float, @@ -1163,6 +1548,10 @@ date1 == Js.Date.fromString("1973-12-29T21:34:56.789Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setUTCMonth` instead.", + migrate: Date.setUTCMonth(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setUTCMonth: (t, float) => float = "setUTCMonth" @@ -1182,6 +1571,7 @@ date1 == Js.Date.fromString("1973-12-08T21:34:56.789Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated("Use `Date.setUTCMonth` then `Date.setUTCDate`. No direct 1:1 migration available.") @send external setUTCMonthD: (t, ~month: float, ~date: float, unit) => float = "setUTCMonth" @@ -1201,6 +1591,10 @@ date1 == Js.Date.fromString("1973-12-29T21:30:56.321Z00:00") futureTime == Js.Date.getTime(date1) ``` */ +@deprecated({ + reason: "Use `Date.setUTCSeconds` instead.", + migrate: Date.setUTCSeconds(Float.toInt(%insert.unlabelledArgument(1))), +}) @send external setUTCSeconds: (t, float) => float = "setUTCSeconds" @@ -1221,11 +1615,19 @@ futureTime == Js.Date.getTime(date1) ``` */ @send +@deprecated({ + reason: "Use `Date.setUTCSecondsMs` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Date.setUTCSecondsMs( + ~seconds=Float.toInt(%insert.labelledArgument("seconds")), + ~milliseconds=Float.toInt(%insert.labelledArgument("milliseconds")), + ), +}) external setUTCSecondsMs: (t, ~seconds: float, ~milliseconds: float, unit) => float = "setUTCSeconds" /** Same as [`setTime()`](#settime). */ -@send +@deprecated @send external setUTCTime: (t, float) => float = "setTime" @send @deprecated("Use `setFullYear` instead") external setYear: (t, float) => float = "setYear" @@ -1242,10 +1644,19 @@ on MDN. Js.Date.toDateString(exampleDate) == "Thu Nov 29 1973" ``` */ +@deprecated({ + reason: "Use `Date.toDateString` instead.", + migrate: Date.toDateString(), +}) @send external toDateString: t => string = "toDateString" -@send @deprecated("Use `toUTCString` instead") external toGMTString: t => string = "toGMTString" +@send +@deprecated({ + reason: "Use `Date.toUTCString` instead.", + migrate: Date.toUTCString(), +}) +external toGMTString: t => string = "toGMTString" /** Returns a simplified version of the ISO 8601 format for the date. See @@ -1258,14 +1669,18 @@ on MDN. Js.Date.toISOString(exampleDate) == "1973-11-29T21:30:54.321Z" ``` */ +@deprecated({ + reason: "Use `Date.toISOString` instead.", + migrate: Date.toISOString(), +}) @send external toISOString: t => string = "toISOString" +@deprecated({ + reason: "This method is unsafe. It will be changed to return option in a future release. Please use toJSONUnsafe instead.", + migrate: Date.toJSON(), +}) @send -@deprecated( - "This method is unsafe. It will be changed to return option in a future \ - release. Please use toJSONUnsafe instead." -) external toJSON: t => string = "toJSON" /** @@ -1273,6 +1688,10 @@ Returns a string representation of the given date. See [`Date.toJSON`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON) on MDN. */ +@deprecated({ + reason: "Use `Date.toJSON` instead.", + migrate: Date.toJSON(), +}) @send external toJSONUnsafe: t => string = "toJSON" @@ -1289,6 +1708,10 @@ Js.Date.toLocaleDateString(exampleDate) == "11/29/1973" // for en_US.utf8 Js.Date.toLocaleDateString(exampleDate) == "29.11.73" // for de_DE.utf8 ``` */ +@deprecated({ + reason: "Use `Date.toLocaleDateString` instead.", + migrate: Date.toLocaleDateString(), +}) @send external toLocaleDateString: t => string = "toLocaleDateString" @@ -1307,6 +1730,10 @@ Js.Date.toLocaleString(exampleDate) == "11/29/1973, 10:30:54 PM" // for en_US.ut Js.Date.toLocaleString(exampleDate) == "29.11.1973, 22:30:54" // for de_DE.utf8 ``` */ +@deprecated({ + reason: "Use `Date.toLocaleString` instead.", + migrate: Date.toLocaleString(), +}) @send external toLocaleString: t => string = "toLocaleString" @@ -1324,6 +1751,10 @@ Js.Date.toLocaleString(exampleDate) == "10:30:54 PM" // for en_US.utf8 Js.Date.toLocaleString(exampleDate) == "22:30:54" // for de_DE.utf8 ``` */ +@deprecated({ + reason: "Use `Date.toLocaleTimeString` instead.", + migrate: Date.toLocaleTimeString(), +}) @send external toLocaleTimeString: t => string = "toLocaleTimeString" @@ -1343,6 +1774,10 @@ Js.Date.toString( ) == "Thu Nov 29 1973 22:30:54 GMT+0100 (Central European Standard Time)" ``` */ +@deprecated({ + reason: "Use `Date.toString` instead.", + migrate: Date.toString(), +}) @send external toString: t => string = "toString" @@ -1358,6 +1793,10 @@ on MDN. Js.Date.toTimeString(exampleDate) == "22:30:54 GMT+0100 (Central European Standard Time)" ``` */ +@deprecated({ + reason: "Use `Date.toTimeString` instead.", + migrate: Date.toTimeString(), +}) @send external toTimeString: t => string = "toTimeString" @@ -1373,5 +1812,9 @@ on MDN. Js.Date.toUTCString(exampleDate) == "Thu, 29 Nov 1973 21:30:54 GMT" ``` */ +@deprecated({ + reason: "Use `Date.toUTCString` instead.", + migrate: Date.toUTCString(), +}) @send external toUTCString: t => string = "toUTCString" diff --git a/packages/@rescript/runtime/Js_dict.resi b/packages/@rescript/runtime/Js_dict.resi index eb293554c8..9f0eb68c72 100644 --- a/packages/@rescript/runtime/Js_dict.resi +++ b/packages/@rescript/runtime/Js_dict.resi @@ -39,11 +39,19 @@ Dictionary type (ie an '{ }' JS object). However it is restricted to hold a single type; therefore values must have the same type. This Dictionary type is mostly used with the Js_json.t type. */ +@deprecated({ + reason: "Use `dict` directly instead.", + migrate: %replace.type(: dict), +}) type t<'a> = dict<'a> /** The type for dictionary keys. This means that dictionaries *must* use `string`s as their keys. */ +@deprecated({ + reason: "Use `string` directly instead.", + migrate: %replace.type(: string), +}) type key = string /** @@ -57,6 +65,10 @@ Js.Dict.get(ages, "Vinh") == Some(22) Js.Dict.get(ages, "Paul") == None ``` */ +@deprecated({ + reason: "Use `Dict.get` instead.", + migrate: Dict.get(), +}) let get: (t<'a>, key) => option<'a> /** @@ -69,6 +81,10 @@ Js.Dict.unsafeGet(ages, "Fred") == 49 Js.Dict.unsafeGet(ages, "Paul") // returns undefined ``` */ +@deprecated({ + reason: "Use `Dict.getUnsafe` instead.", + migrate: Dict.getUnsafe(), +}) @get_index external unsafeGet: (t<'a>, key) => 'a = "" @@ -88,6 +104,10 @@ Js.Dict.set(ages, "David", 66) Js.log(ages == Js.Dict.fromList(list{("Maria", 31), ("Vinh", 22), ("Fred", 49), ("David", 66)})) ``` */ +@deprecated({ + reason: "Use `Dict.set` instead.", + migrate: Dict.set(), +}) @set_index external set: (t<'a>, key, 'a) => unit = "" @@ -100,14 +120,26 @@ Returns all the keys in the dictionary `dict`. Js.Dict.keys(ages) == ["Maria", "Vinh", "Fred"] ``` */ +@deprecated({ + reason: "Use `Dict.keysToArray` instead.", + migrate: Dict.keysToArray(), +}) @val external keys: t<'a> => array = "Object.keys" /** Returns an empty dictionary. */ +@deprecated({ + reason: "Use `Dict.make` instead.", + migrate: Dict.make(), +}) @obj external empty: unit => t<'a> = "" /** Experimental internal function */ +@deprecated({ + reason: "Use `Dict.delete` instead.", + migrate: Dict.delete(), +}) let unsafeDeleteKey: (t, string) => unit /** @@ -119,6 +151,10 @@ Returns an array of key/value pairs in the given dictionary (ES2017). Js.Dict.entries(ages) == [("Maria", 30), ("Vinh", 22), ("Fred", 49)] ``` */ +@deprecated({ + reason: "Use `Dict.toArray` instead.", + migrate: Dict.toArray(), +}) let entries: t<'a> => array<(key, 'a)> /** @@ -130,6 +166,10 @@ Returns the values in the given dictionary (ES2017). Js.Dict.values(ages) == [30, 22, 49] ``` */ +@deprecated({ + reason: "Use `Dict.valuesToArray` instead.", + migrate: Dict.valuesToArray(), +}) let values: t<'a> => array<'a> /** @@ -142,6 +182,7 @@ argument. let capitals = Js.Dict.fromList(list{("Japan", "Tokyo"), ("France", "Paris"), ("Egypt", "Cairo")}) ``` */ +@deprecated("Use `Dict.fromArray(List.toArray(...))` instead.") let fromList: list<(key, 'a)> => t<'a> /** @@ -154,6 +195,10 @@ argument. let capitals2 = Js.Dict.fromArray([("Germany", "Berlin"), ("Burkina Faso", "Ouagadougou")]) ``` */ +@deprecated({ + reason: "Use `Dict.fromArray` instead.", + migrate: Dict.fromArray(), +}) let fromArray: array<(key, 'a)> => t<'a> /** @@ -171,4 +216,9 @@ let salePrices = Js.Dict.map(discount, prices) salePrices == Js.Dict.fromList(list{("pen", 0.90), ("book", 4.50), ("stapler", 6.30)}) ``` */ +@deprecated({ + reason: "Use `Dict.mapValues` instead.", + migrate: Dict.mapValues(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), + migrateInPipeChain: Dict.mapValues(), +}) let map: ('a => 'b, t<'a>) => t<'b> diff --git a/packages/@rescript/runtime/Js_extern.res b/packages/@rescript/runtime/Js_extern.res index f1e49974e4..baced59fa3 100644 --- a/packages/@rescript/runtime/Js_extern.res +++ b/packages/@rescript/runtime/Js_extern.res @@ -1,7 +1,23 @@ +@deprecated({ + reason: "Use `Nullable.isNullable` instead.", + migrate: Nullable.isNullable(), +}) external testAny: 'a => bool = "%is_nullable" +@deprecated({ + reason: "Use `Nullable.null` instead.", + migrate: Nullable.null, +}) external null: Primitive_js_extern.null<'a> = "%null" +@deprecated({ + reason: "Use `Nullable.undefined` instead.", + migrate: Nullable.undefined, +}) external undefined: Primitive_js_extern.null<'a> = "%undefined" +@deprecated({ + reason: "Use `Type.typeof` instead.", + migrate: Type.typeof(), +}) external typeof: 'a => string = "%typeof" diff --git a/packages/@rescript/runtime/Js_float.res b/packages/@rescript/runtime/Js_float.res index 19d81f0f8f..e4416ad1e4 100644 --- a/packages/@rescript/runtime/Js_float.res +++ b/packages/@rescript/runtime/Js_float.res @@ -29,6 +29,10 @@ Provide utilities for JS float. /** The special value "Not a Number". See [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) on MDN. */ +@deprecated({ + reason: "Use `Float.Constants.nan` instead.", + migrate: Float.Constants.nan, +}) @val external _NaN: float = "NaN" @@ -39,7 +43,12 @@ Note that both `_NaN = _NaN` and `_NaN == _NaN` will return `false`. `isNaN` is therefore necessary to test for `_NaN`. Return `true` if the given value is `_NaN`, `false` otherwise. See [`isNaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN) on MDN. */ -@val @scope("Number") +@deprecated({ + reason: "Use `Float.isNaN` instead.", + migrate: Float.isNaN(), +}) +@val +@scope("Number") external isNaN: float => bool = "isNaN" /** @@ -62,7 +71,12 @@ Js.Float.isFinite(Js.Float._NaN) Js.Float.isFinite(1234.) ``` */ -@val @scope("Number") +@deprecated({ + reason: "Use `Float.isFinite` instead.", + migrate: Float.isFinite(), +}) +@val +@scope("Number") external isFinite: float => bool = "isFinite" /** @@ -80,6 +94,10 @@ Js.Float.toExponential(77.1234)->Js.log Js.Float.toExponential(77.)->Js.log ``` */ +@deprecated({ + reason: "Use `Float.toExponential` instead.", + migrate: Float.toExponential(), +}) @send external toExponential: float => string = "toExponential" @@ -98,6 +116,10 @@ See [`toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re Js.Float.toExponentialWithPrecision(77.1234, ~digits=2)->Js.log ``` */ +@deprecated({ + reason: "Use `Float.toExponential` instead.", + migrate: Float.toExponential(~digits=%insert.labelledArgument("digits")), +}) @send external toExponentialWithPrecision: (float, ~digits: int) => string = "toExponential" @@ -116,6 +138,10 @@ Js.Float.toFixed(12345.6789)->Js.log Js.Float.toFixed(1.2e21)->Js.log ``` */ +@deprecated({ + reason: "Use `Float.toFixed` instead.", + migrate: Float.toFixed(), +}) @send external toFixed: float => string = "toFixed" @@ -139,6 +165,10 @@ Js.Float.toFixedWithPrecision(12345.6789, ~digits=1)->Js.log Js.Float.toFixedWithPrecision(0., ~digits=2)->Js.log ``` */ +@deprecated({ + reason: "Use `Float.toFixed` instead.", + migrate: Float.toFixed(~digits=%insert.labelledArgument("digits")), +}) @send external toFixedWithPrecision: (float, ~digits: int) => string = "toFixed" @@ -161,6 +191,10 @@ Js.Float.toPrecision(12345.6789)->Js.log Js.Float.toPrecision(1.2e21)->Js.log ``` */ +@deprecated({ + reason: "Use `Float.toPrecision` instead.", + migrate: Float.toPrecision(), +}) @send external toPrecision: float => string = "toPrecision" @@ -193,6 +227,10 @@ Js.Float.toPrecisionWithPrecision(12345.6789, ~digits=1)->Js.log Js.Float.toPrecisionWithPrecision(0., ~digits=2)->Js.log ``` */ +@deprecated({ + reason: "Use `Float.toPrecision` instead.", + migrate: Float.toPrecision(~digits=%insert.labelledArgument("digits")), +}) @send external toPrecisionWithPrecision: (float, ~digits: int) => string = "toPrecision" @@ -207,6 +245,10 @@ fixed-point (usually). See [`toString`](https://developer.mozilla.org/en-US/docs Js.Float.toString(12345.6789)->Js.log ``` */ +@deprecated({ + reason: "Use `Float.toString` instead.", + migrate: Float.toString(), +}) @send external toString: float => string = "toString" @@ -233,6 +275,10 @@ Js.Float.toStringWithRadix(3735928559., ~radix=16)->Js.log Js.Float.toStringWithRadix(123.456, ~radix=36)->Js.log ``` */ +@deprecated({ + reason: "Use `Float.toString` instead.", + migrate: Float.toString(~radix=%insert.labelledArgument("radix")), +}) @send external toStringWithRadix: (float, ~radix: int) => string = "toString" @@ -268,5 +314,9 @@ Js.Float.fromString("hello") Js.Float.fromString("100a") ``` */ +@deprecated({ + reason: "Use `Float.parseFloat` instead.", + migrate: Float.parseFloat(), +}) @val external fromString: string => float = "Number" diff --git a/packages/@rescript/runtime/Js_global.res b/packages/@rescript/runtime/Js_global.res index 153779b198..6fee58a024 100644 --- a/packages/@rescript/runtime/Js_global.res +++ b/packages/@rescript/runtime/Js_global.res @@ -27,9 +27,17 @@ Contains functions available in the global scope (`window` in a browser context) */ /** Identify an interval started by `Js.Global.setInterval`. */ +@deprecated({ + reason: "Use `intervalId` directly instead.", + migrate: %replace.type(: intervalId), +}) type intervalId = Stdlib_Global.intervalId /** Identify timeout started by `Js.Global.setTimeout`. */ +@deprecated({ + reason: "Use `timeoutId` directly instead.", + migrate: %replace.type(: timeoutId), +}) type timeoutId = Stdlib_Global.timeoutId /** @@ -55,6 +63,10 @@ let cancel = () => Js.Nullable.iter(interval.contents, intervalId => Js.Global.clearInterval(intervalId)) ``` */ +@deprecated({ + reason: "Use `clearInterval` instead.", + migrate: clearInterval(), +}) @val external clearInterval: intervalId => unit = "clearInterval" @@ -78,6 +90,10 @@ let procrastinate = mins => { } ``` */ +@deprecated({ + reason: "Use `clearTimeout` instead.", + migrate: clearTimeout(), +}) @val external clearTimeout: timeoutId => unit = "clearTimeout" @@ -101,6 +117,10 @@ let tick = () => { Js.Global.setInterval(tick, 1000) ``` */ +@deprecated({ + reason: "Use `setInterval` instead.", + migrate: setInterval(), +}) @val external setInterval: (unit => unit, int) => intervalId = "setInterval" @@ -124,6 +144,10 @@ let tick = () => { Js.Global.setIntervalFloat(tick, 1000.0) ``` */ +@deprecated({ + reason: "Use `setIntervalFloat` instead.", + migrate: setIntervalFloat(), +}) @val external setIntervalFloat: (unit => unit, float) => intervalId = "setInterval" @@ -142,6 +166,10 @@ let message = "Timed out!" Js.Global.setTimeout(() => Js.log(message), 1000) ``` */ +@deprecated({ + reason: "Use `setTimeout` instead.", + migrate: setTimeout(), +}) @val external setTimeout: (unit => unit, int) => timeoutId = "setTimeout" @@ -160,6 +188,10 @@ let message = "Timed out!" Js.Global.setTimeoutFloat(() => Js.log(message), 1000.0) ``` */ +@deprecated({ + reason: "Use `setTimeoutFloat` instead.", + migrate: setTimeoutFloat(), +}) @val external setTimeoutFloat: (unit => unit, float) => timeoutId = "setTimeout" @@ -168,6 +200,10 @@ URL-encodes a string. See [`encodeURI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI) on MDN. */ +@deprecated({ + reason: "Use `encodeURI` instead.", + migrate: encodeURI(), +}) @val external encodeURI: string => string = "encodeURI" @@ -176,6 +212,10 @@ Decodes a URL-enmcoded string produced by `encodeURI` See [`decodeURI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI) on MDN. */ +@deprecated({ + reason: "Use `decodeURI` instead.", + migrate: decodeURI(), +}) @val external decodeURI: string => string = "decodeURI" @@ -184,6 +224,10 @@ URL-encodes a string, including characters with special meaning in a URI. See [`encodeURIComponent`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) on MDN. */ +@deprecated({ + reason: "Use `encodeURIComponent` instead.", + migrate: encodeURIComponent(), +}) @val external encodeURIComponent: string => string = "encodeURIComponent" @@ -192,5 +236,9 @@ Decodes a URL-enmcoded string produced by `encodeURIComponent` See [`decodeURIComponent`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent) on MDN. */ +@deprecated({ + reason: "Use `decodeURIComponent` instead.", + migrate: decodeURIComponent(), +}) @val external decodeURIComponent: string => string = "decodeURIComponent" diff --git a/packages/@rescript/runtime/Js_int.res b/packages/@rescript/runtime/Js_int.res index da4c40e306..0cf4807c9d 100644 --- a/packages/@rescript/runtime/Js_int.res +++ b/packages/@rescript/runtime/Js_int.res @@ -49,6 +49,10 @@ See [`toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re Js.log(Js.Int.toExponential(77)) ``` */ +@deprecated({ + reason: "Use `Int.toExponential` instead.", + migrate: Int.toExponential(), +}) @send external toExponential: int => string = "toExponential" @@ -73,6 +77,10 @@ Js.log(Js.Int.toExponentialWithPrecision(77, ~digits=2)) Js.log(Js.Int.toExponentialWithPrecision(5678, ~digits=2)) ``` */ +@deprecated({ + reason: "Use `Int.toExponential` instead.", + migrate: Int.toExponential(~digits=%insert.labelledArgument("digits")), +}) @send external toExponentialWithPrecision: (int, ~digits: int) => string = "toExponential" @@ -92,6 +100,10 @@ See [`toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe Js.log(Js.Int.toPrecision(123456789)) ``` */ +@deprecated({ + reason: "Use `Int.toPrecision` instead.", + migrate: Int.toPrecision(), +}) @send external toPrecision: int => string = "toPrecision" @@ -120,6 +132,10 @@ Js.log(Js.Int.toPrecisionWithPrecision(123456789, ~digits=2)) Js.log(Js.Int.toPrecisionWithPrecision(0, ~digits=2)) ``` */ +@deprecated({ + reason: "Use `Int.toPrecision` instead.", + migrate: Int.toPrecision(~digits=%insert.labelledArgument("digits")), +}) @send external toPrecisionWithPrecision: (int, ~digits: int) => string = "toPrecision" @@ -136,6 +152,10 @@ See [`toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen Js.log(Js.Int.toString(123456789)) ``` */ +@deprecated({ + reason: "Use `Int.toString` instead.", + migrate: Int.toString(), +}) @send external toString: int => string = "toString" @@ -161,11 +181,23 @@ Js.log(Js.Int.toStringWithRadix(3735928559, ~radix=16)) Js.log(Js.Int.toStringWithRadix(123456, ~radix=36)) ``` */ +@deprecated({ + reason: "Use `Int.toString` instead.", + migrate: Int.toString(~radix=%insert.labelledArgument("radix")), +}) @send external toStringWithRadix: (int, ~radix: int) => string = "toString" +@deprecated({ + reason: "Use `Int.toFloat` instead.", + migrate: Int.toFloat(), +}) external toFloat: int => float = "%floatofint" +@deprecated({ + reason: "Use `Int.equal` instead.", + migrate: Int.equal(), +}) let equal = (x: int, y) => x == y let max: int = 2147483647 let min: int = -2147483648 diff --git a/packages/@rescript/runtime/Js_json.resi b/packages/@rescript/runtime/Js_json.resi index 888757e7a5..bb68773fd1 100644 --- a/packages/@rescript/runtime/Js_json.resi +++ b/packages/@rescript/runtime/Js_json.resi @@ -31,6 +31,10 @@ Efficient JSON encoding using JavaScript API /* ## Types */ /** The JSON data structure */ +@deprecated({ + reason: "Use `JSON.t` instead.", + migrate: %replace.type(: JSON.t), +}) @unboxed type rec t = Stdlib_JSON.t = | Boolean(bool) @@ -40,6 +44,7 @@ type rec t = Stdlib_JSON.t = | Object(dict) | Array(array) +@deprecated("This functionality has been deprecated and will be removed in v13.") module Kind: { type json = t /** Underlying type of a JSON value */ @@ -52,6 +57,7 @@ module Kind: { | Null: t } +@deprecated("This functionality has been deprecated and will be removed in v13.") type tagged_t = | JSONFalse | JSONTrue @@ -63,41 +69,67 @@ type tagged_t = /* ## Accessors */ +@deprecated("This functionality has been deprecated and will be removed in v13.") let classify: t => tagged_t /** `test(v, kind)` returns `true` if `v` is of `kind`. */ +@deprecated("This functionality has been deprecated and will be removed in v13.") let test: ('a, Kind.t<'b>) => bool /** `decodeString(json)` returns `Some(s)` if `json` is a `string`, `None` otherwise. */ +@deprecated({ + reason: "Use `JSON.Decode.string` instead.", + migrate: JSON.Decode.string(), +}) let decodeString: t => option /** `decodeNumber(json)` returns `Some(n)` if `json` is a `number`, `None` otherwise. */ +@deprecated({ + reason: "Use `JSON.Decode.float` instead.", + migrate: JSON.Decode.float(), +}) let decodeNumber: t => option /** `decodeObject(json)` returns `Some(o)` if `json` is an `object`, `None` otherwise. */ +@deprecated({ + reason: "Use `JSON.Decode.object` instead.", + migrate: JSON.Decode.object(), +}) let decodeObject: t => option> /** `decodeArray(json)` returns `Some(a)` if `json` is an `array`, `None` otherwise. */ +@deprecated({ + reason: "Use `JSON.Decode.array` instead.", + migrate: JSON.Decode.array(), +}) let decodeArray: t => option> /** `decodeBoolean(json)` returns `Some(b)` if `json` is a `boolean`, `None` otherwise. */ +@deprecated({ + reason: "Use `JSON.Decode.bool` instead.", + migrate: JSON.Decode.bool(), +}) let decodeBoolean: t => option /** `decodeNull(json)` returns `Some(null)` if `json` is a `null`, `None` otherwise. */ +@deprecated({ + reason: "Use JSON.Decode.null instead.", + migrate: JSON.Decode.null(), +}) let decodeNull: t => option> /* ## Constructors */ @@ -108,22 +140,46 @@ let decodeNull: t => option> */ /** `null` is the singleton null JSON value. */ +@deprecated({ + reason: "Use `JSON.Encode.null` instead.", + migrate: JSON.Encode.null, +}) @val external null: t = "null" /** `string(s)` makes a JSON string of the `string` `s`. */ +@deprecated({ + reason: "Use `JSON.Encode.string` instead.", + migrate: JSON.Encode.string(), +}) external string: string => t = "%identity" /** `number(n)` makes a JSON number of the `float` `n`. */ +@deprecated({ + reason: "Use `JSON.Encode.float` instead.", + migrate: JSON.Encode.float(), +}) external number: float => t = "%identity" /** `boolean(b)` makes a JSON boolean of the `bool` `b`. */ +@deprecated({ + reason: "Use `JSON.Encode.bool` instead.", + migrate: JSON.Encode.bool(), +}) external boolean: bool => t = "%identity" /** `object_(dict)` makes a JSON object of the `dict`. */ +@deprecated({ + reason: "Use `JSON.Encode.object` instead.", + migrate: JSON.Encode.object(), +}) external object_: dict => t = "%identity" /** `array_(a)` makes a JSON array of the `Js.Json.t` array `a`. */ +@deprecated({ + reason: "Use `JSON.Encode.array` instead.", + migrate: JSON.Encode.array(), +}) external array: array => t = "%identity" /* @@ -133,15 +189,31 @@ external array: array => t = "%identity" */ /** `stringArray(a)` makes a JSON array of the `string` array `a`. */ +@deprecated({ + reason: "Use `JSON.Encode.stringArray` instead.", + migrate: JSON.Encode.stringArray(), +}) external stringArray: array => t = "%identity" /** `numberArray(a)` makes a JSON array of the `float` array `a`. */ +@deprecated({ + reason: "Use `JSON.Encode.floatArray` instead.", + migrate: JSON.Encode.floatArray(), +}) external numberArray: array => t = "%identity" /** `booleanArray(a)` makes a JSON array of the `bool` array `a`. */ +@deprecated({ + reason: "Use `JSON.Encode.boolArray` instead.", + migrate: JSON.Encode.boolArray(), +}) external booleanArray: array => t = "%identity" /** `objectArray(a) makes a JSON array of the `JsDict.t` array `a`. */ +@deprecated({ + reason: "Use `JSON.Encode.objectArray` instead.", + migrate: JSON.Encode.objectArray(), +}) external objectArray: array> => t = "%identity" /* ## String conversion */ @@ -196,7 +268,12 @@ let getIds = s => { Js.log(getIds(` { "ids" : [1, 2, 3 ] } `)) ``` */ -@val @scope("JSON") +@deprecated({ + reason: "Use `JSON.parseOrThrow` instead.", + migrate: JSON.parseOrThrow(), +}) +@val +@scope("JSON") external parseExn: string => t = "parse" /** @@ -218,7 +295,12 @@ Js.Dict.set(dict, "likes", Js.Json.stringArray(["ReScript", "ocaml", "js"])) Js.log(Js.Json.stringify(Js.Json.object_(dict))) ``` */ -@val @scope("JSON") +@deprecated({ + reason: "Use `JSON.stringify` instead.", + migrate: JSON.stringify(), +}) +@val +@scope("JSON") external stringify: t => string = "stringify" /** @@ -240,7 +322,12 @@ Js.Dict.set(dict, "likes", Js.Json.stringArray(["ReScript", "ocaml", "js"])) Js.log(Js.Json.stringifyWithSpace(Js.Json.object_(dict), 2)) ``` */ -@val @scope("JSON") +@deprecated({ + reason: "Use `JSON.stringify` with optional `~space` instead.", + migrate: JSON.stringify(~space=%insert.unlabelledArgument(2)), +}) +@val +@scope("JSON") external stringifyWithSpace: (t, @as(json`null`) _, int) => string = "stringify" /** @@ -253,7 +340,12 @@ external stringifyWithSpace: (t, @as(json`null`) _, int) => string = "stringify" Js.log(Js.Json.stringifyAny(["hello", "world"])) ``` */ -@val @scope("JSON") +@deprecated({ + reason: "Use `JSON.stringifyAny` instead.", + migrate: JSON.stringifyAny(), +}) +@val +@scope("JSON") external stringifyAny: 'a => option = "stringify" /** @@ -264,6 +356,7 @@ It is unsafe in two aspects - It may throw during parsing - when you cast it to a specific type, it may have a type mismatch */ +@deprecated("This functionality has been deprecated and will be removed in v13.") let deserializeUnsafe: string => 'a /** @@ -272,4 +365,5 @@ It will throw in such situations: - There are cycles - Some JS engines can not stringify deeply nested json objects */ +@deprecated("This functionality has been deprecated and will be removed in v13.") let serializeExn: 'a => string diff --git a/packages/@rescript/runtime/Js_map.res b/packages/@rescript/runtime/Js_map.res index 1f9cbdf19f..827c66b9ab 100644 --- a/packages/@rescript/runtime/Js_map.res +++ b/packages/@rescript/runtime/Js_map.res @@ -1,3 +1,7 @@ /*** ES6 Map API */ +@deprecated({ + reason: "Use `Map.t` instead.", + migrate: %replace.type(: Map.t), +}) type t<'k, 'v> = Stdlib_Map.t<'k, 'v> diff --git a/packages/@rescript/runtime/Js_math.res b/packages/@rescript/runtime/Js_math.res index 1771a7671b..aadec6db3d 100644 --- a/packages/@rescript/runtime/Js_math.res +++ b/packages/@rescript/runtime/Js_math.res @@ -34,7 +34,12 @@ Euler's number; ≈ 2.718281828459045. See [`Math.E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/E) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Constants.e` instead.", + migrate: Math.Constants.e, +}) +@val +@scope("Math") external _E: float = "E" /** @@ -42,7 +47,12 @@ Natural logarithm of 2; ≈ 0.6931471805599453. See [`Math.LN2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LN2) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Constants.ln2` instead.", + migrate: Math.Constants.ln2, +}) +@val +@scope("Math") external _LN2: float = "LN2" /** @@ -50,7 +60,12 @@ Natural logarithm of 10; ≈ 2.302585092994046. See [`Math.LN10`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LN10) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Constants.ln10` instead.", + migrate: Math.Constants.ln10, +}) +@val +@scope("Math") external _LN10: float = "LN10" /** @@ -58,7 +73,12 @@ Base 2 logarithm of E; ≈ 1.4426950408889634. See [`Math.LOG2E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LOG2E) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Constants.log2e` instead.", + migrate: Math.Constants.log2e, +}) +@val +@scope("Math") external _LOG2E: float = "LOG2E" /** @@ -66,7 +86,12 @@ Base 10 logarithm of E; ≈ 0.4342944819032518. See [`Math.LOG10E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LOG10E) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Constants.log10e` instead.", + migrate: Math.Constants.log10e, +}) +@val +@scope("Math") external _LOG10E: float = "LOG10E" /** @@ -74,7 +99,12 @@ Pi - ratio of the circumference to the diameter of a circle; ≈ 3.1415926535897 [`Math.PI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Constants.pi` instead.", + migrate: Math.Constants.pi, +}) +@val +@scope("Math") external _PI: float = "PI" /** @@ -82,7 +112,12 @@ Square root of 1/2; ≈ 0.7071067811865476. See [`Math.SQRT1_2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/SQRT1_2) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Constants.sqrt1_2` instead.", + migrate: Math.Constants.sqrt1_2, +}) +@val +@scope("Math") external _SQRT1_2: float = "SQRT1_2" /** @@ -90,7 +125,12 @@ Square root of 2; ≈ 1.4142135623730951. See [`Math.SQRT2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/SQRT2) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Constants.sqrt2` instead.", + migrate: Math.Constants.sqrt2, +}) +@val +@scope("Math") external _SQRT2: float = "SQRT2" /** @@ -98,7 +138,12 @@ Absolute value for integer argument. See [`Math.abs`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Int.abs` instead.", + migrate: Math.Int.abs(), +}) +@val +@scope("Math") external abs_int: int => int = "abs" /** @@ -106,7 +151,12 @@ Absolute value for float argument. See [`Math.abs`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.abs` instead.", + migrate: Math.abs(), +}) +@val +@scope("Math") external abs_float: float => float = "abs" /** @@ -115,7 +165,12 @@ the range [-1.0, 1.0]. See [`Math.acos`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.acos` instead.", + migrate: Math.acos(), +}) +@val +@scope("Math") external acos: float => float = "acos" /** @@ -124,7 +179,12 @@ is less than 1.0. See [`Math.acosh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.acosh` instead.", + migrate: Math.acosh(), +}) +@val +@scope("Math") external acosh: float => float = "acosh" /** @@ -133,7 +193,12 @@ the range [-1.0, 1.0]. See [`Math.asin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.asin` instead.", + migrate: Math.asin(), +}) +@val +@scope("Math") external asin: float => float = "asin" /** @@ -141,7 +206,12 @@ Hyperbolic arcsine (in radians) of argument. See [`Math.asinh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.asinh` instead.", + migrate: Math.asinh(), +}) +@val +@scope("Math") external asinh: float => float = "asinh" /** @@ -149,7 +219,12 @@ Arctangent (in radians) of argument. See [`Math.atan`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.atan` instead.", + migrate: Math.atan(), +}) +@val +@scope("Math") external atan: float => float = "atan" /** @@ -159,7 +234,12 @@ arguments -1.0 and 1.0. See [`Math.atanh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.atanh` instead.", + migrate: Math.atanh(), +}) +@val +@scope("Math") external atanh: float => float = "atanh" /** @@ -178,7 +258,13 @@ Js.Math.atan2(~x=-5.0, ~y=5.0, ()) == 3.0 *. Js.Math._PI /. 4.0 Js.Math.atan2(~x=-0.0, ~y=-5.0, ()) == -.Js.Math._PI /. 2.0 ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.atan2` instead.", + migrate: @apply.transforms(["dropUnitArgumentsInApply"]) + Math.atan2(~y=%insert.labelledArgument("y"), ~x=%insert.labelledArgument("x")), +}) +@val +@scope("Math") external atan2: (~y: float, ~x: float, unit) => float = "atan2" /** @@ -186,7 +272,12 @@ Cube root. See [`Math.cbrt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt) on MDN */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.cbrt` instead.", + migrate: Math.cbrt(), +}) +@val +@scope("Math") external cbrt: float => float = "cbrt" /** @@ -207,10 +298,19 @@ Js.Math.unsafe_ceil_int(-3.1) == -3 Js.Math.unsafe_ceil_int(1.0e15) // result is outside range of int datatype ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Int.ceil` instead.", + migrate: Math.Int.ceil(), +}) +@val +@scope("Math") external unsafe_ceil_int: float => int = "ceil" -@deprecated("Please use `unsafe_ceil_int` instead") let unsafe_ceil = unsafe_ceil_int +@deprecated({ + reason: "Use `Math.Int.ceil` instead.", + migrate: Math.Int.ceil(), +}) +let unsafe_ceil = unsafe_ceil_int /** Returns the smallest `int` greater than or equal to the argument; the result @@ -228,6 +328,10 @@ Js.Math.ceil_int(-1.0e15) == -2147483648 Js.Math.ceil_int(1.0e15) == 2147483647 ``` */ +@deprecated({ + reason: "Use `Math.Int.ceil` instead.", + migrate: Math.Int.ceil(), +}) let ceil_int = (f: float): int => if f > Js_int.toFloat(Js_int.max) { Js_int.max @@ -237,7 +341,11 @@ let ceil_int = (f: float): int => unsafe_ceil_int(f) } -@deprecated("Please use `ceil_int` instead") let ceil = ceil_int +@deprecated({ + reason: "Use `Math.Int.ceil` instead.", + migrate: Math.Int.ceil(), +}) +let ceil = ceil_int /** Returns the smallest integral value greater than or equal to the argument. @@ -255,7 +363,12 @@ Js.Math.ceil_float(-3.1) == -3.0 Js.Math.ceil_float(2_150_000_000.3) == 2_150_000_001.0 ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.ceil` instead.", + migrate: Math.ceil(), +}) +@val +@scope("Math") external ceil_float: float => float = "ceil" /** @@ -271,7 +384,12 @@ Js.Math.clz32(-1) == 0 Js.Math.clz32(255) == 24 ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Int.clz32` instead.", + migrate: Math.Int.clz32(), +}) +@val +@scope("Math") external clz32: int => int = "clz32" /** @@ -279,7 +397,12 @@ Cosine of argument, which must be specified in radians. See [`Math.cos`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.cos` instead.", + migrate: Math.cos(), +}) +@val +@scope("Math") external cos: float => float = "cos" /** @@ -287,7 +410,12 @@ Hyperbolic cosine of argument, which must be specified in radians. See [`Math.cosh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.cosh` instead.", + migrate: Math.cosh(), +}) +@val +@scope("Math") external cosh: float => float = "cosh" /** @@ -296,7 +424,12 @@ power of the given argument. See [`Math.exp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.exp` instead.", + migrate: Math.exp(), +}) +@val +@scope("Math") external exp: float => float = "exp" /** @@ -305,7 +438,12 @@ argument minus 1. See [`Math.expm1`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.expm1` instead.", + migrate: Math.expm1(), +}) +@val +@scope("Math") external expm1: float => float = "expm1" /** @@ -326,10 +464,19 @@ Js.Math.unsafe_floor_int(-3.7) == -4 Js.Math.unsafe_floor_int(1.0e15) // result is outside range of int datatype ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Int.floor` instead.", + migrate: Math.Int.floor(), +}) +@val +@scope("Math") external unsafe_floor_int: float => int = "floor" -@deprecated("Please use `unsafe_floor_int` instead") let unsafe_floor = unsafe_floor_int +@deprecated({ + reason: "Use `Math.Int.floor` instead.", + migrate: Math.Int.floor(), +}) +let unsafe_floor = unsafe_floor_int /** Returns the largest `int` less than or equal to the argument; the result is @@ -347,6 +494,10 @@ Js.Math.floor_int(-1.0e15) == -2147483648 Js.Math.floor_int(1.0e15) == 2147483647 ``` */ +@deprecated({ + reason: "Use `Math.Int.floor` instead.", + migrate: Math.Int.floor(), +}) let floor_int = f => if f > Js_int.toFloat(Js_int.max) { Js_int.max @@ -356,7 +507,11 @@ let floor_int = f => unsafe_floor(f) } -@deprecated("Please use `floor_int` instead") let floor = floor_int +@deprecated({ + reason: "Use `Math.Int.floor` instead.", + migrate: Math.Int.floor(), +}) +let floor = floor_int /** Returns the largest integral value less than or equal to the argument. The @@ -373,7 +528,12 @@ Js.Math.floor_float(-3.1) == -4.0 Js.Math.floor_float(2_150_000_000.3) == 2_150_000_000.0 ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.floor` instead.", + migrate: Math.floor(), +}) +@val +@scope("Math") external floor_float: float => float = "floor" /** @@ -388,7 +548,12 @@ Js.Math.fround(5.5) == 5.5 Js.Math.fround(5.05) == 5.050000190734863 ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.fround` instead.", + migrate: Math.fround(), +}) +@val +@scope("Math") external fround: float => float = "fround" /** @@ -397,7 +562,12 @@ Pythagorean formula). See [`Math.hypot`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.hypot` instead.", + migrate: Math.hypot(), +}) +@val +@scope("Math") external hypot: (float, float) => float = "hypot" /** @@ -413,7 +583,13 @@ on MDN. Js.Math.hypotMany([3.0, 4.0, 12.0]) == 13.0 ``` */ -@val @variadic @scope("Math") +@deprecated({ + reason: "Use `Math.hypotMany` instead.", + migrate: Math.hypotMany(), +}) +@val +@variadic +@scope("Math") external hypotMany: array => float = "hypot" /** @@ -422,7 +598,12 @@ performance of multiplication of numbers stored as 32-bit integers. See [`Math.imul`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Int.imul` instead.", + migrate: Math.Int.imul(), +}) +@val +@scope("Math") external imul: (int, int) => int = "imul" /** @@ -439,7 +620,12 @@ Js.Math.log(Js.Math._E) == 1.0 Js.Math.log(100.0) == 4.605170185988092 ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.log` instead.", + migrate: Math.log(), +}) +@val +@scope("Math") external log: float => float = "log" /** @@ -455,7 +641,12 @@ Js.Math.log1p(Js.Math._E -. 1.0) == 1.0 Js.Math.log1p(99.0) == 4.605170185988092 ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.log1p` instead.", + migrate: Math.log1p(), +}) +@val +@scope("Math") external log1p: float => float = "log1p" /** @@ -472,7 +663,12 @@ Js.Math.log10(0.01) == -2.0 Js.Math.log10(Js.Math.sqrt(10.0)) == 0.5 ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.log10` instead.", + migrate: Math.log10(), +}) +@val +@scope("Math") external log10: float => float = "log10" /** @@ -489,7 +685,12 @@ Js.Math.log2(0.125) == -3.0 Js.Math.log2(Js.Math._SQRT2) == 0.5000000000000001 // due to precision ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.log2` instead.", + migrate: Math.log2(), +}) +@val +@scope("Math") external log2: float => float = "log2" /** @@ -497,7 +698,12 @@ Returns the maximum of its two integer arguments. See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Int.max` instead.", + migrate: Math.Int.max(), +}) +@val +@scope("Math") external max_int: (int, int) => int = "max" /** @@ -505,7 +711,13 @@ Returns the maximum of the integers in the given array. See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) on MDN. */ -@val @variadic @scope("Math") +@deprecated({ + reason: "Use `Math.Int.maxMany` instead.", + migrate: Math.Int.maxMany(), +}) +@val +@variadic +@scope("Math") external maxMany_int: array => int = "max" /** @@ -513,7 +725,12 @@ Returns the maximum of its two floating point arguments. See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.max` instead.", + migrate: Math.max(), +}) +@val +@scope("Math") external max_float: (float, float) => float = "max" /** @@ -521,7 +738,13 @@ Returns the maximum of the floating point values in the given array. See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) on MDN. */ -@val @variadic @scope("Math") +@deprecated({ + reason: "Use `Math.maxMany` instead.", + migrate: Math.maxMany(), +}) +@val +@variadic +@scope("Math") external maxMany_float: array => float = "max" /** @@ -529,7 +752,12 @@ Returns the minimum of its two integer arguments. See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Int.min` instead.", + migrate: Math.Int.min(), +}) +@val +@scope("Math") external min_int: (int, int) => int = "min" /** @@ -537,7 +765,13 @@ Returns the minimum of the integers in the given array. See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) on MDN. */ -@val @variadic @scope("Math") +@deprecated({ + reason: "Use `Math.Int.minMany` instead.", + migrate: Math.Int.minMany(), +}) +@val +@variadic +@scope("Math") external minMany_int: array => int = "min" /** @@ -545,7 +779,12 @@ Returns the minimum of its two floating point arguments. See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.min` instead.", + migrate: Math.min(), +}) +@val +@scope("Math") external min_float: (float, float) => float = "min" /** @@ -553,7 +792,13 @@ Returns the minimum of the floating point values in the given array. See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) on MDN. */ -@val @variadic @scope("Math") +@deprecated({ + reason: "Use `Math.minMany` instead.", + migrate: Math.minMany(), +}) +@val +@variadic +@scope("Math") external minMany_float: array => float = "min" /** @@ -568,7 +813,12 @@ on MDN. Js.Math.pow_int(~base=3, ~exp=4) == 81 ``` */ -@val @scope("Math") @deprecated("use `pow_float` instead, the return type may be not int") +@deprecated({ + reason: "Use `Math.Int.pow` instead.", + migrate: Math.Int.pow(%insert.labelledArgument("base"), ~exp=%insert.labelledArgument("exp")), +}) +@val +@scope("Math") external pow_int: (~base: int, ~exp: int) => int = "pow" /** @@ -587,7 +837,12 @@ Js.Math.pow_float(~base=625.0, ~exp=-0.5) == 0.04 Js.Float.isNaN(Js.Math.pow_float(~base=-2.0, ~exp=0.5)) == true ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.pow` instead.", + migrate: Math.pow(%insert.labelledArgument("base"), ~exp=%insert.labelledArgument("exp")), +}) +@val +@scope("Math") external pow_float: (~base: float, ~exp: float) => float = "pow" /** @@ -595,7 +850,12 @@ Returns a random number in the half-closed interval [0,1). See [`Math.random`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.random` instead.", + migrate: Math.random(), +}) +@val +@scope("Math") external random: unit => float = "random" /** @@ -604,6 +864,10 @@ half-closed interval [minVal, maxVal). See [`Math.random`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) on MDN. */ +@deprecated({ + reason: "Use `Math.Int.random` instead.", + migrate: Math.Int.random(), +}) let random_int = (min, max) => floor(random() *. Js_int.toFloat(max - min)) + min /** @@ -624,7 +888,12 @@ Js.Math.unsafe_round(-3.5) == -3 Js.Math.unsafe_round(2_150_000_000_000.3) // out of range for int ``` */ -@val @scope("Math") +@deprecated({ + reason: "Use `Float.toInt(Math.round(_))` instead.", + migrate: Float.toInt(Math.round(%insert.unlabelledArgument(0))), +}) +@val +@scope("Math") external unsafe_round: float => int = "round" /** @@ -632,7 +901,12 @@ Rounds to nearest integral value (expressed as a float). See [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.round` instead.", + migrate: Math.round(), +}) +@val +@scope("Math") external round: float => float = "round" /** @@ -641,7 +915,12 @@ positive. See [`Math.sign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.Int.sign` instead.", + migrate: Math.Int.sign(), +}) +@val +@scope("Math") external sign_int: int => int = "sign" /** @@ -650,7 +929,12 @@ positive. See [`Math.sign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.sign` instead.", + migrate: Math.sign(), +}) +@val +@scope("Math") external sign_float: float => float = "sign" /** @@ -658,7 +942,12 @@ Sine of argument, which must be specified in radians. See [`Math.sin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.sin` instead.", + migrate: Math.sin(), +}) +@val +@scope("Math") external sin: float => float = "sin" /** @@ -666,7 +955,12 @@ Hyperbolic sine of argument, which must be specified in radians. See [`Math.sinh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.sinh` instead.", + migrate: Math.sinh(), +}) +@val +@scope("Math") external sinh: float => float = "sinh" /** @@ -674,7 +968,12 @@ Square root. If the argument is negative, this function returns `NaN`. See [`Math.sqrt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.sqrt` instead.", + migrate: Math.sqrt(), +}) +@val +@scope("Math") external sqrt: float => float = "sqrt" /** @@ -683,7 +982,12 @@ argument is positive infinity or negative infinity. See [`Math.cos`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.tan` instead.", + migrate: Math.tan(), +}) +@val +@scope("Math") external tan: float => float = "tan" /** @@ -691,7 +995,12 @@ Hyperbolic tangent of argument, which must be specified in radians. See [`Math.tanh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.tanh` instead.", + migrate: Math.tanh(), +}) +@val +@scope("Math") external tanh: float => float = "tanh" /** @@ -703,7 +1012,12 @@ exactly. See [`Math.trunc`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Float.toInt(Math.trunc(_))` instead.", + migrate: Float.toInt(Math.trunc(%insert.unlabelledArgument(0))), +}) +@val +@scope("Math") external unsafe_trunc: float => int = "trunc" /** @@ -711,5 +1025,10 @@ Truncates its argument; i.e., removes fractional digits. See [`Math.trunc`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc) on MDN. */ -@val @scope("Math") +@deprecated({ + reason: "Use `Math.trunc` instead.", + migrate: Math.trunc(), +}) +@val +@scope("Math") external trunc: float => float = "trunc" diff --git a/packages/@rescript/runtime/Js_null.resi b/packages/@rescript/runtime/Js_null.resi index 7d97c19237..765f5104ff 100644 --- a/packages/@rescript/runtime/Js_null.resi +++ b/packages/@rescript/runtime/Js_null.resi @@ -24,20 +24,45 @@ /*** Provides functionality for dealing with the `Js.null<'a>` type */ +@deprecated({ + reason: "Use `Null.t` instead.", + migrate: %replace.type(: Null.t), +}) @unboxed type t<+'a> = Primitive_js_extern.null<'a> = Value('a) | @as(null) Null /** Constructs a value of `Js.null<'a>` containing a value of `'a`. */ +@deprecated({ + reason: "Use `Null.make` instead.", + migrate: Null.make(), +}) external return: 'a => t<'a> = "%identity" /** Returns `true` if the given value is empty (`null`), `false` otherwise. */ -@deprecated("Use = Js.null directly ") +@deprecated({ + reason: "Use `== Js.null` directly.", + migrate: %insert.unlabelledArgument(0) === Null.null, + migrateInPipeChain: Null.equal(Null, (a, b) => a === b), +}) let test: t<'a> => bool /** The empty value, `null` */ +@deprecated({ + reason: "Use `Null.null` instead.", + migrate: Null.null, +}) external empty: t<'a> = "%null" +@deprecated({ + reason: "Use `Null.getUnsafe` instead.", + migrate: Null.getUnsafe(), +}) external getUnsafe: t<'a> => 'a = "%identity" + +@deprecated({ + reason: "Use `Null.getOrThrow` instead.", + migrate: Null.getOrThrow(), +}) let getExn: t<'a> => 'a /** @@ -54,6 +79,10 @@ let maybeGreetWorld = (maybeGreeting: Js.null) => Js.Null.bind(maybeGreeting, greeting => greeting ++ " world!") ``` */ +@deprecated({ + reason: "Use `Null.map` instead.", + migrate: Null.map(), +}) let bind: (t<'a>, 'a => 'b) => t<'b> /** @@ -67,6 +96,10 @@ let maybeSay = (maybeMessage: Js.null) => Js.Null.iter(maybeMessage, message => Js.log(message)) ``` */ +@deprecated({ + reason: "Use `Null.forEach` instead.", + migrate: Null.forEach(), +}) let iter: (t<'a>, 'a => unit) => unit /** @@ -74,15 +107,31 @@ Maps `option<'a>` to `Js.null<'a>`. `Some(a)` => `a` `None` => `empty` */ +@deprecated({ + reason: "Use `Null.fromOption` instead.", + migrate: Null.fromOption(), +}) let fromOption: option<'a> => t<'a> -@deprecated("Use fromOption instead") let from_opt: option<'a> => t<'a> +@deprecated({ + reason: "Use `Null.fromOption` instead.", + migrate: Null.fromOption(), +}) +let from_opt: option<'a> => t<'a> /** Maps `Js.null<'a>` to `option<'a>`. `a` => `Some(a)` `empty` => `None` */ +@deprecated({ + reason: "Use `Null.toOption` instead.", + migrate: Null.toOption(), +}) external toOption: t<'a> => option<'a> = "%null_to_opt" -@deprecated("Use toOption instead") external to_opt: t<'a> => option<'a> = "%null_to_opt" +@deprecated({ + reason: "Use `Null.toOption` instead.", + migrate: Null.toOption(), +}) +external to_opt: t<'a> => option<'a> = "%null_to_opt" diff --git a/packages/@rescript/runtime/Js_null_undefined.resi b/packages/@rescript/runtime/Js_null_undefined.resi index 6dbbff513e..9b434331f7 100644 --- a/packages/@rescript/runtime/Js_null_undefined.resi +++ b/packages/@rescript/runtime/Js_null_undefined.resi @@ -26,20 +26,40 @@ Contains functionality for dealing with values that can be both `null` and `undefined` */ +@deprecated({ + reason: "Use `Nullable.t` instead.", + migrate: %replace.type(: Nullable.t), +}) @unboxed type t<+'a> = Primitive_js_extern.nullable<'a> = Value('a) | @as(null) Null | @as(undefined) Undefined /** Constructs a value of `Js.null_undefined<'a>` containing a value of `'a`. */ +@deprecated({ + reason: "Use `Nullable.make` instead.", + migrate: Nullable.make(), +}) external return: 'a => t<'a> = "%identity" /** Returns `true` if the given value is null or undefined, `false` otherwise. */ +@deprecated({ + reason: "Use `Nullable.isNullable` instead.", + migrate: Nullable.isNullable(), +}) external isNullable: t<'a> => bool = "%is_nullable" /** The null value of type `Js.null_undefined<'a>`. */ +@deprecated({ + reason: "Use `Nullable.null` instead.", + migrate: Nullable.null, +}) external null: t<'a> = "%null" /** The undefined value of type `Js.null_undefined<'a>`. */ +@deprecated({ + reason: "Use `Nullable.undefined` instead.", + migrate: Nullable.undefined, +}) external undefined: t<'a> = "%undefined" /** @@ -56,6 +76,10 @@ let maybeGreetWorld = (maybeGreeting: Js.null_undefined) => Js.Null_undefined.bind(maybeGreeting, greeting => greeting ++ " world!") ``` */ +@deprecated({ + reason: "Use `Nullable.map` instead.", + migrate: Nullable.map(), +}) let bind: (t<'a>, 'a => 'b) => t<'b> /** @@ -69,6 +93,10 @@ let maybeSay = (maybeMessage: Js.null_undefined) => Js.Null_undefined.iter(maybeMessage, message => Js.log(message)) ``` */ +@deprecated({ + reason: "Use `Nullable.forEach` instead.", + migrate: Nullable.forEach(), +}) let iter: (t<'a>, 'a => unit) => unit /** @@ -76,9 +104,17 @@ Maps `option<'a>` to `Js.null_undefined<'a>`. `Some(a)` => `a` `None` => `undefined` */ +@deprecated({ + reason: "Use `Nullable.fromOption` instead.", + migrate: Nullable.fromOption(), +}) let fromOption: option<'a> => t<'a> -@deprecated("Use fromOption instead") let from_opt: option<'a> => t<'a> +@deprecated({ + reason: "Use `Nullable.fromOption` instead.", + migrate: Nullable.fromOption(), +}) +let from_opt: option<'a> => t<'a> /** Maps `Js.null_undefined<'a>` to `option<'a>`. @@ -86,6 +122,14 @@ Maps `Js.null_undefined<'a>` to `option<'a>`. `undefined` => `None` `null` => `None` */ +@deprecated({ + reason: "Use `Nullable.toOption` instead.", + migrate: Nullable.toOption(), +}) external toOption: t<'a> => option<'a> = "%nullable_to_opt" -@deprecated("Use toOption instead") external to_opt: t<'a> => option<'a> = "%nullable_to_opt" +@deprecated({ + reason: "Use `Nullable.toOption` instead.", + migrate: Nullable.toOption(), +}) +external to_opt: t<'a> => option<'a> = "%nullable_to_opt" diff --git a/packages/@rescript/runtime/Js_obj.res b/packages/@rescript/runtime/Js_obj.res index 5b8896068d..e42c663d6e 100644 --- a/packages/@rescript/runtime/Js_obj.res +++ b/packages/@rescript/runtime/Js_obj.res @@ -27,6 +27,10 @@ Provides functions for inspecting and manipulating native JavaScript objects */ /** `empty()` returns the empty object `{}` */ +@deprecated({ + reason: "Use `Object.make` instead.", + migrate: Object.make(), +}) @obj external empty: unit => {..} = "" @@ -63,6 +67,10 @@ Js.log(obj) Js.log(target) ``` */ +@deprecated({ + reason: "Use `Object.assign` instead.", + migrate: Object.assign(), +}) @val external assign: ({..}, {..}) => {..} = "Object.assign" @@ -100,5 +108,9 @@ external assign: ({..}, {..}) => {..} = "Object.assign" */ /** `keys(obj)` returns an `array` of the keys of `obj`'s own enumerable properties. */ +@deprecated({ + reason: "Use `Object.keysToArray` instead.", + migrate: Object.keysToArray(), +}) @val external keys: {..} => array = "Object.keys" diff --git a/packages/@rescript/runtime/Js_option.resi b/packages/@rescript/runtime/Js_option.resi index 8a5f6f01e3..1dd6765b2c 100644 --- a/packages/@rescript/runtime/Js_option.resi +++ b/packages/@rescript/runtime/Js_option.resi @@ -22,29 +22,88 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +@deprecated({ + reason: "Use `option` directly instead.", + migrate: %replace.type(: option), +}) type t<'a> = option<'a> +@deprecated({ + reason: "Use `Some()` directly instead.", + migrate: Some(), +}) let some: 'a => option<'a> +@deprecated({ + reason: "Use `Option.isSome` instead.", + migrate: Option.isSome(), +}) let isSome: option<'a> => bool +// Skipping automatic migration because this is a rather weird function that is probably not that much used. +@deprecated("Use `Option.equal` instead.") let isSomeValue: (('a, 'a) => bool, 'a, option<'a>) => bool +@deprecated({ + reason: "Use `Option.isNone` instead.", + migrate: Option.isNone(), +}) let isNone: option<'a> => bool +@deprecated({ + reason: "Use `Option.getOrThrow` instead.", + migrate: Option.getOrThrow(), +}) let getExn: option<'a> => 'a +@deprecated({ + reason: "Use `Option.equal` instead.", + migrate: Option.equal( + %insert.unlabelledArgument(1), + %insert.unlabelledArgument(2), + %insert.unlabelledArgument(0), + ), +}) let equal: (('a, 'b) => bool, option<'a>, option<'b>) => bool +@deprecated({ + reason: "Use `Option.flatMap` instead.", + migrate: Option.flatMap(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), + migrateInPipeChain: Option.flatMap(%insert.unlabelledArgument(0)), +}) let andThen: ('a => option<'b>, option<'a>) => option<'b> +@deprecated({ + reason: "Use `Option.map` instead.", + migrate: Option.map(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), + migrateInPipeChain: Option.map(%insert.unlabelledArgument(0)), +}) let map: ('a => 'b, option<'a>) => option<'b> +@deprecated({ + reason: "Use `Option.getOr` instead.", + migrate: Option.getOr(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), + migrateInPipeChain: Option.getOr(%insert.unlabelledArgument(0)), +}) let getWithDefault: ('a, option<'a>) => 'a -@deprecated("Use `getWithDefault` instead since default has special meaning in ES module") +@deprecated({ + reason: "Use `Option.getOr` instead. Note: `default` has special meaning in ES modules.", + migrate: Option.getOr(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), + migrateInPipeChain: Option.getOr(%insert.unlabelledArgument(0)), +}) let default: ('a, option<'a>) => 'a +@deprecated({ + reason: "Use `Option.filter` instead.", + migrate: Option.filter(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), + migrateInPipeChain: Option.filter(%insert.unlabelledArgument(0)), +}) let filter: ('a => bool, option<'a>) => option<'a> +@deprecated({ + reason: "Use `Option.orElse` instead.", + migrate: Option.orElse(), + migrateInPipeChain: Option.orElse(%insert.unlabelledArgument(0)), +}) let firstSome: (option<'a>, option<'a>) => option<'a> diff --git a/packages/@rescript/runtime/Js_promise.res b/packages/@rescript/runtime/Js_promise.res index 5960b5efdf..a4e7635fa4 100644 --- a/packages/@rescript/runtime/Js_promise.res +++ b/packages/@rescript/runtime/Js_promise.res @@ -33,6 +33,7 @@ https://rescript-lang.org/docs/manual/latest/promise#promise-legacy @@warning("-103") type t<+'a> = promise<'a> + type error = Js_promise2.error /* @@ -47,12 +48,16 @@ type error external make: ((~resolve: 'a => unit, ~reject: exn => unit) => unit) => promise<'a> = "Promise" /* `make (fun resolve reject -> .. )` */ -@val @scope("Promise") external resolve: 'a => promise<'a> = "resolve" -@val @scope("Promise") external reject: exn => promise<'a> = "reject" +@val @scope("Promise") +external resolve: 'a => promise<'a> = "resolve" +@val @scope("Promise") +external reject: exn => promise<'a> = "reject" -@val @scope("Promise") external all: array> => promise> = "all" +@val @scope("Promise") +external all: array> => promise> = "all" -@val @scope("Promise") external all2: ((promise<'a0>, promise<'a1>)) => promise<('a0, 'a1)> = "all" +@val @scope("Promise") +external all2: ((promise<'a0>, promise<'a1>)) => promise<('a0, 'a1)> = "all" @val @scope("Promise") external all3: ((promise<'a0>, promise<'a1>, promise<'a2>)) => promise<('a0, 'a1, 'a2)> = "all" @@ -79,9 +84,11 @@ external all6: ( (promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>, promise<'a4>, promise<'a5>) ) => promise<('a0, 'a1, 'a2, 'a3, 'a4, 'a5)> = "all" -@val @scope("Promise") external race: array> => promise<'a> = "race" +@val @scope("Promise") +external race: array> => promise<'a> = "race" -@send external then_: (promise<'a>, 'a => promise<'b>) => promise<'b> = "then" +@send +external then_: (promise<'a>, 'a => promise<'b>) => promise<'b> = "then" let then_ = (arg1, obj) => then_(obj, arg1) @send diff --git a/packages/@rescript/runtime/Js_promise.resi b/packages/@rescript/runtime/Js_promise.resi new file mode 100644 index 0000000000..79a1c972ea --- /dev/null +++ b/packages/@rescript/runtime/Js_promise.resi @@ -0,0 +1,180 @@ +/* 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. */ + +/*** +Deprecation note: These bindings are pretty outdated and cannot be used properly +with the `->` operator. + +More details on proper Promise usage can be found here: +https://rescript-lang.org/docs/manual/latest/promise#promise-legacy +*/ + +@@warning("-103") + +@deprecated({ + reason: "Use `promise` directly instead.", + migrate: %replace.type(: promise), +}) +type t<+'a> = promise<'a> + +@deprecated({ + reason: "Use `exn` directly instead.", + migrate: %replace.type(: exn), +}) +type error = Js_promise2.error + +/* +## Examples + +```rescript +type error +``` +*/ + +@deprecated({ + reason: "Use `Promise.make` instead.", + migrate: Promise.make( + @apply.transforms(["labelledToUnlabelledArgumentsInFnDefinition"]) + %insert.unlabelledArgument(0), + ), +}) +@new +external make: ((~resolve: 'a => unit, ~reject: exn => unit) => unit) => promise<'a> = "Promise" + +/* `make (fun resolve reject -> .. )` */ +@deprecated({ + reason: "Use `Promise.resolve` instead.", + migrate: Promise.resolve(), +}) +@val +@scope("Promise") +external resolve: 'a => promise<'a> = "resolve" +@deprecated({ + reason: "Use `Promise.reject` instead.", + migrate: Promise.reject(), +}) +@val +@scope("Promise") +external reject: exn => promise<'a> = "reject" + +@deprecated({ + reason: "Use `Promise.all` instead.", + migrate: Promise.all(), +}) +@val +@scope("Promise") +external all: array> => promise> = "all" + +@deprecated({ + reason: "Use `Promise.all2` instead.", + migrate: Promise.all2(), +}) +@val +@scope("Promise") +external all2: ((promise<'a0>, promise<'a1>)) => promise<('a0, 'a1)> = "all" + +@deprecated({ + reason: "Use `Promise.all3` instead.", + migrate: Promise.all3(), +}) +@val +@scope("Promise") +external all3: ((promise<'a0>, promise<'a1>, promise<'a2>)) => promise<('a0, 'a1, 'a2)> = "all" + +@deprecated({ + reason: "Use `Promise.all4` instead.", + migrate: Promise.all4(), +}) +@val +@scope("Promise") +external all4: ((promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>)) => promise<( + 'a0, + 'a1, + 'a2, + 'a3, +)> = "all" + +@deprecated({ + reason: "Use `Promise.all5` instead.", + migrate: Promise.all5(), +}) +@val +@scope("Promise") +external all5: ((promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>, promise<'a4>)) => promise<( + 'a0, + 'a1, + 'a2, + 'a3, + 'a4, +)> = "all" + +@deprecated({ + reason: "Use `Promise.all6` instead.", + migrate: Promise.all6(), +}) +@val +@scope("Promise") +external all6: ( + (promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>, promise<'a4>, promise<'a5>) +) => promise<('a0, 'a1, 'a2, 'a3, 'a4, 'a5)> = "all" + +@deprecated({ + reason: "Use `Promise.race` instead.", + migrate: Promise.race(), +}) +@val +@scope("Promise") +external race: array> => promise<'a> = "race" + +@deprecated({ + reason: "Use `Promise.then` instead.", + migrate: Promise.then(), +}) +@deprecated({ + reason: "Use `Promise.then` instead.", + migrate: Promise.then(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), + migrateInPipeChain: Promise.then(%insert.unlabelledArgument(0)), +}) +let then_: ('a => promise<'b>, promise<'a>) => promise<'b> + +@deprecated({ + reason: "Use `Promise.catch` instead.", + migrate: Promise.catch(%insert.unlabelledArgument(1), %insert.unlabelledArgument(0)), + migrateInPipeChain: Promise.catch(%insert.unlabelledArgument(0)), +}) +let catch: (error => promise<'a>, promise<'a>) => promise<'a> +/* ` p|> catch handler` + Note in JS the returned promise type is actually runtime dependent, + if promise is rejected, it will pick the `handler` otherwise the original promise, + to make it strict we enforce reject handler + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch +*/ + +/* +let errorAsExn (x : error) (e : (exn ->'a option))= + if Caml_exceptions.isCamlExceptionOrOpenVariant (Obj.magic x ) then + e (Obj.magic x) + else None +[%bs.error? ] +*/ diff --git a/packages/@rescript/runtime/Js_promise2.res b/packages/@rescript/runtime/Js_promise2.res index 8bdaae73fe..2d3768600a 100644 --- a/packages/@rescript/runtime/Js_promise2.res +++ b/packages/@rescript/runtime/Js_promise2.res @@ -18,12 +18,17 @@ let catch: (promise<'a>, error => promise<'a>) => promise<'a> = %raw(` @new external make: ((~resolve: 'a => unit, ~reject: exn => unit) => unit) => promise<'a> = "Promise" -@val @scope("Promise") external resolve: 'a => promise<'a> = "resolve" -@val @scope("Promise") external reject: exn => promise<'a> = "reject" +@val @scope("Promise") +external resolve: 'a => promise<'a> = "resolve" + +@val @scope("Promise") +external reject: exn => promise<'a> = "reject" -@val @scope("Promise") external all: array> => promise> = "all" +@val @scope("Promise") +external all: array> => promise> = "all" -@val @scope("Promise") external all2: ((promise<'a0>, promise<'a1>)) => promise<('a0, 'a1)> = "all" +@val @scope("Promise") +external all2: ((promise<'a0>, promise<'a1>)) => promise<('a0, 'a1)> = "all" @val @scope("Promise") external all3: ((promise<'a0>, promise<'a1>, promise<'a2>)) => promise<('a0, 'a1, 'a2)> = "all" @@ -50,7 +55,8 @@ external all6: ( (promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>, promise<'a4>, promise<'a5>) ) => promise<('a0, 'a1, 'a2, 'a3, 'a4, 'a5)> = "all" -@val @scope("Promise") external race: array> => promise<'a> = "race" +@val @scope("Promise") +external race: array> => promise<'a> = "race" external unsafe_async: 'a => promise<'a> = "%identity" external unsafe_await: promise<'a> => 'a = "%await" diff --git a/packages/@rescript/runtime/Js_promise2.resi b/packages/@rescript/runtime/Js_promise2.resi new file mode 100644 index 0000000000..9be0adb6cd --- /dev/null +++ b/packages/@rescript/runtime/Js_promise2.resi @@ -0,0 +1,117 @@ +@deprecated({ + reason: "Use `promise` directly instead.", + migrate: %replace.type(: promise), +}) +type t<+'a> = promise<'a> +type error + +/** Type-safe t-first then */ +@deprecated({ + reason: "Use `Promise.then` instead.", + migrate: Promise.then(), +}) +let then: (promise<'a>, 'a => promise<'b>) => promise<'b> + +/** Type-safe t-first catch */ +@deprecated({ + reason: "Use `Promise.catch` instead.", + migrate: Promise.catch(), +}) +let catch: (promise<'a>, error => promise<'a>) => promise<'a> + +@deprecated({ + reason: "Use `Promise.make` instead.", + migrate: Promise.make( + @apply.transforms(["labelledToUnlabelledArgumentsInFnDefinition"]) + %insert.unlabelledArgument(0), + ), +}) +@new +external make: ((~resolve: 'a => unit, ~reject: exn => unit) => unit) => promise<'a> = "Promise" + +@deprecated({ + reason: "Use `Promise.resolve` instead.", + migrate: Promise.resolve(), +}) +@val +@scope("Promise") +external resolve: 'a => promise<'a> = "resolve" +@deprecated({ + reason: "Use `Promise.reject` instead.", + migrate: Promise.reject(), +}) +@val +@scope("Promise") +external reject: exn => promise<'a> = "reject" + +@deprecated({ + reason: "Use `Promise.all` instead.", + migrate: Promise.all(), +}) +@val +@scope("Promise") +external all: array> => promise> = "all" + +@deprecated({ + reason: "Use `Promise.all2` instead.", + migrate: Promise.all2(), +}) +@val +@scope("Promise") +external all2: ((promise<'a0>, promise<'a1>)) => promise<('a0, 'a1)> = "all" + +@deprecated({ + reason: "Use `Promise.all3` instead.", + migrate: Promise.all3(), +}) +@val +@scope("Promise") +external all3: ((promise<'a0>, promise<'a1>, promise<'a2>)) => promise<('a0, 'a1, 'a2)> = "all" + +@deprecated({ + reason: "Use `Promise.all4` instead.", + migrate: Promise.all4(), +}) +@val +@scope("Promise") +external all4: ((promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>)) => promise<( + 'a0, + 'a1, + 'a2, + 'a3, +)> = "all" + +@deprecated({ + reason: "Use `Promise.all5` instead.", + migrate: Promise.all5(), +}) +@val +@scope("Promise") +external all5: ((promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>, promise<'a4>)) => promise<( + 'a0, + 'a1, + 'a2, + 'a3, + 'a4, +)> = "all" + +@deprecated({ + reason: "Use `Promise.all6` instead.", + migrate: Promise.all6(), +}) +@val +@scope("Promise") +external all6: ( + (promise<'a0>, promise<'a1>, promise<'a2>, promise<'a3>, promise<'a4>, promise<'a5>) +) => promise<('a0, 'a1, 'a2, 'a3, 'a4, 'a5)> = "all" + +@deprecated({ + reason: "Use `Promise.race` instead.", + migrate: Promise.race(), +}) +@val +@scope("Promise") +external race: array> => promise<'a> = "race" + +external unsafe_async: 'a => promise<'a> = "%identity" +external unsafe_await: promise<'a> => 'a = "%await" diff --git a/packages/@rescript/runtime/Js_re.res b/packages/@rescript/runtime/Js_re.res index 41d57f0070..b275c56ddf 100644 --- a/packages/@rescript/runtime/Js_re.res +++ b/packages/@rescript/runtime/Js_re.res @@ -31,6 +31,10 @@ and subsequent uses will continue the search from the previous [`lastIndex`](). */ /** The RegExp object. */ +@deprecated({ + reason: "Use `RegExp.t` instead.", + migrate: %replace.type(: RegExp.t), +}) type t = Stdlib_RegExp.t /** The result of a executing a RegExp on a string. */ @@ -40,16 +44,31 @@ type result An `array` of the match and captures, the first is the full match and the remaining are the substring captures. */ +@deprecated({ + reason: "Use `RegExp.Result.matches` instead.", + migrate: RegExp.Result.matches(), +}) external captures: result => array> = "%identity" -@deprecated("Use Js.Re.captures instead") +@deprecated({ + reason: "Use `RegExp.Result.matches` instead.", + migrate: RegExp.Result.matches(), +}) external matches: result => array = "%identity" /** 0-based index of the match in the input string. */ +@deprecated({ + reason: "Use `RegExp.Result.index` instead.", + migrate: RegExp.Result.index(), +}) @get external index: result => int = "index" /** The original input string. */ +@deprecated({ + reason: "Use `RegExp.Result.input` instead.", + migrate: RegExp.Result.input(), +}) @get external input: result => string = "input" @@ -74,6 +93,10 @@ let firstReScriptFileExtension = (filename, content) => { firstReScriptFileExtension("School", "School.res School.resi Main.js School.bs.js") ``` */ +@deprecated({ + reason: "Use `RegExp.fromString` instead.", + migrate: RegExp.fromString(), +}) @new external fromString: string => t = "RegExp" @@ -89,18 +112,34 @@ Valid flags: - **u** unicode (es2015) - **y** sticky (es2015) */ +@deprecated({ + reason: "Use `RegExp.fromString` instead.", + migrate: RegExp.fromString(), +}) @new external fromStringWithFlags: (string, ~flags: string) => t = "RegExp" /** Returns the enabled flags as a string. */ +@deprecated({ + reason: "Use `RegExp.flags` instead.", + migrate: RegExp.flags(), +}) @get external flags: t => string = "flags" /** Returns a `bool` indicating whether the global flag is set. */ +@deprecated({ + reason: "Use `RegExp.global` instead.", + migrate: RegExp.global(), +}) @get external global: t => bool = "global" /** Returns a `bool` indicating whether the ignoreCase flag is set. */ +@deprecated({ + reason: "Use `RegExp.ignoreCase` instead.", + migrate: RegExp.ignoreCase(), +}) @get external ignoreCase: t => bool = "ignoreCase" @@ -132,26 +171,50 @@ See [`RegExp: lastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) on MDN. */ +@deprecated({ + reason: "Use `RegExp.lastIndex` instead.", + migrate: RegExp.lastIndex(), +}) @get external lastIndex: t => int = "lastIndex" /** Sets the index at which the next match will start its search from. */ +@deprecated({ + reason: "Use `RegExp.setLastIndex` instead.", + migrate: RegExp.setLastIndex(), +}) @set external setLastIndex: (t, int) => unit = "lastIndex" /** Returns a `bool` indicating whether the multiline flag is set. */ +@deprecated({ + reason: "Use `RegExp.multiline` instead.", + migrate: RegExp.multiline(), +}) @get external multiline: t => bool = "multiline" /** Returns the pattern as a `string`. */ +@deprecated({ + reason: "Use `RegExp.source` instead.", + migrate: RegExp.source(), +}) @get external source: t => string = "source" /** Returns a `bool` indicating whether the sticky flag is set. */ +@deprecated({ + reason: "Use `RegExp.sticky` instead.", + migrate: RegExp.sticky(), +}) @get external sticky: t => bool = "sticky" /** Returns a `bool` indicating whether the unicode flag is set. */ +@deprecated({ + reason: "Use `RegExp.unicode` instead.", + migrate: RegExp.unicode(), +}) @get external unicode: t => bool = "unicode" @@ -174,7 +237,12 @@ let result = Js.Re.exec_(re, "The Quick Brown Fox Jumps Over The Lazy Dog") See [`RegExp.prototype.exec()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) on MDN. */ -@send @return(null_to_opt) +@deprecated({ + reason: "Use `RegExp.exec` instead.", + migrate: RegExp.exec(), +}) +@send +@return(null_to_opt) external exec_: (t, string) => option = "exec" /** @@ -196,5 +264,9 @@ Js.log(str->startsWith("hello")) /* prints "true" */ See [`RegExp.prototype.test()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test) on MDN. */ +@deprecated({ + reason: "Use `RegExp.test` instead.", + migrate: RegExp.test(), +}) @send external test_: (t, string) => bool = "test" diff --git a/packages/@rescript/runtime/Js_result.res b/packages/@rescript/runtime/Js_result.res index 8cb2ab13f3..3b65dff42b 100644 --- a/packages/@rescript/runtime/Js_result.res +++ b/packages/@rescript/runtime/Js_result.res @@ -22,7 +22,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -@deprecated("Please use `Belt.Result.t` instead") +@deprecated({ + reason: "Use `result` directly instead", + migrate: %replace.type(: result), +}) type t<+'good, +'bad> = | Ok('good) | Error('bad) diff --git a/packages/@rescript/runtime/Js_result.resi b/packages/@rescript/runtime/Js_result.resi index 8cb2ab13f3..740fdc149c 100644 --- a/packages/@rescript/runtime/Js_result.resi +++ b/packages/@rescript/runtime/Js_result.resi @@ -22,7 +22,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -@deprecated("Please use `Belt.Result.t` instead") +@deprecated({ + reason: "Use `result` directly instead.", + migrate: %replace.type(: result), +}) type t<+'good, +'bad> = | Ok('good) | Error('bad) diff --git a/packages/@rescript/runtime/Js_set.res b/packages/@rescript/runtime/Js_set.res index bb195cd4f4..80d89dbb81 100644 --- a/packages/@rescript/runtime/Js_set.res +++ b/packages/@rescript/runtime/Js_set.res @@ -1,3 +1,7 @@ /*** ES6 Set API */ +@deprecated({ + reason: "Use `Set.t` instead.", + migrate: %replace.type(: Set.t), +}) type t<'a> = Stdlib_Set.t<'a> diff --git a/packages/@rescript/runtime/Js_string.res b/packages/@rescript/runtime/Js_string.res index 65fe1c674f..d0d0bc27a8 100644 --- a/packages/@rescript/runtime/Js_string.res +++ b/packages/@rescript/runtime/Js_string.res @@ -26,6 +26,10 @@ @@warning("-103") +@deprecated({ + reason: "Use `string` directly instead.", + migrate: %replace.type(: string), +}) type t = string /** @@ -38,6 +42,10 @@ Js.String2.make(3.5) == "3.5" Js.String2.make([1, 2, 3]) == "1,2,3" ``` */ +@deprecated({ + reason: "Use `String.make` instead.", + migrate: String.make(), +}) @val external make: 'a => t = "String" @@ -54,6 +62,10 @@ Js.String2.fromCharCode(0xd55c) == `한` Js.String2.fromCharCode(-64568) == `ψ` ``` */ +@deprecated({ + reason: "Use `String.fromCharCode` instead.", + migrate: String.fromCharCode(), +}) @val external fromCharCode: int => t = "String.fromCharCode" @@ -63,7 +75,12 @@ corresponding to the given numbers, using the same rules as `fromCharCode`. See [`String.fromCharCode`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) on MDN. */ -@val @variadic +@deprecated({ + reason: "Use `String.fromCharCodeMany` instead.", + migrate: String.fromCharCodeMany(), +}) +@val +@variadic external fromCharCodeMany: array => t = "String.fromCharCode" /** @@ -85,6 +102,10 @@ Js.String2.fromCodePoint(0xd55c) == `한` Js.String2.fromCodePoint(0x1f63a) == `😺` ``` */ +@deprecated({ + reason: "Use `String.fromCodePoint` instead.", + migrate: String.fromCodePoint(), +}) @val external fromCodePoint: int => t = "String.fromCodePoint" @@ -102,7 +123,12 @@ on MDN. Js.String2.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` ``` */ -@val @variadic +@deprecated({ + reason: "Use `String.fromCodePointMany` instead.", + migrate: String.fromCodePointMany(), +}) +@val +@variadic external fromCodePointMany: array => t = "String.fromCodePoint" /* String.raw: ES2015, meant to be used with template strings, not directly */ @@ -118,6 +144,10 @@ on MDN. Js.String2.length("abcd") == 4 ``` */ +@deprecated({ + reason: "Use `String.length` instead.", + migrate: String.length(), +}) @get external length: t => int = "length" @@ -134,6 +164,10 @@ Js.String2.get("Reason", 4) == "o" Js.String2.get(`Rẽasöń`, 5) == `ń` ``` */ +@deprecated({ + reason: "Use `String.get` instead.", + migrate: String.get(), +}) @get_index external get: (t, int) => t = "" @@ -461,6 +495,10 @@ on MDN. See also [Unicode technical report #15](https://unicode.org/reports/tr15/) for details. */ +@deprecated({ + reason: "Use `String.normalize` instead.", + migrate: String.normalize(), +}) @send external normalize: t => t = "normalize" @@ -929,6 +967,10 @@ Js.String.toLowerCase(`ΣΠ`) == `σπ` Js.String.toLowerCase(`ΠΣ`) == `πς` ``` */ +@deprecated({ + reason: "Use `String.toLowerCase` instead.", + migrate: String.toLowerCase(), +}) @send external toLowerCase: t => t = "toLowerCase" @@ -938,6 +980,10 @@ external toLowerCase: t => t = "toLowerCase" See [`String.toLocaleLowerCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase) on MDN. */ +@deprecated({ + reason: "Use `String.toLocaleLowerCase` instead.", + migrate: String.toLocaleLowerCase(), +}) @send external toLocaleLowerCase: t => t = "toLocaleLowerCase" @@ -958,6 +1004,10 @@ Js.String.toUpperCase(`Straße`) == `STRASSE` Js.String.toUpperCase(`πς`) == `ΠΣ` ``` */ +@deprecated({ + reason: "Use `String.toUpperCase` instead.", + migrate: String.toUpperCase(), +}) @send external toUpperCase: t => t = "toUpperCase" @@ -967,6 +1017,10 @@ external toUpperCase: t => t = "toUpperCase" See [`String.to:LocaleUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase) on MDN. */ +@deprecated({ + reason: "Use `String.toLocaleUpperCase` instead.", + migrate: String.toLocaleUpperCase(), +}) @send external toLocaleUpperCase: t => t = "toLocaleUpperCase" @@ -984,6 +1038,10 @@ Js.String.trim(" abc def ") == "abc def" Js.String.trim("\n\r\t abc def \n\n\t\r ") == "abc def" ``` */ +@deprecated({ + reason: "Use `String.trim` instead.", + migrate: String.trim(), +}) @send external trim: t => t = "trim" @@ -1037,4 +1095,7 @@ let arr = Js.Array2.fromMap(Js.String.castToArrayLike(s), x => x) arr == ["a", "b", "c", "d", "e"] ``` */ +@deprecated( + "This has been deprecated and will be removed in v13. Use functions from the `String` module instead." +) external castToArrayLike: t => Js_array2.array_like = "%identity" diff --git a/packages/@rescript/runtime/Js_string2.res b/packages/@rescript/runtime/Js_string2.res index 3485edd501..3fbdda4f9f 100644 --- a/packages/@rescript/runtime/Js_string2.res +++ b/packages/@rescript/runtime/Js_string2.res @@ -24,6 +24,10 @@ /*** Provide bindings to JS string. Optimized for pipe-first. */ +@deprecated({ + reason: "Use `string` directly instead.", + migrate: %replace.type(: string), +}) type t = string /** @@ -36,6 +40,10 @@ Js.String2.make(3.5) == "3.5" Js.String2.make([1, 2, 3]) == "1,2,3" ``` */ +@deprecated({ + reason: "Use `String.make` instead", + migrate: String.make(), +}) @val external make: 'a => t = "String" @@ -57,6 +65,10 @@ Js.String2.fromCharCode(0xd55c) == `한` Js.String2.fromCharCode(-64568) == `ψ` ``` */ +@deprecated({ + reason: "Use `String.fromCharCode` instead", + migrate: String.fromCharCode(), +}) @val external fromCharCode: int => t = "String.fromCharCode" @@ -67,7 +79,12 @@ corresponding to the given numbers, using the same rules as `fromCharCode`. See [`String.fromCharCode`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) on MDN. */ -@val @variadic +@deprecated({ + reason: "Use `String.fromCharCodeMany` instead", + migrate: String.fromCharCodeMany(), +}) +@val +@variadic external fromCharCodeMany: array => t = "String.fromCharCode" /** @@ -89,6 +106,10 @@ Js.String2.fromCodePoint(0xd55c) == `한` Js.String2.fromCodePoint(0x1f63a) == `😺` ``` */ +@deprecated({ + reason: "Use `String.fromCodePoint` instead", + migrate: String.fromCodePoint(), +}) @val external fromCodePoint: int => t = "String.fromCodePoint" @@ -106,7 +127,12 @@ on MDN. Js.String2.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` ``` */ -@val @variadic +@deprecated({ + reason: "Use `String.fromCodePointMany` instead", + migrate: String.fromCodePointMany(), +}) +@val +@variadic external fromCodePointMany: array => t = "String.fromCodePoint" /* String.raw: ES2015, meant to be used with template strings, not directly */ @@ -123,6 +149,10 @@ on MDN. Js.String2.length("abcd") == 4 ``` */ +@deprecated({ + reason: "Use `String.length` instead", + migrate: String.length(), +}) @get external length: t => int = "length" @@ -139,6 +169,10 @@ Js.String2.get("Reason", 4) == "o" Js.String2.get(`Rẽasöń`, 5) == `ń` ``` */ +@deprecated({ + reason: "Use `String.getUnsafe` instead. Or use `String.get` for a safe version that returns an option.", + migrate: String.getUnsafe(), +}) @get_index external get: (t, int) => t = "" @@ -159,6 +193,10 @@ Js.String2.charAt("Reason", 12) == "" Js.String2.charAt(`Rẽasöń`, 5) == `ń` ``` */ +@deprecated({ + reason: "Use `String.charAt` instead", + migrate: String.charAt(), +}) @send external charAt: (t, int) => t = "charAt" @@ -179,6 +217,10 @@ Js.String2.charCodeAt(`😺`, 0) == 0xd83d->Belt.Int.toFloat Js.String2.codePointAt(`😺`, 0) == Some(0x1f63a) ``` */ +@deprecated({ + reason: "Use `String.charCodeAt` instead", + migrate: String.charCodeAt(), +}) @send external charCodeAt: (t, int) => float = "charCodeAt" @@ -198,6 +240,10 @@ Js.String2.codePointAt(`¿😺?`, 1) == Some(0x1f63a) Js.String2.codePointAt("abc", 5) == None ``` */ +@deprecated({ + reason: "Use `String.codePointAt` instead", + migrate: String.codePointAt(), +}) @send external codePointAt: (t, int) => option = "codePointAt" @@ -214,6 +260,10 @@ on MDN. Js.String2.concat("cow", "bell") == "cowbell" ``` */ +@deprecated({ + reason: "Use `String.concat` instead", + migrate: String.concat(), +}) @send external concat: (t, t) => t = "concat" @@ -230,7 +280,12 @@ on MDN. Js.String2.concatMany("1st", ["2nd", "3rd", "4th"]) == "1st2nd3rd4th" ``` */ -@send @variadic +@deprecated({ + reason: "Use `String.concatMany` instead", + migrate: String.concatMany(), +}) +@send +@variadic external concatMany: (t, array) => t = "concat" /** @@ -247,6 +302,10 @@ Js.String2.endsWith("ReScript", "Script") == true Js.String2.endsWith("C++", "Script") == false ``` */ +@deprecated({ + reason: "Use `String.endsWith` instead", + migrate: String.endsWith(), +}) @send external endsWith: (t, t) => bool = "endsWith" @@ -268,6 +327,10 @@ Js.String2.endsWithFrom("abcde", "cde", 99) == true Js.String2.endsWithFrom("example.dat", "ple", 7) == true ``` */ +@deprecated({ + reason: "Use `String.endsWithFrom` instead", + migrate: String.endsWithFrom(), +}) @send external endsWithFrom: (t, t, int) => bool = "endsWith" @@ -287,6 +350,10 @@ Js.String2.includes("programmer", "pro") == true Js.String2.includes("programmer.dat", "xyz") == false ``` */ +@deprecated({ + reason: "Use `String.includes` instead", + migrate: String.includes(), +}) @send external includes: (t, t) => bool = "includes" @@ -306,6 +373,10 @@ Js.String2.includesFrom("programmer", "gram", 4) == false Js.String2.includesFrom(`대한민국`, `한`, 1) == true ``` */ +@deprecated({ + reason: "Use `String.includesFrom` instead", + migrate: String.includesFrom(), +}) @send external includesFrom: (t, t, int) => bool = "includes" @@ -325,6 +396,10 @@ Js.String2.indexOf("beekeeper", "ee") == 1 Js.String2.indexOf("bookseller", "xyz") == -1 ``` */ +@deprecated({ + reason: "Use `String.indexOf` instead", + migrate: String.indexOf(), +}) @send external indexOf: (t, t) => int = "indexOf" @@ -346,6 +421,10 @@ Js.String2.indexOfFrom("bookseller", "sell", 2) == 4 Js.String2.indexOfFrom("bookseller", "sell", 5) == -1 ``` */ +@deprecated({ + reason: "Use `String.indexOfFrom` instead", + migrate: String.indexOfFrom(), +}) @send external indexOfFrom: (t, t, int) => int = "indexOf" @@ -366,6 +445,10 @@ Js.String2.lastIndexOf("beekeeper", "ee") == 4 Js.String2.lastIndexOf("abcdefg", "xyz") == -1 ``` */ +@deprecated({ + reason: "Use `String.lastIndexOf` instead", + migrate: String.lastIndexOf(), +}) @send external lastIndexOf: (t, t) => int = "lastIndexOf" @@ -387,6 +470,10 @@ Js.String2.lastIndexOfFrom("beekeeper", "ee", 3) == 1 Js.String2.lastIndexOfFrom("abcdefg", "xyz", 4) == -1 ``` */ +@deprecated({ + reason: "Use `String.lastIndexOfFrom` instead", + migrate: String.lastIndexOfFrom(), +}) @send external lastIndexOfFrom: (t, t, int) => int = "lastIndexOf" @@ -409,6 +496,10 @@ Js.String2.localeCompare("cat", "cat") == 0.0 Js.String2.localeCompare("CAT", "cat") > 0.0 ``` */ +@deprecated({ + reason: "Use `String.localeCompare` instead", + migrate: String.localeCompare(), +}) @send external localeCompare: (t, t) => float = "localeCompare" @@ -434,7 +525,12 @@ Js.String2.match_("Today is 2018-04-05.", /(\d+)-(\d+)-(\d+)/) == Js.String2.match_("The large container.", /b[aeiou]g/) == None ``` */ -@send @return({null_to_opt: null_to_opt}) +@deprecated({ + reason: "Use `String.match` instead", + migrate: String.match(), +}) +@send +@return({null_to_opt: null_to_opt}) external match_: (t, Js_re.t) => option>> = "match" /** @@ -448,6 +544,10 @@ See [`String.normalize`](https://developer.mozilla.org/en-US/docs/Web/JavaScript on MDN. See also [Unicode technical report #15](https://unicode.org/reports/tr15/) for details. */ +@deprecated({ + reason: "Use `String.normalize` instead", + migrate: String.normalize(), +}) @send external normalize: t => t = "normalize" @@ -462,6 +562,10 @@ specified form of normalization, which may be one of: See [`String.normalize`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize) on MDN. See also [Unicode technical report #15](https://unicode.org/reports/tr15/) for details. */ +@deprecated({ + reason: "Use `String.normalizeByForm` instead", + migrate: String.normalizeByForm(), +}) @send external normalizeByForm: (t, t) => t = "normalize" @@ -479,6 +583,10 @@ Js.String2.repeat("ha", 3) == "hahaha" Js.String2.repeat("empty", 0) == "" ``` */ +@deprecated({ + reason: "Use `String.repeat` instead", + migrate: String.repeat(), +}) @send external repeat: (t, int) => t = "repeat" @@ -498,6 +606,10 @@ Js.String2.replace("old string", "old", "new") == "new string" Js.String2.replace("the cat and the dog", "the", "this") == "this cat and the dog" ``` */ +@deprecated({ + reason: "Use `String.replace` instead", + migrate: String.replace(), +}) @send external replace: (t, t, t) => t = "replace" @@ -515,6 +627,10 @@ Js.String2.replaceByRe("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" Js.String2.replaceByRe("Juan Fulano", /(\w+) (\w+)/, "$2, $1") == "Fulano, Juan" ``` */ +@deprecated({ + reason: "Use `String.replaceRegExp` instead", + migrate: String.replaceRegExp(), +}) @send external replaceByRe: (t, Js_re.t, t) => t = "replace" @@ -537,6 +653,10 @@ let matchFn = (matchPart, _offset, _wholeString) => Js.String2.toUpperCase(match Js.String2.unsafeReplaceBy0(str, re, matchFn) == "bEAUtIfUl vOwEls" ``` */ +@deprecated({ + reason: "Use `String.replaceRegExpBy0Unsafe` instead", + migrate: String.replaceRegExpBy0Unsafe(), +}) @send external unsafeReplaceBy0: (t, Js_re.t, (t, int, t) => t) => t = "replace" @@ -562,6 +682,10 @@ let matchFn = (_match, part1, _offset, _wholeString) => { Js.String2.unsafeReplaceBy1(str, re, matchFn) == "Jony is 41" ``` */ +@deprecated({ + reason: "Use `String.replaceRegExpBy1Unsafe` instead", + migrate: String.replaceRegExpBy1Unsafe(), +}) @send external unsafeReplaceBy1: (t, Js_re.t, (t, t, int, t) => t) => t = "replace" @@ -590,6 +714,10 @@ let matchFn = (_match, p1, p2, _offset, _wholeString) => { Js.String2.unsafeReplaceBy2(str, re, matchFn) == "42" ``` */ +@deprecated({ + reason: "Use `String.replaceRegExpBy2Unsafe` instead", + migrate: String.replaceRegExpBy2Unsafe(), +}) @send external unsafeReplaceBy2: (t, Js_re.t, (t, t, t, int, t) => t) => t = "replace" @@ -603,6 +731,10 @@ matched. See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) on MDN. */ +@deprecated({ + reason: "Use `String.replaceRegExpBy3Unsafe` instead", + migrate: String.replaceRegExpBy3Unsafe(), +}) @send external unsafeReplaceBy3: (t, Js_re.t, (t, t, t, t, int, t) => t) => t = "replace" @@ -620,6 +752,10 @@ Js.String2.search("testing 1 2 3", /\d+/) == 8 Js.String2.search("no numbers", /\d+/) == -1 ``` */ +@deprecated({ + reason: "Use `String.search` instead", + migrate: String.search(), +}) @send external search: (t, Js_re.t) => int = "search" @@ -641,6 +777,13 @@ Js.String2.slice("abcdefg", ~from=-4, ~to_=-2) == "de" Js.String2.slice("abcdefg", ~from=5, ~to_=1) == "" ``` */ +@deprecated({ + reason: "Use `String.slice` instead", + migrate: String.slice( + ~start=%insert.labelledArgument("from"), + ~end=%insert.labelledArgument("to_"), + ), +}) @send external slice: (t, ~from: int, ~to_: int) => t = "slice" @@ -660,6 +803,10 @@ Js.String2.sliceToEnd("abcdefg", ~from=-2) == "fg" Js.String2.sliceToEnd("abcdefg", ~from=7) == "" ``` */ +@deprecated({ + reason: "Use `String.slice` instead", + migrate: String.slice(~start=%insert.labelledArgument("from")), +}) @send external sliceToEnd: (t, ~from: int) => t = "slice" @@ -679,6 +826,10 @@ Js.String2.split("good::bad as great::awful", "::") == ["good", "bad as great", Js.String2.split("has-no-delimiter", ";") == ["has-no-delimiter"] ``` */ +@deprecated({ + reason: "Use `String.split` instead", + migrate: String.split(), +}) @send external split: (t, t) => array = "split" @@ -691,6 +842,10 @@ splitAtMost "ant/bee/cat/dog/elk" "/" ~limit: 0 = [| |];; splitAtMost "ant/bee/cat/dog/elk" "/" ~limit: 9 = [|"ant"; "bee"; "cat"; "dog"; "elk"|];; ``` */ +@deprecated({ + reason: "Use `String.splitAtMost` instead", + migrate: String.splitAtMost(), +}) @send external splitAtMost: (t, t, ~limit: int) => array = "split" @@ -712,6 +867,10 @@ Js.String2.splitByRe("art; bed , cog ;dad", /\s*[,;]\s*TODO/) == [ ] ``` */ +@deprecated({ + reason: "Use `String.splitByRegExp` instead", + migrate: String.splitByRegExp(), +}) @send external splitByRe: (t, Js_re.t) => array> = "split" @@ -743,6 +902,10 @@ Js.String2.splitByReAtMost("one: two: three: four", /\s*:\s*TODO/, ~limit=8) == ] ``` */ +@deprecated({ + reason: "Use `String.splitByRegExpAtMost` instead", + migrate: String.splitByRegExpAtMost(), +}) @send external splitByReAtMost: (t, Js_re.t, ~limit: int) => array> = "split" @@ -761,6 +924,10 @@ Js.String2.startsWith("ReScript", "") == true Js.String2.startsWith("JavaScript", "Re") == false ``` */ +@deprecated({ + reason: "Use `String.startsWith` instead", + migrate: String.startsWith(), +}) @send external startsWith: (t, t) => bool = "startsWith" @@ -780,6 +947,10 @@ Js.String2.startsWithFrom("ReScript", "", 2) == true Js.String2.startsWithFrom("JavaScript", "Scri", 2) == false ``` */ +@deprecated({ + reason: "Use `String.startsWithFrom` instead", + migrate: String.startsWithFrom(), +}) @send external startsWithFrom: (t, t, int) => bool = "startsWith" @@ -803,7 +974,7 @@ Js.String2.substr("abcdefghij", ~from=-3) == "hij" Js.String2.substr("abcdefghij", ~from=12) == "" ``` */ -@send +@deprecated("Use `String.substring` instead") @send external substr: (t, ~from: int) => t = "substr" /** @@ -827,7 +998,7 @@ Js.String2.substrAtMost("abcdefghij", ~from=-3, ~length=4) == "hij" Js.String2.substrAtMost("abcdefghij", ~from=12, ~length=2) == "" ``` */ -@send +@deprecated("Use `String.substringAtMost` instead") @send external substrAtMost: (t, ~from: int, ~length: int) => t = "substr" /** @@ -847,6 +1018,13 @@ Js.String2.substring("playground", ~from=6, ~to_=3) == "ygr" Js.String2.substring("playground", ~from=4, ~to_=12) == "ground" ``` */ +@deprecated({ + reason: "Use `String.substring` instead", + migrate: String.substring( + ~start=%insert.labelledArgument("from"), + ~end=%insert.labelledArgument("to_"), + ), +}) @send external substring: (t, ~from: int, ~to_: int) => t = "substring" @@ -866,6 +1044,10 @@ Js.String2.substringToEnd("playground", ~from=-3) == "playground" Js.String2.substringToEnd("playground", ~from=12) == "" ``` */ +@deprecated({ + reason: "Use `String.substringToEnd` instead", + migrate: String.substringToEnd(~start=%insert.labelledArgument("from")), +}) @send external substringToEnd: (t, ~from: int) => t = "substring" @@ -887,6 +1069,10 @@ Js.String2.toLowerCase(`ΣΠ`) == `σπ` Js.String2.toLowerCase(`ΠΣ`) == `πς` ``` */ +@deprecated({ + reason: "Use `String.toLowerCase` instead", + migrate: String.toLowerCase(), +}) @send external toLowerCase: t => t = "toLowerCase" @@ -895,6 +1081,10 @@ external toLowerCase: t => t = "toLowerCase" See [`String.toLocaleLowerCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase) on MDN. */ +@deprecated({ + reason: "Use `String.toLocaleLowerCase` instead", + migrate: String.toLocaleLowerCase(), +}) @send external toLocaleLowerCase: t => t = "toLocaleLowerCase" @@ -915,6 +1105,10 @@ Js.String2.toUpperCase(`Straße`) == `STRASSE` Js.String2.toUpperCase(`πς`) == `ΠΣ` ``` */ +@deprecated({ + reason: "Use `String.toUpperCase` instead", + migrate: String.toUpperCase(), +}) @send external toUpperCase: t => t = "toUpperCase" @@ -923,6 +1117,10 @@ external toUpperCase: t => t = "toUpperCase" See [`String.to:LocaleUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase) on MDN. */ +@deprecated({ + reason: "Use `String.toLocaleUpperCase` instead", + migrate: String.toLocaleUpperCase(), +}) @send external toLocaleUpperCase: t => t = "toLocaleUpperCase" @@ -940,6 +1138,10 @@ Js.String2.trim(" abc def ") == "abc def" Js.String2.trim("\n\r\t abc def \n\n\t\r ") == "abc def" ``` */ +@deprecated({ + reason: "Use `String.trim` instead", + migrate: String.trim(), +}) @send external trim: t => t = "trim" @@ -959,7 +1161,7 @@ on MDN. Js.String2.anchor("Page One", "page1") == "Page One" ``` */ -@send +@deprecated("This function has been removed from the relevant web standards.") @send external anchor: (t, t) => t = "anchor" /** @@ -975,7 +1177,7 @@ on MDN. Js.String2.link("Go to page two", "page2.html") == "Go to page two" ``` */ -@send +@deprecated("This function has been removed from the relevant web standards.") @send external link: (t, t) => t = "link" /* FIXME: we should not encourage people to use [%identity], better @@ -994,4 +1196,8 @@ let arr = Js.Array2.fromMap(Js.String2.castToArrayLike(s), x => x) arr == ["a", "b", "c", "d", "e"] ``` */ +@deprecated({ + reason: "Use `Array.fromString` instead", + migrate: Array.fromString(), +}) external castToArrayLike: t => Js_array2.array_like = "%identity" diff --git a/packages/@rescript/runtime/Js_typed_array.res b/packages/@rescript/runtime/Js_typed_array.res index 0df3c01515..c0a595ea74 100644 --- a/packages/@rescript/runtime/Js_typed_array.res +++ b/packages/@rescript/runtime/Js_typed_array.res @@ -30,7 +30,15 @@ JavaScript Typed Array API @@warning("-103") +@deprecated({ + reason: "Use `ArrayBuffer.t` instead.", + migrate: %replace.type(: ArrayBuffer.t), +}) type array_buffer = Js_typed_array2.array_buffer + +@deprecated( + "This has been deprecated and will be removed in v13. Use functions and types from the `TypedArray` module instead." +) type array_like<'a> = Js_typed_array2.array_like<'a> module type Type = { @@ -102,6 +110,10 @@ module type S = { /* Accessor functions */ // @bs.send.pipe(: t) /** ES2016 */ + @deprecated({ + reason: "Use `TypedArray.includes` instead.", + migrate: TypedArray.includes(), + }) external includes: elt => bool = "includes" // @bs.send.pipe(: t) external indexOf: elt => int = "indexOf" @@ -189,12 +201,25 @@ module Int8Array = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ // @bs.send.pipe(: t) external copyWithin: (~to_: int) => t = "copyWithin" // @bs.send.pipe(: t) external copyWithinFrom: (~to_: int, ~from: int) => t = "copyWithin" // @bs.send.pipe(: t) + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) external copyWithinFromRange: (~to_: int, ~start: int, ~end_: int) => t = "copyWithin" // @bs.send.pipe(: t) external fillInPlace: elt => t = "fill" @@ -218,14 +243,16 @@ module Int8Array = { // @bs.send.pipe(: t) external lastIndexOf: elt => int = "lastIndexOf" // @bs.send.pipe(: t) external lastIndexOfFrom: (elt, ~from: int) => int = "lastIndexOf" - // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ - external slice: (~start: int, ~end_: int) => t = "slice" + @deprecated("Use `TypedArray.slice` instead.") + external // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + slice: (~start: int, ~end_: int) => t = "slice" // @bs.send.pipe(: t) external copy: t = "slice" - // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" + @deprecated("Use `TypedArray.sliceToEnd` instead.") + external // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ - external subarray: (~start: int, ~end_: int) => t = "subarray" + subarray: (~start: int, ~end_: int) => t = "subarray" // @bs.send.pipe(: t) external subarrayFrom: int => t = "subarray" @@ -267,9 +294,19 @@ module Int8Array = { // @bs.send.pipe(: t) external some: ((. elt) => bool) => bool = "some" // @bs.send.pipe(: t) external somei: ((. elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Int8Array.BYTES_PER_ELEMENT" - - @new external make: array => t = "Int8Array" + @deprecated({ + reason: "Use `Int8Array.Constants.bytesPerElement` instead.", + migrate: Int8Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Int8Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Int8Array.fromArray` instead.", + migrate: Int8Array.fromArray(), + }) + @new + external make: array => t = "Int8Array" /** can throw */ @new external fromBuffer: array_buffer => t = "Int8Array" @@ -279,19 +316,39 @@ module Int8Array = { param offset is in bytes */ - @new - external fromBufferOffset: (array_buffer, int) => t = "Int8Array" + @deprecated({ + reason: "Use `Int8Array.fromBufferToEnd` instead.", + migrate: Int8Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) + @new external fromBufferOffset: (array_buffer, int) => t = "Int8Array" /** throw Js.Exn.Error throws Js exception param offset is in bytes, length in elements */ + @deprecated({ + reason: "Use `Int8Array.fromBufferWithRange` instead.", + migrate: Int8Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) @new external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Int8Array" - @new external fromLength: int => t = "Int8Array" - @val external from: array_like => t = "Int8Array.from" + @deprecated({ + reason: "Use `Int8Array.fromLength` instead.", + migrate: Int8Array.fromLength(), + }) + @new + external fromLength: int => t = "Int8Array" + @deprecated({ + reason: "Use `Int8Array.fromArrayLikeOrIterable` instead.", + migrate: Int8Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Int8Array.from" /* *Array.of is redundant, use make */ } @@ -313,12 +370,25 @@ module Uint8Array = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ // @bs.send.pipe(: t) external copyWithin: (~to_: int) => t = "copyWithin" // @bs.send.pipe(: t) external copyWithinFrom: (~to_: int, ~from: int) => t = "copyWithin" // @bs.send.pipe(: t) + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) external copyWithinFromRange: (~to_: int, ~start: int, ~end_: int) => t = "copyWithin" // @bs.send.pipe(: t) external fillInPlace: elt => t = "fill" @@ -343,12 +413,28 @@ module Uint8Array = { // @bs.send.pipe(: t) external lastIndexOfFrom: (elt, ~from: int) => int = "lastIndexOf" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) external slice: (~start: int, ~end_: int) => t = "slice" // @bs.send.pipe(: t) external copy: t = "slice" // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) external subarray: (~start: int, ~end_: int) => t = "subarray" // @bs.send.pipe(: t) external subarrayFrom: int => t = "subarray" @@ -391,9 +477,19 @@ module Uint8Array = { // @bs.send.pipe(: t) external some: ((. elt) => bool) => bool = "some" // @bs.send.pipe(: t) external somei: ((. elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Uint8Array.BYTES_PER_ELEMENT" - - @new external make: array => t = "Uint8Array" + @deprecated({ + reason: "Use `Uint8Array.Constants.bytesPerElement` instead.", + migrate: Uint8Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Uint8Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Uint8Array.fromArray` instead.", + migrate: Uint8Array.fromArray(), + }) + @new + external make: array => t = "Uint8Array" /** can throw */ @new external fromBuffer: array_buffer => t = "Uint8Array" @@ -403,19 +499,39 @@ module Uint8Array = { **param** offset is in bytes */ - @new - external fromBufferOffset: (array_buffer, int) => t = "Uint8Array" + @deprecated({ + reason: "Use `Uint8Array.fromBufferToEnd` instead.", + migrate: Uint8Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) + @new external fromBufferOffset: (array_buffer, int) => t = "Uint8Array" /** **throw** Js.Exn.Error throws Js exception **param** offset is in bytes, length in elements */ + @deprecated({ + reason: "Use `Uint8Array.fromBufferWithRange` instead.", + migrate: Uint8Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) @new external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Uint8Array" - @new external fromLength: int => t = "Uint8Array" - @val external from: array_like => t = "Uint8Array.from" + @deprecated({ + reason: "Use `Uint8Array.fromLength` instead.", + migrate: Uint8Array.fromLength(), + }) + @new + external fromLength: int => t = "Uint8Array" + @deprecated({ + reason: "Use `Uint8Array.fromArrayLikeOrIterable` instead.", + migrate: Uint8Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Uint8Array.from" /* *Array.of is redundant, use make */ } @@ -437,12 +553,25 @@ module Uint8ClampedArray = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ // @bs.send.pipe(: t) external copyWithin: (~to_: int) => t = "copyWithin" // @bs.send.pipe(: t) external copyWithinFrom: (~to_: int, ~from: int) => t = "copyWithin" // @bs.send.pipe(: t) + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) external copyWithinFromRange: (~to_: int, ~start: int, ~end_: int) => t = "copyWithin" // @bs.send.pipe(: t) external fillInPlace: elt => t = "fill" @@ -467,12 +596,20 @@ module Uint8ClampedArray = { // @bs.send.pipe(: t) external lastIndexOfFrom: (elt, ~from: int) => int = "lastIndexOf" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) external slice: (~start: int, ~end_: int) => t = "slice" // @bs.send.pipe(: t) external copy: t = "slice" // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) external subarray: (~start: int, ~end_: int) => t = "subarray" // @bs.send.pipe(: t) external subarrayFrom: int => t = "subarray" @@ -515,9 +652,19 @@ module Uint8ClampedArray = { // @bs.send.pipe(: t) external some: ((. elt) => bool) => bool = "some" // @bs.send.pipe(: t) external somei: ((. elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Uint8ClampedArray.BYTES_PER_ELEMENT" - - @new external make: array => t = "Uint8ClampedArray" + @deprecated({ + reason: "Use `Uint8ClampedArray.Constants.bytesPerElement` instead.", + migrate: Uint8ClampedArray.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Uint8ClampedArray.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Uint8ClampedArray.fromArray` instead.", + migrate: Uint8ClampedArray.fromArray(), + }) + @new + external make: array => t = "Uint8ClampedArray" /** can throw */ @new external fromBuffer: array_buffer => t = "Uint8ClampedArray" @@ -527,19 +674,39 @@ module Uint8ClampedArray = { **param** offset is in bytes */ - @new - external fromBufferOffset: (array_buffer, int) => t = "Uint8ClampedArray" + @deprecated({ + reason: "Use `Uint8ClampedArray.fromBufferToEnd` instead.", + migrate: Uint8ClampedArray.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) + @new external fromBufferOffset: (array_buffer, int) => t = "Uint8ClampedArray" /** **throw** Js.Exn.Error throws Js exception **param** offset is in bytes, length in elements */ + @deprecated({ + reason: "Use `Uint8ClampedArray.fromBufferWithRange` instead.", + migrate: Uint8ClampedArray.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) @new external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Uint8ClampedArray" - @new external fromLength: int => t = "Uint8ClampedArray" - @val external from: array_like => t = "Uint8ClampedArray.from" + @deprecated({ + reason: "Use `Uint8ClampedArray.fromLength` instead.", + migrate: Uint8ClampedArray.fromLength(), + }) + @new + external fromLength: int => t = "Uint8ClampedArray" + @deprecated({ + reason: "Use `Uint8ClampedArray.fromArrayLikeOrIterable` instead.", + migrate: Uint8ClampedArray.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Uint8ClampedArray.from" /* *Array.of is redundant, use make */ } @@ -561,12 +728,25 @@ module Int16Array = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ // @bs.send.pipe(: t) external copyWithin: (~to_: int) => t = "copyWithin" // @bs.send.pipe(: t) external copyWithinFrom: (~to_: int, ~from: int) => t = "copyWithin" // @bs.send.pipe(: t) + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) external copyWithinFromRange: (~to_: int, ~start: int, ~end_: int) => t = "copyWithin" // @bs.send.pipe(: t) external fillInPlace: elt => t = "fill" @@ -591,12 +771,20 @@ module Int16Array = { // @bs.send.pipe(: t) external lastIndexOfFrom: (elt, ~from: int) => int = "lastIndexOf" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) external slice: (~start: int, ~end_: int) => t = "slice" // @bs.send.pipe(: t) external copy: t = "slice" // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) external subarray: (~start: int, ~end_: int) => t = "subarray" // @bs.send.pipe(: t) external subarrayFrom: int => t = "subarray" @@ -639,11 +827,25 @@ module Int16Array = { // @bs.send.pipe(: t) external some: ((. elt) => bool) => bool = "some" // @bs.send.pipe(: t) external somei: ((. elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Int16Array.BYTES_PER_ELEMENT" - - @new external make: array => t = "Int16Array" + @deprecated({ + reason: "Use `Int16Array.Constants.bytesPerElement` instead.", + migrate: Int16Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Int16Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Int16Array.fromArray` instead.", + migrate: Int16Array.fromArray(), + }) + @new + external make: array => t = "Int16Array" /** can throw */ @new + @deprecated({ + reason: "Use `Int16Array.fromBuffer` instead.", + migrate: Int16Array.fromBuffer(), + }) external fromBuffer: array_buffer => t = "Int16Array" /** @@ -652,6 +854,10 @@ module Int16Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Int16Array.fromBufferToEnd` instead.", + migrate: Int16Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Int16Array" /** @@ -660,10 +866,27 @@ module Int16Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Int16Array.fromBufferWithRange` instead.", + migrate: Int16Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Int16Array" - @new external fromLength: int => t = "Int16Array" - @val external from: array_like => t = "Int16Array.from" + @deprecated({ + reason: "Use `Int16Array.fromLength` instead.", + migrate: Int16Array.fromLength(), + }) + @new + external fromLength: int => t = "Int16Array" + @deprecated({ + reason: "Use `Int16Array.fromArrayLikeOrIterable` instead.", + migrate: Int16Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Int16Array.from" /* *Array.of is redundant, use make */ } @@ -685,12 +908,25 @@ module Uint16Array = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ // @bs.send.pipe(: t) external copyWithin: (~to_: int) => t = "copyWithin" // @bs.send.pipe(: t) external copyWithinFrom: (~to_: int, ~from: int) => t = "copyWithin" // @bs.send.pipe(: t) + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) external copyWithinFromRange: (~to_: int, ~start: int, ~end_: int) => t = "copyWithin" // @bs.send.pipe(: t) external fillInPlace: elt => t = "fill" @@ -715,12 +951,20 @@ module Uint16Array = { // @bs.send.pipe(: t) external lastIndexOfFrom: (elt, ~from: int) => int = "lastIndexOf" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) external slice: (~start: int, ~end_: int) => t = "slice" // @bs.send.pipe(: t) external copy: t = "slice" // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) external subarray: (~start: int, ~end_: int) => t = "subarray" // @bs.send.pipe(: t) external subarrayFrom: int => t = "subarray" @@ -763,11 +1007,25 @@ module Uint16Array = { // @bs.send.pipe(: t) external some: ((. elt) => bool) => bool = "some" // @bs.send.pipe(: t) external somei: ((. elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Uint16Array.BYTES_PER_ELEMENT" - - @new external make: array => t = "Uint16Array" + @deprecated({ + reason: "Use `Uint16Array.Constants.bytesPerElement` instead.", + migrate: Uint16Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Uint16Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Uint16Array.fromArray` instead.", + migrate: Uint16Array.fromArray(), + }) + @new + external make: array => t = "Uint16Array" /** can throw */ @new + @deprecated({ + reason: "Use `Uint16Array.fromBuffer` instead.", + migrate: Uint16Array.fromBuffer(), + }) external fromBuffer: array_buffer => t = "Uint16Array" /** @@ -776,6 +1034,10 @@ module Uint16Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Uint16Array.fromBufferToEnd` instead.", + migrate: Uint16Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Uint16Array" /** @@ -784,10 +1046,27 @@ module Uint16Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Uint16Array.fromBufferWithRange` instead.", + migrate: Uint16Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Uint16Array" - @new external fromLength: int => t = "Uint16Array" - @val external from: array_like => t = "Uint16Array.from" + @deprecated({ + reason: "Use `Uint16Array.fromLength` instead.", + migrate: Uint16Array.fromLength(), + }) + @new + external fromLength: int => t = "Uint16Array" + @deprecated({ + reason: "Use `Uint16Array.fromArrayLikeOrIterable` instead.", + migrate: Uint16Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Uint16Array.from" /* *Array.of is redundant, use make */ } @@ -809,12 +1088,25 @@ module Int32Array = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ // @bs.send.pipe(: t) external copyWithin: (~to_: int) => t = "copyWithin" // @bs.send.pipe(: t) external copyWithinFrom: (~to_: int, ~from: int) => t = "copyWithin" // @bs.send.pipe(: t) + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) external copyWithinFromRange: (~to_: int, ~start: int, ~end_: int) => t = "copyWithin" // @bs.send.pipe(: t) external fillInPlace: elt => t = "fill" @@ -839,12 +1131,20 @@ module Int32Array = { // @bs.send.pipe(: t) external lastIndexOfFrom: (elt, ~from: int) => int = "lastIndexOf" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) external slice: (~start: int, ~end_: int) => t = "slice" // @bs.send.pipe(: t) external copy: t = "slice" // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) external subarray: (~start: int, ~end_: int) => t = "subarray" // @bs.send.pipe(: t) external subarrayFrom: int => t = "subarray" @@ -887,11 +1187,25 @@ module Int32Array = { // @bs.send.pipe(: t) external some: ((. elt) => bool) => bool = "some" // @bs.send.pipe(: t) external somei: ((. elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Int32Array.BYTES_PER_ELEMENT" - - @new external make: array => t = "Int32Array" + @deprecated({ + reason: "Use `Int32Array.Constants.bytesPerElement` instead.", + migrate: Int32Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Int32Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Int32Array.fromArray` instead.", + migrate: Int32Array.fromArray(), + }) + @new + external make: array => t = "Int32Array" /** can throw */ @new + @deprecated({ + reason: "Use `Int32Array.fromBuffer` instead.", + migrate: Int32Array.fromBuffer(), + }) external fromBuffer: array_buffer => t = "Int32Array" /** @@ -900,6 +1214,10 @@ module Int32Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Int32Array.fromBufferToEnd", + migrate: Int32Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Int32Array" /** @@ -908,10 +1226,27 @@ module Int32Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Int32Array.fromBufferWithRange` instead.", + migrate: Int32Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Int32Array" - @new external fromLength: int => t = "Int32Array" - @val external from: array_like => t = "Int32Array.from" + @deprecated({ + reason: "Use `Int32Array.fromLength` instead.", + migrate: Int32Array.fromLength(), + }) + @new + external fromLength: int => t = "Int32Array" + @deprecated({ + reason: "Use `Int32Array.fromArrayLikeOrIterable` instead.", + migrate: Int32Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Int32Array.from" /* *Array.of is redundant, use make */ @new @deprecated("use `make` instead") external create: array => t = "Int32Array" @new @deprecated("use `fromBuffer` instead") external of_buffer: array_buffer => t = "Int32Array" @@ -936,12 +1271,25 @@ module Uint32Array = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ // @bs.send.pipe(: t) external copyWithin: (~to_: int) => t = "copyWithin" // @bs.send.pipe(: t) external copyWithinFrom: (~to_: int, ~from: int) => t = "copyWithin" // @bs.send.pipe(: t) + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) external copyWithinFromRange: (~to_: int, ~start: int, ~end_: int) => t = "copyWithin" // @bs.send.pipe(: t) external fillInPlace: elt => t = "fill" @@ -966,12 +1314,20 @@ module Uint32Array = { // @bs.send.pipe(: t) external lastIndexOfFrom: (elt, ~from: int) => int = "lastIndexOf" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) external slice: (~start: int, ~end_: int) => t = "slice" // @bs.send.pipe(: t) external copy: t = "slice" // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) external subarray: (~start: int, ~end_: int) => t = "subarray" // @bs.send.pipe(: t) external subarrayFrom: int => t = "subarray" @@ -1014,11 +1370,25 @@ module Uint32Array = { // @bs.send.pipe(: t) external some: ((. elt) => bool) => bool = "some" // @bs.send.pipe(: t) external somei: ((. elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Uint32Array.BYTES_PER_ELEMENT" - - @new external make: array => t = "Uint32Array" + @deprecated({ + reason: "Use `Uint32Array.Constants.bytesPerElement` instead.", + migrate: Uint32Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Uint32Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Uint32Array.fromArray` instead.", + migrate: Uint32Array.fromArray(), + }) + @new + external make: array => t = "Uint32Array" /** can throw */ @new + @deprecated({ + reason: "Use `Uint32Array.fromBuffer` instead.", + migrate: Uint32Array.fromBuffer(), + }) external fromBuffer: array_buffer => t = "Uint32Array" /** @@ -1027,6 +1397,10 @@ module Uint32Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Uint32Array.fromBufferToEnd` instead.", + migrate: Uint32Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Uint32Array" /** @@ -1035,10 +1409,27 @@ module Uint32Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Uint32Array.fromBufferWithRange` instead.", + migrate: Uint32Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Uint32Array" - @new external fromLength: int => t = "Uint32Array" - @val external from: array_like => t = "Uint32Array.from" + @deprecated({ + reason: "Use `Uint32Array.fromLength` instead.", + migrate: Uint32Array.fromLength(), + }) + @new + external fromLength: int => t = "Uint32Array" + @deprecated({ + reason: "Use `Uint32Array.fromArrayLikeOrIterable` instead.", + migrate: Uint32Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Uint32Array.from" /* *Array.of is redundant, use make */ } @@ -1063,12 +1454,25 @@ module Float32Array = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ // @bs.send.pipe(: t) external copyWithin: (~to_: int) => t = "copyWithin" // @bs.send.pipe(: t) external copyWithinFrom: (~to_: int, ~from: int) => t = "copyWithin" // @bs.send.pipe(: t) + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) external copyWithinFromRange: (~to_: int, ~start: int, ~end_: int) => t = "copyWithin" // @bs.send.pipe(: t) external fillInPlace: elt => t = "fill" @@ -1093,12 +1497,20 @@ module Float32Array = { // @bs.send.pipe(: t) external lastIndexOfFrom: (elt, ~from: int) => int = "lastIndexOf" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) external slice: (~start: int, ~end_: int) => t = "slice" // @bs.send.pipe(: t) external copy: t = "slice" // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) external subarray: (~start: int, ~end_: int) => t = "subarray" // @bs.send.pipe(: t) external subarrayFrom: int => t = "subarray" @@ -1141,11 +1553,25 @@ module Float32Array = { // @bs.send.pipe(: t) external some: ((. elt) => bool) => bool = "some" // @bs.send.pipe(: t) external somei: ((. elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Float32Array.BYTES_PER_ELEMENT" - - @new external make: array => t = "Float32Array" + @deprecated({ + reason: "Use `Float32Array.Constants.bytesPerElement` instead.", + migrate: Float32Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Float32Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Float32Array.fromArray` instead.", + migrate: Float32Array.fromArray(), + }) + @new + external make: array => t = "Float32Array" /** can throw */ @new + @deprecated({ + reason: "Use `Float32Array.fromBuffer` instead.", + migrate: Float32Array.fromBuffer(), + }) external fromBuffer: array_buffer => t = "Float32Array" /** @@ -1154,6 +1580,10 @@ module Float32Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Float32Array.fromBufferToEnd` instead.", + migrate: Float32Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Float32Array" /** @@ -1162,10 +1592,27 @@ module Float32Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Float32Array.fromBufferWithRange` instead.", + migrate: Float32Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Float32Array" - @new external fromLength: int => t = "Float32Array" - @val external from: array_like => t = "Float32Array.from" + @deprecated({ + reason: "Use `Float32Array.fromLength` instead.", + migrate: Float32Array.fromLength(), + }) + @new + external fromLength: int => t = "Float32Array" + @deprecated({ + reason: "Use `Float32Array.fromArrayLikeOrIterable` instead.", + migrate: Float32Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Float32Array.from" /* *Array.of is redundant, use make */ @new @deprecated("use `make` instead") external create: array => t = "Float32Array" @new @deprecated("use `fromBuffer` instead") @@ -1191,12 +1638,25 @@ module Float64Array = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ // @bs.send.pipe(: t) external copyWithin: (~to_: int) => t = "copyWithin" // @bs.send.pipe(: t) external copyWithinFrom: (~to_: int, ~from: int) => t = "copyWithin" // @bs.send.pipe(: t) + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) external copyWithinFromRange: (~to_: int, ~start: int, ~end_: int) => t = "copyWithin" // @bs.send.pipe(: t) external fillInPlace: elt => t = "fill" @@ -1221,12 +1681,20 @@ module Float64Array = { // @bs.send.pipe(: t) external lastIndexOfFrom: (elt, ~from: int) => int = "lastIndexOf" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) external slice: (~start: int, ~end_: int) => t = "slice" // @bs.send.pipe(: t) external copy: t = "slice" // @bs.send.pipe(: t) external sliceFrom: int => t = "slice" // @bs.send.pipe(: t) /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) external subarray: (~start: int, ~end_: int) => t = "subarray" // @bs.send.pipe(: t) external subarrayFrom: int => t = "subarray" @@ -1269,11 +1737,25 @@ module Float64Array = { // @bs.send.pipe(: t) external some: ((. elt) => bool) => bool = "some" // @bs.send.pipe(: t) external somei: ((. elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Float64Array.BYTES_PER_ELEMENT" - - @new external make: array => t = "Float64Array" + @deprecated({ + reason: "Use `Float64Array.Constants.bytesPerElement` instead.", + migrate: Float64Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Float64Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Float64Array.fromArray` instead.", + migrate: Float64Array.fromArray(), + }) + @new + external make: array => t = "Float64Array" /** can throw */ @new + @deprecated({ + reason: "Use `Float64Array.fromBuffer` instead.", + migrate: Float64Array.fromBuffer(), + }) external fromBuffer: array_buffer => t = "Float64Array" /** @@ -1282,6 +1764,10 @@ module Float64Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Float64Array.fromBufferToEnd` instead.", + migrate: Float64Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Float64Array" /** @@ -1290,10 +1776,27 @@ module Float64Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Float64Array.fromBufferWithRange` instead.", + migrate: Float64Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Float64Array" - @new external fromLength: int => t = "Float64Array" - @val external from: array_like => t = "Float64Array.from" + @deprecated({ + reason: "Use `Float64Array.fromLength` instead.", + migrate: Float64Array.fromLength(), + }) + @new + external fromLength: int => t = "Float64Array" + @deprecated({ + reason: "Use `Float64Array.fromArrayLikeOrIterable` instead.", + migrate: Float64Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Float64Array.from" /* *Array.of is redundant, use make */ @new @deprecated("use `make` instead") external create: array => t = "Float64Array" @new @deprecated("use `fromBuffer` instead") diff --git a/packages/@rescript/runtime/Js_typed_array2.res b/packages/@rescript/runtime/Js_typed_array2.res index a84623f725..6093ecf0cf 100644 --- a/packages/@rescript/runtime/Js_typed_array2.res +++ b/packages/@rescript/runtime/Js_typed_array2.res @@ -52,8 +52,18 @@ module ArrayBuffer = { @get external byteLength: t => int = "byteLength" - @send external slice: (t, ~start: int, ~end_: int) => array_buffer = "slice" - @send external sliceFrom: (t, int) => array_buffer = "slice" + @deprecated({ + reason: "Use `ArrayBuffer.slice` instead.", + migrate: ArrayBuffer.slice(~end=%insert.labelledArgument("end_")), + }) + @send + external slice: (t, ~start: int, ~end_: int) => array_buffer = "slice" + @deprecated({ + reason: "Use `ArrayBuffer.sliceToEnd` instead.", + migrate: ArrayBuffer.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) + @send + external sliceFrom: (t, int) => array_buffer = "slice" } /* commented out until bs has a plan for iterators @@ -73,93 +83,337 @@ module Int8Array = { @get external byteLength: t => int = "byteLength" @get external byteOffset: t => int = "byteOffset" - @send external setArray: (t, array) => unit = "set" - @send external setArrayOffset: (t, array, int) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArray` instead.", + migrate: TypedArray.setArray(), + }) + @send + external setArray: (t, array) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArrayFrom` instead.", + migrate: TypedArray.setArrayFrom(%insert.unlabelledArgument(2)), + }) + @send + external setArrayOffset: (t, array, int) => unit = "set" /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ - @send external copyWithin: (t, ~to_: int) => t = "copyWithin" - @send external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" - @send external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - - @send external fillInPlace: (t, elt) => t = "fill" - @send external fillFromInPlace: (t, elt, ~from: int) => t = "fill" - @send external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.copyAllWithin` instead.", + migrate: TypedArray.copyAllWithin(~target=%insert.labelledArgument("to_")), + }) + @send + external copyWithin: (t, ~to_: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithinToEnd` instead.", + migrate: TypedArray.copyWithinToEnd( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("from"), + ), + }) + @send + external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - @send external reverseInPlace: t => t = "reverse" + @deprecated({ + reason: "Use `TypedArray.fillAll` instead.", + migrate: TypedArray.fillAll(), + }) + @send + external fillInPlace: (t, elt) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fillToEnd` instead.", + migrate: TypedArray.fillToEnd(~start=%insert.labelledArgument("from")), + }) + @send + external fillFromInPlace: (t, elt, ~from: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fill` instead.", + migrate: TypedArray.fill( + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" - @send external sortInPlace: t => t = "sort" - @send external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" + @deprecated({ + reason: "Use `TypedArray.reverse` instead.", + migrate: TypedArray.reverse(), + }) + @send + external reverseInPlace: t => t = "reverse" + + @deprecated({ + reason: "Use `TypedArray.toSorted` instead.", + migrate: TypedArray.toSorted((a, b) => + %todo_("This needs a comparator function. Use `Int.compare` for ints, etc.") + ), + }) + @send + external sortInPlace: t => t = "sort" + @deprecated({ + reason: "Use `TypedArray.sort` instead.", + migrate: TypedArray.sort(), + }) + @deprecated({ + reason: "Use `TypedArray.sort` instead.", + migrate: TypedArray.sort(), + }) + @send + external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" /* Accessor functions */ - @send external includes: (t, elt) => bool = "includes" /* ES2016 */ + @deprecated({ + reason: "Use `TypedArray.includes` instead.", + migrate: TypedArray.includes(), + }) + @send + external includes: (t, elt) => bool = "includes" /* ES2016 */ - @send external indexOf: (t, elt) => int = "indexOf" - @send external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOf` instead.", + migrate: TypedArray.indexOf(), + }) + @send + external indexOf: (t, elt) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOfFrom` instead.", + migrate: TypedArray.indexOfFrom(%insert.labelledArgument("from")), + }) + @send + external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" - @send external join: t => string = "join" - @send external joinWith: (t, string) => string = "join" + @deprecated({ + reason: "Use `TypedArray.joinWith` instead.", + migrate: TypedArray.joinWith(","), + }) + @send + external join: t => string = "join" + @deprecated({ + reason: "Use `TypedArray.joinWith` instead.", + migrate: TypedArray.joinWith(), + }) + @send + external joinWith: (t, string) => string = "join" - @send external lastIndexOf: (t, elt) => int = "lastIndexOf" - @send external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOf` instead.", + migrate: TypedArray.lastIndexOf(), + }) + @send + external lastIndexOf: (t, elt) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOfFrom` instead.", + migrate: TypedArray.lastIndexOfFrom(%insert.labelledArgument("from")), + }) + @send + external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) @send external slice: (t, ~start: int, ~end_: int) => t = "slice" - @send external copy: t => t = "slice" - @send external sliceFrom: (t, int) => t = "slice" + @deprecated({ + reason: "Use `TypedArray.copy` instead.", + migrate: TypedArray.copy(), + }) + @send + external copy: t => t = "slice" + @deprecated({ + reason: "Use `TypedArray.sliceToEnd` instead.", + migrate: TypedArray.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) + @send + external sliceFrom: (t, int) => t = "slice" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) @send external subarray: (t, ~start: int, ~end_: int) => t = "subarray" - @send external subarrayFrom: (t, int) => t = "subarray" + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~start=%insert.unlabelledArgument(1)), + }) + @send + external subarrayFrom: (t, int) => t = "subarray" - @send external toString: t => string = "toString" - @send external toLocaleString: t => string = "toLocaleString" + @deprecated({ + reason: "Use `TypedArray.toString` instead.", + migrate: TypedArray.toString(), + }) + @send + external toString: t => string = "toString" + @deprecated({ + reason: "Use `TypedArray.toLocaleString` instead.", + migrate: TypedArray.toLocaleString(), + }) + @send + external toLocaleString: t => string = "toLocaleString" /* Iteration functions */ /* commented out until bs has a plan for iterators external entries : t -> (int * elt) array_iter = "" [@@send] */ - @send external every: (t, elt => bool) => bool = "every" - @send external everyi: (t, (elt, int) => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.every` instead.", + migrate: TypedArray.every(), + }) + @send + external every: (t, elt => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.everyWithIndex` instead.", + migrate: TypedArray.everyWithIndex(), + }) + @send + external everyi: (t, (elt, int) => bool) => bool = "every" - @send external filter: (t, elt => bool) => t = "filter" - @send external filteri: (t, (elt, int) => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filter` instead.", + migrate: TypedArray.filter(), + }) + @send + external filter: (t, elt => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filterWithIndex` instead.", + migrate: TypedArray.filterWithIndex(), + }) + @send + external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js_undefined.t = "find" - @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.find` instead.", + migrate: TypedArray.find(), + }) + @send + external find: (t, elt => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.findWithIndex` instead.", + migrate: TypedArray.findWithIndex(), + }) + @send + external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - @send external findIndex: (t, elt => bool) => int = "findIndex" - @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndex` instead.", + migrate: TypedArray.findIndex(), + }) + @send + external findIndex: (t, elt => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndexWithIndex` instead.", + migrate: TypedArray.findIndexWithIndex(), + }) + @send + external findIndexi: (t, (elt, int) => bool) => int = "findIndex" - @send external forEach: (t, elt => unit) => unit = "forEach" - @send external forEachi: (t, (elt, int) => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEach` instead.", + migrate: TypedArray.forEach(), + }) + @send + external forEach: (t, elt => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEachWithIndex` instead.", + migrate: TypedArray.forEachWithIndex(), + }) + @send + external forEachi: (t, (elt, int) => unit) => unit = "forEach" /* commented out until bs has a plan for iterators external keys : t -> int array_iter = "" [@@send] */ - @send external map: (t, elt => 'b) => typed_array<'b> = "map" - @send external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - - @send external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" - @send external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - - @send external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" - @send external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.map` instead.", + migrate: TypedArray.map(), + }) + @send + external map: (t, elt => 'b) => typed_array<'b> = "map" + @deprecated({ + reason: "Use `TypedArray.mapWithIndex` instead.", + migrate: TypedArray.mapWithIndex(), + }) + @send + external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - @send external some: (t, elt => bool) => bool = "some" - @send external somei: (t, (elt, int) => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.reduce` instead.", + migrate: TypedArray.reduce(), + }) + @send + external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" + @deprecated({ + reason: "Use `TypedArray.reduceWithIndex` instead.", + migrate: TypedArray.reduceWithIndex(), + }) + @send + external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - @val external _BYTES_PER_ELEMENT: int = "Int8Array.BYTES_PER_ELEMENT" + @deprecated({ + reason: "Use `TypedArray.reduceRight` instead.", + migrate: TypedArray.reduceRight(), + }) + @send + external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.reduceRightWithIndex` instead.", + migrate: TypedArray.reduceRightWithIndex(), + }) + @send + external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" - @new external make: array => t = "Int8Array" + @deprecated({ + reason: "Use `TypedArray.some` instead.", + migrate: TypedArray.some(), + }) + @send + external some: (t, elt => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.someWithIndex` instead.", + migrate: TypedArray.someWithIndex(), + }) + @send + external somei: (t, (elt, int) => bool) => bool = "some" + + @deprecated({ + reason: "Use `Int8Array.Constants.bytesPerElement` instead.", + migrate: Int8Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Int8Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Int8Array.fromArray` instead.", + migrate: Int8Array.fromArray(), + }) + @new + external make: array => t = "Int8Array" /** can throw */ @new external fromBuffer: array_buffer => t = "Int8Array" @@ -169,19 +423,39 @@ module Int8Array = { **param** offset is in bytes */ - @new - external fromBufferOffset: (array_buffer, int) => t = "Int8Array" + @deprecated({ + reason: "Use `Int8Array.fromBufferToEnd` instead.", + migrate: Int8Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) + @new external fromBufferOffset: (array_buffer, int) => t = "Int8Array" /** **throw** Js.Exn.Error throws Js exception **param** offset is in bytes, length in elements */ + @deprecated({ + reason: "Use `Int8Array.fromBufferWithRange` instead.", + migrate: Int8Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) @new external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Int8Array" - @new external fromLength: int => t = "Int8Array" - @val external from: array_like => t = "Int8Array.from" + @deprecated({ + reason: "Use `Int8Array.fromLength` instead.", + migrate: Int8Array.fromLength(), + }) + @new + external fromLength: int => t = "Int8Array" + @deprecated({ + reason: "Use `Int8Array.fromArrayLikeOrIterable` instead.", + migrate: Int8Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Int8Array.from" /* *Array.of is redundant, use make */ } @@ -198,93 +472,326 @@ module Uint8Array = { @get external byteLength: t => int = "byteLength" @get external byteOffset: t => int = "byteOffset" - @send external setArray: (t, array) => unit = "set" - @send external setArrayOffset: (t, array, int) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArray` instead.", + migrate: TypedArray.setArray(), + }) + @send + external setArray: (t, array) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArrayFrom` instead.", + migrate: TypedArray.setArrayFrom(%insert.unlabelledArgument(2)), + }) + @send + external setArrayOffset: (t, array, int) => unit = "set" /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ - @send external copyWithin: (t, ~to_: int) => t = "copyWithin" - @send external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" - @send external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - - @send external fillInPlace: (t, elt) => t = "fill" - @send external fillFromInPlace: (t, elt, ~from: int) => t = "fill" - @send external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.copyAllWithin` instead.", + migrate: TypedArray.copyAllWithin(~target=%insert.labelledArgument("to_")), + }) + @send + external copyWithin: (t, ~to_: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithinToEnd` instead.", + migrate: TypedArray.copyWithinToEnd( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("from"), + ), + }) + @send + external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - @send external reverseInPlace: t => t = "reverse" + @deprecated({ + reason: "Use `TypedArray.fillAll` instead.", + migrate: TypedArray.fillAll(), + }) + @send + external fillInPlace: (t, elt) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fillToEnd` instead.", + migrate: TypedArray.fillToEnd(~start=%insert.labelledArgument("from")), + }) + @send + external fillFromInPlace: (t, elt, ~from: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fill` instead.", + migrate: TypedArray.fill( + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" - @send external sortInPlace: t => t = "sort" + @deprecated({ + reason: "Use `TypedArray.reverse` instead.", + migrate: TypedArray.reverse(), + }) + @send + external reverseInPlace: t => t = "reverse" + + @deprecated({ + reason: "Use `TypedArray.toSorted` instead.", + migrate: TypedArray.toSorted((a, b) => + %todo_("This needs a comparator function. Use an appropriate comparator (e.g. Int.compare).") + ), + }) + @send + external sortInPlace: t => t = "sort" @send external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" /* Accessor functions */ - @send external includes: (t, elt) => bool = "includes" /* ES2016 */ + @deprecated({ + reason: "Use `TypedArray.includes` instead.", + migrate: TypedArray.includes(), + }) + @send + external includes: (t, elt) => bool = "includes" /* ES2016 */ - @send external indexOf: (t, elt) => int = "indexOf" - @send external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOf` instead.", + migrate: TypedArray.indexOf(), + }) + @send + external indexOf: (t, elt) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOfFrom` instead.", + migrate: TypedArray.indexOfFrom(%insert.labelledArgument("from")), + }) + @send + external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" - @send external join: t => string = "join" - @send external joinWith: (t, string) => string = "join" + @deprecated({ + reason: "Use `TypedArray.joinWith` instead.", + migrate: TypedArray.joinWith(","), + }) + @send + external join: t => string = "join" + @deprecated({ + reason: "Use `TypedArray.joinWith` instead.", + migrate: TypedArray.joinWith(), + }) + @send + external joinWith: (t, string) => string = "join" - @send external lastIndexOf: (t, elt) => int = "lastIndexOf" - @send external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOf` instead.", + migrate: TypedArray.lastIndexOf(), + }) + @send + external lastIndexOf: (t, elt) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOfFrom` instead.", + migrate: TypedArray.lastIndexOfFrom(%insert.labelledArgument("from")), + }) + @send + external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) + @send external slice: (t, ~start: int, ~end_: int) => t = "slice" + + @deprecated({ + reason: "Use `TypedArray.copy` instead.", + migrate: TypedArray.copy(), + }) @send - external slice: (t, ~start: int, ~end_: int) => t = "slice" - - @send external copy: t => t = "slice" - @send external sliceFrom: (t, int) => t = "slice" + external copy: t => t = "slice" + @deprecated({ + reason: "Use `TypedArray.sliceToEnd` instead.", + migrate: TypedArray.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) + @send + external sliceFrom: (t, int) => t = "slice" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) + @send external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~start=%insert.unlabelledArgument(1)), + }) @send - external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + external subarrayFrom: (t, int) => t = "subarray" - @send external subarrayFrom: (t, int) => t = "subarray" - - @send external toString: t => string = "toString" - @send external toLocaleString: t => string = "toLocaleString" + @deprecated({ + reason: "Use `TypedArray.toString` instead.", + migrate: TypedArray.toString(), + }) + @send + external toString: t => string = "toString" + @deprecated({ + reason: "Use `TypedArray.toLocaleString` instead.", + migrate: TypedArray.toLocaleString(), + }) + @send + external toLocaleString: t => string = "toLocaleString" /* Iteration functions */ /* commented out until bs has a plan for iterators external entries : t -> (int * elt) array_iter = "" [@@send] */ - @send external every: (t, elt => bool) => bool = "every" - @send external everyi: (t, (elt, int) => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.every` instead.", + migrate: TypedArray.every(), + }) + @send + external every: (t, elt => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.everyWithIndex` instead.", + migrate: TypedArray.everyWithIndex(), + }) + @send + external everyi: (t, (elt, int) => bool) => bool = "every" - @send external filter: (t, elt => bool) => t = "filter" - @send external filteri: (t, (elt, int) => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filter` instead.", + migrate: TypedArray.filter(), + }) + @send + external filter: (t, elt => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filterWithIndex` instead.", + migrate: TypedArray.filterWithIndex(), + }) + @send + external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js_undefined.t = "find" - @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.find` instead.", + migrate: TypedArray.find(), + }) + @send + external find: (t, elt => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.findWithIndex` instead.", + migrate: TypedArray.findWithIndex(), + }) + @send + external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - @send external findIndex: (t, elt => bool) => int = "findIndex" - @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndex` instead.", + migrate: TypedArray.findIndex(), + }) + @send + external findIndex: (t, elt => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndexWithIndex` instead.", + migrate: TypedArray.findIndexWithIndex(), + }) + @send + external findIndexi: (t, (elt, int) => bool) => int = "findIndex" - @send external forEach: (t, elt => unit) => unit = "forEach" - @send external forEachi: (t, (elt, int) => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEach` instead.", + migrate: TypedArray.forEach(), + }) + @send + external forEach: (t, elt => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEachWithIndex` instead.", + migrate: TypedArray.forEachWithIndex(), + }) + @send + external forEachi: (t, (elt, int) => unit) => unit = "forEach" /* commented out until bs has a plan for iterators external keys : t -> int array_iter = "" [@@send] */ - @send external map: (t, elt => 'b) => typed_array<'b> = "map" - @send external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - - @send external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" - @send external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - - @send external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" - @send external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.map` instead.", + migrate: TypedArray.map(), + }) + @send + external map: (t, elt => 'b) => typed_array<'b> = "map" + @deprecated({ + reason: "Use `TypedArray.mapWithIndex` instead.", + migrate: TypedArray.mapWithIndex(), + }) + @send + external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - @send external some: (t, elt => bool) => bool = "some" - @send external somei: (t, (elt, int) => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.reduce` instead.", + migrate: TypedArray.reduce(), + }) + @send + external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" + @deprecated({ + reason: "Use `TypedArray.reduceWithIndex` instead.", + migrate: TypedArray.reduceWithIndex(), + }) + @send + external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - @val external _BYTES_PER_ELEMENT: int = "Uint8Array.BYTES_PER_ELEMENT" + @deprecated({ + reason: "Use `TypedArray.reduceRight` instead.", + migrate: TypedArray.reduceRight(), + }) + @send + external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.reduceRightWithIndex` instead.", + migrate: TypedArray.reduceRightWithIndex(), + }) + @send + external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" - @new external make: array => t = "Uint8Array" + @deprecated({ + reason: "Use `TypedArray.some` instead.", + migrate: TypedArray.some(), + }) + @send + external some: (t, elt => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.someWithIndex` instead.", + migrate: TypedArray.someWithIndex(), + }) + @send + external somei: (t, (elt, int) => bool) => bool = "some" + + @deprecated({ + reason: "Use `Uint8Array.Constants.bytesPerElement` instead.", + migrate: Uint8Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Uint8Array.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Uint8Array.fromArray` instead.", + migrate: Uint8Array.fromArray(), + }) + @new + external make: array => t = "Uint8Array" /** can throw */ @new external fromBuffer: array_buffer => t = "Uint8Array" @@ -294,19 +801,39 @@ module Uint8Array = { **param** offset is in bytes */ - @new - external fromBufferOffset: (array_buffer, int) => t = "Uint8Array" + @deprecated({ + reason: "Use `Uint8Array.fromBufferToEnd` instead.", + migrate: Uint8Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) + @new external fromBufferOffset: (array_buffer, int) => t = "Uint8Array" /** **throw** Js.Exn.Error throws Js exception **param** offset is in bytes, length in elements */ + @deprecated({ + reason: "Use `Uint8Array.fromBufferWithRange` instead.", + migrate: Uint8Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) @new external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Uint8Array" - @new external fromLength: int => t = "Uint8Array" - @val external from: array_like => t = "Uint8Array.from" + @deprecated({ + reason: "Use `Uint8Array.fromLength` instead.", + migrate: Uint8Array.fromLength(), + }) + @new + external fromLength: int => t = "Uint8Array" + @deprecated({ + reason: "Use `Uint8Array.fromArrayLikeOrIterable` instead.", + migrate: Uint8Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Uint8Array.from" /* *Array.of is redundant, use make */ } @@ -323,93 +850,326 @@ module Uint8ClampedArray = { @get external byteLength: t => int = "byteLength" @get external byteOffset: t => int = "byteOffset" - @send external setArray: (t, array) => unit = "set" - @send external setArrayOffset: (t, array, int) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArray` instead.", + migrate: TypedArray.setArray(), + }) + @send + external setArray: (t, array) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArrayFrom` instead.", + migrate: TypedArray.setArrayFrom(%insert.unlabelledArgument(2)), + }) + @send + external setArrayOffset: (t, array, int) => unit = "set" /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ - @send external copyWithin: (t, ~to_: int) => t = "copyWithin" - @send external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" - @send external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - - @send external fillInPlace: (t, elt) => t = "fill" - @send external fillFromInPlace: (t, elt, ~from: int) => t = "fill" - @send external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.copyAllWithin` instead.", + migrate: TypedArray.copyAllWithin(~target=%insert.labelledArgument("to_")), + }) + @send + external copyWithin: (t, ~to_: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithinToEnd` instead.", + migrate: TypedArray.copyWithinToEnd( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("from"), + ), + }) + @send + external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - @send external reverseInPlace: t => t = "reverse" + @deprecated({ + reason: "Use `TypedArray.fillAll` instead.", + migrate: TypedArray.fillAll(), + }) + @send + external fillInPlace: (t, elt) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fillToEnd` instead.", + migrate: TypedArray.fillToEnd(~start=%insert.labelledArgument("from")), + }) + @send + external fillFromInPlace: (t, elt, ~from: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fill` instead.", + migrate: TypedArray.fill( + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" - @send external sortInPlace: t => t = "sort" + @deprecated({ + reason: "Use `TypedArray.reverse` instead.", + migrate: TypedArray.reverse(), + }) + @send + external reverseInPlace: t => t = "reverse" + + @deprecated({ + reason: "Use `TypedArray.toSorted` instead.", + migrate: TypedArray.toSorted((a, b) => + %todo_("This needs a comparator function. Use an appropriate comparator (e.g. Int.compare).") + ), + }) + @send + external sortInPlace: t => t = "sort" @send external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" /* Accessor functions */ - @send external includes: (t, elt) => bool = "includes" /* ES2016 */ + @deprecated({ + reason: "Use `TypedArray.includes` instead.", + migrate: TypedArray.includes(), + }) + @send + external includes: (t, elt) => bool = "includes" /* ES2016 */ - @send external indexOf: (t, elt) => int = "indexOf" - @send external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOf` instead.", + migrate: TypedArray.indexOf(), + }) + @send + external indexOf: (t, elt) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOfFrom` instead.", + migrate: TypedArray.indexOfFrom(%insert.labelledArgument("from")), + }) + @send + external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" - @send external join: t => string = "join" - @send external joinWith: (t, string) => string = "join" + @deprecated({ + reason: "Use `TypedArray.joinWith` instead.", + migrate: TypedArray.joinWith(","), + }) + @send + external join: t => string = "join" + @deprecated({ + reason: "Use `TypedArray.joinWith` instead.", + migrate: TypedArray.joinWith(), + }) + @send + external joinWith: (t, string) => string = "join" - @send external lastIndexOf: (t, elt) => int = "lastIndexOf" - @send external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOf` instead.", + migrate: TypedArray.lastIndexOf(), + }) + @send + external lastIndexOf: (t, elt) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOfFrom` instead.", + migrate: TypedArray.lastIndexOfFrom(%insert.labelledArgument("from")), + }) + @send + external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) + @send external slice: (t, ~start: int, ~end_: int) => t = "slice" + + @deprecated({ + reason: "Use `TypedArray.copy` instead.", + migrate: TypedArray.copy(), + }) @send - external slice: (t, ~start: int, ~end_: int) => t = "slice" - - @send external copy: t => t = "slice" - @send external sliceFrom: (t, int) => t = "slice" + external copy: t => t = "slice" + @deprecated({ + reason: "Use `TypedArray.sliceToEnd` instead.", + migrate: TypedArray.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) + @send + external sliceFrom: (t, int) => t = "slice" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) + @send external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~start=%insert.unlabelledArgument(1)), + }) @send - external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + external subarrayFrom: (t, int) => t = "subarray" - @send external subarrayFrom: (t, int) => t = "subarray" - - @send external toString: t => string = "toString" - @send external toLocaleString: t => string = "toLocaleString" + @deprecated({ + reason: "Use `TypedArray.toString` instead.", + migrate: TypedArray.toString(), + }) + @send + external toString: t => string = "toString" + @deprecated({ + reason: "Use `TypedArray.toLocaleString` instead.", + migrate: TypedArray.toLocaleString(), + }) + @send + external toLocaleString: t => string = "toLocaleString" /* Iteration functions */ /* commented out until bs has a plan for iterators external entries : t -> (int * elt) array_iter = "" [@@send] */ - @send external every: (t, elt => bool) => bool = "every" - @send external everyi: (t, (elt, int) => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.every` instead.", + migrate: TypedArray.every(), + }) + @send + external every: (t, elt => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.everyWithIndex` instead.", + migrate: TypedArray.everyWithIndex(), + }) + @send + external everyi: (t, (elt, int) => bool) => bool = "every" - @send external filter: (t, elt => bool) => t = "filter" - @send external filteri: (t, (elt, int) => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filter` instead.", + migrate: TypedArray.filter(), + }) + @send + external filter: (t, elt => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filterWithIndex` instead.", + migrate: TypedArray.filterWithIndex(), + }) + @send + external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js_undefined.t = "find" - @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.find` instead.", + migrate: TypedArray.find(), + }) + @send + external find: (t, elt => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.findWithIndex` instead.", + migrate: TypedArray.findWithIndex(), + }) + @send + external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - @send external findIndex: (t, elt => bool) => int = "findIndex" - @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndex` instead.", + migrate: TypedArray.findIndex(), + }) + @send + external findIndex: (t, elt => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndexWithIndex` instead.", + migrate: TypedArray.findIndexWithIndex(), + }) + @send + external findIndexi: (t, (elt, int) => bool) => int = "findIndex" - @send external forEach: (t, elt => unit) => unit = "forEach" - @send external forEachi: (t, (elt, int) => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEach` instead.", + migrate: TypedArray.forEach(), + }) + @send + external forEach: (t, elt => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEachWithIndex` instead.", + migrate: TypedArray.forEachWithIndex(), + }) + @send + external forEachi: (t, (elt, int) => unit) => unit = "forEach" /* commented out until bs has a plan for iterators external keys : t -> int array_iter = "" [@@send] */ - @send external map: (t, elt => 'b) => typed_array<'b> = "map" - @send external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - - @send external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" - @send external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - - @send external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" - @send external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.map` instead.", + migrate: TypedArray.map(), + }) + @send + external map: (t, elt => 'b) => typed_array<'b> = "map" + @deprecated({ + reason: "Use `TypedArray.mapWithIndex` instead.", + migrate: TypedArray.mapWithIndex(), + }) + @send + external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - @send external some: (t, elt => bool) => bool = "some" - @send external somei: (t, (elt, int) => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.reduce` instead.", + migrate: TypedArray.reduce(), + }) + @send + external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" + @deprecated({ + reason: "Use `TypedArray.reduceWithIndex` instead.", + migrate: TypedArray.reduceWithIndex(), + }) + @send + external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - @val external _BYTES_PER_ELEMENT: int = "Uint8ClampedArray.BYTES_PER_ELEMENT" + @deprecated({ + reason: "Use `TypedArray.reduceRight` instead.", + migrate: TypedArray.reduceRight(), + }) + @send + external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.reduceRightWithIndex` instead.", + migrate: TypedArray.reduceRightWithIndex(), + }) + @send + external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" - @new external make: array => t = "Uint8ClampedArray" + @deprecated({ + reason: "Use `TypedArray.some` instead.", + migrate: TypedArray.some(), + }) + @send + external some: (t, elt => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.someWithIndex` instead.", + migrate: TypedArray.someWithIndex(), + }) + @send + external somei: (t, (elt, int) => bool) => bool = "some" + + @deprecated({ + reason: "Use `Uint8ClampedArray.Constants.bytesPerElement` instead.", + migrate: Uint8ClampedArray.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Uint8ClampedArray.BYTES_PER_ELEMENT" + + @deprecated({ + reason: "Use `Uint8ClampedArray.fromArray` instead.", + migrate: Uint8ClampedArray.fromArray(), + }) + @new + external make: array => t = "Uint8ClampedArray" /** can throw */ @new external fromBuffer: array_buffer => t = "Uint8ClampedArray" @@ -419,19 +1179,39 @@ module Uint8ClampedArray = { **param** offset is in bytes */ - @new - external fromBufferOffset: (array_buffer, int) => t = "Uint8ClampedArray" + @deprecated({ + reason: "Use `Uint8ClampedArray.fromBufferToEnd` instead.", + migrate: Uint8ClampedArray.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) + @new external fromBufferOffset: (array_buffer, int) => t = "Uint8ClampedArray" /** **throw** Js.Exn.Error throws Js exception **param** offset is in bytes, length in elements */ + @deprecated({ + reason: "Use `Uint8ClampedArray.fromBufferWithRange` instead.", + migrate: Uint8ClampedArray.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) @new external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Uint8ClampedArray" - @new external fromLength: int => t = "Uint8ClampedArray" - @val external from: array_like => t = "Uint8ClampedArray.from" + @deprecated({ + reason: "Use `Uint8ClampedArray.fromLength` instead.", + migrate: Uint8ClampedArray.fromLength(), + }) + @new + external fromLength: int => t = "Uint8ClampedArray" + @deprecated({ + reason: "Use `Uint8ClampedArray.fromArrayLikeOrIterable` instead.", + migrate: Uint8ClampedArray.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Uint8ClampedArray.from" /* *Array.of is redundant, use make */ } @@ -448,89 +1228,239 @@ module Int16Array = { @get external byteLength: t => int = "byteLength" @get external byteOffset: t => int = "byteOffset" - @send external setArray: (t, array) => unit = "set" - @send external setArrayOffset: (t, array, int) => unit = "set" + @deprecated({reason: "Use `TypedArray.setArray` instead.", migrate: TypedArray.setArray()}) @send + external setArray: (t, array) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArrayFrom` instead.", + migrate: TypedArray.setArrayFrom(%insert.unlabelledArgument(2)), + }) + @send + external setArrayOffset: (t, array, int) => unit = "set" /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({reason: "Use `TypedArray.length` instead.", migrate: TypedArray.length()}) @get + external length: t => int = "length" /* Mutator functions */ - @send external copyWithin: (t, ~to_: int) => t = "copyWithin" - @send external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" - @send external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - - @send external fillInPlace: (t, elt) => t = "fill" - @send external fillFromInPlace: (t, elt, ~from: int) => t = "fill" - @send external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.copyAllWithin` instead.", + migrate: TypedArray.copyAllWithin(~target=%insert.labelledArgument("to_")), + }) + @send + external copyWithin: (t, ~to_: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithinToEnd` instead.", + migrate: TypedArray.copyWithinToEnd( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("from"), + ), + }) + @send + external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithin", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external /* end mapped below */ - @send external reverseInPlace: t => t = "reverse" + copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - @send external sortInPlace: t => t = "sort" - @send external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" + @deprecated({reason: "Use `TypedArray.fillAll` instead.", migrate: TypedArray.fillAll()}) @send + external fillInPlace: (t, elt) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fillToEnd` instead.", + migrate: TypedArray.fillToEnd(~start=%insert.labelledArgument("from")), + }) + @send + external fillFromInPlace: (t, elt, ~from: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fill` instead.", + migrate: TypedArray.fill( + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" - /* Accessor functions */ - @send external includes: (t, elt) => bool = "includes" /* ES2016 */ + @deprecated({reason: "Use `TypedArray.reverse` instead.", migrate: TypedArray.reverse()}) @send + external reverseInPlace: t => t = "reverse" - @send external indexOf: (t, elt) => int = "indexOf" - @send external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" - - @send external join: t => string = "join" - @send external joinWith: (t, string) => string = "join" + @deprecated({ + reason: "Use `TypedArray.toSorted` instead.", + migrate: TypedArray.toSorted((a, b) => + %todo_("This needs a comparator function. Use an appropriate comparator (e.g. Int.compare).") + ), + }) + @send + external sortInPlace: t => t = "sort" + @deprecated({reason: "Use `TypedArray.sort` instead.", migrate: TypedArray.sort()}) @send + external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" - @send external lastIndexOf: (t, elt) => int = "lastIndexOf" - @send external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" + /* Accessor functions */ + @deprecated({reason: "Use `TypedArray.includes` instead.", migrate: TypedArray.includes()}) @send + external includes: (t, elt) => bool = "includes" /* ES2016 */ + + @deprecated({reason: "Use `TypedArray.indexOf` instead.", migrate: TypedArray.indexOf()}) @send + external indexOf: (t, elt) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOfFrom` instead.", + migrate: TypedArray.indexOfFrom(%insert.labelledArgument("from")), + }) + @send + external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" - /** `start` is inclusive, `end_` exclusive */ + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith(",")}) @send - external slice: (t, ~start: int, ~end_: int) => t = "slice" + external join: t => string = "join" + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith()}) @send + external joinWith: (t, string) => string = "join" - @send external copy: t => t = "slice" - @send external sliceFrom: (t, int) => t = "slice" + @deprecated({reason: "Use `TypedArray.lastIndexOf` instead.", migrate: TypedArray.lastIndexOf()}) + @send + external lastIndexOf: (t, elt) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOfFrom` instead.", + migrate: TypedArray.lastIndexOfFrom(%insert.labelledArgument("from")), + }) + @send + external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) + @send external slice: (t, ~start: int, ~end_: int) => t = "slice" + + @deprecated({reason: "Use `TypedArray.copy` instead.", migrate: TypedArray.copy()}) @send + external copy: t => t = "slice" + @deprecated({ + reason: "Use `TypedArray.sliceToEnd` instead.", + migrate: TypedArray.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) @send - external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + external sliceFrom: (t, int) => t = "slice" - @send external subarrayFrom: (t, int) => t = "subarray" - - @send external toString: t => string = "toString" - @send external toLocaleString: t => string = "toLocaleString" + /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) + @send external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~start=%insert.unlabelledArgument(1)), + }) + @send + external subarrayFrom: (t, int) => t = "subarray" + + @deprecated({reason: "Use `TypedArray.toString` instead.", migrate: TypedArray.toString()}) @send + external toString: t => string = "toString" + @deprecated({ + reason: "Use `TypedArray.toLocaleString` instead.", + migrate: TypedArray.toLocaleString(), + }) + @send + external toLocaleString: t => string = "toLocaleString" /* Iteration functions */ /* commented out until bs has a plan for iterators external entries : t -> (int * elt) array_iter = "" [@@send] */ - @send external every: (t, elt => bool) => bool = "every" - @send external everyi: (t, (elt, int) => bool) => bool = "every" - - @send external filter: (t, elt => bool) => t = "filter" - @send external filteri: (t, (elt, int) => bool) => t = "filter" - - @send external find: (t, elt => bool) => Js_undefined.t = "find" - @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - - @send external findIndex: (t, elt => bool) => int = "findIndex" - @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + @deprecated({reason: "Use `TypedArray.every` instead.", migrate: TypedArray.every()}) @send + external every: (t, elt => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.everyWithIndex` instead.", + migrate: TypedArray.everyWithIndex(), + }) + @send + external everyi: (t, (elt, int) => bool) => bool = "every" + + @deprecated({reason: "Use `TypedArray.filter` instead.", migrate: TypedArray.filter()}) @send + external filter: (t, elt => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filterWithIndex` instead.", + migrate: TypedArray.filterWithIndex(), + }) + @send + external filteri: (t, (elt, int) => bool) => t = "filter" + + @deprecated({reason: "Use `TypedArray.find` instead.", migrate: TypedArray.find()}) @send + external find: (t, elt => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.findWithIndex` instead.", + migrate: TypedArray.findWithIndex(), + }) + @send + external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - @send external forEach: (t, elt => unit) => unit = "forEach" - @send external forEachi: (t, (elt, int) => unit) => unit = "forEach" + @deprecated({reason: "Use `TypedArray.findIndex` instead.", migrate: TypedArray.findIndex()}) + @send + external findIndex: (t, elt => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndexWithIndex` instead.", + migrate: TypedArray.findIndexWithIndex(), + }) + @send + external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + + @deprecated({reason: "Use `TypedArray.forEach` instead.", migrate: TypedArray.forEach()}) @send + external forEach: (t, elt => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEachWithIndex` instead.", + migrate: TypedArray.forEachWithIndex(), + }) + @send + external forEachi: (t, (elt, int) => unit) => unit = "forEach" /* commented out until bs has a plan for iterators external keys : t -> int array_iter = "" [@@send] */ - @send external map: (t, elt => 'b) => typed_array<'b> = "map" - @send external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - - @send external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" - @send external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - - @send external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" - @send external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + @deprecated({reason: "Use `TypedArray.map` instead.", migrate: TypedArray.map()}) @send + external map: (t, elt => 'b) => typed_array<'b> = "map" + @deprecated({ + reason: "Use `TypedArray.mapWithIndex` instead.", + migrate: TypedArray.mapWithIndex(), + }) + @send + external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" + + @deprecated({reason: "Use `TypedArray.reduce` instead.", migrate: TypedArray.reduce()}) @send + external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" + @deprecated({ + reason: "Use `TypedArray.reduceWithIndex` instead.", + migrate: TypedArray.reduceWithIndex(), + }) + @send + external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - @send external some: (t, elt => bool) => bool = "some" - @send external somei: (t, (elt, int) => bool) => bool = "some" + @deprecated({reason: "Use `TypedArray.reduceRight` instead.", migrate: TypedArray.reduceRight()}) + @send + external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.reduceRightWithIndex` instead.", + migrate: TypedArray.reduceRightWithIndex(), + }) + @send + external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + + @deprecated({reason: "Use `TypedArray.some` instead.", migrate: TypedArray.some()}) @send + external some: (t, elt => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.someWithIndex` instead.", + migrate: TypedArray.someWithIndex(), + }) + @send + external somei: (t, (elt, int) => bool) => bool = "some" @val external _BYTES_PER_ELEMENT: int = "Int16Array.BYTES_PER_ELEMENT" @@ -578,7 +1508,12 @@ module Uint16Array = { /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({ + reason: "Use `TypedArray.length` instead.", + migrate: TypedArray.length(), + }) + @get + external length: t => int = "length" /* Mutator functions */ @send external copyWithin: (t, ~to_: int) => t = "copyWithin" @@ -595,10 +1530,20 @@ module Uint16Array = { @send external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" /* Accessor functions */ - @send external includes: (t, elt) => bool = "includes" /* ES2016 */ + @deprecated({ + reason: "Use `TypedArray.includes` instead.", + migrate: TypedArray.includes(), + }) + @send + external includes: (t, elt) => bool = "includes" /* ES2016 */ @send external indexOf: (t, elt) => int = "indexOf" - @send external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOfFrom` instead.", + migrate: TypedArray.indexOfFrom(%insert.labelledArgument("from")), + }) + @send + external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" @send external join: t => string = "join" @send external joinWith: (t, string) => string = "join" @@ -607,17 +1552,35 @@ module Uint16Array = { @send external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) @send external slice: (t, ~start: int, ~end_: int) => t = "slice" @send external copy: t => t = "slice" - @send external sliceFrom: (t, int) => t = "slice" + @deprecated({ + reason: "Use `TypedArray.sliceToEnd` instead.", + migrate: TypedArray.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) + @send + external sliceFrom: (t, int) => t = "slice" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) @send external subarray: (t, ~start: int, ~end_: int) => t = "subarray" - @send external subarrayFrom: (t, int) => t = "subarray" + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~start=%insert.unlabelledArgument(1)), + }) + @send + external subarrayFrom: (t, int) => t = "subarray" @send external toString: t => string = "toString" @send external toLocaleString: t => string = "toLocaleString" @@ -645,10 +1608,20 @@ module Uint16Array = { external keys : t -> int array_iter = "" [@@send] */ - @send external map: (t, elt => 'b) => typed_array<'b> = "map" + @deprecated({ + reason: "Use `TypedArray.map` instead.", + migrate: TypedArray.map(), + }) + @send + external map: (t, elt => 'b) => typed_array<'b> = "map" @send external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - @send external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" + @deprecated({ + reason: "Use `TypedArray.reduce` instead.", + migrate: TypedArray.reduce(), + }) + @send + external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" @send external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" @send external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" @@ -657,11 +1630,19 @@ module Uint16Array = { @send external some: (t, elt => bool) => bool = "some" @send external somei: (t, (elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Uint16Array.BYTES_PER_ELEMENT" + @deprecated({ + reason: "Use `Uint16Array.Constants.bytesPerElement` instead.", + migrate: Uint16Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Uint16Array.BYTES_PER_ELEMENT" - @new external make: array => t = "Uint16Array" + @deprecated({reason: "Use `Uint16Array.fromArray` instead.", migrate: Uint16Array.fromArray()}) + @new + external make: array => t = "Uint16Array" /** can throw */ @new + @deprecated({reason: "Use `Uint16Array.fromBuffer` instead.", migrate: Uint16Array.fromBuffer()}) external fromBuffer: array_buffer => t = "Uint16Array" /** @@ -670,6 +1651,10 @@ module Uint16Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Uint16Array.fromBufferToEnd` instead.", + migrate: Uint16Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Uint16Array" /** @@ -678,10 +1663,24 @@ module Uint16Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Uint16Array.fromBufferWithRange", + migrate: Uint16Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Uint16Array" - @new external fromLength: int => t = "Uint16Array" - @val external from: array_like => t = "Uint16Array.from" + @deprecated({reason: "Use `Uint16Array.fromLength` instead.", migrate: Uint16Array.fromLength()}) + @new + external fromLength: int => t = "Uint16Array" + @deprecated({ + reason: "Use `Uint16Array.fromArrayLikeOrIterable` instead.", + migrate: Uint16Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Uint16Array.from" /* *Array.of is redundant, use make */ } @@ -698,95 +1697,249 @@ module Int32Array = { @get external byteLength: t => int = "byteLength" @get external byteOffset: t => int = "byteOffset" - @send external setArray: (t, array) => unit = "set" - @send external setArrayOffset: (t, array, int) => unit = "set" + @deprecated({reason: "Use `TypedArray.setArray` instead.", migrate: TypedArray.setArray()}) @send + external setArray: (t, array) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArrayFrom` instead.", + migrate: TypedArray.setArrayFrom(%insert.unlabelledArgument(2)), + }) + @send + external setArrayOffset: (t, array, int) => unit = "set" /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({reason: "Use `TypedArray.length` instead.", migrate: TypedArray.length()}) @get + external length: t => int = "length" /* Mutator functions */ - @send external copyWithin: (t, ~to_: int) => t = "copyWithin" - @send external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" - @send external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - - @send external fillInPlace: (t, elt) => t = "fill" - @send external fillFromInPlace: (t, elt, ~from: int) => t = "fill" - @send external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.copyAllWithin` instead.", + migrate: TypedArray.copyAllWithin(~target=%insert.labelledArgument("to_")), + }) + @send + external copyWithin: (t, ~to_: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithinToEnd` instead.", + migrate: TypedArray.copyWithinToEnd( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("from"), + ), + }) + @send + external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" + + @deprecated({reason: "Use `TypedArray.fillAll` instead.", migrate: TypedArray.fillAll()}) @send + external fillInPlace: (t, elt) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fillToEnd` instead.", + migrate: TypedArray.fillToEnd(~start=%insert.labelledArgument("from")), + }) + @send + external fillFromInPlace: (t, elt, ~from: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fill` instead.", + migrate: TypedArray.fill( + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" - @send external reverseInPlace: t => t = "reverse" + @deprecated({reason: "Use `TypedArray.reverse` instead.", migrate: TypedArray.reverse()}) @send + external reverseInPlace: t => t = "reverse" - @send external sortInPlace: t => t = "sort" - @send external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" + @deprecated({ + reason: "Use `TypedArray.toSorted` instead.", + migrate: TypedArray.toSorted((a, b) => + %todo_("This needs a comparator function. Use an appropriate comparator (e.g. Int.compare).") + ), + }) + @send + external sortInPlace: t => t = "sort" + @deprecated({reason: "Use `TypedArray.sort` instead.", migrate: TypedArray.sort()}) @send + external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" /* Accessor functions */ - @send external includes: (t, elt) => bool = "includes" /* ES2016 */ - - @send external indexOf: (t, elt) => int = "indexOf" - @send external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" + @deprecated({reason: "Use `TypedArray.includes` instead.", migrate: TypedArray.includes()}) @send + external includes: (t, elt) => bool = "includes" /* ES2016 */ + + @deprecated({reason: "Use `TypedArray.indexOf` instead.", migrate: TypedArray.indexOf()}) @send + external indexOf: (t, elt) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOfFrom` instead.", + migrate: TypedArray.indexOfFrom(%insert.labelledArgument("from")), + }) + @send + external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" - @send external join: t => string = "join" - @send external joinWith: (t, string) => string = "join" + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith(",")}) + @send + external join: t => string = "join" + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith()}) @send + external joinWith: (t, string) => string = "join" - @send external lastIndexOf: (t, elt) => int = "lastIndexOf" - @send external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" + @deprecated({reason: "Use `TypedArray.lastIndexOf` instead.", migrate: TypedArray.lastIndexOf()}) + @send + external lastIndexOf: (t, elt) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOfFrom` instead.", + migrate: TypedArray.lastIndexOfFrom(%insert.labelledArgument("from")), + }) + @send + external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) + @send external slice: (t, ~start: int, ~end_: int) => t = "slice" + + @deprecated({reason: "Use `TypedArray.copy` instead.", migrate: TypedArray.copy()}) @send + external copy: t => t = "slice" + @deprecated({ + reason: "Use `TypedArray.sliceToEnd` instead.", + migrate: TypedArray.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) @send - external slice: (t, ~start: int, ~end_: int) => t = "slice" - - @send external copy: t => t = "slice" - @send external sliceFrom: (t, int) => t = "slice" + external sliceFrom: (t, int) => t = "slice" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) + @send external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~start=%insert.unlabelledArgument(1)), + }) @send - external subarray: (t, ~start: int, ~end_: int) => t = "subarray" - - @send external subarrayFrom: (t, int) => t = "subarray" - - @send external toString: t => string = "toString" - @send external toLocaleString: t => string = "toLocaleString" + external subarrayFrom: (t, int) => t = "subarray" + + @deprecated({reason: "Use `TypedArray.toString` instead.", migrate: TypedArray.toString()}) @send + external toString: t => string = "toString" + @deprecated({ + reason: "Use `TypedArray.toLocaleString` instead.", + migrate: TypedArray.toLocaleString(), + }) + @send + external toLocaleString: t => string = "toLocaleString" /* Iteration functions */ /* commented out until bs has a plan for iterators external entries : t -> (int * elt) array_iter = "" [@@send] */ - @send external every: (t, elt => bool) => bool = "every" - @send external everyi: (t, (elt, int) => bool) => bool = "every" - - @send external filter: (t, elt => bool) => t = "filter" - @send external filteri: (t, (elt, int) => bool) => t = "filter" - - @send external find: (t, elt => bool) => Js_undefined.t = "find" - @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - - @send external findIndex: (t, elt => bool) => int = "findIndex" - @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + @deprecated({reason: "Use `TypedArray.every` instead.", migrate: TypedArray.every()}) @send + external every: (t, elt => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.everyWithIndex` instead.", + migrate: TypedArray.everyWithIndex(), + }) + @send + external everyi: (t, (elt, int) => bool) => bool = "every" + + @deprecated({reason: "Use `TypedArray.filter` instead.", migrate: TypedArray.filter()}) @send + external filter: (t, elt => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filterWithIndex` instead.", + migrate: TypedArray.filterWithIndex(), + }) + @send + external filteri: (t, (elt, int) => bool) => t = "filter" + + @deprecated({reason: "Use `TypedArray.find` instead.", migrate: TypedArray.find()}) @send + external find: (t, elt => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.findWithIndex` instead.", + migrate: TypedArray.findWithIndex(), + }) + @send + external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - @send external forEach: (t, elt => unit) => unit = "forEach" - @send external forEachi: (t, (elt, int) => unit) => unit = "forEach" + @deprecated({reason: "Use `TypedArray.findIndex` instead.", migrate: TypedArray.findIndex()}) + @send + external findIndex: (t, elt => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndexWithIndex` instead.", + migrate: TypedArray.findIndexWithIndex(), + }) + @send + external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + + @deprecated({reason: "Use `TypedArray.forEach` instead.", migrate: TypedArray.forEach()}) @send + external forEach: (t, elt => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEachWithIndex` instead.", + migrate: TypedArray.forEachWithIndex(), + }) + @send + external forEachi: (t, (elt, int) => unit) => unit = "forEach" /* commented out until bs has a plan for iterators external keys : t -> int array_iter = "" [@@send] */ - @send external map: (t, elt => 'b) => typed_array<'b> = "map" - @send external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - - @send external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" - @send external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - - @send external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" - @send external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + @deprecated({reason: "Use `TypedArray.map` instead.", migrate: TypedArray.map()}) @send + external map: (t, elt => 'b) => typed_array<'b> = "map" + @deprecated({ + reason: "Use `TypedArray.mapWithIndex` instead.", + migrate: TypedArray.mapWithIndex(), + }) + @send + external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" + + @deprecated({reason: "Use `TypedArray.reduce` instead.", migrate: TypedArray.reduce()}) @send + external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" + @deprecated({ + reason: "Use `TypedArray.reduceWithIndex` instead.", + migrate: TypedArray.reduceWithIndex(), + }) + @send + external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - @send external some: (t, elt => bool) => bool = "some" - @send external somei: (t, (elt, int) => bool) => bool = "some" + @deprecated({reason: "Use `TypedArray.reduceRight` instead.", migrate: TypedArray.reduceRight()}) + @send + external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.reduceRightWithIndex` instead.", + migrate: TypedArray.reduceRightWithIndex(), + }) + @send + external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + + @deprecated({reason: "Use `TypedArray.some` instead.", migrate: TypedArray.some()}) @send + external some: (t, elt => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.someWithIndex` instead.", + migrate: TypedArray.someWithIndex(), + }) + @send + external somei: (t, (elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Int32Array.BYTES_PER_ELEMENT" + @deprecated({ + reason: "Use `Int32Array.Constants.bytesPerElement` instead.", + migrate: Int32Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Int32Array.BYTES_PER_ELEMENT" - @new external make: array => t = "Int32Array" + @deprecated({reason: "Use `Int32Array.fromArray` instead.", migrate: Int32Array.fromArray()}) @new + external make: array => t = "Int32Array" /** can throw */ - @new + @new @deprecated({reason: "Use `Int32Array.fromBuffer", migrate: Int32Array.fromBuffer()}) external fromBuffer: array_buffer => t = "Int32Array" /** @@ -795,6 +1948,10 @@ module Int32Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Int32Array.fromBufferToEnd` instead.", + migrate: Int32Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Int32Array" /** @@ -803,10 +1960,24 @@ module Int32Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Int32Array.fromBufferWithRange", + migrate: Int32Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Int32Array" - @new external fromLength: int => t = "Int32Array" - @val external from: array_like => t = "Int32Array.from" + @deprecated({reason: "Use `Int32Array.fromLength` instead.", migrate: Int32Array.fromLength()}) + @new + external fromLength: int => t = "Int32Array" + @deprecated({ + reason: "Use `Int32Array.fromArrayLikeOrIterable` instead.", + migrate: Int32Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Int32Array.from" /* *Array.of is redundant, use make */ } @@ -823,95 +1994,251 @@ module Uint32Array = { @get external byteLength: t => int = "byteLength" @get external byteOffset: t => int = "byteOffset" - @send external setArray: (t, array) => unit = "set" - @send external setArrayOffset: (t, array, int) => unit = "set" + @deprecated({reason: "Use `TypedArray.setArray` instead.", migrate: TypedArray.setArray()}) @send + external setArray: (t, array) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArrayFrom` instead.", + migrate: TypedArray.setArrayFrom(%insert.unlabelledArgument(2)), + }) + @send + external setArrayOffset: (t, array, int) => unit = "set" /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({reason: "Use `TypedArray.length` instead.", migrate: TypedArray.length()}) @get + external length: t => int = "length" /* Mutator functions */ - @send external copyWithin: (t, ~to_: int) => t = "copyWithin" - @send external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" - @send external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - - @send external fillInPlace: (t, elt) => t = "fill" - @send external fillFromInPlace: (t, elt, ~from: int) => t = "fill" - @send external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.copyAllWithin` instead.", + migrate: TypedArray.copyAllWithin(~target=%insert.labelledArgument("to_")), + }) + @send + external copyWithin: (t, ~to_: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithinToEnd` instead.", + migrate: TypedArray.copyWithinToEnd( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("from"), + ), + }) + @send + external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" + + @deprecated({reason: "Use `TypedArray.fillAll` instead.", migrate: TypedArray.fillAll()}) @send + external fillInPlace: (t, elt) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fillToEnd` instead.", + migrate: TypedArray.fillToEnd(~start=%insert.labelledArgument("from")), + }) + @send + external fillFromInPlace: (t, elt, ~from: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fill` instead.", + migrate: TypedArray.fill( + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" - @send external reverseInPlace: t => t = "reverse" + @deprecated({reason: "Use `TypedArray.reverse` instead.", migrate: TypedArray.reverse()}) @send + external reverseInPlace: t => t = "reverse" - @send external sortInPlace: t => t = "sort" - @send external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" + @deprecated({ + reason: "Use `TypedArray.toSorted` instead.", + migrate: TypedArray.toSorted((a, b) => + %todo_("This needs a comparator function. Use an appropriate comparator (e.g. Int.compare).") + ), + }) + @send + external sortInPlace: t => t = "sort" + @deprecated({reason: "Use `TypedArray.sort` instead.", migrate: TypedArray.sort()}) @send + external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" /* Accessor functions */ - @send external includes: (t, elt) => bool = "includes" /* ES2016 */ - - @send external indexOf: (t, elt) => int = "indexOf" - @send external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" + @deprecated({reason: "Use `TypedArray.includes` instead.", migrate: TypedArray.includes()}) @send + external includes: (t, elt) => bool = "includes" /* ES2016 */ + + @deprecated({reason: "Use `TypedArray.indexOf` instead.", migrate: TypedArray.indexOf()}) @send + external indexOf: (t, elt) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOfFrom` instead.", + migrate: TypedArray.indexOfFrom(%insert.labelledArgument("from")), + }) + @send + external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" - @send external join: t => string = "join" - @send external joinWith: (t, string) => string = "join" + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith(",")}) + @send + external join: t => string = "join" + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith()}) @send + external joinWith: (t, string) => string = "join" - @send external lastIndexOf: (t, elt) => int = "lastIndexOf" - @send external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" + @deprecated({reason: "Use `TypedArray.lastIndexOf` instead.", migrate: TypedArray.lastIndexOf()}) + @send + external lastIndexOf: (t, elt) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOfFrom` instead.", + migrate: TypedArray.lastIndexOfFrom(%insert.labelledArgument("from")), + }) + @send + external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) + @send external slice: (t, ~start: int, ~end_: int) => t = "slice" + + @deprecated({reason: "Use `TypedArray.copy` instead.", migrate: TypedArray.copy()}) @send + external copy: t => t = "slice" + @deprecated({ + reason: "Use `TypedArray.sliceToEnd` instead.", + migrate: TypedArray.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) @send - external slice: (t, ~start: int, ~end_: int) => t = "slice" - - @send external copy: t => t = "slice" - @send external sliceFrom: (t, int) => t = "slice" + external sliceFrom: (t, int) => t = "slice" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) + @send external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~start=%insert.unlabelledArgument(1)), + }) @send - external subarray: (t, ~start: int, ~end_: int) => t = "subarray" - - @send external subarrayFrom: (t, int) => t = "subarray" - - @send external toString: t => string = "toString" - @send external toLocaleString: t => string = "toLocaleString" + external subarrayFrom: (t, int) => t = "subarray" + + @deprecated({reason: "Use `TypedArray.toString` instead.", migrate: TypedArray.toString()}) @send + external toString: t => string = "toString" + @deprecated({ + reason: "Use `TypedArray.toLocaleString` instead.", + migrate: TypedArray.toLocaleString(), + }) + @send + external toLocaleString: t => string = "toLocaleString" /* Iteration functions */ /* commented out until bs has a plan for iterators external entries : t -> (int * elt) array_iter = "" [@@send] */ - @send external every: (t, elt => bool) => bool = "every" - @send external everyi: (t, (elt, int) => bool) => bool = "every" - - @send external filter: (t, elt => bool) => t = "filter" - @send external filteri: (t, (elt, int) => bool) => t = "filter" - - @send external find: (t, elt => bool) => Js_undefined.t = "find" - @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - - @send external findIndex: (t, elt => bool) => int = "findIndex" - @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + @deprecated({reason: "Use `TypedArray.every` instead.", migrate: TypedArray.every()}) @send + external every: (t, elt => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.everyWithIndex` instead.", + migrate: TypedArray.everyWithIndex(), + }) + @send + external everyi: (t, (elt, int) => bool) => bool = "every" + + @deprecated({reason: "Use `TypedArray.filter` instead.", migrate: TypedArray.filter()}) @send + external filter: (t, elt => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filterWithIndex` instead.", + migrate: TypedArray.filterWithIndex(), + }) + @send + external filteri: (t, (elt, int) => bool) => t = "filter" + + @deprecated({reason: "Use `TypedArray.find` instead.", migrate: TypedArray.find()}) @send + external find: (t, elt => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.findWithIndex` instead.", + migrate: TypedArray.findWithIndex(), + }) + @send + external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - @send external forEach: (t, elt => unit) => unit = "forEach" - @send external forEachi: (t, (elt, int) => unit) => unit = "forEach" + @deprecated({reason: "Use `TypedArray.findIndex` instead.", migrate: TypedArray.findIndex()}) + @send + external findIndex: (t, elt => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndexWithIndex` instead.", + migrate: TypedArray.findIndexWithIndex(), + }) + @send + external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + + @deprecated({reason: "Use `TypedArray.forEach` instead.", migrate: TypedArray.forEach()}) @send + external forEach: (t, elt => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEachWithIndex` instead.", + migrate: TypedArray.forEachWithIndex(), + }) + @send + external forEachi: (t, (elt, int) => unit) => unit = "forEach" /* commented out until bs has a plan for iterators external keys : t -> int array_iter = "" [@@send] */ - @send external map: (t, elt => 'b) => typed_array<'b> = "map" - @send external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - - @send external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" - @send external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - - @send external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" - @send external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + @deprecated({reason: "Use `TypedArray.map` instead.", migrate: TypedArray.map()}) @send + external map: (t, elt => 'b) => typed_array<'b> = "map" + @deprecated({ + reason: "Use `TypedArray.mapWithIndex` instead.", + migrate: TypedArray.mapWithIndex(), + }) + @send + external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" + + @deprecated({reason: "Use `TypedArray.reduce` instead.", migrate: TypedArray.reduce()}) @send + external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" + @deprecated({ + reason: "Use `TypedArray.reduceWithIndex` instead.", + migrate: TypedArray.reduceWithIndex(), + }) + @send + external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - @send external some: (t, elt => bool) => bool = "some" - @send external somei: (t, (elt, int) => bool) => bool = "some" + @deprecated({reason: "Use `TypedArray.reduceRight` instead.", migrate: TypedArray.reduceRight()}) + @send + external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.reduceRightWithIndex` instead.", + migrate: TypedArray.reduceRightWithIndex(), + }) + @send + external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + + @deprecated({reason: "Use `TypedArray.some` instead.", migrate: TypedArray.some()}) @send + external some: (t, elt => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.someWithIndex` instead.", + migrate: TypedArray.someWithIndex(), + }) + @send + external somei: (t, (elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Uint32Array.BYTES_PER_ELEMENT" + @deprecated({ + reason: "Use `Uint32Array.Constants.bytesPerElement` instead.", + migrate: Uint32Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Uint32Array.BYTES_PER_ELEMENT" - @new external make: array => t = "Uint32Array" + @deprecated({reason: "Use `Uint32Array.fromArray` instead.", migrate: Uint32Array.fromArray()}) + @new + external make: array => t = "Uint32Array" /** can throw */ @new + @deprecated({reason: "Use `Uint32Array.fromBuffer` instead.", migrate: Uint32Array.fromBuffer()}) external fromBuffer: array_buffer => t = "Uint32Array" /** @@ -920,6 +2247,10 @@ module Uint32Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Uint32Array.fromBufferToEnd` instead.", + migrate: Uint32Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Uint32Array" /** @@ -928,10 +2259,24 @@ module Uint32Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Uint32Array.fromBufferWithRange` instead.", + migrate: Uint32Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Uint32Array" - @new external fromLength: int => t = "Uint32Array" - @val external from: array_like => t = "Uint32Array.from" + @deprecated({reason: "Use `Uint32Array.fromLength` instead.", migrate: Uint32Array.fromLength()}) + @new + external fromLength: int => t = "Uint32Array" + @deprecated({ + reason: "Use `Uint32Array.fromArrayLikeOrIterable` instead.", + migrate: Uint32Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Uint32Array.from" /* *Array.of is redundant, use make */ } @@ -951,95 +2296,256 @@ module Float32Array = { @get external byteLength: t => int = "byteLength" @get external byteOffset: t => int = "byteOffset" - @send external setArray: (t, array) => unit = "set" - @send external setArrayOffset: (t, array, int) => unit = "set" + @deprecated({reason: "Use `TypedArray.setArray` instead.", migrate: TypedArray.setArray()}) @send + external setArray: (t, array) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArrayFrom` instead.", + migrate: TypedArray.setArrayFrom(%insert.unlabelledArgument(2)), + }) + @send + external setArrayOffset: (t, array, int) => unit = "set" /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({reason: "Use `TypedArray.length` instead.", migrate: TypedArray.length()}) @get + external length: t => int = "length" /* Mutator functions */ - @send external copyWithin: (t, ~to_: int) => t = "copyWithin" - @send external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" - @send external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - - @send external fillInPlace: (t, elt) => t = "fill" - @send external fillFromInPlace: (t, elt, ~from: int) => t = "fill" - @send external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" - - @send external reverseInPlace: t => t = "reverse" - - @send external sortInPlace: t => t = "sort" - @send external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" + @deprecated({ + reason: "Use `TypedArray.copyAllWithin` instead.", + migrate: TypedArray.copyAllWithin(~target=%insert.labelledArgument("to_")), + }) + @send + external copyWithin: (t, ~to_: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithinToEnd` instead.", + migrate: TypedArray.copyWithinToEnd( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("from"), + ), + }) + @send + external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" + + @deprecated({reason: "Use `TypedArray.fillAll` instead.", migrate: TypedArray.fillAll()}) @send + external fillInPlace: (t, elt) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fillToEnd` instead.", + migrate: TypedArray.fillToEnd(~start=%insert.labelledArgument("from")), + }) + @send + external fillFromInPlace: (t, elt, ~from: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fill` instead.", + migrate: TypedArray.fill( + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" + + @deprecated({reason: "Use `TypedArray.reverse` instead.", migrate: TypedArray.reverse()}) @send + external reverseInPlace: t => t = "reverse" + + @deprecated({ + reason: "Use `TypedArray.toSorted` instead.", + migrate: TypedArray.toSorted((a, b) => + %todo_( + "This needs a comparator function. Use an appropriate comparator (e.g. Float.compare)." + ) + ), + }) + @send + external sortInPlace: t => t = "sort" + @deprecated({reason: "Use `TypedArray.sort` instead.", migrate: TypedArray.sort()}) @send + external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" /* Accessor functions */ - @send external includes: (t, elt) => bool = "includes" /* ES2016 */ - - @send external indexOf: (t, elt) => int = "indexOf" - @send external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" + @deprecated({reason: "Use `TypedArray.includes` instead.", migrate: TypedArray.includes()}) @send + external includes: (t, elt) => bool = "includes" /* ES2016 */ + + @deprecated({reason: "Use `TypedArray.indexOf` instead.", migrate: TypedArray.indexOf()}) @send + external indexOf: (t, elt) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOfFrom` instead.", + migrate: TypedArray.indexOfFrom(%insert.labelledArgument("from")), + }) + @send + external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" - @send external join: t => string = "join" - @send external joinWith: (t, string) => string = "join" + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith(",")}) + @send + external join: t => string = "join" + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith()}) @send + external joinWith: (t, string) => string = "join" - @send external lastIndexOf: (t, elt) => int = "lastIndexOf" - @send external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" + @deprecated({reason: "Use `TypedArray.lastIndexOf` instead.", migrate: TypedArray.lastIndexOf()}) + @send + external lastIndexOf: (t, elt) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOfFrom` instead.", + migrate: TypedArray.lastIndexOfFrom(%insert.labelledArgument("from")), + }) + @send + external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) + @send external slice: (t, ~start: int, ~end_: int) => t = "slice" + + @deprecated({reason: "Use `TypedArray.copy` instead.", migrate: TypedArray.copy()}) @send + external copy: t => t = "slice" + @deprecated({ + reason: "Use `TypedArray.sliceToEnd` instead.", + migrate: TypedArray.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) @send - external slice: (t, ~start: int, ~end_: int) => t = "slice" - - @send external copy: t => t = "slice" - @send external sliceFrom: (t, int) => t = "slice" + external sliceFrom: (t, int) => t = "slice" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) + @send external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~start=%insert.unlabelledArgument(1)), + }) @send - external subarray: (t, ~start: int, ~end_: int) => t = "subarray" - - @send external subarrayFrom: (t, int) => t = "subarray" - - @send external toString: t => string = "toString" - @send external toLocaleString: t => string = "toLocaleString" + external subarrayFrom: (t, int) => t = "subarray" + + @deprecated({reason: "Use `TypedArray.toString` instead.", migrate: TypedArray.toString()}) @send + external toString: t => string = "toString" + @deprecated({ + reason: "Use `TypedArray.toLocaleString` instead.", + migrate: TypedArray.toLocaleString(), + }) + @send + external toLocaleString: t => string = "toLocaleString" /* Iteration functions */ /* commented out until bs has a plan for iterators external entries : t -> (int * elt) array_iter = "" [@@send] */ - @send external every: (t, elt => bool) => bool = "every" - @send external everyi: (t, (elt, int) => bool) => bool = "every" - - @send external filter: (t, elt => bool) => t = "filter" - @send external filteri: (t, (elt, int) => bool) => t = "filter" - - @send external find: (t, elt => bool) => Js_undefined.t = "find" - @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - - @send external findIndex: (t, elt => bool) => int = "findIndex" - @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + @deprecated({reason: "Use `TypedArray.every` instead.", migrate: TypedArray.every()}) @send + external every: (t, elt => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.everyWithIndex` instead.", + migrate: TypedArray.everyWithIndex(), + }) + @send + external everyi: (t, (elt, int) => bool) => bool = "every" + + @deprecated({reason: "Use `TypedArray.filter` instead.", migrate: TypedArray.filter()}) @send + external filter: (t, elt => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filterWithIndex` instead.", + migrate: TypedArray.filterWithIndex(), + }) + @send + external filteri: (t, (elt, int) => bool) => t = "filter" + + @deprecated({reason: "Use `TypedArray.find` instead.", migrate: TypedArray.find()}) @send + external find: (t, elt => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.findWithIndex` instead.", + migrate: TypedArray.findWithIndex(), + }) + @send + external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - @send external forEach: (t, elt => unit) => unit = "forEach" - @send external forEachi: (t, (elt, int) => unit) => unit = "forEach" + @deprecated({reason: "Use `TypedArray.findIndex` instead.", migrate: TypedArray.findIndex()}) + @send + external findIndex: (t, elt => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndexWithIndex` instead.", + migrate: TypedArray.findIndexWithIndex(), + }) + @send + external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + + @deprecated({reason: "Use `TypedArray.forEach` instead.", migrate: TypedArray.forEach()}) @send + external forEach: (t, elt => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEachWithIndex` instead.", + migrate: TypedArray.forEachWithIndex(), + }) + @send + external forEachi: (t, (elt, int) => unit) => unit = "forEach" /* commented out until bs has a plan for iterators external keys : t -> int array_iter = "" [@@send] */ - @send external map: (t, elt => 'b) => typed_array<'b> = "map" - @send external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - - @send external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" - @send external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - - @send external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" - @send external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + @deprecated({reason: "Use `TypedArray.map` instead.", migrate: TypedArray.map()}) @send + external map: (t, elt => 'b) => typed_array<'b> = "map" + @deprecated({ + reason: "Use `TypedArray.mapWithIndex` instead.", + migrate: TypedArray.mapWithIndex(), + }) + @send + external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" + + @deprecated({reason: "Use `TypedArray.reduce` instead.", migrate: TypedArray.reduce()}) @send + external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" + @deprecated({ + reason: "Use `TypedArray.reduceWithIndex` instead.", + migrate: TypedArray.reduceWithIndex(), + }) + @send + external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - @send external some: (t, elt => bool) => bool = "some" - @send external somei: (t, (elt, int) => bool) => bool = "some" + @deprecated({reason: "Use `TypedArray.reduceRight` instead.", migrate: TypedArray.reduceRight()}) + @send + external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.reduceRightWithIndex` instead.", + migrate: TypedArray.reduceRightWithIndex(), + }) + @send + external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + + @deprecated({reason: "Use `TypedArray.some` instead.", migrate: TypedArray.some()}) @send + external some: (t, elt => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.someWithIndex` instead.", + migrate: TypedArray.someWithIndex(), + }) + @send + external somei: (t, (elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Float32Array.BYTES_PER_ELEMENT" + @deprecated({ + reason: "Use `Float32Array.Constants.bytesPerElement` instead.", + migrate: Float32Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Float32Array.BYTES_PER_ELEMENT" - @new external make: array => t = "Float32Array" + @deprecated({reason: "Use `Float32Array.fromArray` instead.", migrate: Float32Array.fromArray()}) + @new + external make: array => t = "Float32Array" /** can throw */ @new + @deprecated({ + reason: "Use `Float32Array.fromBuffer` instead.", + migrate: Float32Array.fromBuffer(), + }) external fromBuffer: array_buffer => t = "Float32Array" /** @@ -1048,6 +2554,10 @@ module Float32Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Float32Array.fromBufferToEnd` instead.", + migrate: Float32Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Float32Array" /** @@ -1056,10 +2566,27 @@ module Float32Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Float32Array.fromBufferWithRange` instead.", + migrate: Float32Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Float32Array" - @new external fromLength: int => t = "Float32Array" - @val external from: array_like => t = "Float32Array.from" + @deprecated({ + reason: "Use `Float32Array.fromLength` instead.", + migrate: Float32Array.fromLength(), + }) + @new + external fromLength: int => t = "Float32Array" + @deprecated({ + reason: "Use `Float32Array.fromArrayLikeOrIterable` instead.", + migrate: Float32Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Float32Array.from" /* *Array.of is redundant, use make */ } @@ -1076,95 +2603,256 @@ module Float64Array = { @get external byteLength: t => int = "byteLength" @get external byteOffset: t => int = "byteOffset" - @send external setArray: (t, array) => unit = "set" - @send external setArrayOffset: (t, array, int) => unit = "set" + @deprecated({reason: "Use `TypedArray.setArray` instead.", migrate: TypedArray.setArray()}) @send + external setArray: (t, array) => unit = "set" + @deprecated({ + reason: "Use `TypedArray.setArrayFrom` instead.", + migrate: TypedArray.setArrayFrom(%insert.unlabelledArgument(2)), + }) + @send + external setArrayOffset: (t, array, int) => unit = "set" /* There's also an overload for typed arrays, but don't know how to model that without subtyping */ /* Array interface(-ish) */ - @get external length: t => int = "length" + @deprecated({reason: "Use `TypedArray.length` instead.", migrate: TypedArray.length()}) @get + external length: t => int = "length" /* Mutator functions */ - @send external copyWithin: (t, ~to_: int) => t = "copyWithin" - @send external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" - @send external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" - - @send external fillInPlace: (t, elt) => t = "fill" - @send external fillFromInPlace: (t, elt, ~from: int) => t = "fill" - @send external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" - - @send external reverseInPlace: t => t = "reverse" - - @send external sortInPlace: t => t = "sort" - @send external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" + @deprecated({ + reason: "Use `TypedArray.copyAllWithin` instead.", + migrate: TypedArray.copyAllWithin(~target=%insert.labelledArgument("to_")), + }) + @send + external copyWithin: (t, ~to_: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithinToEnd` instead.", + migrate: TypedArray.copyWithinToEnd( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("from"), + ), + }) + @send + external copyWithinFrom: (t, ~to_: int, ~from: int) => t = "copyWithin" + @deprecated({ + reason: "Use `TypedArray.copyWithin` instead.", + migrate: TypedArray.copyWithin( + ~target=%insert.labelledArgument("to_"), + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external copyWithinFromRange: (t, ~to_: int, ~start: int, ~end_: int) => t = "copyWithin" + + @deprecated({reason: "Use `TypedArray.fillAll` instead.", migrate: TypedArray.fillAll()}) @send + external fillInPlace: (t, elt) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fillToEnd` instead.", + migrate: TypedArray.fillToEnd(~start=%insert.labelledArgument("from")), + }) + @send + external fillFromInPlace: (t, elt, ~from: int) => t = "fill" + @deprecated({ + reason: "Use `TypedArray.fill` instead.", + migrate: TypedArray.fill( + ~start=%insert.labelledArgument("start"), + ~end=%insert.labelledArgument("end_"), + ), + }) + @send + external fillRangeInPlace: (t, elt, ~start: int, ~end_: int) => t = "fill" + + @deprecated({reason: "Use `TypedArray.reverse` instead.", migrate: TypedArray.reverse()}) @send + external reverseInPlace: t => t = "reverse" + + @deprecated({ + reason: "Use `TypedArray.toSorted` instead.", + migrate: TypedArray.toSorted((a, b) => + %todo_( + "This needs a comparator function. Use an appropriate comparator (e.g. Float.compare)." + ) + ), + }) + @send + external sortInPlace: t => t = "sort" + @deprecated({reason: "Use `TypedArray.sort` instead.", migrate: TypedArray.sort()}) @send + external sortInPlaceWith: (t, (elt, elt) => int) => t = "sort" /* Accessor functions */ - @send external includes: (t, elt) => bool = "includes" /* ES2016 */ - - @send external indexOf: (t, elt) => int = "indexOf" - @send external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" + @deprecated({reason: "Use `TypedArray.includes` instead.", migrate: TypedArray.includes()}) @send + external includes: (t, elt) => bool = "includes" /* ES2016 */ + + @deprecated({reason: "Use `TypedArray.indexOf` instead.", migrate: TypedArray.indexOf()}) @send + external indexOf: (t, elt) => int = "indexOf" + @deprecated({ + reason: "Use `TypedArray.indexOfFrom` instead.", + migrate: TypedArray.indexOfFrom(%insert.labelledArgument("from")), + }) + @send + external indexOfFrom: (t, elt, ~from: int) => int = "indexOf" - @send external join: t => string = "join" - @send external joinWith: (t, string) => string = "join" + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith(",")}) + @send + external join: t => string = "join" + @deprecated({reason: "Use `TypedArray.joinWith` instead.", migrate: TypedArray.joinWith()}) @send + external joinWith: (t, string) => string = "join" - @send external lastIndexOf: (t, elt) => int = "lastIndexOf" - @send external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" + @deprecated({reason: "Use `TypedArray.lastIndexOf` instead.", migrate: TypedArray.lastIndexOf()}) + @send + external lastIndexOf: (t, elt) => int = "lastIndexOf" + @deprecated({ + reason: "Use `TypedArray.lastIndexOfFrom` instead.", + migrate: TypedArray.lastIndexOfFrom(%insert.labelledArgument("from")), + }) + @send + external lastIndexOfFrom: (t, elt, ~from: int) => int = "lastIndexOf" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.slice` instead.", + migrate: TypedArray.slice(~end=%insert.labelledArgument("end_")), + }) + @send external slice: (t, ~start: int, ~end_: int) => t = "slice" + + @deprecated({reason: "Use `TypedArray.copy` instead.", migrate: TypedArray.copy()}) @send + external copy: t => t = "slice" + @deprecated({ + reason: "Use `TypedArray.sliceToEnd` instead.", + migrate: TypedArray.sliceToEnd(~start=%insert.unlabelledArgument(1)), + }) @send - external slice: (t, ~start: int, ~end_: int) => t = "slice" - - @send external copy: t => t = "slice" - @send external sliceFrom: (t, int) => t = "slice" + external sliceFrom: (t, int) => t = "slice" /** `start` is inclusive, `end_` exclusive */ + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~end=%insert.labelledArgument("end_")), + }) + @send external subarray: (t, ~start: int, ~end_: int) => t = "subarray" + + @deprecated({ + reason: "Use `TypedArray.subarray` instead.", + migrate: TypedArray.subarray(~start=%insert.unlabelledArgument(1)), + }) @send - external subarray: (t, ~start: int, ~end_: int) => t = "subarray" - - @send external subarrayFrom: (t, int) => t = "subarray" - - @send external toString: t => string = "toString" - @send external toLocaleString: t => string = "toLocaleString" + external subarrayFrom: (t, int) => t = "subarray" + + @deprecated({reason: "Use `TypedArray.toString` instead.", migrate: TypedArray.toString()}) @send + external toString: t => string = "toString" + @deprecated({ + reason: "Use `TypedArray.toLocaleString` instead.", + migrate: TypedArray.toLocaleString(), + }) + @send + external toLocaleString: t => string = "toLocaleString" /* Iteration functions */ /* commented out until bs has a plan for iterators external entries : t -> (int * elt) array_iter = "" [@@send] */ - @send external every: (t, elt => bool) => bool = "every" - @send external everyi: (t, (elt, int) => bool) => bool = "every" - - @send external filter: (t, elt => bool) => t = "filter" - @send external filteri: (t, (elt, int) => bool) => t = "filter" - - @send external find: (t, elt => bool) => Js_undefined.t = "find" - @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - - @send external findIndex: (t, elt => bool) => int = "findIndex" - @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + @deprecated({reason: "Use `TypedArray.every` instead.", migrate: TypedArray.every()}) @send + external every: (t, elt => bool) => bool = "every" + @deprecated({ + reason: "Use `TypedArray.everyWithIndex` instead.", + migrate: TypedArray.everyWithIndex(), + }) + @send + external everyi: (t, (elt, int) => bool) => bool = "every" + + @deprecated({reason: "Use `TypedArray.filter` instead.", migrate: TypedArray.filter()}) @send + external filter: (t, elt => bool) => t = "filter" + @deprecated({ + reason: "Use `TypedArray.filterWithIndex` instead.", + migrate: TypedArray.filterWithIndex(), + }) + @send + external filteri: (t, (elt, int) => bool) => t = "filter" + + @deprecated({reason: "Use `TypedArray.find` instead.", migrate: TypedArray.find()}) @send + external find: (t, elt => bool) => Js_undefined.t = "find" + @deprecated({ + reason: "Use `TypedArray.findWithIndex` instead.", + migrate: TypedArray.findWithIndex(), + }) + @send + external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" - @send external forEach: (t, elt => unit) => unit = "forEach" - @send external forEachi: (t, (elt, int) => unit) => unit = "forEach" + @deprecated({reason: "Use `TypedArray.findIndex` instead.", migrate: TypedArray.findIndex()}) + @send + external findIndex: (t, elt => bool) => int = "findIndex" + @deprecated({ + reason: "Use `TypedArray.findIndexWithIndex` instead.", + migrate: TypedArray.findIndexWithIndex(), + }) + @send + external findIndexi: (t, (elt, int) => bool) => int = "findIndex" + + @deprecated({reason: "Use `TypedArray.forEach` instead.", migrate: TypedArray.forEach()}) @send + external forEach: (t, elt => unit) => unit = "forEach" + @deprecated({ + reason: "Use `TypedArray.forEachWithIndex` instead.", + migrate: TypedArray.forEachWithIndex(), + }) + @send + external forEachi: (t, (elt, int) => unit) => unit = "forEach" /* commented out until bs has a plan for iterators external keys : t -> int array_iter = "" [@@send] */ - @send external map: (t, elt => 'b) => typed_array<'b> = "map" - @send external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" - - @send external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" - @send external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - - @send external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" - @send external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + @deprecated({reason: "Use `TypedArray.map` instead.", migrate: TypedArray.map()}) @send + external map: (t, elt => 'b) => typed_array<'b> = "map" + @deprecated({ + reason: "Use `TypedArray.mapWithIndex` instead.", + migrate: TypedArray.mapWithIndex(), + }) + @send + external mapi: (t, (elt, int) => 'b) => typed_array<'b> = "map" + + @deprecated({reason: "Use `TypedArray.reduce` instead.", migrate: TypedArray.reduce()}) @send + external reduce: (t, ('b, elt) => 'b, 'b) => 'b = "reduce" + @deprecated({ + reason: "Use `TypedArray.reduceWithIndex` instead.", + migrate: TypedArray.reduceWithIndex(), + }) + @send + external reducei: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduce" - @send external some: (t, elt => bool) => bool = "some" - @send external somei: (t, (elt, int) => bool) => bool = "some" + @deprecated({reason: "Use `TypedArray.reduceRight` instead.", migrate: TypedArray.reduceRight()}) + @send + external reduceRight: (t, ('b, elt) => 'b, 'b) => 'b = "reduceRight" + @deprecated({ + reason: "Use `TypedArray.reduceRightWithIndex` instead.", + migrate: TypedArray.reduceRightWithIndex(), + }) + @send + external reduceRighti: (t, ('b, elt, int) => 'b, 'b) => 'b = "reduceRight" + + @deprecated({reason: "Use `TypedArray.some` instead.", migrate: TypedArray.some()}) @send + external some: (t, elt => bool) => bool = "some" + @deprecated({ + reason: "Use `TypedArray.someWithIndex` instead.", + migrate: TypedArray.someWithIndex(), + }) + @send + external somei: (t, (elt, int) => bool) => bool = "some" - @val external _BYTES_PER_ELEMENT: int = "Float64Array.BYTES_PER_ELEMENT" + @deprecated({ + reason: "Use `Float64Array.Constants.bytesPerElement` instead.", + migrate: Float64Array.Constants.bytesPerElement, + }) + @val + external _BYTES_PER_ELEMENT: int = "Float64Array.BYTES_PER_ELEMENT" - @new external make: array => t = "Float64Array" + @deprecated({reason: "Use `Float64Array.fromArray` instead.", migrate: Float64Array.fromArray()}) + @new + external make: array => t = "Float64Array" /** can throw */ @new + @deprecated({ + reason: "Use `Float64Array.fromBuffer` instead.", + migrate: Float64Array.fromBuffer(), + }) external fromBuffer: array_buffer => t = "Float64Array" /** @@ -1173,6 +2861,10 @@ module Float64Array = { **param** offset is in bytes */ @new + @deprecated({ + reason: "Use `Float64Array.fromBufferToEnd` instead.", + migrate: Float64Array.fromBufferToEnd(~byteOffset=%insert.unlabelledArgument(1)), + }) external fromBufferOffset: (array_buffer, int) => t = "Float64Array" /** @@ -1181,10 +2873,27 @@ module Float64Array = { **param** offset is in bytes, length in elements */ @new + @deprecated({ + reason: "Use `Float64Array.fromBufferWithRange` instead.", + migrate: Float64Array.fromBufferWithRange( + ~byteOffset=%insert.labelledArgument("offset"), + ~length=%insert.labelledArgument("length"), + ), + }) external fromBufferRange: (array_buffer, ~offset: int, ~length: int) => t = "Float64Array" - @new external fromLength: int => t = "Float64Array" - @val external from: array_like => t = "Float64Array.from" + @deprecated({ + reason: "Use `Float64Array.fromLength` instead.", + migrate: Float64Array.fromLength(), + }) + @new + external fromLength: int => t = "Float64Array" + @deprecated({ + reason: "Use `Float64Array.fromArrayLikeOrIterable` instead.", + migrate: Float64Array.fromArrayLikeOrIterable(), + }) + @val + external from: array_like => t = "Float64Array.from" /* *Array.of is redundant, use make */ } diff --git a/packages/@rescript/runtime/Js_types.resi b/packages/@rescript/runtime/Js_types.resi index 7ac929ff11..1144a53618 100644 --- a/packages/@rescript/runtime/Js_types.resi +++ b/packages/@rescript/runtime/Js_types.resi @@ -25,18 +25,39 @@ /*** Provide utilities for manipulating JS types. */ /** Js symbol type (only available in ES6) */ +@deprecated({ + reason: "Use `Symbol.t` instead.", + migrate: %replace.type(: Symbol.t), +}) type symbol = Stdlib_Symbol.t +@deprecated({ + reason: "Use `Type.Classify.object` instead.", + migrate: %replace.type(: Type.Classify.object), +}) type obj_val = Stdlib_Type.Classify.object /** This type has only one value `undefined` */ +@deprecated( + "This has been deprecated and will be removed in v13. Use functions and types from the `Type` module instead." +) type undefined_val /** This type has only one value `null` */ +@deprecated( + "This has been deprecated and will be removed in v13. Use functions and types from the `Type` module instead." +) type null_val +@deprecated({ + reason: "Use `Type.Classify.function` instead.", + migrate: %replace.type(: Type.Classify.function), +}) type function_val = Stdlib_Type.Classify.function +@deprecated( + "This has been deprecated and will be removed in v13. Use functions and types from the `Type` module instead." +) type rec t<_> = | Undefined: t | Null: t @@ -60,8 +81,14 @@ test(() => true, Function) == true test("test", Boolean) == false ``` */ +@deprecated( + "This has been deprecated and will be removed in v13. Use functions and types from the `Type` module instead." +) let test: ('a, t<'b>) => bool +@deprecated( + "This has been deprecated and will be removed in v13. Use functions and types from the `Type` module instead." +) type tagged_t = | JSFalse | JSTrue @@ -74,4 +101,7 @@ type tagged_t = | JSSymbol(symbol) | JSBigInt(bigint) +@deprecated( + "This has been deprecated and will be removed in v13. Use functions and types from the `Type` module instead." +) let classify: 'a => tagged_t diff --git a/packages/@rescript/runtime/Js_undefined.resi b/packages/@rescript/runtime/Js_undefined.resi index f33ffa39d4..b625fa8919 100644 --- a/packages/@rescript/runtime/Js_undefined.resi +++ b/packages/@rescript/runtime/Js_undefined.resi @@ -25,13 +25,21 @@ /*** Provides functionality for dealing with the `Js.undefined<'a>` type */ /** Local alias for `Js.undefined<'a>` */ +@deprecated({ + reason: "Use `undefined` directly instead.", + migrate: %replace.type(: undefined), +}) type t<+'a> = Primitive_js_extern.undefined<'a> /** Constructs a value of `Js.undefined<'a>` containing a value of `'a`. */ +@deprecated({ + reason: "Use `Nullable.make` or `option` directly instead.", + migrate: Nullable.make(), +}) external return: 'a => t<'a> = "%identity" /** Returns `true` if the given value is empty (undefined), `false` otherwise. */ -@deprecated("Use = Js.undefined directly") +@deprecated let test: t<'a> => bool /** @@ -39,12 +47,26 @@ Returns `true` if the given value is empty (undefined). **since 1.6.1** */ +@deprecated let testAny: 'a => bool /** The empty value, `undefined` */ +@deprecated({ + reason: "Use `Nullable.undefined` instead.", + migrate: Nullable.undefined, +}) external empty: t<'a> = "%undefined" +@deprecated({ + reason: "Use `Nullable.getUnsafe` instead.", + migrate: Nullable.getUnsafe(), +}) external getUnsafe: t<'a> => 'a = "%identity" + +@deprecated({ + reason: "Use `Nullable.getOrThrow` instead.", + migrate: Nullable.getOrThrow(), +}) let getExn: t<'a> => 'a /** @@ -60,6 +82,10 @@ let maybeGreetWorld = (maybeGreeting: Js.undefined) => Js.Undefined.bind(maybeGreeting, greeting => greeting ++ " world!") ``` */ +@deprecated({ + reason: "Use `Nullable.map` instead.", + migrate: Nullable.map(), +}) let bind: (t<'a>, 'a => 'b) => t<'b> /** @@ -74,6 +100,10 @@ let maybeSay = (maybeMessage: Js.undefined) => Js.Undefined.iter(maybeMessage, message => Js.log(message)) ``` */ +@deprecated({ + reason: "Use `Nullable.forEach` instead.", + migrate: Nullable.forEach(), +}) let iter: (t<'a>, 'a => unit) => unit /** @@ -81,15 +111,31 @@ Maps `option<'a>` to `Js.undefined<'a>`. `Some(a)` => `a` `None` => `empty` */ +@deprecated({ + reason: "Use `Nullable.fromOption` instead.", + migrate: Nullable.fromOption(), +}) let fromOption: option<'a> => t<'a> -@deprecated("Use fromOption instead") let from_opt: option<'a> => t<'a> +@deprecated({ + reason: "Use `Nullable.fromOption` instead.", + migrate: Nullable.fromOption(), +}) +let from_opt: option<'a> => t<'a> /** Maps `Js.undefined<'a>` to `option<'a>` `a` => `Some(a)` `empty` => `None` */ +@deprecated({ + reason: "Use `Nullable.toOption` instead.", + migrate: Nullable.toOption(), +}) let toOption: t<'a> => option<'a> -@deprecated("use toOption instead") let to_opt: t<'a> => option<'a> +@deprecated({ + reason: "Use `Nullable.toOption` instead.", + migrate: Nullable.toOption(), +}) +let to_opt: t<'a> => option<'a> diff --git a/packages/@rescript/runtime/Js_weakmap.res b/packages/@rescript/runtime/Js_weakmap.res index 152ecb2be6..c034ba108e 100644 --- a/packages/@rescript/runtime/Js_weakmap.res +++ b/packages/@rescript/runtime/Js_weakmap.res @@ -1,3 +1,7 @@ /*** ES6 WeakMap API */ +@deprecated({ + reason: "Use `WeakMap.t` instead.", + migrate: %replace.type(: WeakMap.t), +}) type t<'k, 'v> = Stdlib_WeakMap.t<'k, 'v> diff --git a/packages/@rescript/runtime/Js_weakset.res b/packages/@rescript/runtime/Js_weakset.res index 492912f2af..bb5851460f 100644 --- a/packages/@rescript/runtime/Js_weakset.res +++ b/packages/@rescript/runtime/Js_weakset.res @@ -1,3 +1,7 @@ /*** ES6 WeakSet API */ +@deprecated({ + reason: "Use `WeakSet.t` instead.", + migrate: %replace.type(: WeakSet.t), +}) type t<'a> = Stdlib_WeakSet.t<'a> diff --git a/packages/@rescript/runtime/Pervasives.res b/packages/@rescript/runtime/Pervasives.res index 056d34a3be..5083bd96f2 100644 --- a/packages/@rescript/runtime/Pervasives.res +++ b/packages/@rescript/runtime/Pervasives.res @@ -22,9 +22,10 @@ result == "Caught exception: Out of milk" */ external throw: exn => 'a = "%raise" -@deprecated( - "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw` instead" -) +@deprecated({ + reason: "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw` instead", + migrate: throw(), +}) external raise: exn => 'a = "%raise" @deprecated("Use custom exception instead") diff --git a/packages/@rescript/runtime/Stdlib_Array.res b/packages/@rescript/runtime/Stdlib_Array.res index f3c1a42a28..30dd573fd7 100644 --- a/packages/@rescript/runtime/Stdlib_Array.res +++ b/packages/@rescript/runtime/Stdlib_Array.res @@ -13,9 +13,20 @@ external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" @val external fromArrayLikeWithMap: (arrayLike<'a>, 'a => 'b) => array<'b> = "Array.from" -@deprecated("Use `fill` instead") @send external fillAll: (array<'a>, 'a) => unit = "fill" +@deprecated({ + reason: "Use `fill` instead", + migrate: Array.fill(), +}) +@send +external fillAll: (array<'a>, 'a) => unit = "fill" + +@val external fromString: string => array = "Array.from" -@deprecated("Use `fill` instead") @send +@deprecated({ + reason: "Use `fill` instead", + migrate: Array.fill(~start=%insert.labelledArgument("start")), +}) +@send external fillToEnd: (array<'a>, 'a, ~start: int) => unit = "fill" @send external fill: (array<'a>, 'a, ~start: int=?, ~end: int=?) => unit = "fill" @@ -86,10 +97,18 @@ let compare = (a, b, cmp) => { : compareFromIndex(a, b, 0, cmp, lenA) } -@deprecated("Use `copyWithin` instead") @send +@deprecated({ + reason: "Use `copyWithin` instead", + migrate: Array.copyWithin(~start=0), +}) +@send external copyAllWithin: (array<'a>, ~target: int) => array<'a> = "copyWithin" -@deprecated("Use `copyWithin` instead") @send +@deprecated({ + reason: "Use `copyWithin` instead", + migrate: Array.copyWithin(), +}) +@send external copyWithinToEnd: (array<'a>, ~target: int, ~start: int) => array<'a> = "copyWithin" @send @@ -134,17 +153,29 @@ let indexOfOpt = (arr, item) => | -1 => None | index => Some(index) } -@deprecated("Use `indexOf` instead") @send +@deprecated({ + reason: "Use `indexOf` instead", + migrate: Array.indexOf(~from=%insert.unlabelledArgument(2)), +}) +@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf" @send external join: (array, string) => string = "join" -@deprecated("Use `join` instead") @send +@deprecated({ + reason: "Use `join` instead", + migrate: Array.join(), +}) +@send external joinWith: (array, string) => string = "join" @send external joinUnsafe: (array<'a>, string) => string = "join" -@deprecated("Use `joinUnsafe` instead") @send +@deprecated({ + reason: "Use `joinUnsafe` instead", + migrate: Array.joinUnsafe(), +}) +@send external joinWithUnsafe: (array<'a>, string) => string = "join" @send external lastIndexOf: (array<'a>, 'a, ~from: int=?) => int = "lastIndexOf" @@ -153,11 +184,19 @@ let lastIndexOfOpt = (arr, item) => | -1 => None | index => Some(index) } -@deprecated("Use `lastIndexOf` instead") @send +@deprecated({ + reason: "Use `lastIndexOf` instead", + migrate: Array.lastIndexOf(~from=%insert.unlabelledArgument(2)), +}) +@send external lastIndexOfFrom: (array<'a>, 'a, int) => int = "lastIndexOf" @send external slice: (array<'a>, ~start: int=?, ~end: int=?) => array<'a> = "slice" -@deprecated("Use `slice` instead") @send +@deprecated({ + reason: "Use `slice` instead", + migrate: Array.slice(), +}) +@send external sliceToEnd: (array<'a>, ~start: int) => array<'a> = "slice" @send external copy: array<'a> => array<'a> = "slice" diff --git a/packages/@rescript/runtime/Stdlib_Array.resi b/packages/@rescript/runtime/Stdlib_Array.resi index b194e89f2d..56b9cf8fb5 100644 --- a/packages/@rescript/runtime/Stdlib_Array.resi +++ b/packages/@rescript/runtime/Stdlib_Array.resi @@ -31,6 +31,17 @@ external fromIterator: Stdlib_Iterator.t<'a> => array<'a> = "Array.from" @val external fromArrayLikeWithMap: (arrayLike<'a>, 'a => 'b) => array<'b> = "Array.from" +/** +`fromString(str)` creates an array of each character as a separate string from the provided `str`. + +## Examples + +```rescript +Array.fromString("abcde") == ["a", "b", "c", "d", "e"] +``` +*/ +@val external fromString: string => array = "Array.from" + /** `make(~length, init)` creates an array of length `length` initialized with the value of `init`. @@ -97,16 +108,25 @@ nonEmptyArray->Array.isEmpty->assertEqual(false) */ let isEmpty: array<'a> => bool -// TODO: Docs -@deprecated("Use `copyWithin` instead") @send -external copyAllWithin: (array<'a>, ~target: int) => array<'a> = "copyWithin" +/** +`isEmpty(array)` returns `true` if the array is empty (has length 0), `false` otherwise. -// TODO: Docs -@deprecated("Use `copyWithin` instead") @send -external copyWithinToEnd: (array<'a>, ~target: int, ~start: int) => array<'a> = "copyWithin" +## Examples + +```rescript +let arr = [100, 101, 102, 103, 104] +arr->Array.copyAllWithin(~target=2) == [100, 101, 100, 101, 102] +arr == [100, 101, 100, 101, 102] +``` +*/ +@deprecated({ + reason: "Use `copyWithin` instead", + migrate: Array.copyWithin(~start=0), +}) +@send external copyAllWithin: (array<'a>, ~target: int) => array<'a> = "copyWithin" /** -`copyWithin(array, ~target, ~start, ~end)` copies the sequence of array elements within the array to the position starting at `target`. The copy is taken from the index positions `start` to `end`. +`copyWithinToEnd(array, ~target, ~start)` copies starting at element `start` in the given array to the designated `target` position, returning the resulting array. Beware this will *mutate* the array. @@ -115,11 +135,31 @@ See [`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript ## Examples ```rescript -let myArray = [1, 2, 3, 4, 5] -myArray->Array.copyWithin(~target=0, ~start=3) == [4, 5, 3, 4, 5] +let arr = [100, 101, 102, 103, 104] +arr->Array.copyWithinToEnd(~target=0, ~start=2) == [102, 103, 104, 103, 104] +arr == [102, 103, 104, 103, 104] +``` +*/ +@deprecated({ + reason: "Use `copyWithin` instead", + migrate: Array.copyWithin(), +}) +@send +external copyWithinToEnd: (array<'a>, ~target: int, ~start: int) => array<'a> = "copyWithin" -let myArray = [1, 2, 3, 4, 5] -myArray->Array.copyWithin(~target=1, ~start=3, ~end=4) == [1, 4, 3, 4, 5] +/** +`copyWithin(array, ~target, ~start, ~end)` copies starting at element `start` in the given array up to but not including `end` to the designated `target` position, returning the resulting array. + +Beware this will *mutate* the array. + +See [`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin) on MDN. + +## Examples + +```rescript +let arr = [100, 101, 102, 103, 104, 105] +arr->Array.copyWithin(~target=1, ~start=2, ~end=5) == [100, 102, 103, 104, 104, 105] +arr == [100, 102, 103, 104, 104, 105] ``` */ @send @@ -140,7 +180,11 @@ myArray->Array.fillAll(9) myArray == [9, 9, 9, 9] ``` */ -@deprecated("Use `fill` instead") @send +@deprecated({ + reason: "Use `fill` instead", + migrate: Array.fill(), +}) +@send external fillAll: (array<'a>, 'a) => unit = "fill" /** @@ -158,7 +202,11 @@ myArray->Array.fillToEnd(9, ~start=1) myArray == [1, 9, 9, 9] ``` */ -@deprecated("Use `fill` instead") @send +@deprecated({ + reason: "Use `fill` instead", + migrate: Array.fill(~start=%insert.labelledArgument("start")), +}) +@send external fillToEnd: (array<'a>, 'a, ~start: int) => unit = "fill" /** @@ -488,7 +536,11 @@ See [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re ``` */ let indexOfOpt: (array<'a>, 'a) => option -@deprecated("Use `indexOf` instead") @send +@deprecated({ + reason: "Use `indexOf` instead", + migrate: Array.indexOf(~from=%insert.unlabelledArgument(2)), +}) +@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf" /** @@ -514,7 +566,11 @@ external join: (array, string) => string = "join" ["One", "Two", "Three"]->Array.joinWith(" -- ") == "One -- Two -- Three" ``` */ -@deprecated("Use `join` instead") @send +@deprecated({ + reason: "Use `join` instead", + migrate: Array.join(), +}) +@send external joinWith: (array, string) => string = "join" /** @@ -540,7 +596,11 @@ external joinUnsafe: (array<'a>, string) => string = "join" [1, 2, 3]->Array.joinWithUnsafe(" -- ") == "1 -- 2 -- 3" ``` */ -@deprecated("Use `joinUnsafe` instead") @send +@deprecated({ + reason: "Use `joinUnsafe` instead", + migrate: Array.joinUnsafe(), +}) +@send external joinWithUnsafe: (array<'a>, string) => string = "join" /** `lastIndexOf(array, item, ~from)` returns the last index of the provided `item` in `array`, searching backwards from `from`. Uses [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) when comparing items. @@ -561,7 +621,11 @@ See [`Array.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScrip */ @send external lastIndexOf: (array<'a>, 'a, ~from: int=?) => int = "lastIndexOf" let lastIndexOfOpt: (array<'a>, 'a) => option -@deprecated("Use `lastIndexOf` instead") @send +@deprecated({ + reason: "Use `lastIndexOf` instead", + migrate: Array.lastIndexOf(~from=%insert.unlabelledArgument(2)), +}) +@send external lastIndexOfFrom: (array<'a>, 'a, int) => int = "lastIndexOf" /** @@ -591,7 +655,11 @@ See [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe [1, 2, 3, 4]->Array.sliceToEnd(~start=1) == [2, 3, 4] ``` */ -@deprecated("Use `slice` instead") @send +@deprecated({ + reason: "Use `slice` instead", + migrate: Array.slice(), +}) +@send external sliceToEnd: (array<'a>, ~start: int) => array<'a> = "slice" /** `copy(array)` makes a copy of the array with the items in it, but does not make copies of the items themselves. @@ -1096,7 +1164,10 @@ for index in 0 to array->Array.length - 1 { } ``` */ -@deprecated("Use getUnsafe instead. This will be removed in v13") +@deprecated({ + reason: "Use getUnsafe instead. This will be removed in v13", + migrate: Array.getUnsafe(), +}) external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" /** diff --git a/packages/@rescript/runtime/Stdlib_ArrayBuffer.res b/packages/@rescript/runtime/Stdlib_ArrayBuffer.res index a2e6420116..df14c7f193 100644 --- a/packages/@rescript/runtime/Stdlib_ArrayBuffer.res +++ b/packages/@rescript/runtime/Stdlib_ArrayBuffer.res @@ -6,4 +6,9 @@ type t @send external slice: (t, ~start: int=?, ~end: int=?) => t = "slice" -@deprecated("Use `slice` instead.") @send external sliceToEnd: (t, ~start: int) => t = "slice" +@deprecated({ + reason: "Use `slice` instead.", + migrate: ArrayBuffer.slice(), +}) +@send +external sliceToEnd: (t, ~start: int) => t = "slice" diff --git a/packages/@rescript/runtime/Stdlib_ArrayBuffer.resi b/packages/@rescript/runtime/Stdlib_ArrayBuffer.resi index 657f4364c0..fb9a467a8e 100644 --- a/packages/@rescript/runtime/Stdlib_ArrayBuffer.resi +++ b/packages/@rescript/runtime/Stdlib_ArrayBuffer.resi @@ -53,4 +53,9 @@ ArrayBuffer.byteLength(sliced) == 8 */ @send external slice: (t, ~start: int=?, ~end: int=?) => t = "slice" -@deprecated("Use `slice` instead.") @send external sliceToEnd: (t, ~start: int) => t = "slice" +@deprecated({ + reason: "Use `slice` instead.", + migrate: ArrayBuffer.slice(), +}) +@send +external sliceToEnd: (t, ~start: int) => t = "slice" diff --git a/packages/@rescript/runtime/Stdlib_BigInt.resi b/packages/@rescript/runtime/Stdlib_BigInt.resi index 41d8421ad5..86c1ea9203 100644 --- a/packages/@rescript/runtime/Stdlib_BigInt.resi +++ b/packages/@rescript/runtime/Stdlib_BigInt.resi @@ -80,7 +80,11 @@ BigInt.fromString("invalid") == None */ let fromString: string => option -@deprecated("Use `fromStringOrThrow` instead") @val +@deprecated({ + reason: "Use `fromStringOrThrow` instead", + migrate: BigInt.fromStringOrThrow(), +}) +@val external fromStringExn: string => bigint = "BigInt" /** @@ -147,7 +151,11 @@ BigInt.toString(123n) == "123" @send external toString: (bigint, ~radix: int=?) => string = "toString" -@deprecated("Use `toString` with `~radix` instead") @send +@deprecated({ + reason: "Use `toString` with `~radix` instead", + migrate: BigInt.toString(), +}) +@send external toStringWithRadix: (bigint, ~radix: int) => string = "toString" /** @@ -339,7 +347,11 @@ external ignore: bigint => unit = "%ignore" BigInt.land(7n, 4n) == 4n ``` */ -@deprecated("Use `&` operator or `bitwiseAnd` instead.") +@deprecated({ + reason: "Use `&` operator or `bitwiseAnd` instead.", + migrate: %insert.unlabelledArgument(0) & %insert.unlabelledArgument(1), + migrateInPipeChain: BigInt.bitwiseAnd(), +}) external land: (bigint, bigint) => bigint = "%andbigint" /** @@ -353,7 +365,10 @@ external land: (bigint, bigint) => bigint = "%andbigint" BigInt.lor(7n, 4n) == 7n ``` */ -@deprecated("Use `bitwiseOr` instead.") +@deprecated({ + reason: "Use `bitwiseOr` instead.", + migrate: BigInt.bitwiseOr(), +}) external lor: (bigint, bigint) => bigint = "%orbigint" /** @@ -367,7 +382,11 @@ external lor: (bigint, bigint) => bigint = "%orbigint" BigInt.lxor(7n, 4n) == 3n ``` */ -@deprecated("Use `^` operator or `bitwiseXor` instead.") +@deprecated({ + reason: "Use `^` operator or `bitwiseXor` instead.", + migrate: %insert.unlabelledArgument(0) ^ %insert.unlabelledArgument(1), + migrateInPipeChain: BigInt.bitwiseXor(), +}) external lxor: (bigint, bigint) => bigint = "%xorbigint" /** @@ -381,7 +400,11 @@ external lxor: (bigint, bigint) => bigint = "%xorbigint" BigInt.lnot(2n) == -3n ``` */ -@deprecated("Use `~` operator or `bitwiseNot` instead.") +@deprecated({ + reason: "Use `~` operator or `bitwiseNot` instead.", + migrate: ~(%insert.unlabelledArgument(0)), + migrateInPipeChain: BigInt.bitwiseNot(), +}) external lnot: bigint => bigint = "%bitnot_bigint" /** @@ -395,7 +418,11 @@ external lnot: bigint => bigint = "%bitnot_bigint" BigInt.lsl(4n, 1n) == 8n ``` */ -@deprecated("Use `<<` operator or `shiftLeft` instead.") +@deprecated({ + reason: "Use `<<` operator or `shiftLeft` instead.", + migrate: %insert.unlabelledArgument(0) << %insert.unlabelledArgument(1), + migrateInPipeChain: BigInt.shiftLeft(), +}) external lsl: (bigint, bigint) => bigint = "%lslbigint" /** @@ -409,5 +436,9 @@ external lsl: (bigint, bigint) => bigint = "%lslbigint" BigInt.asr(8n, 1n) == 4n ``` */ -@deprecated("Use `>>` operator or `shiftRight` instead.") +@deprecated({ + reason: "Use `>>` operator or `shiftRight` instead.", + migrate: %insert.unlabelledArgument(0) >> %insert.unlabelledArgument(1), + migrateInPipeChain: BigInt.shiftRight(), +}) external asr: (bigint, bigint) => bigint = "%asrbigint" diff --git a/packages/@rescript/runtime/Stdlib_BigInt64Array.res b/packages/@rescript/runtime/Stdlib_BigInt64Array.res index c90f743a99..e0545460c0 100644 --- a/packages/@rescript/runtime/Stdlib_BigInt64Array.res +++ b/packages/@rescript/runtime/Stdlib_BigInt64Array.res @@ -27,14 +27,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: BigInt64Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "BigInt64Array" /** `fromBufferWithRange` creates a `BigInt64Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array/BigInt64Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: BigInt64Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "BigInt64Array" @@ -52,7 +60,11 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => bigint=?) => t = "BigI /** `fromArrayLikeOrIterableWithMap` creates a `BigInt64Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: BigInt64Array.fromArrayLikeOrIterable(~map=%insert.unlabelledArgument(1)), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => bigint) => t = "BigInt64Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_BigUint64Array.res b/packages/@rescript/runtime/Stdlib_BigUint64Array.res index 6bce30f6f6..3c8aab184b 100644 --- a/packages/@rescript/runtime/Stdlib_BigUint64Array.res +++ b/packages/@rescript/runtime/Stdlib_BigUint64Array.res @@ -27,14 +27,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: BigUint64Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "BigUint64Array" /** `fromBufferWithRange` creates a `BigUint64Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array/BigUint64Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: BigUint64Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "BigUint64Array" @@ -52,7 +60,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => bigint=?) => t = "BigU /** `fromArrayLikeOrIterableWithMap` creates a `BigUint64Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: BigUint64Array.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => bigint) => t = "BigUint64Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_Bool.res b/packages/@rescript/runtime/Stdlib_Bool.res index f6b467fbaf..3785d3f25e 100644 --- a/packages/@rescript/runtime/Stdlib_Bool.res +++ b/packages/@rescript/runtime/Stdlib_Bool.res @@ -22,7 +22,10 @@ let fromStringOrThrow = param => | _ => throw(Invalid_argument(`Bool.fromStringOrThrow: value is neither "true" nor "false"`)) } -@deprecated("Use `fromStringOrThrow` instead") +@deprecated({ + reason: "Use `fromStringOrThrow` instead", + migrate: Bool.fromStringOrThrow(), +}) let fromStringExn = fromStringOrThrow external compare: (bool, bool) => Stdlib_Ordering.t = "%compare" diff --git a/packages/@rescript/runtime/Stdlib_Bool.resi b/packages/@rescript/runtime/Stdlib_Bool.resi index 041da855d7..7f3408e504 100644 --- a/packages/@rescript/runtime/Stdlib_Bool.resi +++ b/packages/@rescript/runtime/Stdlib_Bool.resi @@ -62,7 +62,10 @@ switch Bool.fromStringExn("notAValidBoolean") { } ``` */ -@deprecated("Use `fromStringOrThrow` instead") +@deprecated({ + reason: "Use `fromStringOrThrow` instead", + migrate: Bool.fromStringOrThrow(), +}) let fromStringExn: string => bool /** diff --git a/packages/@rescript/runtime/Stdlib_DataView.res b/packages/@rescript/runtime/Stdlib_DataView.res index 2edf23d82c..e1aae2469f 100644 --- a/packages/@rescript/runtime/Stdlib_DataView.res +++ b/packages/@rescript/runtime/Stdlib_DataView.res @@ -3,7 +3,16 @@ type t @new external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) => t = "DataView" -@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "DataView" +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: DataView.fromBuffer(), +}) +@new +external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "DataView" +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: DataView.fromBuffer(), +}) @new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "DataView" diff --git a/packages/@rescript/runtime/Stdlib_DataView.resi b/packages/@rescript/runtime/Stdlib_DataView.resi index 024307a246..173cba3e61 100644 --- a/packages/@rescript/runtime/Stdlib_DataView.resi +++ b/packages/@rescript/runtime/Stdlib_DataView.resi @@ -61,7 +61,11 @@ DataView.fromBuffer(ArrayBuffer.make(16), ~byteOffset=4, ~length=8) DataView.fromBufferToEnd(buffer, ~byteOffset=4) ``` */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: DataView.fromBuffer(~byteOffset=%insert.labelledArgument("byteOffset")), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "DataView" /** @@ -77,7 +81,11 @@ See [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referen DataView.fromBufferWithRange(ArrayBuffer.make(16), ~byteOffset=2, ~length=8) ``` */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: DataView.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "DataView" diff --git a/packages/@rescript/runtime/Stdlib_Error.resi b/packages/@rescript/runtime/Stdlib_Error.resi index 40467129e2..3abc756f86 100644 --- a/packages/@rescript/runtime/Stdlib_Error.resi +++ b/packages/@rescript/runtime/Stdlib_Error.resi @@ -5,10 +5,16 @@ See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/ */ /** Represents a JavaScript exception. */ -@deprecated("Use `JsError.t` instead") +@deprecated({ + reason: "Use `JsError.t` instead", + migrate: %replace.type(: JsError.t), +}) type t = Stdlib_Exn.t -@deprecated("Use `JsExn.fromException` instead") +@deprecated({ + reason: "Use `JsExn.fromException` instead", + migrate: JsExn.fromException(), +}) let fromException: exn => option /** @@ -35,7 +41,11 @@ let error = Error.make("error") Console.log(error->Error.stack) // Logs `stack` if it exists on `someError` ``` */ -@deprecated("Use `JsError.stack` instead") @get +@deprecated({ + reason: "Use `JsError.stack` instead", + migrate: JsError.stack(), +}) +@get external stack: t => option = "stack" /** @@ -49,7 +59,11 @@ let error = Error.SyntaxError.make("Some message here") Console.log(error->Error.message) // Logs "Some message here" to the console ``` */ -@deprecated("Use `JsError.message` instead") @get +@deprecated({ + reason: "Use `JsError.message` instead", + migrate: JsError.message(), +}) +@get external message: t => option = "message" /** @@ -63,7 +77,11 @@ let error = Error.SyntaxError.make("Some message here") Console.log(error->Error.name) // Logs "SyntaxError" to the console ``` */ -@deprecated("Use `JsError.name` instead") @get +@deprecated({ + reason: "Use `JsError.name` instead", + migrate: JsError.name(), +}) +@get external name: t => option = "name" /** @@ -71,7 +89,11 @@ external name: t => option = "name" See [`Error.prototype.fileName`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/fileName) on MDN. */ -@deprecated("Use `JsError.fileName` instead") @get +@deprecated({ + reason: "Use `JsError.fileName` instead", + migrate: JsError.fileName(), +}) +@get external fileName: t => option = "fileName" /** @@ -86,7 +108,11 @@ Console.log(error->Error.message) // Logs "Some message here" to the console Console.log(error->Error.name) // Logs "Error" to the console, because this is a regular error ``` */ -@deprecated("Use `JsError.make` instead") @new +@deprecated({ + reason: "Use `JsError.make` instead", + migrate: JsError.make(), +}) +@new external make: string => t = "Error" module EvalError: { @@ -95,7 +121,11 @@ module EvalError: { See [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) on MDN. */ - @deprecated("Use `JsError.EvalError.make` instead") @new + @deprecated({ + reason: "Use `JsError.EvalError.make` instead", + migrate: JsError.EvalError.make(), + }) + @new external make: string => t = "EvalError" } module RangeError: { @@ -104,7 +134,11 @@ module RangeError: { See [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) on MDN. */ - @deprecated("Use `JsError.RangeError.make` instead") @new + @deprecated({ + reason: "Use `JsError.RangeError.make` instead", + migrate: JsError.RangeError.make(), + }) + @new external make: string => t = "RangeError" } module ReferenceError: { @@ -113,7 +147,11 @@ module ReferenceError: { See [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) on MDN. */ - @deprecated("Use `JsError.ReferenceError.make` instead") @new + @deprecated({ + reason: "Use `JsError.ReferenceError.make` instead", + migrate: JsError.ReferenceError.make(), + }) + @new external make: string => t = "ReferenceError" } module SyntaxError: { @@ -122,7 +160,11 @@ module SyntaxError: { See [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) on MDN. */ - @deprecated("Use `JsError.SyntaxError.make` instead") @new + @deprecated({ + reason: "Use `JsError.SyntaxError.make` instead", + migrate: JsError.SyntaxError.make(), + }) + @new external make: string => t = "SyntaxError" } module TypeError: { @@ -131,7 +173,11 @@ module TypeError: { See [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) on MDN. */ - @deprecated("Use `JsError.TypeError.make` instead") @new + @deprecated({ + reason: "Use `JsError.TypeError.make` instead", + migrate: JsError.TypeError.make(), + }) + @new external make: string => t = "TypeError" } module URIError: { @@ -140,7 +186,11 @@ module URIError: { See [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) on MDN. */ - @deprecated("Use `JsError.URIError.make` instead") @new + @deprecated({ + reason: "Use `JsError.URIError.make` instead", + migrate: JsError.URIError.make(), + }) + @new external make: string => t = "URIError" } @@ -158,9 +208,10 @@ if 5 > 10 { } ``` */ -@deprecated( - "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `JsError.throw` instead" -) +@deprecated({ + reason: "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `JsError.throw` instead", + migrate: JsError.throw(), +}) external raise: t => 'a = "%raise" /** @@ -178,7 +229,10 @@ if 5 > 10 { } ``` */ -@deprecated("Use `JsError.throw` instead") +@deprecated({ + reason: "Use `JsError.throw` instead", + migrate: JsError.throw(), +}) external throw: t => 'a = "%raise" /** @@ -203,7 +257,10 @@ try { } ``` */ -@deprecated("Use `JsError.panic` instead") +@deprecated({ + reason: "Use `JsError.panic` instead", + migrate: JsError.panic(), +}) let panic: string => 'a /** @@ -212,5 +269,8 @@ let panic: string => 'a This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further. */ -@deprecated("Use `JsError.ignore` instead") +@deprecated({ + reason: "Use `JsError.ignore` instead", + migrate: JsError.ignore(), +}) external ignore: t => unit = "%ignore" diff --git a/packages/@rescript/runtime/Stdlib_Exn.resi b/packages/@rescript/runtime/Stdlib_Exn.resi index 5842b83694..de3fcf64c1 100644 --- a/packages/@rescript/runtime/Stdlib_Exn.resi +++ b/packages/@rescript/runtime/Stdlib_Exn.resi @@ -27,18 +27,44 @@ Provide utilities for dealing with JS exceptions. */ /** Represents a JS exception */ -@deprecated("Use `JsExn.t` instead") +@deprecated({ + reason: "Use `JsExn.t` instead", + migrate: %replace.type(: JsExn.t), +}) type t type exn += private Error(t) -@deprecated("Use `JsExn.fromException` instead") +@deprecated({ + reason: "Use `JsExn.fromException` instead", + migrate: JsExn.fromException(), +}) let asJsExn: exn => option -@deprecated("Use `JsExn.stack` instead") @get external stack: t => option = "stack" -@deprecated("Use `JsExn.message` instead") @get external message: t => option = "message" -@deprecated("Use `JsExn.name` instead") @get external name: t => option = "name" -@deprecated("Use `JsExn.fileName` instead") @get external fileName: t => option = "fileName" +@deprecated({ + reason: "Use `JsExn.stack` instead", + migrate: JsExn.stack(), +}) +@get +external stack: t => option = "stack" +@deprecated({ + reason: "Use `JsExn.message` instead", + migrate: JsExn.message(), +}) +@get +external message: t => option = "message" +@deprecated({ + reason: "Use `JsExn.name` instead", + migrate: JsExn.name(), +}) +@get +external name: t => option = "name" +@deprecated({ + reason: "Use `JsExn.fileName` instead", + migrate: JsExn.fileName(), +}) +@get +external fileName: t => option = "fileName" /** `anyToExnInternal(obj)` will take any value `obj` and wrap it @@ -51,23 +77,47 @@ a value passed to a Promise.catch callback) **IMPORTANT**: This is an internal API and may be changed / removed any time in the future. */ -@deprecated("Use `JsExn.anyToExnInternal` instead") +@deprecated({ + reason: "Use `JsExn.anyToExnInternal` instead", + migrate: JsExn.anyToExnInternal(), +}) external anyToExnInternal: 'a => exn = "%wrap_exn" /** Raise Js exception Error object with stacktrace */ -@deprecated("Use `JsError.throwWithMessage` instead") +@deprecated({ + reason: "Use `JsError.throwWithMessage` instead", + migrate: JsError.throwWithMessage(), +}) let raiseError: string => 'a -@deprecated("Use `JsError.EvalError.throwWithMessage` instead") +@deprecated({ + reason: "Use `JsError.EvalError.throwWithMessage` instead", + migrate: JsError.EvalError.throwWithMessage(), +}) let raiseEvalError: string => 'a -@deprecated("Use `JsError.RangeError.throwWithMessage` instead") +@deprecated({ + reason: "Use `JsError.RangeError.throwWithMessage` instead", + migrate: JsError.RangeError.throwWithMessage(), +}) let raiseRangeError: string => 'a -@deprecated("Use `JsError.ReferenceError.throwWithMessage` instead") +@deprecated({ + reason: "Use `JsError.ReferenceError.throwWithMessage` instead", + migrate: JsError.ReferenceError.throwWithMessage(), +}) let raiseReferenceError: string => 'a -@deprecated("Use `JsError.SyntaxError.throwWithMessage` instead") +@deprecated({ + reason: "Use `JsError.SyntaxError.throwWithMessage` instead", + migrate: JsError.SyntaxError.throwWithMessage(), +}) let raiseSyntaxError: string => 'a -@deprecated("Use `JsError.TypeError.throwWithMessage` instead") +@deprecated({ + reason: "Use `JsError.TypeError.throwWithMessage` instead", + migrate: JsError.TypeError.throwWithMessage(), +}) let raiseTypeError: string => 'a -@deprecated("Use `JsError.URIError.throwWithMessage` instead") +@deprecated({ + reason: "Use `JsError.URIError.throwWithMessage` instead", + migrate: JsError.URIError.throwWithMessage(), +}) let raiseUriError: string => 'a /** @@ -76,5 +126,8 @@ let raiseUriError: string => 'a This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further. */ -@deprecated("Use `JsExn.ignore` instead") +@deprecated({ + reason: "Use `JsExn.ignore` instead", + migrate: JsExn.ignore(), +}) external ignore: t => unit = "%ignore" diff --git a/packages/@rescript/runtime/Stdlib_Float.res b/packages/@rescript/runtime/Stdlib_Float.res index 3e66e97caf..fbefcc262f 100644 --- a/packages/@rescript/runtime/Stdlib_Float.res +++ b/packages/@rescript/runtime/Stdlib_Float.res @@ -18,23 +18,43 @@ external compare: (float, float) => Stdlib_Ordering.t = "%compare" @val external parseFloat: 'a => float = "parseFloat" // parseInt's return type is a float because it can be NaN @val external parseInt: ('a, ~radix: int=?) => float = "parseInt" -@deprecated("Use `parseInt` instead") @val +@deprecated({ + reason: "Use `parseInt` instead", + migrate: Float.parseInt(), +}) +@val external parseIntWithRadix: ('a, ~radix: int) => float = "parseInt" @send external toExponential: (float, ~digits: int=?) => string = "toExponential" -@deprecated("Use `toExponential` instead") @send +@deprecated({ + reason: "Use `toExponential` instead", + migrate: Float.toExponential(), +}) +@send external toExponentialWithPrecision: (float, ~digits: int) => string = "toExponential" @send external toFixed: (float, ~digits: int=?) => string = "toFixed" -@deprecated("Use `toFixed` instead") @send +@deprecated({ + reason: "Use `toFixed` instead", + migrate: Float.toFixed(), +}) +@send external toFixedWithPrecision: (float, ~digits: int) => string = "toFixed" @send external toPrecision: (float, ~digits: int=?) => string = "toPrecision" -@deprecated("Use `toPrecision` instead") @send +@deprecated({ + reason: "Use `toPrecision` instead", + migrate: Float.toPrecision(), +}) +@send external toPrecisionWithPrecision: (float, ~digits: int) => string = "toPrecision" @send external toString: (float, ~radix: int=?) => string = "toString" -@deprecated("Use `toString` instead") @send +@deprecated({ + reason: "Use `toString` instead", + migrate: Float.toString(), +}) +@send external toStringWithRadix: (float, ~radix: int) => string = "toString" @send external toLocaleString: float => string = "toLocaleString" diff --git a/packages/@rescript/runtime/Stdlib_Float.resi b/packages/@rescript/runtime/Stdlib_Float.resi index f0f2b78a5b..606a861677 100644 --- a/packages/@rescript/runtime/Stdlib_Float.resi +++ b/packages/@rescript/runtime/Stdlib_Float.resi @@ -227,7 +227,11 @@ Float.parseIntWithRadix("12", ~radix=13) == 15.0 Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN == true ``` */ -@deprecated("Use `parseInt` instead") @val +@deprecated({ + reason: "Use `parseInt` instead", + migrate: Float.parseInt(), +}) +@val external parseIntWithRadix: ('a, ~radix: int) => float = "parseInt" /** @@ -269,7 +273,11 @@ Float.toExponentialWithPrecision(5678.0, ~digits=2) == "5.68e+3" - `RangeError`: If `digits` less than 0 or greater than 10. */ -@deprecated("Use `toExponential` instead") @send +@deprecated({ + reason: "Use `toExponential` instead", + migrate: Float.toExponential(), +}) +@send external toExponentialWithPrecision: (float, ~digits: int) => string = "toExponential" /** @@ -311,7 +319,11 @@ Float.toFixedWithPrecision(300.0, ~digits=1) == "300.0" - `RangeError`: If `digits` is less than 0 or larger than 100. */ -@deprecated("Use `toFixed` instead") @send +@deprecated({ + reason: "Use `toFixed` instead", + migrate: Float.toFixed(), +}) +@send external toFixedWithPrecision: (float, ~digits: int) => string = "toFixed" /** @@ -356,7 +368,11 @@ Float.toPrecisionWithPrecision(1.0, ~digits=1) == "1" ECMA-262 only requires a precision of up to 21 significant digits. */ -@deprecated("Use `toPrecision` instead") @send +@deprecated({ + reason: "Use `toPrecision` instead", + migrate: Float.toPrecision(), +}) +@send external toPrecisionWithPrecision: (float, ~digits: int) => string = "toPrecision" /** @@ -390,7 +406,11 @@ Float.toStringWithRadix(123456.0, ~radix=36) == "2n9c" `RangeError`: if `radix` is less than 2 or greater than 36. */ -@deprecated("Use `toString` with `~radix` instead") @send +@deprecated({ + reason: "Use `toString` with `~radix` instead", + migrate: Float.toString(), +}) +@send external toStringWithRadix: (float, ~radix: int) => string = "toString" /** diff --git a/packages/@rescript/runtime/Stdlib_Float32Array.res b/packages/@rescript/runtime/Stdlib_Float32Array.res index 1a0ccc51b5..f916dce88b 100644 --- a/packages/@rescript/runtime/Stdlib_Float32Array.res +++ b/packages/@rescript/runtime/Stdlib_Float32Array.res @@ -27,14 +27,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Float32Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "Float32Array" /** `fromBufferWithRange` creates a `Float32Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array/Float32Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Float32Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Float32Array" @@ -52,7 +60,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => float=?) => t = "Float /** `fromArrayLikeOrIterableWithMap` creates a `Float32Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: Float32Array.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => float) => t = "Float32Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_Float64Array.res b/packages/@rescript/runtime/Stdlib_Float64Array.res index 7884de062a..fffb73704c 100644 --- a/packages/@rescript/runtime/Stdlib_Float64Array.res +++ b/packages/@rescript/runtime/Stdlib_Float64Array.res @@ -27,14 +27,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Float64Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "Float64Array" /** `fromBufferWithRange` creates a `Float64Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array/Float64Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Float64Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Float64Array" @@ -52,7 +60,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => float=?) => t = "Float /** `fromArrayLikeOrIterableWithMap` creates a `Float64Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: Float64Array.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => float) => t = "Float64Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_Int.res b/packages/@rescript/runtime/Stdlib_Int.res index 3228ed4114..dc3c7244c5 100644 --- a/packages/@rescript/runtime/Stdlib_Int.res +++ b/packages/@rescript/runtime/Stdlib_Int.res @@ -10,19 +10,35 @@ external equal: (int, int) => bool = "%equal" external compare: (int, int) => Stdlib_Ordering.t = "%compare" @send external toExponential: (int, ~digits: int=?) => string = "toExponential" -@deprecated("Use `toExponential` instead") @send +@deprecated({ + reason: "Use `toExponential` instead", + migrate: Int.toExponential(), +}) +@send external toExponentialWithPrecision: (int, ~digits: int) => string = "toExponential" @send external toFixed: (int, ~digits: int=?) => string = "toFixed" -@deprecated("Use `toFixed` instead") @send +@deprecated({ + reason: "Use `toFixed` instead", + migrate: Int.toFixed(), +}) +@send external toFixedWithPrecision: (int, ~digits: int) => string = "toFixed" @send external toPrecision: (int, ~digits: int=?) => string = "toPrecision" -@deprecated("Use `toPrecision` instead") @send +@deprecated({ + reason: "Use `toPrecision` instead", + migrate: Int.toPrecision(), +}) +@send external toPrecisionWithPrecision: (int, ~digits: int) => string = "toPrecision" @send external toString: (int, ~radix: int=?) => string = "toString" -@deprecated("Use `toString` instead") @send +@deprecated({ + reason: "Use `toString` instead", + migrate: Int.toString(), +}) +@send external toStringWithRadix: (int, ~radix: int) => string = "toString" @send external toLocaleString: int => string = "toLocaleString" @@ -81,7 +97,11 @@ let range = (start, end, ~options: rangeOptions={}) => { Stdlib_Array.fromInitializer(~length, i => start + i * step) } -@deprecated("Use `range` instead") @send +@deprecated({ + reason: "Use `range` instead", + migrate: Int.range(~options=%insert.unlabelledArgument(2)), +}) +@send let rangeWithOptions = (start, end, options) => range(start, end, ~options) let clamp = (~min=?, ~max=?, value): int => { @@ -105,6 +125,18 @@ external shiftLeft: (int, int) => int = "%lslint" external shiftRight: (int, int) => int = "%asrint" external shiftRightUnsigned: (int, int) => int = "%lsrint" +module Bitwise = { + external land: (int, int) => int = "%andint" + external lor: (int, int) => int = "%orint" + external lxor: (int, int) => int = "%xorint" + + external lsl: (int, int) => int = "%lslint" + external lsr: (int, int) => int = "%lsrint" + external asr: (int, int) => int = "%asrint" + + let lnot = x => lxor(x, -1) +} + external ignore: int => unit = "%ignore" module Ref = { diff --git a/packages/@rescript/runtime/Stdlib_Int.resi b/packages/@rescript/runtime/Stdlib_Int.resi index edee442ec0..72a2b9669d 100644 --- a/packages/@rescript/runtime/Stdlib_Int.resi +++ b/packages/@rescript/runtime/Stdlib_Int.resi @@ -103,7 +103,11 @@ Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" - `RangeError`: If `digits` less than 0 or greater than 10. */ -@deprecated("Use `toExponential` instead") @send +@deprecated({ + reason: "Use `toExponential` instead", + migrate: Int.toExponential(), +}) +@send external toExponentialWithPrecision: (int, ~digits: int) => string = "toExponential" /** @@ -145,7 +149,11 @@ Int.toFixedWithPrecision(300, ~digits=1) // "300.0" - `RangeError`: If `digits` is less than 0 or larger than 100. */ -@deprecated("Use `toFixed` instead") @send +@deprecated({ + reason: "Use `toFixed` instead", + migrate: Int.toFixed(), +}) +@send external toFixedWithPrecision: (int, ~digits: int) => string = "toFixed" /** @@ -186,9 +194,12 @@ Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" - `RangeError`: If `digits` is not between 1 and 100 (inclusive). Implementations are allowed to support larger and smaller values as well. ECMA-262 only requires a precision of up to 21 significant digits. - */ -@send @deprecated("Use `toPrecision` instead") +@send +@deprecated({ + reason: "Use `toPrecision` instead", + migrate: Int.toPrecision(), +}) external toPrecisionWithPrecision: (int, ~digits: int) => string = "toPrecision" /** @@ -232,7 +243,11 @@ Int.toStringWithRadix(123456, ~radix=36) // "2n9c" `RangeError`: if `radix` is less than 2 or greater than 36. */ -@deprecated("Use `toString` instead") @send +@deprecated({ + reason: "Use `toString` instead", + migrate: Int.toString(), +}) +@send external toStringWithRadix: (int, ~radix: int) => string = "toString" /** @@ -370,7 +385,10 @@ Int.rangeWithOptions(3, 6, {step: -2}) // RangeError - Raises `RangeError` if `step == 0 && start != end`. */ -@deprecated("Use `range` instead") +@deprecated({ + reason: "Use `range` instead", + migrate: Int.range(~options=%insert.unlabelledArgument(2)), +}) let rangeWithOptions: (int, int, rangeOptions) => array /** @@ -471,6 +489,46 @@ Int.shiftRightUnsigned(4, 1) == 2 */ external shiftRightUnsigned: (int, int) => int = "%lsrint" +module Bitwise: { + @deprecated({ + reason: "Use `Int.bitwiseAnd` instead", + migrate: Int.bitwiseAnd(), + }) + external land: (int, int) => int = "%andint" + @deprecated({ + reason: "Use `Int.bitwiseOr` instead", + migrate: Int.bitwiseOr(), + }) + external lor: (int, int) => int = "%orint" + @deprecated({ + reason: "Use `Int.bitwiseXor` instead", + migrate: Int.bitwiseXor(), + }) + external lxor: (int, int) => int = "%xorint" + + @deprecated({ + reason: "Use `Int.shiftLeft` instead", + migrate: Int.shiftLeft(), + }) + external lsl: (int, int) => int = "%lslint" + @deprecated({ + reason: "Use `Int.shiftRightUnsigned` instead", + migrate: Int.shiftRightUnsigned(), + }) + external lsr: (int, int) => int = "%lsrint" + @deprecated({ + reason: "Use `Int.shiftRight` instead", + migrate: Int.shiftRight(), + }) + external asr: (int, int) => int = "%asrint" + + @deprecated({ + reason: "Use `Int.bitwiseNot` instead", + migrate: Int.bitwiseNot(), + }) + let lnot: int => int +} + /** `ignore(int)` ignores the provided int and returns unit. diff --git a/packages/@rescript/runtime/Stdlib_Int16Array.res b/packages/@rescript/runtime/Stdlib_Int16Array.res index 615d6dcf96..72aa31ea66 100644 --- a/packages/@rescript/runtime/Stdlib_Int16Array.res +++ b/packages/@rescript/runtime/Stdlib_Int16Array.res @@ -26,14 +26,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Int16Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "Int16Array" /** `fromBufferWithRange` creates a `Int16Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array/Int16Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Int16Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Int16Array" @@ -51,7 +59,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => int=?) => t = "Int16Ar /** `fromArrayLikeOrIterableWithMap` creates a `Int16Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: Int16Array.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => int) => t = "Int16Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_Int32Array.res b/packages/@rescript/runtime/Stdlib_Int32Array.res index f0fe4d03f3..f537411e29 100644 --- a/packages/@rescript/runtime/Stdlib_Int32Array.res +++ b/packages/@rescript/runtime/Stdlib_Int32Array.res @@ -26,14 +26,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Int32Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "Int32Array" /** `fromBufferWithRange` creates a `Int32Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array/Int32Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Int32Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Int32Array" @@ -51,7 +59,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => int=?) => t = "Int32Ar /** `fromArrayLikeOrIterableWithMap` creates a `Int32Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: Int32Array.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => int) => t = "Int32Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_Int8Array.res b/packages/@rescript/runtime/Stdlib_Int8Array.res index f8b2d9b596..d129824acd 100644 --- a/packages/@rescript/runtime/Stdlib_Int8Array.res +++ b/packages/@rescript/runtime/Stdlib_Int8Array.res @@ -26,14 +26,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Int8Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "Int8Array" /** `fromBufferWithRange` creates a `Int8Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array/Int8Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Int8Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Int8Array" @@ -51,7 +59,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => int=?) => t = "Int8Arr /** `fromArrayLikeOrIterableWithMap` creates a `Int8Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: Int8Array.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => int) => t = "Int8Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_JSON.res b/packages/@rescript/runtime/Stdlib_JSON.res index b7fc9d21e3..50012e67c8 100644 --- a/packages/@rescript/runtime/Stdlib_JSON.res +++ b/packages/@rescript/runtime/Stdlib_JSON.res @@ -12,37 +12,120 @@ type replacer = Keys(array) | Replacer((string, t) => t) @throws @val external parseOrThrow: (string, ~reviver: (string, t) => t=?) => t = "JSON.parse" -@deprecated("Use `parseOrThrow` instead") @throws @val +@deprecated({ + reason: "Use `JSON.parseOrThrow` instead", + migrate: JSON.parseOrThrow(), +}) +@raises +@val external parseExn: (string, ~reviver: (string, t) => t=?) => t = "JSON.parse" -@deprecated("Use `parseOrThrow` with optional parameter instead") @throws @val +@deprecated({ + reason: "Use `JSON.parseOrThrow` with optional parameter instead", + migrate: JSON.parseOrThrow(%insert.unlabelledArgument(0), ~reviver=%insert.unlabelledArgument(1)), +}) +@raises +@val external parseExnWithReviver: (string, (string, t) => t) => t = "JSON.parse" @val external stringify: (t, ~replacer: replacer=?, ~space: int=?) => string = "JSON.stringify" -@deprecated("Use `stringify` with optional parameter instead") @val +@deprecated({ + reason: "Use `JSON.stringify` with optional parameter instead", + migrate: JSON.stringify(%insert.unlabelledArgument(0), ~space=%insert.unlabelledArgument(2)), +}) +@val external stringifyWithIndent: (t, @as(json`null`) _, int) => string = "JSON.stringify" -@deprecated("Use `stringify` with optional parameter instead") @val +@deprecated({ + reason: "Use `JSON.stringify` with optional parameter instead", + migrate: JSON.stringify( + %insert.unlabelledArgument(0), + ~replacer=Replacer(%insert.unlabelledArgument(1)), + ), +}) +@val external stringifyWithReplacer: (t, (string, t) => t) => string = "JSON.stringify" -@deprecated("Use `stringify` with optional parameters instead") @val +@deprecated({ + reason: "Use `JSON.stringify` with optional parameters instead", + migrate: JSON.stringify( + %insert.unlabelledArgument(0), + ~replacer=Replacer(%insert.unlabelledArgument(1)), + ~space=%insert.unlabelledArgument(2), + ), +}) +@val external stringifyWithReplacerAndIndent: (t, (string, t) => t, int) => string = "JSON.stringify" -@deprecated("Use `stringify` with optional parameter instead") @val +@deprecated({ + reason: "Use `JSON.stringify` with optional parameter instead", + migrate: JSON.stringify( + %insert.unlabelledArgument(0), + ~replacer=Keys(%insert.unlabelledArgument(1)), + ), +}) +@val external stringifyWithFilter: (t, array) => string = "JSON.stringify" -@deprecated("Use `stringify` with optional parameters instead") @val +@deprecated({ + reason: "Use `JSON.stringify` with optional parameters instead", + migrate: JSON.stringify( + %insert.unlabelledArgument(0), + ~replacer=Keys(%insert.unlabelledArgument(1)), + ~space=%insert.unlabelledArgument(2), + ), +}) +@val external stringifyWithFilterAndIndent: (t, array, int) => string = "JSON.stringify" @throws @val external stringifyAny: ('a, ~replacer: replacer=?, ~space: int=?) => option = "JSON.stringify" -@deprecated("Use `stringifyAny` with optional parameter instead") @throws @val +@deprecated({ + reason: "Use `JSON.stringifyAny` with optional parameter instead", + migrate: JSON.stringifyAny(%insert.unlabelledArgument(0), ~space=%insert.unlabelledArgument(2)), +}) +@raises +@val external stringifyAnyWithIndent: ('a, @as(json`null`) _, int) => option = "JSON.stringify" -@deprecated("Use `stringifyAny` with optional parameter instead") @throws @val +@deprecated({ + reason: "Use `JSON.stringifyAny` with optional parameter instead", + migrate: JSON.stringifyAny( + %insert.unlabelledArgument(0), + ~replacer=Replacer(%insert.unlabelledArgument(1)), + ), +}) +@raises +@val external stringifyAnyWithReplacer: ('a, (string, t) => t) => option = "JSON.stringify" -@deprecated("Use `stringifyAny` with optional parameters instead") @throws @val +@deprecated({ + reason: "Use `JSON.stringifyAny` with optional parameters instead", + migrate: JSON.stringifyAny( + %insert.unlabelledArgument(0), + ~replacer=Replacer(%insert.unlabelledArgument(1)), + ~space=%insert.unlabelledArgument(2), + ), +}) +@raises +@val external stringifyAnyWithReplacerAndIndent: ('a, (string, t) => t, int) => option = "JSON.stringify" -@deprecated("Use `stringifyAny` with optional parameter instead") @throws @val +@deprecated({ + reason: "Use `JSON.stringifyAny` with optional parameter instead", + migrate: JSON.stringifyAny( + %insert.unlabelledArgument(0), + ~replacer=Keys(%insert.unlabelledArgument(1)), + ), +}) +@raises +@val external stringifyAnyWithFilter: ('a, array) => string = "JSON.stringify" -@deprecated("Use `stringifyAny` with optional parameters instead") @throws @val +@deprecated({ + reason: "Use `JSON.stringifyAny` with optional parameters instead", + migrate: JSON.stringifyAny( + %insert.unlabelledArgument(0), + ~replacer=Keys(%insert.unlabelledArgument(1)), + ~space=%insert.unlabelledArgument(2), + ), +}) +@raises +@val external stringifyAnyWithFilterAndIndent: ('a, array, int) => string = "JSON.stringify" module Classify = { @@ -82,6 +165,12 @@ module Encode = { external float: float => t = "%identity" external object: dict => t = "%identity" external array: array => t = "%identity" + + external stringArray: array => t = "%identity" + external floatArray: array => t = "%identity" + external intArray: array => t = "%identity" + external boolArray: array => t = "%identity" + external objectArray: array> => t = "%identity" } module Decode = { diff --git a/packages/@rescript/runtime/Stdlib_JSON.resi b/packages/@rescript/runtime/Stdlib_JSON.resi index 7ad1b60a20..18b3870b49 100644 --- a/packages/@rescript/runtime/Stdlib_JSON.resi +++ b/packages/@rescript/runtime/Stdlib_JSON.resi @@ -654,7 +654,7 @@ module Classify: { module Encode: { /** - Returns a boolean as a JSON object. + Returns a boolean as JSON. ## Examples ```rescript @@ -664,7 +664,7 @@ module Encode: { external bool: bool => t = "%identity" /** - Returns null as a JSON object. + Returns null as a JSON value. ## Examples ```rescript @@ -674,7 +674,7 @@ module Encode: { external null: t = "#null" /** - Returns a string as a JSON object. + Returns a string as JSON. ## Examples ```rescript @@ -684,7 +684,7 @@ module Encode: { external string: string => t = "%identity" /** - Returns an int as a JSON object. + Returns an int as JSON. ## Examples ```rescript @@ -694,7 +694,7 @@ module Encode: { external int: int => t = "%identity" /** - Returns a float as a JSON object. + Returns a float as JSON. ## Examples ```rescript @@ -719,7 +719,7 @@ module Encode: { external object: dict => t = "%identity" /** - Returns an array as a JSON object. + Returns an array as JSON. ## Examples ```rescript @@ -729,6 +729,31 @@ module Encode: { ``` */ external array: array => t = "%identity" + + /** + Returns an array of strings as a JSON object. + */ + external stringArray: array => t = "%identity" + + /** + Returns an array of floats as a JSON object. + */ + external floatArray: array => t = "%identity" + + /** + Returns an array of integers as a JSON object. + */ + external intArray: array => t = "%identity" + + /** + Returns an array of booleans as a JSON object. + */ + external boolArray: array => t = "%identity" + + /** + Returns an array of objects as a JSON object. + */ + external objectArray: array> => t = "%identity" } module Decode: { diff --git a/packages/@rescript/runtime/Stdlib_Lazy.resi b/packages/@rescript/runtime/Stdlib_Lazy.resi index e4e733412a..9098977f5a 100644 --- a/packages/@rescript/runtime/Stdlib_Lazy.resi +++ b/packages/@rescript/runtime/Stdlib_Lazy.resi @@ -73,7 +73,10 @@ exception Undefined Throw `Undefined` if the forcing of `x` tries to force `x` itself recursively. */ -@deprecated("Use `Lazy.get` instead") +@deprecated({ + reason: "Use `Lazy.get` instead", + migrate: Lazy.get(), +}) let force: t<'a> => 'a /** @@ -85,7 +88,10 @@ let force: t<'a> => 'a If the computation of `x` throws an exception, it is unspecified whether `force_val(x)` throws the same exception or `Undefined`. */ -@deprecated("Use `Lazy.get` instead") +@deprecated({ + reason: "Use `Lazy.get` instead", + migrate: Lazy.get(), +}) let force_val: t<'a> => 'a /** @@ -94,19 +100,28 @@ let force_val: t<'a> => 'a The function returns a lazy value of type `Lazy.t<'a>`. The computation is not executed until the lazy value is accessed. */ -@deprecated("Use `Lazy.make` instead") +@deprecated({ + reason: "Use `Lazy.make` instead", + migrate: Lazy.make(), +}) let from_fun: (unit => 'a) => t<'a> /** `from_val(v)` returns an already-forced suspension of `v`. This is for special purposes only. */ -@deprecated("Use `Lazy.make` instead") +@deprecated({ + reason: "Use `Lazy.make` instead", + migrate: Lazy.make(() => %insert.unlabelledArgument(0)), +}) let from_val: 'a => t<'a> /** `is_val(x)` returns `true` if `x has already been forced and did not throw an exception. */ -@deprecated("Use `Lazy.isEvaluated` instead") +@deprecated({ + reason: "Use `Lazy.isEvaluated` instead", + migrate: Lazy.isEvaluated(), +}) let is_val: t<'a> => bool diff --git a/packages/@rescript/runtime/Stdlib_List.resi b/packages/@rescript/runtime/Stdlib_List.resi index b275d5f6f4..82c100e2d4 100644 --- a/packages/@rescript/runtime/Stdlib_List.resi +++ b/packages/@rescript/runtime/Stdlib_List.resi @@ -90,7 +90,10 @@ switch List.headExn(list{}) { - Throws an Error if list is empty. */ -@deprecated("Use `headOrThrow` instead") +@deprecated({ + reason: "Use `headOrThrow` instead", + migrate: List.headOrThrow(), +}) let headExn: list<'a> => 'a /** @@ -145,7 +148,10 @@ switch List.tailExn(list{}) { - Throws an Error if list is empty. */ -@deprecated("Use `tailOrThrow` instead") +@deprecated({ + reason: "Use `tailOrThrow` instead", + migrate: List.tailOrThrow(), +}) let tailExn: list<'a> => list<'a> /** @@ -217,7 +223,10 @@ switch abc->List.getExn(4) { - Throws an Error if `index` is larger than the length of list. */ -@deprecated("Use `getOrThrow` instead") +@deprecated({ + reason: "Use `getOrThrow` instead", + migrate: List.getOrThrow(), +}) let getExn: (list<'a>, int) => 'a /** @@ -288,7 +297,10 @@ let shuffle: list<'a> => list<'a> List.toShuffled(list{1, 2, 3}) // list{2, 1, 3} ``` */ -@deprecated("Use `shuffle` instead") +@deprecated({ + reason: "Use `shuffle` instead", + migrate: List.shuffle(), +}) let toShuffled: list<'a> => list<'a> /** diff --git a/packages/@rescript/runtime/Stdlib_Null.resi b/packages/@rescript/runtime/Stdlib_Null.resi index 73fa022485..1855cb2e11 100644 --- a/packages/@rescript/runtime/Stdlib_Null.resi +++ b/packages/@rescript/runtime/Stdlib_Null.resi @@ -132,7 +132,10 @@ Null.null->Null.toOption->greet // "Greetings Anonymous" */ let getOr: (t<'a>, 'a) => 'a -@deprecated("Use getOr instead") +@deprecated({ + reason: "Use getOr instead", + migrate: Null.getOr(), +}) let getWithDefault: (t<'a>, 'a) => 'a /** @@ -156,7 +159,10 @@ switch Null.getExn(%raw("null")) { - Throws `Invalid_argument` if `value` is `null` */ -@deprecated("Use `getOrThrow` instead") +@deprecated({ + reason: "Use `getOrThrow` instead", + migrate: Null.getOrThrow(), +}) let getExn: t<'a> => 'a /** @@ -240,7 +246,10 @@ noneValue->Null.mapOr(0, x => x + 5) // 0 */ let mapOr: (t<'a>, 'b, 'a => 'b) => 'b -@deprecated("Use mapOr instead") +@deprecated({ + reason: "Use mapOr instead", + migrate: Null.mapOr(), +}) let mapWithDefault: (t<'a>, 'b, 'a => 'b) => 'b /** diff --git a/packages/@rescript/runtime/Stdlib_Nullable.resi b/packages/@rescript/runtime/Stdlib_Nullable.resi index dee061906a..1fbb44a314 100644 --- a/packages/@rescript/runtime/Stdlib_Nullable.resi +++ b/packages/@rescript/runtime/Stdlib_Nullable.resi @@ -129,7 +129,10 @@ Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" */ let getOr: (t<'a>, 'a) => 'a -@deprecated("Use getOr instead") +@deprecated({ + reason: "Use getOr instead", + migrate: Nullable.getOr(), +}) let getWithDefault: (t<'a>, 'a) => 'a /** @@ -156,7 +159,10 @@ switch Nullable.getExn(%raw("undefined")) { - Throws `Invalid_argument` if `value` is `null` or `undefined` */ -@deprecated("Use `getOrThrow` instead") +@deprecated({ + reason: "Use `getOrThrow` instead", + migrate: Nullable.getOrThrow(), +}) let getExn: t<'a> => 'a /** @@ -244,7 +250,10 @@ noneValue->Nullable.mapOr(0, x => x + 5) // 0 */ let mapOr: (t<'a>, 'b, 'a => 'b) => 'b -@deprecated("Use mapOr instead") +@deprecated({ + reason: "Use mapOr instead", + migrate: Nullable.mapOr(), +}) let mapWithDefault: (t<'a>, 'b, 'a => 'b) => 'b /** diff --git a/packages/@rescript/runtime/Stdlib_Option.resi b/packages/@rescript/runtime/Stdlib_Option.resi index 7a964bf19a..6f2c577641 100644 --- a/packages/@rescript/runtime/Stdlib_Option.resi +++ b/packages/@rescript/runtime/Stdlib_Option.resi @@ -91,7 +91,10 @@ switch Option.getExn(None, ~message="was None!") { - Throws an error if `opt` is `None` */ -@deprecated("Use `getOrThrow` instead") +@deprecated({ + reason: "Use `getOrThrow` instead", + migrate: Option.getOrThrow(), +}) let getExn: (option<'a>, ~message: string=?) => 'a /** @@ -148,7 +151,10 @@ noneValue->Option.mapOr(0, x => x + 5) // 0 */ let mapOr: (option<'a>, 'b, 'a => 'b) => 'b -@deprecated("Use mapOr instead") +@deprecated({ + reason: "Use mapOr instead", + migrate: Option.mapOr(), +}) let mapWithDefault: (option<'a>, 'b, 'a => 'b) => 'b /** @@ -200,7 +206,10 @@ None->greet // "Greetings Anonymous" */ let getOr: (option<'a>, 'a) => 'a -@deprecated("Use getOr instead") +@deprecated({ + reason: "Use getOr instead", + migrate: Option.getOr(), +}) let getWithDefault: (option<'a>, 'a) => 'a /** diff --git a/packages/@rescript/runtime/Stdlib_Promise.resi b/packages/@rescript/runtime/Stdlib_Promise.resi index a502a5ddda..6ea5d74158 100644 --- a/packages/@rescript/runtime/Stdlib_Promise.resi +++ b/packages/@rescript/runtime/Stdlib_Promise.resi @@ -431,7 +431,10 @@ external allSettled6: ((t<'a>, t<'b>, t<'c>, t<'d>, t<'e>, t<'f>)) => t<( `done(p)` is a safe way to ignore a promise. If a value is anything else than a promise, it will throw a type error. */ -@deprecated("Please use `Promise.ignore` instead") +@deprecated({ + reason: "Please use `Promise.ignore` instead", + migrate: Promise.ignore(), +}) external done: promise<'a> => unit = "%ignore" /** diff --git a/packages/@rescript/runtime/Stdlib_RegExp.resi b/packages/@rescript/runtime/Stdlib_RegExp.resi index d16a599d10..f682267897 100644 --- a/packages/@rescript/runtime/Stdlib_RegExp.resi +++ b/packages/@rescript/runtime/Stdlib_RegExp.resi @@ -118,7 +118,11 @@ switch regexp->RegExp.exec("ReScript is pretty cool, right?") { } ``` */ -@deprecated("Use `fromString` instead") @new +@deprecated({ + reason: "Use `fromString` instead", + migrate: RegExp.fromString(~flags=%insert.labelledArgument("flags")), +}) +@new external fromStringWithFlags: (string, ~flags: string) => t = "RegExp" /** diff --git a/packages/@rescript/runtime/Stdlib_Result.resi b/packages/@rescript/runtime/Stdlib_Result.resi index 1b84301fba..e99da81000 100644 --- a/packages/@rescript/runtime/Stdlib_Result.resi +++ b/packages/@rescript/runtime/Stdlib_Result.resi @@ -64,7 +64,10 @@ type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err) } == true ``` */ -@deprecated("Use 'getOrThrow' instead") +@deprecated({ + reason: "Use 'getOrThrow' instead", + migrate: Result.getOrThrow(), +}) let getExn: (result<'a, 'b>, ~message: string=?) => 'a /** @@ -101,7 +104,10 @@ Result.mapOr(error, 0, x => x / 2) == 0 */ let mapOr: (result<'a, 'c>, 'b, 'a => 'b) => 'b -@deprecated("Use mapOr instead") +@deprecated({ + reason: "Use mapOr instead", + migrate: Result.mapOr(), +}) let mapWithDefault: (result<'a, 'c>, 'b, 'a => 'b) => 'b /** @@ -158,7 +164,10 @@ Result.getOr(Error("Invalid Data"), 0) == 0 */ let getOr: (result<'a, 'b>, 'a) => 'a -@deprecated("Use getOr instead") +@deprecated({ + reason: "Use getOr instead", + migrate: Result.getOr(), +}) let getWithDefault: (result<'a, 'b>, 'a) => 'a /** diff --git a/packages/@rescript/runtime/Stdlib_String.res b/packages/@rescript/runtime/Stdlib_String.res index 4cd3914f5b..d9cdc20177 100644 --- a/packages/@rescript/runtime/Stdlib_String.res +++ b/packages/@rescript/runtime/Stdlib_String.res @@ -145,7 +145,11 @@ let searchOpt = (s, re) => } @send external slice: (string, ~start: int, ~end: int=?) => string = "slice" -@deprecated("Use `slice` instead") @send +@deprecated({ + reason: "Use `slice` instead", + migrate: String.slice(), +}) +@send external sliceToEnd: (string, ~start: int) => string = "slice" @send external split: (string, string) => array = "split" @@ -159,7 +163,11 @@ external splitByRegExpAtMost: (string, Stdlib_RegExp.t, ~limit: int) => array bool = "startsWith" @send external substring: (string, ~start: int, ~end: int=?) => string = "substring" -@deprecated("Use `substring` instead") @send +@deprecated({ + reason: "Use `substring` instead", + migrate: String.substring(), +}) +@send external substringToEnd: (string, ~start: int) => string = "substring" @send external toLowerCase: string => string = "toLowerCase" diff --git a/packages/@rescript/runtime/Stdlib_String.resi b/packages/@rescript/runtime/Stdlib_String.resi index b62d72fcb2..b0144f2b09 100644 --- a/packages/@rescript/runtime/Stdlib_String.resi +++ b/packages/@rescript/runtime/Stdlib_String.resi @@ -631,7 +631,11 @@ let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match) String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls" ``` */ -@deprecated("Use `replaceRegExpBy0Unsafe` instead") @send +@deprecated({ + reason: "Use `replaceRegExpBy0Unsafe` instead", + migrate: String.replaceRegExpBy0Unsafe(), +}) +@send external unsafeReplaceRegExpBy0: ( string, Stdlib_RegExp.t, @@ -654,7 +658,11 @@ let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => { String.unsafeReplaceRegExpBy1(str, re, matchFn) == "Jony is 41" ``` */ -@deprecated("Use `replaceRegExpBy1Unsafe` instead") @send +@deprecated({ + reason: "Use `replaceRegExpBy1Unsafe` instead", + migrate: String.replaceRegExpBy1Unsafe(), +}) +@send external unsafeReplaceRegExpBy1: ( string, Stdlib_RegExp.t, @@ -680,7 +688,11 @@ let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => { String.unsafeReplaceRegExpBy2(str, re, matchFn) == "42" ``` */ -@deprecated("Use `replaceRegExpBy2Unsafe` instead") @send +@deprecated({ + reason: "Use `replaceRegExpBy2Unsafe` instead", + migrate: String.replaceRegExpBy2Unsafe(), +}) +@send external unsafeReplaceRegExpBy2: ( string, Stdlib_RegExp.t, @@ -692,7 +704,11 @@ external unsafeReplaceRegExpBy2: ( has three group parameters. See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) on MDN. */ -@deprecated("Use `replaceRegExpBy3Unsafe` instead") @send +@deprecated({ + reason: "Use `replaceRegExpBy3Unsafe` instead", + migrate: String.replaceRegExpBy3Unsafe(), +}) +@send external unsafeReplaceRegExpBy3: ( string, Stdlib_RegExp.t, @@ -894,7 +910,11 @@ String.sliceToEnd("abcdefg", ~start=-2) == "fg" String.sliceToEnd("abcdefg", ~start=7) == "" ``` */ -@deprecated("Use `slice` instead") @send +@deprecated({ + reason: "Use `slice` instead", + migrate: String.slice(), +}) +@send external sliceToEnd: (string, ~start: int) => string = "slice" /** @@ -1036,7 +1056,11 @@ String.substringToEnd("playground", ~start=-3) == "playground" String.substringToEnd("playground", ~start=12) == "" ``` */ -@deprecated("Use `substring` instead") @send +@deprecated({ + reason: "Use `substring` instead", + migrate: String.substring(), +}) +@send external substringToEnd: (string, ~start: int) => string = "substring" /** @@ -1121,7 +1145,7 @@ String.trimStart(" Hello world! ") == "Hello world! " external trimStart: string => string = "trimStart" /** -`trinEnd(str)` returns a string that is `str` with whitespace stripped from the +`trimEnd(str)` returns a string that is `str` with whitespace stripped from the end of a string. Internal whitespace is not removed. See [`String.trimEnd`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd) on MDN. diff --git a/packages/@rescript/runtime/Stdlib_TypedArray.res b/packages/@rescript/runtime/Stdlib_TypedArray.res index 5478156168..406337229b 100644 --- a/packages/@rescript/runtime/Stdlib_TypedArray.res +++ b/packages/@rescript/runtime/Stdlib_TypedArray.res @@ -14,13 +14,21 @@ type t<'a> @get external length: t<'a> => int = "length" @send external copyAllWithin: (t<'a>, ~target: int) => array<'a> = "copyWithin" -@deprecated("Use `copyWithin` instead") @send +@deprecated({ + reason: "Use `copyWithin` instead", + migrate: TypedArray.copyWithin(), +}) +@send external copyWithinToEnd: (t<'a>, ~target: int, ~start: int) => array<'a> = "copyWithin" @send external copyWithin: (t<'a>, ~target: int, ~start: int, ~end: int=?) => array<'a> = "copyWithin" @send external fillAll: (t<'a>, 'a) => t<'a> = "fill" -@deprecated("Use `fill` instead") @send +@deprecated({ + reason: "Use `fill` instead", + migrate: TypedArray.fill(), +}) +@send external fillToEnd: (t<'a>, 'a, ~start: int) => t<'a> = "fill" @send external fill: (t<'a>, 'a, ~start: int, ~end: int=?) => t<'a> = "fill" @@ -43,12 +51,20 @@ external fillToEnd: (t<'a>, 'a, ~start: int) => t<'a> = "fill" @send external lastIndexOfFrom: (t<'a>, 'a, int) => int = "lastIndexOf" @send external slice: (t<'a>, ~start: int, ~end: int=?) => t<'a> = "slice" -@deprecated("Use `slice` instead") @send +@deprecated({ + reason: "Use `slice` instead", + migrate: TypedArray.slice(), +}) +@send external sliceToEnd: (t<'a>, ~start: int) => t<'a> = "slice" @send external copy: t<'a> => t<'a> = "slice" @send external subarray: (t<'a>, ~start: int, ~end: int=?) => t<'a> = "subarray" -@deprecated("Use `subarray` instead") @send +@deprecated({ + reason: "Use `subarray` instead", + migrate: TypedArray.subarray(), +}) +@send external subarrayToEnd: (t<'a>, ~start: int) => t<'a> = "subarray" @send external toString: t<'a> => string = "toString" diff --git a/packages/@rescript/runtime/Stdlib_Uint16Array.res b/packages/@rescript/runtime/Stdlib_Uint16Array.res index a080ae7f41..7f0dcbf844 100644 --- a/packages/@rescript/runtime/Stdlib_Uint16Array.res +++ b/packages/@rescript/runtime/Stdlib_Uint16Array.res @@ -26,14 +26,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Uint16Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "Uint16Array" /** `fromBufferWithRange` creates a `Uint16Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array/Uint16Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Uint16Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Uint16Array" @@ -51,7 +59,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => int=?) => t = "Uint16A /** `fromArrayLikeOrIterableWithMap` creates a `Uint16Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: Uint16Array.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => int) => t = "Uint16Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_Uint32Array.res b/packages/@rescript/runtime/Stdlib_Uint32Array.res index 27f5850be9..b18795a8b4 100644 --- a/packages/@rescript/runtime/Stdlib_Uint32Array.res +++ b/packages/@rescript/runtime/Stdlib_Uint32Array.res @@ -26,14 +26,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Uint32Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "Uint32Array" /** `fromBufferWithRange` creates a `Uint32Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array/Uint32Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Uint32Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Uint32Array" @@ -51,7 +59,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => int=?) => t = "Uint32A /** `fromArrayLikeOrIterableWithMap` creates a `Uint32Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: Uint32Array.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => int) => t = "Uint32Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_Uint8Array.res b/packages/@rescript/runtime/Stdlib_Uint8Array.res index 45519fe144..4866d45956 100644 --- a/packages/@rescript/runtime/Stdlib_Uint8Array.res +++ b/packages/@rescript/runtime/Stdlib_Uint8Array.res @@ -26,14 +26,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Uint8Array.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "Uint8Array" /** `fromBufferWithRange` creates a `Uint8Array` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/Uint8Array) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Uint8Array.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Uint8Array" @@ -51,7 +59,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => int=?) => t = "Uint8Ar /** `fromArrayLikeOrIterableWithMap` creates a `Uint8Array` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: Uint8Array.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => int) => t = "Uint8Array.from" /** diff --git a/packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res b/packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res index 295c6a4dbf..769267c019 100644 --- a/packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res +++ b/packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res @@ -27,14 +27,22 @@ external fromBuffer: (Stdlib_ArrayBuffer.t, ~byteOffset: int=?, ~length: int=?) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Uint8ClampedArray.fromBuffer(), +}) +@new external fromBufferToEnd: (Stdlib_ArrayBuffer.t, ~byteOffset: int) => t = "Uint8ClampedArray" /** `fromBufferWithRange` creates a `Uint8ClampedArray` from an `ArrayBuffer.t`, starting at a particular offset and consuming `length` **bytes**. See [TypedArray constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray/Uint8ClampedArray) **Note:** This is a potentially unsafe operation. Ensure the buffer is large enough and only accessed within its bounds. */ -@deprecated("Use `fromBuffer` instead") @new +@deprecated({ + reason: "Use `fromBuffer` instead", + migrate: Uint8ClampedArray.fromBuffer(), +}) +@new external fromBufferWithRange: (Stdlib_ArrayBuffer.t, ~byteOffset: int, ~length: int) => t = "Uint8ClampedArray" @@ -52,7 +60,14 @@ external fromArrayLikeOrIterable: ('a, ~map: ('b, int) => int=?) => t = "Uint8Cl /** `fromArrayLikeOrIterableWithMap` creates a `Uint8ClampedArray` from an array-like or iterable object and applies the mapping function to each item. The mapping function expects (value, index). See [TypedArray.from on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from) */ -@deprecated("Use `fromArrayLikeOrIterable` instead") @val +@deprecated({ + reason: "Use `fromArrayLikeOrIterable` instead", + migrate: Uint8ClampedArray.fromArrayLikeOrIterable( + %insert.unlabelledArgument(0), + ~map=%insert.unlabelledArgument(1), + ), +}) +@val external fromArrayLikeOrIterableWithMap: ('a, ('b, int) => int) => t = "Uint8ClampedArray.from" /** diff --git a/packages/@rescript/runtime/lib/es6/Stdlib_Int.js b/packages/@rescript/runtime/lib/es6/Stdlib_Int.js index 9f2ba3a6d1..50ae323535 100644 --- a/packages/@rescript/runtime/lib/es6/Stdlib_Int.js +++ b/packages/@rescript/runtime/lib/es6/Stdlib_Int.js @@ -62,6 +62,14 @@ function clamp(min, max, value) { } } +function lnot(x) { + return x ^ -1; +} + +let Bitwise = { + lnot: lnot +}; + let Ref = {}; let Constants = { @@ -75,6 +83,7 @@ export { range, rangeWithOptions, clamp, + Bitwise, Ref, } /* No side effect */ diff --git a/packages/@rescript/runtime/lib/js/Stdlib_Int.js b/packages/@rescript/runtime/lib/js/Stdlib_Int.js index dbd70277e6..7fef767214 100644 --- a/packages/@rescript/runtime/lib/js/Stdlib_Int.js +++ b/packages/@rescript/runtime/lib/js/Stdlib_Int.js @@ -62,6 +62,14 @@ function clamp(min, max, value) { } } +function lnot(x) { + return x ^ -1; +} + +let Bitwise = { + lnot: lnot +}; + let Ref = {}; let Constants = { @@ -74,5 +82,6 @@ exports.fromString = fromString; exports.range = range; exports.rangeWithOptions = rangeWithOptions; exports.clamp = clamp; +exports.Bitwise = Bitwise; exports.Ref = Ref; /* No side effect */ diff --git a/packages/artifacts.json b/packages/artifacts.json index 45d4646461..e7a445b3ef 100644 --- a/packages/artifacts.json +++ b/packages/artifacts.json @@ -735,11 +735,15 @@ "lib/ocaml/Js_promise.cmi", "lib/ocaml/Js_promise.cmj", "lib/ocaml/Js_promise.cmt", + "lib/ocaml/Js_promise.cmti", "lib/ocaml/Js_promise.res", + "lib/ocaml/Js_promise.resi", "lib/ocaml/Js_promise2.cmi", "lib/ocaml/Js_promise2.cmj", "lib/ocaml/Js_promise2.cmt", + "lib/ocaml/Js_promise2.cmti", "lib/ocaml/Js_promise2.res", + "lib/ocaml/Js_promise2.resi", "lib/ocaml/Js_re.cmi", "lib/ocaml/Js_re.cmj", "lib/ocaml/Js_re.cmt", diff --git a/rewatch/testrepo/packages/dep01/src/Dep01.res b/rewatch/testrepo/packages/dep01/src/Dep01.res index f3b84140c1..6868ee6495 100644 --- a/rewatch/testrepo/packages/dep01/src/Dep01.res +++ b/rewatch/testrepo/packages/dep01/src/Dep01.res @@ -1,4 +1,4 @@ let log = () => { - Js.log("02") + Console.log("02") Dep02.log() } diff --git a/rewatch/testrepo/packages/dep02/src/Array.mjs b/rewatch/testrepo/packages/dep02/src/Array.mjs index 8b7653917d..833aba905f 100644 --- a/rewatch/testrepo/packages/dep02/src/Array.mjs +++ b/rewatch/testrepo/packages/dep02/src/Array.mjs @@ -1,6 +1,5 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Js_array from "@rescript/runtime/lib/es6/Js_array.js"; import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js"; import * as Belt_SortArray from "@rescript/runtime/lib/es6/Belt_SortArray.js"; import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; @@ -46,11 +45,11 @@ function flatten(t) { } function find(t, fn) { - return Js_array.find(fn, t); + return fn.find(t); } function findIndex(t, fn) { - return Js_array.findIndex(fn, t); + return fn.findIndex(t); } function filter(prim0, prim1) { diff --git a/rewatch/testrepo/packages/dep02/src/Array.res b/rewatch/testrepo/packages/dep02/src/Array.res index 60e6fe5d10..0f4ee137cb 100644 --- a/rewatch/testrepo/packages/dep02/src/Array.res +++ b/rewatch/testrepo/packages/dep02/src/Array.res @@ -3,7 +3,7 @@ include Belt.Array let at = get -let includes = Js.Array2.includes +let includes = Array.includes let head = t => t->get(0) @@ -21,15 +21,15 @@ let prepend = (t, v) => [v]->concat(t) let flatMap = (t, fn) => t->map(fn)->concatMany -let mapi = Js.Array2.mapi +let mapi = Array.mapWithIndex let flatten = t => t->flatMap(x => x) -let find = (t, fn) => Js.Array.find(fn, t) +let find = (t, fn) => Array.find(fn, t) -let findIndex = (t, fn) => Js.Array.findIndex(fn, t) +let findIndex = (t, fn) => Array.findIndex(fn, t) -let filter = Js.Array2.filter +let filter = Array.filter let reject = (t, fn) => t->filter(el => !fn(el)) @@ -45,7 +45,7 @@ let sortBy = (t, fn) => let sortByRaw = Belt.SortArray.stableSortBy module String = { - let joinWith = Js.Array2.joinWith + let joinWith = Array.join let join = joinWith(_, "") } @@ -164,7 +164,7 @@ let drop = (t, i) => { t->sliceToEnd(start) } -let unsafePop = Js.Array.pop +let unsafePop = Array.pop module Int = { let sum = xs => reduce(xs, 0, (a, b) => a + b) diff --git a/rewatch/testrepo/packages/dep02/src/Dep02.res b/rewatch/testrepo/packages/dep02/src/Dep02.res index e832615245..55c756ac60 100644 --- a/rewatch/testrepo/packages/dep02/src/Dep02.res +++ b/rewatch/testrepo/packages/dep02/src/Dep02.res @@ -1,3 +1,3 @@ open Array -let log = () => ["a", "b"]->forEach(Js.log) -Js.log(NS.Alias.hello_world()) +let log = () => ["a", "b"]->forEach(Console.log) +Console.log(NS.Alias.hello_world()) diff --git a/rewatch/testrepo/packages/main/src/Main.res b/rewatch/testrepo/packages/main/src/Main.res index 619e734d77..3182ad4c75 100644 --- a/rewatch/testrepo/packages/main/src/Main.res +++ b/rewatch/testrepo/packages/main/src/Main.res @@ -1,7 +1,7 @@ -Js.log("01") +Console.log("01") Dep01.log() -Js.log(InternalDep.value) +Console.log(InternalDep.value) module Array = Belt.Array module String = Js.String diff --git a/rewatch/testrepo/packages/new-namespace/src/Other_module.res b/rewatch/testrepo/packages/new-namespace/src/Other_module.res index b265646f33..fe8c6a7fcb 100644 --- a/rewatch/testrepo/packages/new-namespace/src/Other_module.res +++ b/rewatch/testrepo/packages/new-namespace/src/Other_module.res @@ -1 +1 @@ -let bla = () => Js.log("bla") +let bla = () => Console.log("bla") diff --git a/rewatch/testrepo/packages/with-dev-deps/test/FileToTest_test.res b/rewatch/testrepo/packages/with-dev-deps/test/FileToTest_test.res index 45c4bf01a4..04b846d3ee 100644 --- a/rewatch/testrepo/packages/with-dev-deps/test/FileToTest_test.res +++ b/rewatch/testrepo/packages/with-dev-deps/test/FileToTest_test.res @@ -2,5 +2,5 @@ let res = FileToTest.add(1, 2) let expected = 3 if res !== expected { - failwith("Expected " ++ expected->Js.Int.toString ++ ", got " ++ res->Js.Int.toString) + failwith("Expected " ++ expected->Int.toString ++ ", got " ++ res->Int.toString) } diff --git a/rewatch/tests/snapshots/remove-file.txt b/rewatch/tests/snapshots/remove-file.txt index 3ca1a9fb91..9c9337be41 100644 --- a/rewatch/tests/snapshots/remove-file.txt +++ b/rewatch/tests/snapshots/remove-file.txt @@ -15,7 +15,7 @@ Use 'compiler-flags' instead. /packages/dep01/src/Dep01.res:3:9-17 1 │ let log = () => { - 2 │ Js.log("02") + 2 │ Console.log("02") 3 │ Dep02.log() 4 │ } 5 │ diff --git a/rewatch/tests/snapshots/rename-file-internal-dep.txt b/rewatch/tests/snapshots/rename-file-internal-dep.txt index 1459c2381b..fbb8c93803 100644 --- a/rewatch/tests/snapshots/rename-file-internal-dep.txt +++ b/rewatch/tests/snapshots/rename-file-internal-dep.txt @@ -12,11 +12,11 @@ The field 'bsc-flags' found in the package config of '@testrepo/deprecated-confi Use 'compiler-flags' instead. We've found a bug for you! - /packages/main/src/Main.res:4:8-24 + /packages/main/src/Main.res:4:13-29 2 │ Dep01.log() 3 │ - 4 │ Js.log(InternalDep.value) + 4 │ Console.log(InternalDep.value) 5 │ 6 │ module Array = Belt.Array diff --git a/tests/analysis_tests/tests/src/expected/Completion.res.txt b/tests/analysis_tests/tests/src/expected/Completion.res.txt index 2912c7a590..6cc409665a 100644 --- a/tests/analysis_tests/tests/src/expected/Completion.res.txt +++ b/tests/analysis_tests/tests/src/expected/Completion.res.txt @@ -99,13 +99,13 @@ Path Array. "kind": 12, "tags": [1], "detail": "(array, string) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `join` instead\n\n\n`joinWith(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Array items must be strings, to join number or other arrays, use `joinWithUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.\n\n## Examples\n\n```rescript\n[\"One\", \"Two\", \"Three\"]->Array.joinWith(\" -- \") == \"One -- Two -- Three\"\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`joinWith(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Array items must be strings, to join number or other arrays, use `joinWithUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.\n\n## Examples\n\n```rescript\n[\"One\", \"Two\", \"Three\"]->Array.joinWith(\" -- \") == \"One -- Two -- Three\"\n```\n"} }, { "label": "joinWithUnsafe", "kind": 12, "tags": [1], "detail": "(array<'a>, string) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `joinUnsafe` instead\n\n\n`joinWithUnsafe(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items.\n\n## Examples\n\n```rescript\n[1, 2, 3]->Array.joinWithUnsafe(\" -- \") == \"1 -- 2 -- 3\"\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`joinWithUnsafe(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items.\n\n## Examples\n\n```rescript\n[1, 2, 3]->Array.joinWithUnsafe(\" -- \") == \"1 -- 2 -- 3\"\n```\n"} }, { "label": "reduceRight", "kind": 12, @@ -183,7 +183,7 @@ Path Array. "kind": 12, "tags": [1], "detail": "(array<'a>, 'a, ~start: int) => unit", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n\n`fillToEnd(array, value, ~start)` fills `array` with `value` from the `start` index.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\nmyArray->Array.fillToEnd(9, ~start=1)\nmyArray == [1, 9, 9, 9]\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`fillToEnd(array, value, ~start)` fills `array` with `value` from the `start` index.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\nmyArray->Array.fillToEnd(9, ~start=1)\nmyArray == [1, 9, 9, 9]\n```\n"} }, { "label": "includes", "kind": 12, @@ -219,7 +219,7 @@ Path Array. "kind": 12, "tags": [1], "detail": "(array<'a>, 'a, int) => int", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `lastIndexOf` instead\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"} }, { "label": "toLocaleString", "kind": 12, @@ -291,7 +291,7 @@ Path Array. "kind": 12, "tags": [], "detail": "(\n array<'a>,\n ~target: int,\n ~start: int,\n ~end: int=?,\n) => array<'a>", - "documentation": {"kind": "markdown", "value": "\n`copyWithin(array, ~target, ~start, ~end)` copies the sequence of array elements within the array to the position starting at `target`. The copy is taken from the index positions `start` to `end`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4, 5]\nmyArray->Array.copyWithin(~target=0, ~start=3) == [4, 5, 3, 4, 5]\n\nlet myArray = [1, 2, 3, 4, 5]\nmyArray->Array.copyWithin(~target=1, ~start=3, ~end=4) == [1, 4, 3, 4, 5]\n```\n"} + "documentation": {"kind": "markdown", "value": "\n`copyWithin(array, ~target, ~start, ~end)` copies starting at element `start` in the given array up to but not including `end` to the designated `target` position, returning the resulting array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin) on MDN.\n\n## Examples\n\n```rescript\nlet arr = [100, 101, 102, 103, 104, 105]\narr->Array.copyWithin(~target=1, ~start=2, ~end=5) == [100, 102, 103, 104, 104, 105]\narr == [100, 102, 103, 104, 104, 105]\n```\n"} }, { "label": "toString", "kind": 12, @@ -322,6 +322,12 @@ Path Array. "tags": [], "detail": "array<'a> => unit", "documentation": {"kind": "markdown", "value": "\n`reverse(array)` reverses the order of the items in `array`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.reverse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.reverse\n\nsomeArray == [\"hello\", \"hi\"]\n```\n"} + }, { + "label": "fromString", + "kind": 12, + "tags": [], + "detail": "string => array", + "documentation": {"kind": "markdown", "value": "\n`fromString(str)` creates an array of each character as a separate string from the provided `str`.\n\n## Examples\n\n```rescript\nArray.fromString(\"abcde\") == [\"a\", \"b\", \"c\", \"d\", \"e\"]\n```\n"} }, { "label": "findLastIndexWithIndex", "kind": 12, @@ -417,7 +423,7 @@ Path Array. "kind": 12, "tags": [1], "detail": "(array<'a>, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n\n`sliceToEnd(array, start)` creates a new array from `array`, with all items from `array` starting from `start`.\n\nSee [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]->Array.sliceToEnd(~start=1) == [2, 3, 4]\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`sliceToEnd(array, start)` creates a new array from `array`, with all items from `array` starting from `start`.\n\nSee [`Array.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) on MDN.\n\n## Examples\n\n```rescript\n[1, 2, 3, 4]->Array.sliceToEnd(~start=1) == [2, 3, 4]\n```\n"} }, { "label": "fromArrayLikeWithMap", "kind": 12, @@ -429,7 +435,7 @@ Path Array. "kind": 12, "tags": [1], "detail": "(array<'a>, 'a) => unit", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n\n`fillAll(array, value)` fills the entire `array` with `value`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\nmyArray->Array.fillAll(9)\nmyArray == [9, 9, 9, 9]\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`fillAll(array, value)` fills the entire `array` with `value`.\n\nBeware this will *mutate* the array.\n\nSee [`Array.fill`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) on MDN.\n\n## Examples\n\n```rescript\nlet myArray = [1, 2, 3, 4]\nmyArray->Array.fillAll(9)\nmyArray == [9, 9, 9, 9]\n```\n"} }, { "label": "set", "kind": 12, @@ -489,7 +495,7 @@ Path Array. "kind": 12, "tags": [1], "detail": "(array<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`copyWithinToEnd(array, ~target, ~start)` copies starting at element `start` in the given array to the designated `target` position, returning the resulting array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin) on MDN.\n\n## Examples\n\n```rescript\nlet arr = [100, 101, 102, 103, 104]\narr->Array.copyWithinToEnd(~target=0, ~start=2) == [102, 103, 104, 103, 104]\narr == [102, 103, 104, 103, 104]\n```\n"} }, { "label": "unshift", "kind": 12, @@ -531,13 +537,13 @@ Path Array. "kind": 12, "tags": [1], "detail": "(array<'a>, int) => 'a", - "documentation": {"kind": "markdown", "value": "Deprecated: Use getUnsafe instead. This will be removed in v13\n\n\n`unsafe_get(array, index)` returns the element at `index` of `array`.\n\nThis is _unsafe_, meaning it will return `undefined` value if `index` does not exist in `array`.\n\nUse `Array.unsafe_get` only when you are sure the `index` exists (i.e. when using for-loop).\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3]\nfor index in 0 to array->Array.length - 1 {\n let value = array->Array.unsafe_get(index)\n Console.log(value)\n}\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`unsafe_get(array, index)` returns the element at `index` of `array`.\n\nThis is _unsafe_, meaning it will return `undefined` value if `index` does not exist in `array`.\n\nUse `Array.unsafe_get` only when you are sure the `index` exists (i.e. when using for-loop).\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3]\nfor index in 0 to array->Array.length - 1 {\n let value = array->Array.unsafe_get(index)\n Console.log(value)\n}\n```\n"} }, { "label": "copyAllWithin", "kind": 12, "tags": [1], "detail": "(array<'a>, ~target: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`isEmpty(array)` returns `true` if the array is empty (has length 0), `false` otherwise.\n\n## Examples\n\n```rescript\nlet arr = [100, 101, 102, 103, 104]\narr->Array.copyAllWithin(~target=2) == [100, 101, 100, 101, 102]\narr == [100, 101, 100, 101, 102]\n```\n"} }, { "label": "keepSome", "kind": 12, @@ -609,7 +615,7 @@ Path Array. "kind": 12, "tags": [1], "detail": "(array<'a>, 'a, int) => int", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `indexOf` instead\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"} }] Complete src/Completion.res 5:10 @@ -2468,25 +2474,25 @@ Path t "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toExponentialWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toExponential` instead\n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} }, { "label": "Int.toFixedWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toFixed` instead\n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} }, { "label": "Int.toPrecisionWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.toPrecision", "kind": 12, @@ -2540,13 +2546,13 @@ Path t "kind": 12, "tags": [1], "detail": "(float, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` with `~radix` instead\n\n\n`toStringWithRadix(v, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) on MDN.\n\n## Examples\n\n```rescript\nFloat.toStringWithRadix(6.0, ~radix=2) == \"110\"\nFloat.toStringWithRadix(3735928559.0, ~radix=16) == \"deadbeef\"\nFloat.toStringWithRadix(123456.0, ~radix=36) == \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(v, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) on MDN.\n\n## Examples\n\n```rescript\nFloat.toStringWithRadix(6.0, ~radix=2) == \"110\"\nFloat.toStringWithRadix(3735928559.0, ~radix=16) == \"deadbeef\"\nFloat.toStringWithRadix(123456.0, ~radix=36) == \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Float.toExponentialWithPrecision", "kind": 12, "tags": [1], "detail": "(float, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toExponential` instead\n\n\n`toExponential(v, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point.\nSee [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) on MDN.\n\n## Examples\n\n```rescript\nFloat.toExponentialWithPrecision(77.0, ~digits=2) == \"7.70e+1\"\nFloat.toExponentialWithPrecision(5678.0, ~digits=2) == \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toExponential(v, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point.\nSee [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) on MDN.\n\n## Examples\n\n```rescript\nFloat.toExponentialWithPrecision(77.0, ~digits=2) == \"7.70e+1\"\nFloat.toExponentialWithPrecision(5678.0, ~digits=2) == \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} }, { "label": "Float.toInt", "kind": 12, @@ -2558,13 +2564,13 @@ Path t "kind": 12, "tags": [1], "detail": "(float, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toFixed` instead\n\n\n`toFixedWithPrecision(v, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point.\nSee [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) on MDN.\n\n## Examples\n\n```rescript\nFloat.toFixedWithPrecision(300.0, ~digits=4) == \"300.0000\"\nFloat.toFixedWithPrecision(300.0, ~digits=1) == \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toFixedWithPrecision(v, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point.\nSee [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) on MDN.\n\n## Examples\n\n```rescript\nFloat.toFixedWithPrecision(300.0, ~digits=4) == \"300.0000\"\nFloat.toFixedWithPrecision(300.0, ~digits=1) == \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} }, { "label": "Float.toPrecisionWithPrecision", "kind": 12, "tags": [1], "detail": "(float, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(v, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits.\nSee [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nFloat.toPrecisionWithPrecision(100.0, ~digits=2) == \"1.0e+2\"\nFloat.toPrecisionWithPrecision(1.0, ~digits=1) == \"1\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toPrecisionWithPrecision(v, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits.\nSee [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nFloat.toPrecisionWithPrecision(100.0, ~digits=2) == \"1.0e+2\"\nFloat.toPrecisionWithPrecision(1.0, ~digits=1) == \"1\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} }, { "label": "Float.toPrecision", "kind": 12, @@ -2613,7 +2619,7 @@ Path g "kind": 12, "tags": [1], "detail": "(result<'a, 'b>, ~message: string=?) => 'a", - "documentation": {"kind": "markdown", "value": "Deprecated: Use 'getOrThrow' instead\n\n\n `getExn(res, ~message=?)` returns `n` if `res` is `Ok(n)`, otherwise throws an exception with the message provided, or a generic message if no message was provided.\n\n ```res example\n Result.getExn(Result.Ok(42)) == 42\n \n switch Result.getExn(Error(\"Invalid data\")) {\n | exception _ => true\n | _ => false\n } == true\n\n switch Result.getExn(Error(\"Invalid data\"), ~message=\"was Error!\") {\n | exception _ => true // Throws a JsError with the message \"was Error!\"\n | _ => false\n } == true\n ```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n `getExn(res, ~message=?)` returns `n` if `res` is `Ok(n)`, otherwise throws an exception with the message provided, or a generic message if no message was provided.\n\n ```res example\n Result.getExn(Result.Ok(42)) == 42\n \n switch Result.getExn(Error(\"Invalid data\")) {\n | exception _ => true\n | _ => false\n } == true\n\n switch Result.getExn(Error(\"Invalid data\"), ~message=\"was Error!\") {\n | exception _ => true // Throws a JsError with the message \"was Error!\"\n | _ => false\n } == true\n ```\n"} }, { "label": "Result.getOrThrow", "kind": 12, @@ -2631,7 +2637,7 @@ Path g "kind": 12, "tags": [1], "detail": "(result<'a, 'b>, 'a) => 'a", - "documentation": {"kind": "markdown", "value": "Deprecated: Use getOr instead\n\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"} }] Complete src/Completion.res 445:15 @@ -2715,7 +2721,7 @@ Path toS "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toString", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionInferValues.res.txt b/tests/analysis_tests/tests/src/expected/CompletionInferValues.res.txt index 898253f44f..a8840ab77e 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionInferValues.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionInferValues.res.txt @@ -16,25 +16,25 @@ Path t "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toExponentialWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toExponential` instead\n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} }, { "label": "Int.toFixedWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toFixed` instead\n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} }, { "label": "Int.toPrecisionWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.toPrecision", "kind": 12, @@ -334,25 +334,25 @@ Path t "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toExponentialWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toExponential` instead\n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} }, { "label": "Int.toFixedWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toFixed` instead\n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} }, { "label": "Int.toPrecisionWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.toPrecision", "kind": 12, @@ -577,7 +577,7 @@ Path slic "kind": 12, "tags": [1], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} }] Complete src/CompletionInferValues.res 91:82 @@ -600,7 +600,7 @@ Path toS "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toString", "kind": 12, @@ -632,7 +632,7 @@ Path toS "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toString", "kind": 12, @@ -665,7 +665,7 @@ Path toS "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toString", "kind": 12, @@ -700,7 +700,7 @@ Path slic "kind": 12, "tags": [1], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} }] Complete src/CompletionInferValues.res 107:89 @@ -729,7 +729,7 @@ Path slic "kind": 12, "tags": [1], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} }] Complete src/CompletionInferValues.res 111:80 @@ -758,7 +758,7 @@ Path slic "kind": 12, "tags": [1], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"} }] Complete src/CompletionInferValues.res 115:53 @@ -779,7 +779,7 @@ Path toSt "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toString", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt index 88ae80dd76..4ef9123b44 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt @@ -213,13 +213,13 @@ Path "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toExponentialWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toExponential` instead\n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} }, { "label": "Int.bitwiseXor", "kind": 12, @@ -237,13 +237,13 @@ Path "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toFixed` instead\n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} }, { "label": "Int.toPrecisionWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.bitwiseAnd", "kind": 12, @@ -315,7 +315,7 @@ Path "kind": 12, "tags": [1], "detail": "(int, int, rangeOptions) => array", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `range` instead\n\n\n`rangeWithOptions(start, end, options)` is like `range`, but with `step` and\n`inclusive` options configurable.\n\nIf `step` is set, the sequence will increase or decrease by that amount for each\nstep. If `start < end` and `step` is negative, or vice versa, an empty array is\nreturned since the sequence would otherwise never reach or exceed the end value\nand hence be infinite. If `step` is `0` and `start !=` end, a `RangeError` is\nraised as the sequence would never reach or exceed the end value and hence be\ninfinite.\n\nIf `inclusive` is set to `true`, the sequence will include `end` if `step` is\nset such that the sequence includes it.\n\n## Examples\n\n```rescript\nInt.rangeWithOptions(3, 7, {step: 2}) == [3, 5]\nInt.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7]\nInt.rangeWithOptions(3, 6, {step: -2}) // RangeError\n```\n\n## Exceptions\n\n- Raises `RangeError` if `step == 0 && start != end`.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`rangeWithOptions(start, end, options)` is like `range`, but with `step` and\n`inclusive` options configurable.\n\nIf `step` is set, the sequence will increase or decrease by that amount for each\nstep. If `start < end` and `step` is negative, or vice versa, an empty array is\nreturned since the sequence would otherwise never reach or exceed the end value\nand hence be infinite. If `step` is `0` and `start !=` end, a `RangeError` is\nraised as the sequence would never reach or exceed the end value and hence be\ninfinite.\n\nIf `inclusive` is set to `true`, the sequence will include `end` if `step` is\nset such that the sequence includes it.\n\n## Examples\n\n```rescript\nInt.rangeWithOptions(3, 7, {step: 2}) == [3, 5]\nInt.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7]\nInt.rangeWithOptions(3, 6, {step: -2}) // RangeError\n```\n\n## Exceptions\n\n- Raises `RangeError` if `step == 0 && start != end`.\n"} }, { "label": "Int.shiftRightUnsigned", "kind": 12, @@ -383,13 +383,13 @@ Path "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toExponentialWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toExponential` instead\n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} }, { "label": "Int.bitwiseXor", "kind": 12, @@ -407,13 +407,13 @@ Path "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toFixed` instead\n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} }, { "label": "Int.toPrecisionWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.bitwiseAnd", "kind": 12, @@ -485,7 +485,7 @@ Path "kind": 12, "tags": [1], "detail": "(int, int, rangeOptions) => array", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `range` instead\n\n\n`rangeWithOptions(start, end, options)` is like `range`, but with `step` and\n`inclusive` options configurable.\n\nIf `step` is set, the sequence will increase or decrease by that amount for each\nstep. If `start < end` and `step` is negative, or vice versa, an empty array is\nreturned since the sequence would otherwise never reach or exceed the end value\nand hence be infinite. If `step` is `0` and `start !=` end, a `RangeError` is\nraised as the sequence would never reach or exceed the end value and hence be\ninfinite.\n\nIf `inclusive` is set to `true`, the sequence will include `end` if `step` is\nset such that the sequence includes it.\n\n## Examples\n\n```rescript\nInt.rangeWithOptions(3, 7, {step: 2}) == [3, 5]\nInt.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7]\nInt.rangeWithOptions(3, 6, {step: -2}) // RangeError\n```\n\n## Exceptions\n\n- Raises `RangeError` if `step == 0 && start != end`.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`rangeWithOptions(start, end, options)` is like `range`, but with `step` and\n`inclusive` options configurable.\n\nIf `step` is set, the sequence will increase or decrease by that amount for each\nstep. If `start < end` and `step` is negative, or vice versa, an empty array is\nreturned since the sequence would otherwise never reach or exceed the end value\nand hence be infinite. If `step` is `0` and `start !=` end, a `RangeError` is\nraised as the sequence would never reach or exceed the end value and hence be\ninfinite.\n\nIf `inclusive` is set to `true`, the sequence will include `end` if `step` is\nset such that the sequence includes it.\n\n## Examples\n\n```rescript\nInt.rangeWithOptions(3, 7, {step: 2}) == [3, 5]\nInt.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7]\nInt.rangeWithOptions(3, 6, {step: -2}) // RangeError\n```\n\n## Exceptions\n\n- Raises `RangeError` if `step == 0 && start != end`.\n"} }, { "label": "Int.shiftRightUnsigned", "kind": 12, @@ -826,7 +826,7 @@ Path s "kind": 12, "tags": [1], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `substring` instead\n\n\n`substringToEnd(str, ~start)` returns the substring of `str` from position\n`start` to the end.\n- If `start` is less than or equal to zero, the entire string is returned.\n- If `start` is greater than or equal to the length of `str`, the empty string\n is returned.\n See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substringToEnd(\"playground\", ~start=4) == \"ground\"\nString.substringToEnd(\"playground\", ~start=-3) == \"playground\"\nString.substringToEnd(\"playground\", ~start=12) == \"\"\n```\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`substringToEnd(str, ~start)` returns the substring of `str` from position\n`start` to the end.\n- If `start` is less than or equal to zero, the entire string is returned.\n- If `start` is greater than or equal to the length of `str`, the empty string\n is returned.\n See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substringToEnd(\"playground\", ~start=4) == \"ground\"\nString.substringToEnd(\"playground\", ~start=-3) == \"playground\"\nString.substringToEnd(\"playground\", ~start=12) == \"\"\n```\n"}, "sortText": "substringToEnd", "insertText": "->String.substringToEnd", "additionalTextEdits": [{ @@ -862,7 +862,7 @@ Path s "kind": 12, "tags": [1], "detail": "(string, ~start: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`sliceToEnd(str, ~start)` returns the substring of `str` starting at character\n`start` to the end of the string.\n- If `start` is negative, then it is evaluated as `length(str - start)`.\n- If `start` is greater than the length of `str`, then sliceToEnd returns the empty string.\n See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN.\n\n## Examples\n\n```rescript\nString.sliceToEnd(\"abcdefg\", ~start=4) == \"efg\"\nString.sliceToEnd(\"abcdefg\", ~start=-2) == \"fg\"\nString.sliceToEnd(\"abcdefg\", ~start=7) == \"\"\n```\n"}, "sortText": "sliceToEnd", "insertText": "->String.sliceToEnd", "additionalTextEdits": [{ diff --git a/tests/analysis_tests/tests/src/expected/CompletionNullNullable.res.txt b/tests/analysis_tests/tests/src/expected/CompletionNullNullable.res.txt index 8903a5ef5a..7c3aba3e25 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionNullNullable.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionNullNullable.res.txt @@ -53,7 +53,7 @@ Path "kind": 12, "tags": [1], "detail": "t<'a> => 'a", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `getOrThrow` instead\n\n\n`getExn(value)` throws an exception if `null`, otherwise returns the value.\n\n```rescript\nNull.getExn(Null.make(3)) == 3\n\nswitch Null.getExn(%raw(\"'ReScript'\")) {\n| exception Invalid_argument(_) => assert(false)\n| value => value == \"ReScript\"\n}\n\nswitch Null.getExn(%raw(\"null\")) {\n| exception Invalid_argument(_) => assert(true)\n| _ => assert(false)\n}\n```\n\n## Exceptions\n\n- Throws `Invalid_argument` if `value` is `null`\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`getExn(value)` throws an exception if `null`, otherwise returns the value.\n\n```rescript\nNull.getExn(Null.make(3)) == 3\n\nswitch Null.getExn(%raw(\"'ReScript'\")) {\n| exception Invalid_argument(_) => assert(false)\n| value => value == \"ReScript\"\n}\n\nswitch Null.getExn(%raw(\"null\")) {\n| exception Invalid_argument(_) => assert(true)\n| _ => assert(false)\n}\n```\n\n## Exceptions\n\n- Throws `Invalid_argument` if `value` is `null`\n"}, "sortText": "getExn", "insertText": "->Null.getExn", "additionalTextEdits": [{ @@ -137,7 +137,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'b, 'a => 'b) => 'b", - "documentation": {"kind": "markdown", "value": "Deprecated: Use mapOr instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "mapWithDefault", "insertText": "->Null.mapWithDefault", "additionalTextEdits": [{ @@ -149,7 +149,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a) => 'a", - "documentation": {"kind": "markdown", "value": "Deprecated: Use getOr instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "getWithDefault", "insertText": "->Null.getWithDefault", "additionalTextEdits": [{ @@ -249,7 +249,7 @@ Path "kind": 12, "tags": [1], "detail": "t<'a> => 'a", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `getOrThrow` instead\n\n\n`getExn(value)` throws an exception if `null` or `undefined`, otherwise returns the value.\n\n```rescript\nswitch Nullable.getExn(%raw(\"'Hello'\")) {\n| exception Invalid_argument(_) => assert(false)\n| value => value == \"Hello\"\n}\n\nswitch Nullable.getExn(%raw(\"null\")) {\n| exception Invalid_argument(_) => assert(true)\n| _ => assert(false)\n}\n\nswitch Nullable.getExn(%raw(\"undefined\")) {\n| exception Invalid_argument(_) => assert(true)\n| _ => assert(false)\n}\n```\n\n## Exceptions\n\n- Throws `Invalid_argument` if `value` is `null` or `undefined`\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`getExn(value)` throws an exception if `null` or `undefined`, otherwise returns the value.\n\n```rescript\nswitch Nullable.getExn(%raw(\"'Hello'\")) {\n| exception Invalid_argument(_) => assert(false)\n| value => value == \"Hello\"\n}\n\nswitch Nullable.getExn(%raw(\"null\")) {\n| exception Invalid_argument(_) => assert(true)\n| _ => assert(false)\n}\n\nswitch Nullable.getExn(%raw(\"undefined\")) {\n| exception Invalid_argument(_) => assert(true)\n| _ => assert(false)\n}\n```\n\n## Exceptions\n\n- Throws `Invalid_argument` if `value` is `null` or `undefined`\n"}, "sortText": "getExn", "insertText": "->Nullable.getExn", "additionalTextEdits": [{ @@ -333,7 +333,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'b, 'a => 'b) => 'b", - "documentation": {"kind": "markdown", "value": "Deprecated: Use mapOr instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "mapWithDefault", "insertText": "->Nullable.mapWithDefault", "additionalTextEdits": [{ @@ -345,7 +345,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a) => 'a", - "documentation": {"kind": "markdown", "value": "Deprecated: Use getOr instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "getWithDefault", "insertText": "->Nullable.getWithDefault", "additionalTextEdits": [{ diff --git a/tests/analysis_tests/tests/src/expected/CompletionPipeChain.res.txt b/tests/analysis_tests/tests/src/expected/CompletionPipeChain.res.txt index 4fb8e0849f..0ab9d756c0 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionPipeChain.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionPipeChain.res.txt @@ -329,25 +329,25 @@ Path t "kind": 12, "tags": [1], "detail": "(int, ~radix: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"} }, { "label": "Int.toExponentialWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toExponential` instead\n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"} }, { "label": "Int.toFixedWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toFixed` instead\n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"} }, { "label": "Int.toPrecisionWithPrecision", "kind": 12, "tags": [1], "detail": "(int, ~digits: int) => string", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n \n"} + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\n Implementations are allowed to support larger and smaller values as well.\n ECMA-262 only requires a precision of up to 21 significant digits.\n"} }, { "label": "Int.toPrecision", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionTypedArrays.res.txt b/tests/analysis_tests/tests/src/expected/CompletionTypedArrays.res.txt index ce42da68a8..b9daf3e10d 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionTypedArrays.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionTypedArrays.res.txt @@ -223,7 +223,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -271,7 +271,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -307,7 +307,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -439,7 +439,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -913,7 +913,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -961,7 +961,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -997,7 +997,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -1129,7 +1129,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -1603,7 +1603,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -1651,7 +1651,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -1687,7 +1687,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -1819,7 +1819,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -2293,7 +2293,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -2341,7 +2341,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -2377,7 +2377,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -2509,7 +2509,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -2983,7 +2983,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -3031,7 +3031,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -3067,7 +3067,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -3199,7 +3199,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -3673,7 +3673,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -3721,7 +3721,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -3757,7 +3757,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -3889,7 +3889,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -4363,7 +4363,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -4411,7 +4411,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -4447,7 +4447,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -4579,7 +4579,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -5053,7 +5053,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -5101,7 +5101,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -5137,7 +5137,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -5269,7 +5269,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -5743,7 +5743,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -5791,7 +5791,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -5827,7 +5827,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -5959,7 +5959,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -6433,7 +6433,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -6481,7 +6481,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -6517,7 +6517,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -6649,7 +6649,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ @@ -7123,7 +7123,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `slice` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "sliceToEnd", "insertText": "->TypedArray.sliceToEnd", "additionalTextEdits": [{ @@ -7171,7 +7171,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, 'a, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `fill` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "fillToEnd", "insertText": "->TypedArray.fillToEnd", "additionalTextEdits": [{ @@ -7207,7 +7207,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~start: int) => t<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `subarray` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "subarrayToEnd", "insertText": "->TypedArray.subarrayToEnd", "additionalTextEdits": [{ @@ -7339,7 +7339,7 @@ Path "kind": 12, "tags": [1], "detail": "(t<'a>, ~target: int, ~start: int) => array<'a>", - "documentation": {"kind": "markdown", "value": "Deprecated: Use `copyWithin` instead\n\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}, "sortText": "copyWithinToEnd", "insertText": "->TypedArray.copyWithinToEnd", "additionalTextEdits": [{ diff --git a/tests/analysis_tests/tests/src/expected/Debug.res.txt b/tests/analysis_tests/tests/src/expected/Debug.res.txt index f70ae60f0e..aa61765e93 100644 --- a/tests/analysis_tests/tests/src/expected/Debug.res.txt +++ b/tests/analysis_tests/tests/src/expected/Debug.res.txt @@ -13,15 +13,15 @@ Path eqN [{ "label": "eqNullable", "kind": 12, - "tags": [], + "tags": [1], "detail": "('a, nullable<'a>) => bool", - "documentation": null + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"} }, { "label": "eqNull", "kind": 12, - "tags": [], + "tags": [1], "detail": "('a, null<'a>) => bool", - "documentation": null + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n"} }] diff --git a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt index 27187512fb..233a6ab806 100644 --- a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt +++ b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt @@ -263,7 +263,7 @@ Path u "kind": 12, "tags": [1], "detail": "(array<'a>, int) => 'a", - "documentation": {"kind": "markdown", "value": "Deprecated: Use getUnsafe instead. This will be removed in v13\n\n\n`unsafe_get(array, index)` returns the element at `index` of `array`.\n\nThis is _unsafe_, meaning it will return `undefined` value if `index` does not exist in `array`.\n\nUse `Array.unsafe_get` only when you are sure the `index` exists (i.e. when using for-loop).\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3]\nfor index in 0 to array->Array.length - 1 {\n let value = array->Array.unsafe_get(index)\n Console.log(value)\n}\n```\n"}, + "documentation": {"kind": "markdown", "value": "Deprecated: \n\n\n`unsafe_get(array, index)` returns the element at `index` of `array`.\n\nThis is _unsafe_, meaning it will return `undefined` value if `index` does not exist in `array`.\n\nUse `Array.unsafe_get` only when you are sure the `index` exists (i.e. when using for-loop).\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3]\nfor index in 0 to array->Array.length - 1 {\n let value = array->Array.unsafe_get(index)\n Console.log(value)\n}\n```\n"}, "sortText": "unsafe_get", "insertText": "->Array.unsafe_get", "additionalTextEdits": [{ diff --git a/tests/build_tests/super_errors/expected/deprecated_with_automigration.res.expected b/tests/build_tests/super_errors/expected/deprecated_with_automigration.res.expected new file mode 100644 index 0000000000..8b4971c02a --- /dev/null +++ b/tests/build_tests/super_errors/expected/deprecated_with_automigration.res.expected @@ -0,0 +1,11 @@ + + Warning number 3 + /.../fixtures/deprecated_with_automigration.res:1:9-21 + + 1 │ let _ = Js.Array2.map([1, 2], v => v + 1) + 2 │ + + deprecated: Js.Array2.map + Use `Array.map` instead. + + This can be automatically migrated by the ReScript migration tool. Run `rescript-tools migrate-all ` to run all automatic migrations available in your project, or `rescript-tools migrate ` to migrate a single file. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/dict_coercion.res.expected b/tests/build_tests/super_errors/expected/dict_coercion.res.expected index 5e7889860a..2007f230da 100644 --- a/tests/build_tests/super_errors/expected/dict_coercion.res.expected +++ b/tests/build_tests/super_errors/expected/dict_coercion.res.expected @@ -7,4 +7,4 @@ 7 │ let d = (dict :> fakeDict) 8 │ - Type Js.Dict.t = dict is not a subtype of fakeDict \ No newline at end of file + Type dict is not a subtype of fakeDict \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/dict_inference.res.expected b/tests/build_tests/super_errors/expected/dict_inference.res.expected index d7a4a84f49..05533fed97 100644 --- a/tests/build_tests/super_errors/expected/dict_inference.res.expected +++ b/tests/build_tests/super_errors/expected/dict_inference.res.expected @@ -1,10 +1,10 @@ We've found a bug for you! - /.../fixtures/dict_inference.res:4:31-33 + /.../fixtures/dict_inference.res:4:28-30 - 2 │ dict->Js.Dict.set("someKey1", 1) - 3 │ dict->Js.Dict.set("someKey2", 2) - 4 │ dict->Js.Dict.set("someKey2", "2") + 2 │ dict->Dict.set("someKey1", 1) + 3 │ dict->Dict.set("someKey2", 2) + 4 │ dict->Dict.set("someKey2", "2") 5 │ This has type: string diff --git a/tests/build_tests/super_errors/expected/warnings4.res.expected b/tests/build_tests/super_errors/expected/warnings4.res.expected index 0e45f5b371..9eec05e9d6 100644 --- a/tests/build_tests/super_errors/expected/warnings4.res.expected +++ b/tests/build_tests/super_errors/expected/warnings4.res.expected @@ -5,7 +5,7 @@ 9 │ @val external x: myType = "myVariable" 10 │ 11 │ switch x { - 12 │ | #first => Js.log("first") + 12 │ | #first => Console.log("first") 13 │ } 14 │ diff --git a/tests/build_tests/super_errors/expected/warnings5.res.expected b/tests/build_tests/super_errors/expected/warnings5.res.expected index 204f9f1608..23302e6c3f 100644 --- a/tests/build_tests/super_errors/expected/warnings5.res.expected +++ b/tests/build_tests/super_errors/expected/warnings5.res.expected @@ -4,7 +4,7 @@ 10 │ 11 │ switch y { - 12 │ | {otherValue: false} => Js.log("first") + 12 │ | {otherValue: false} => Console.log("first") 13 │ } 14 │ @@ -18,7 +18,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 9 │ @val external y: someRecord = "otherVariable" 10 │ 11 │ switch y { - 12 │ | {otherValue: false} => Js.log("first") + 12 │ | {otherValue: false} => Console.log("first") 13 │ } 14 │ 15 │ switch y { @@ -32,7 +32,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 14 │ 15 │ switch y { - 16 │ | {typ: WithPayload(true)} => Js.log("first") + 16 │ | {typ: WithPayload(true)} => Console.log("first") 17 │ } 18 │ @@ -46,7 +46,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 13 │ } 14 │ 15 │ switch y { - 16 │ | {typ: WithPayload(true)} => Js.log("first") + 16 │ | {typ: WithPayload(true)} => Console.log("first") 17 │ } 18 │ 19 │ let arr = [1] @@ -62,7 +62,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 19 │ let arr = [1] 20 │ 21 │ switch arr { - 22 │ | [] => Js.log("") + 22 │ | [] => Console.log("") 23 │ } 24 │ 25 │ switch arr { @@ -77,7 +77,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 23 │ } 24 │ 25 │ switch arr { - 26 │ | [one] => Js.log(one) + 26 │ | [one] => Console.log(one) 27 │ } 28 │ 29 │ switch arr { diff --git a/tests/build_tests/super_errors/fixtures/curry_in_uncurry.res b/tests/build_tests/super_errors/fixtures/curry_in_uncurry.res index 0c0c3b67e1..92e656deef 100644 --- a/tests/build_tests/super_errors/fixtures/curry_in_uncurry.res +++ b/tests/build_tests/super_errors/fixtures/curry_in_uncurry.res @@ -1,3 +1,3 @@ let f = (a, b) => a + b -f(2, 2)->Js.log +f(2, 2)->Console.log diff --git a/tests/build_tests/super_errors/fixtures/deprecated_with_automigration.res b/tests/build_tests/super_errors/fixtures/deprecated_with_automigration.res new file mode 100644 index 0000000000..ae70045279 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/deprecated_with_automigration.res @@ -0,0 +1 @@ +let _ = Js.Array2.map([1, 2], v => v + 1) diff --git a/tests/build_tests/super_errors/fixtures/dict_coercion.res b/tests/build_tests/super_errors/fixtures/dict_coercion.res index b58fe32d9a..764006ad7b 100644 --- a/tests/build_tests/super_errors/fixtures/dict_coercion.res +++ b/tests/build_tests/super_errors/fixtures/dict_coercion.res @@ -1,6 +1,6 @@ -let dict = Js.Dict.empty() -dict->Js.Dict.set("someKey1", 1) -dict->Js.Dict.set("someKey2", 2) +let dict = Dict.make() +dict->Dict.set("someKey1", 1) +dict->Dict.set("someKey2", 2) type fakeDict<'t> = {dictValuesType?: 't} diff --git a/tests/build_tests/super_errors/fixtures/dict_inference.res b/tests/build_tests/super_errors/fixtures/dict_inference.res index 703f0c672e..b57243cf77 100644 --- a/tests/build_tests/super_errors/fixtures/dict_inference.res +++ b/tests/build_tests/super_errors/fixtures/dict_inference.res @@ -1,4 +1,4 @@ -let dict = Js.Dict.empty() -dict->Js.Dict.set("someKey1", 1) -dict->Js.Dict.set("someKey2", 2) -dict->Js.Dict.set("someKey2", "2") +let dict = Dict.make() +dict->Dict.set("someKey1", 1) +dict->Dict.set("someKey2", 2) +dict->Dict.set("someKey2", "2") diff --git a/tests/build_tests/super_errors/fixtures/polyvariant_constructors_mismatch_second.res b/tests/build_tests/super_errors/fixtures/polyvariant_constructors_mismatch_second.res index d8eace4719..11299b95c3 100644 --- a/tests/build_tests/super_errors/fixtures/polyvariant_constructors_mismatch_second.res +++ b/tests/build_tests/super_errors/fixtures/polyvariant_constructors_mismatch_second.res @@ -1,7 +1,7 @@ let handle = (ev: [#Click | #KeyDown]) => switch ev { - | #Click => Js.log("clicked") - | #KeyDown => Js.log("key down") + | #Click => Console.log("clicked") + | #KeyDown => Console.log("key down") } let _ = handle(#Resize) diff --git a/tests/build_tests/super_errors/fixtures/todo_with_no_payload.res b/tests/build_tests/super_errors/fixtures/todo_with_no_payload.res index d7aa60688c..e6ef3d533f 100644 --- a/tests/build_tests/super_errors/fixtures/todo_with_no_payload.res +++ b/tests/build_tests/super_errors/fixtures/todo_with_no_payload.res @@ -2,4 +2,4 @@ let implementMeLater = (): string => %todo let x = implementMeLater() -Js.log(x->Js.String2.includes("x")) +Console.log(x->String.includes("x")) diff --git a/tests/build_tests/super_errors/fixtures/todo_with_payload.res b/tests/build_tests/super_errors/fixtures/todo_with_payload.res index a52d80d5c1..d13d745dc7 100644 --- a/tests/build_tests/super_errors/fixtures/todo_with_payload.res +++ b/tests/build_tests/super_errors/fixtures/todo_with_payload.res @@ -2,4 +2,4 @@ let implementMeLater = (): string => %todo("This should return a string eventual let x = implementMeLater() -Js.log(x->Js.String2.includes("x")) +Console.log(x->String.includes("x")) diff --git a/tests/build_tests/super_errors/fixtures/warnings4.res b/tests/build_tests/super_errors/fixtures/warnings4.res index 3c65caefe2..94de143aa1 100644 --- a/tests/build_tests/super_errors/fixtures/warnings4.res +++ b/tests/build_tests/super_errors/fixtures/warnings4.res @@ -9,5 +9,5 @@ type myType = [ @val external x: myType = "myVariable" switch x { -| #first => Js.log("first") +| #first => Console.log("first") } diff --git a/tests/build_tests/super_errors/fixtures/warnings5.res b/tests/build_tests/super_errors/fixtures/warnings5.res index 9e69c5076d..a3739d03b6 100644 --- a/tests/build_tests/super_errors/fixtures/warnings5.res +++ b/tests/build_tests/super_errors/fixtures/warnings5.res @@ -9,21 +9,21 @@ type someRecord = { @val external y: someRecord = "otherVariable" switch y { -| {otherValue: false} => Js.log("first") +| {otherValue: false} => Console.log("first") } switch y { -| {typ: WithPayload(true)} => Js.log("first") +| {typ: WithPayload(true)} => Console.log("first") } let arr = [1] switch arr { -| [] => Js.log("") +| [] => Console.log("") } switch arr { -| [one] => Js.log(one) +| [one] => Console.log(one) } switch arr { diff --git a/tests/tools_tests/Makefile b/tests/tools_tests/Makefile index 4d26df85bb..e8d2c1f3fc 100644 --- a/tests/tools_tests/Makefile +++ b/tests/tools_tests/Makefile @@ -5,6 +5,7 @@ build: test: build ./test.sh + yarn build clean: yarn clean diff --git a/tests/tools_tests/package.json b/tests/tools_tests/package.json index e457a210ab..46209fd6de 100644 --- a/tests/tools_tests/package.json +++ b/tests/tools_tests/package.json @@ -2,7 +2,7 @@ "name": "@tests/tools", "private": true, "scripts": { - "build": "rescript-legacy build", + "build": "rescript-legacy build -warn-error -3", "clean": "rescript clean", "dev": "rescript -w" }, diff --git a/tests/tools_tests/src/expected/DeprecatedStuff.res.expected b/tests/tools_tests/src/expected/DeprecatedStuff.res.expected new file mode 100644 index 0000000000..3a9e14c4f2 --- /dev/null +++ b/tests/tools_tests/src/expected/DeprecatedStuff.res.expected @@ -0,0 +1,12 @@ +@send +external slice: (string, ~from: int, ~to_: int) => string = "slice" + +@send +external shift: array<'a> => option<'a> = "shift" + +module Constants = { + let otherThing = [2, 3] +} + +let deprecatedThing = [1, 2] + diff --git a/tests/tools_tests/src/expected/DeprecatedStuff.resi.expected b/tests/tools_tests/src/expected/DeprecatedStuff.resi.expected new file mode 100644 index 0000000000..df7f2f270f --- /dev/null +++ b/tests/tools_tests/src/expected/DeprecatedStuff.resi.expected @@ -0,0 +1,27 @@ +@deprecated({ + reason: "Use `String.slice` instead", + migrate: String.slice( + ~start=%insert.labelledArgument("from"), + ~end=%insert.labelledArgument("to_"), + ), +}) +@send +external slice: (string, ~from: int, ~to_: int) => string = "slice" + +@send +@deprecated({ + reason: "Use `Array.shift` instead.", + migrate: Array.shift(), +}) +external shift: array<'a> => option<'a> = "shift" + +module Constants: { + let otherThing: array +} + +@deprecated({ + reason: "Use `otherThing` instead.", + migrate: DeprecatedStuff.Constants.otherThing, +}) +let deprecatedThing: array + diff --git a/tests/tools_tests/src/expected/FileToMigrate.res.expected b/tests/tools_tests/src/expected/FileToMigrate.res.expected new file mode 100644 index 0000000000..2572499f87 --- /dev/null +++ b/tests/tools_tests/src/expected/FileToMigrate.res.expected @@ -0,0 +1,11 @@ +let someNiceString = String.slice("abcdefg", ~start=2, ~end=5) + +let someNiceString2 = String.slice(String.slice("abcdefg", ~start=0, ~end=1), ~start=2, ~end=5) + +let someNiceString3 = "abcdefg"->String.slice(~start=2, ~end=5) + +let shift1 = Array.shift([1, 2, 3]) +let shift2 = [1, 2, 3]->Array.shift + +let deprecatedThing1 = DeprecatedStuff.Constants.otherThing + diff --git a/tests/tools_tests/src/expected/OptionalArgRename.res.expected b/tests/tools_tests/src/expected/OptionalArgRename.res.expected new file mode 100644 index 0000000000..e4d273ea1d --- /dev/null +++ b/tests/tools_tests/src/expected/OptionalArgRename.res.expected @@ -0,0 +1,12 @@ +module Target = { + let doStuff = (~newName: option=?) => { + ignore(newName) + } +} + +let _ = Target.doStuff + +external doStuff: (~oldName: option=?) => unit = "doStuff" + +/* Intentionally no usage here; this test exercises migration config parsing and ensures optional label rename is preserved and doesn’t crash. */ + diff --git a/tests/tools_tests/src/expected/OptionalArgRename.resi.expected b/tests/tools_tests/src/expected/OptionalArgRename.resi.expected new file mode 100644 index 0000000000..3c8aa0a5ed --- /dev/null +++ b/tests/tools_tests/src/expected/OptionalArgRename.resi.expected @@ -0,0 +1,6 @@ +@deprecated({ + reason: "Use new label name", + migrate: OptionalArgRename.Target.doStuff(~newName=%insert.labelledArgument("oldName")), +}) +external doStuff: (~oldName: option=?) => unit = "doStuff" + diff --git a/tests/tools_tests/src/expected/PipeAndRecursive.res.expected b/tests/tools_tests/src/expected/PipeAndRecursive.res.expected new file mode 100644 index 0000000000..b4c3f023c9 --- /dev/null +++ b/tests/tools_tests/src/expected/PipeAndRecursive.res.expected @@ -0,0 +1,40 @@ +module Target = { + let a = x => x + 1 + let b = x => x + 2 +} + +@deprecated({ + reason: "test piped vs non-piped", + migrate: PipeAndRecursive.Target.a(), + migrateInPipeChain: PipeAndRecursive.Target.b(), +}) +external dep: int => int = "dep" + +let id = x => x + +/* Should use migrate (Target.a), since lhs has 0 pipes */ +let onePipe = PipeAndRecursive.Target.a(1) + +/* Still migrate (Target.a), since lhs has 1 pipe (< 2) */ +let twoPipes = 1->id->PipeAndRecursive.Target.b + +/* Should use migrateInPipeChain (Target.b), since lhs has 2 pipes */ +let threePipes = 1->id->id->PipeAndRecursive.Target.b + +/* Recursion: all dep steps should migrate */ +let many = PipeAndRecursive.Target.a( + PipeAndRecursive.Target.a( + PipeAndRecursive.Target.a( + PipeAndRecursive.Target.a( + PipeAndRecursive.Target.a( + PipeAndRecursive.Target.a( + PipeAndRecursive.Target.a( + PipeAndRecursive.Target.a(PipeAndRecursive.Target.a(PipeAndRecursive.Target.a(1))), + ), + ), + ), + ), + ), + ), +) + diff --git a/tests/tools_tests/src/expected/StdlibMigrationNoCompile_Array.res.expected b/tests/tools_tests/src/expected/StdlibMigrationNoCompile_Array.res.expected new file mode 100644 index 0000000000..009a006db0 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigrationNoCompile_Array.res.expected @@ -0,0 +1,4 @@ +// Migrations that will not compile after migration (by design) +let sortInPlaceWith1 = [3, 1, 2]->Array.sort((a, b) => a - b) +let sortInPlaceWith2 = Array.sort([3, 1, 2], (a, b) => a - b) + diff --git a/tests/tools_tests/src/expected/StdlibMigrationNoCompile_Js_Re.res.expected b/tests/tools_tests/src/expected/StdlibMigrationNoCompile_Js_Re.res.expected new file mode 100644 index 0000000000..1d6923dd1e --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigrationNoCompile_Js_Re.res.expected @@ -0,0 +1,11 @@ +let re2 = RegExp.fromString("foo", ~flags="gi") + +let capture_access = switch re2->RegExp.exec("Foo") { +| None => 0 +| Some(r) => + switch RegExp.Result.matches(r) { + | [Value(full), _] => String.length(full) + | _ => 0 + } +} + diff --git a/tests/tools_tests/src/expected/StdlibMigrationNoCompile_String.res.expected b/tests/tools_tests/src/expected/StdlibMigrationNoCompile_String.res.expected new file mode 100644 index 0000000000..c99e65e613 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigrationNoCompile_String.res.expected @@ -0,0 +1,12 @@ +let normalizeByForm1 = "abcde"->String.normalizeByForm("a") +let normalizeByForm2 = String.normalizeByForm("abcde", "a") + +let unsafeReplaceBy01 = "abcde"->String.replaceRegExpBy0Unsafe(/d/, (_, _, _) => "f") +let unsafeReplaceBy02 = String.replaceRegExpBy0Unsafe("abcde", /d/, (_, _, _) => "f") + +let unsafeReplaceBy11 = "abcde"->String.replaceRegExpBy1Unsafe(/d/, (_, _, _, _) => "f") +let unsafeReplaceBy12 = String.replaceRegExpBy1Unsafe("abcde", /d/, (_, _, _, _) => "f") + +let unsafeReplaceBy21 = "abcde"->String.replaceRegExpBy2Unsafe(/d/, (_, _, _, _, _) => "f") +let unsafeReplaceBy22 = String.replaceRegExpBy2Unsafe("abcde", /d/, (_, _, _, _, _) => "f") + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Array.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Array.res.expected new file mode 100644 index 0000000000..e0a35425f9 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Array.res.expected @@ -0,0 +1,176 @@ +let shift1 = [1, 2, 3]->Array.shift +let shift2 = Array.shift([1, 2, 3]) + +let slice1 = [1, 2, 3]->Array.slice(~start=1, ~end=2) +let slice2 = Array.slice([1, 2, 3], ~start=1, ~end=2) + +external someArrayLike: Array.arrayLike = "whatever" + +let from1 = someArrayLike->Array.fromArrayLike +let from2 = Array.fromArrayLike(someArrayLike) + +let fromMap1 = someArrayLike->Array.fromArrayLikeWithMap(s => s ++ "!") +let fromMap2 = Array.fromArrayLikeWithMap(someArrayLike, s => s ++ "!") + +let isArray1 = [1, 2, 3]->Array.isArray +let isArray2 = Array.isArray([1, 2, 3]) + +let length1 = [1, 2, 3]->Array.length +let length2 = Array.length([1, 2, 3]) + +let fillInPlace1 = [1, 2, 3]->Array.fillAll(0) +let fillInPlace2 = Array.fillAll([1, 2, 3], 0) + +let fillFromInPlace1 = [1, 2, 3, 4]->Array.fillToEnd(0, ~start=2) +let fillFromInPlace2 = Array.fillToEnd([1, 2, 3, 4], 0, ~start=2) + +let fillRangeInPlace1 = [1, 2, 3, 4]->Array.fill(0, ~start=1, ~end=3) +let fillRangeInPlace2 = Array.fill([1, 2, 3, 4], 0, ~start=1, ~end=3) + +let pop1 = [1, 2, 3]->Array.pop +let pop2 = Array.pop([1, 2, 3]) + +let reverseInPlace1 = [1, 2, 3]->Array.reverse +let reverseInPlace2 = Array.reverse([1, 2, 3]) + +let concat1 = [1, 2]->Array.concat([3, 4]) +let concat2 = Array.concat([1, 2], [3, 4]) + +let concatMany1 = [1, 2]->Array.concatMany([[3, 4], [5, 6]]) +let concatMany2 = Array.concatMany([1, 2], [[3, 4], [5, 6]]) + +let includes1 = [1, 2, 3]->Array.includes(2) +let includes2 = Array.includes([1, 2, 3], 2) + +let indexOf1 = [1, 2, 3]->Array.indexOf(2) +let indexOf2 = Array.indexOf([1, 2, 3], 2) + +let indexOfFrom1 = [1, 2, 1, 3]->Array.indexOfFrom(1, 2) +let indexOfFrom2 = Array.indexOfFrom([1, 2, 1, 3], 1, 2) + +let joinWith1 = [1, 2, 3]->Array.joinUnsafe(",") +let joinWith2 = Array.joinUnsafe([1, 2, 3], ",") + +let lastIndexOf1 = [1, 2, 1, 3]->Array.lastIndexOf(1) +let lastIndexOf2 = Array.lastIndexOf([1, 2, 1, 3], 1) + +let lastIndexOfFrom1 = [1, 2, 1, 3, 1]->Array.lastIndexOfFrom(1, 3) +let lastIndexOfFrom2 = Array.lastIndexOfFrom([1, 2, 1, 3, 1], 1, 3) + +let copy1 = [1, 2, 3]->Array.copy +let copy2 = Array.copy([1, 2, 3]) + +let sliceFrom1 = [1, 2, 3, 4]->Array.slice(~start=2) +let sliceFrom2 = Array.slice([1, 2, 3, 4], ~start=2) + +let toString1 = [1, 2, 3]->Array.toString +let toString2 = Array.toString([1, 2, 3]) + +let toLocaleString1 = [1, 2, 3]->Array.toLocaleString +let toLocaleString2 = Array.toLocaleString([1, 2, 3]) + +let every1 = [2, 4, 6]->Array.every(x => mod(x, 2) == 0) +let every2 = Array.every([2, 4, 6], x => mod(x, 2) == 0) + +let everyi1 = [0, 1, 2]->Array.everyWithIndex((x, i) => x == i) +let everyi2 = Array.everyWithIndex([0, 1, 2], (x, i) => x == i) + +let filter1 = [1, 2, 3, 4]->Array.filter(x => x > 2) +let filter2 = Array.filter([1, 2, 3, 4], x => x > 2) + +let filteri1 = [0, 1, 2, 3]->Array.filterWithIndex((_x, i) => i > 1) +let filteri2 = Array.filterWithIndex([0, 1, 2, 3], (_x, i) => i > 1) + +let find1 = [1, 2, 3, 4]->Array.find(x => x > 2) +let find2 = Array.find([1, 2, 3, 4], x => x > 2) + +let findi1 = [0, 1, 2, 3]->Array.findWithIndex((_x, i) => i > 1) +let findi2 = Array.findWithIndex([0, 1, 2, 3], (_x, i) => i > 1) + +let findIndex1 = [1, 2, 3, 4]->Array.findIndex(x => x > 2) +let findIndex2 = Array.findIndex([1, 2, 3, 4], x => x > 2) + +let findIndexi1 = [0, 1, 2, 3]->Array.findIndexWithIndex((_x, i) => i > 1) +let findIndexi2 = Array.findIndexWithIndex([0, 1, 2, 3], (_x, i) => i > 1) + +let forEach1 = [1, 2, 3]->Array.forEach(x => ignore(x)) +let forEach2 = Array.forEach([1, 2, 3], x => ignore(x)) + +let forEachi1 = [1, 2, 3]->Array.forEachWithIndex((x, i) => ignore(x + i)) +let forEachi2 = Array.forEachWithIndex([1, 2, 3], (x, i) => ignore(x + i)) + +let map1 = [1, 2, 3]->Array.map(x => x * 2) +let map2 = Array.map([1, 2, 3], x => x * 2) + +let mapi1 = [1, 2, 3]->Array.mapWithIndex((x, i) => x + i) +let mapi2 = Array.mapWithIndex([1, 2, 3], (x, i) => x + i) + +let some1 = [1, 2, 3, 4]->Array.some(x => x > 3) +let some2 = Array.some([1, 2, 3, 4], x => x > 3) + +let somei1 = [0, 1, 2, 3]->Array.someWithIndex((_x, i) => i > 2) +let somei2 = Array.someWithIndex([0, 1, 2, 3], (_x, i) => i > 2) + +let unsafeGet1 = [1, 2, 3]->Array.getUnsafe(1) +let unsafeGet2 = Array.getUnsafe([1, 2, 3], 1) + +let unsafeSet1 = [1, 2, 3]->Array.setUnsafe(1, 5) +let unsafeSet2 = Array.setUnsafe([1, 2, 3], 1, 5) + +let copyWithin1 = [1, 2, 3, 4, 5]->Array.copyAllWithin(~target=2) +let copyWithin2 = Array.copyAllWithin([1, 2, 3, 4, 5], ~target=2) + +let copyWithinFrom1 = [1, 2, 3, 4, 5]->Array.copyWithinToEnd(~target=0, ~start=2) +let copyWithinFrom2 = Array.copyWithinToEnd([1, 2, 3, 4, 5], ~target=0, ~start=2) + +let copyWithinFromRange1 = [1, 2, 3, 4, 5, 6]->Array.copyWithin(~start=2, ~target=1, ~end=5) +let copyWithinFromRange2 = Array.copyWithin([1, 2, 3, 4, 5, 6], ~start=2, ~target=1, ~end=5) + +let push1 = [1, 2, 3]->Array.push(4) +let push2 = Array.push([1, 2, 3], 4) + +let pushMany1 = [1, 2, 3]->Array.pushMany([4, 5]) +let pushMany2 = Array.pushMany([1, 2, 3], [4, 5]) + +let sortInPlace1 = + ["c", "a", "b"]->Array.toSorted((_a, _b) => + %todo("This needs a comparator function. Use `String.compare` for strings, etc.") + ) +let sortInPlace2 = Array.toSorted(["c", "a", "b"], (_a, _b) => + %todo("This needs a comparator function. Use `String.compare` for strings, etc.") +) + +let unshift1 = [1, 2, 3]->Array.unshift(4) +let unshift2 = Array.unshift([1, 2, 3], 4) + +let unshiftMany1 = [1, 2, 3]->Array.unshiftMany([4, 5]) +let unshiftMany2 = Array.unshiftMany([1, 2, 3], [4, 5]) + +let reduce1 = [1, 2, 3]->Array.reduce(0, (acc, x) => acc + x) +let reduce2 = Array.reduce([1, 2, 3], 0, (acc, x) => acc + x) + +let spliceInPlace1 = [1, 2, 3]->Array.splice(~start=1, ~remove=1, ~insert=[4, 5]) +let spliceInPlace2 = Array.splice([1, 2, 3], ~start=1, ~remove=1, ~insert=[4, 5]) + +let removeFromInPlace1 = [1, 2, 3]->Array.removeInPlace(1) +let removeFromInPlace2 = Array.removeInPlace([1, 2, 3], 1) + +let removeCountInPlace1 = [1, 2, 3]->Array.splice(~start=1, ~remove=1, ~insert=[]) +let removeCountInPlace2 = Array.splice([1, 2, 3], ~start=1, ~remove=1, ~insert=[]) + +let reducei1 = [1, 2, 3]->Array.reduceWithIndex(0, (acc, x, i) => acc + x + i) +let reducei2 = Array.reduceWithIndex([1, 2, 3], 0, (acc, x, i) => acc + x + i) + +let reduceRight1 = [1, 2, 3]->Array.reduceRight(0, (acc, x) => acc + x) +let reduceRight2 = Array.reduceRight([1, 2, 3], 0, (acc, x) => acc + x) + +let reduceRighti1 = [1, 2, 3]->Array.reduceRightWithIndex(0, (acc, x, i) => acc + x + i) +let reduceRighti2 = Array.reduceRightWithIndex([1, 2, 3], 0, (acc, x, i) => acc + x + i) + +let pipeChain = + [1, 2, 3]->Array.map(x => x * 2)->Array.filter(x => x > 2)->Array.reduce(0, (acc, x) => acc + x) + +// Type alias migrations +let arrT: array = [1, 2, 3] +let arr2T: array = [1, 2, 3] + diff --git a/tests/tools_tests/src/expected/StdlibMigration_ArrayAppend.res.expected b/tests/tools_tests/src/expected/StdlibMigration_ArrayAppend.res.expected new file mode 100644 index 0000000000..3d3d701e8d --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_ArrayAppend.res.expected @@ -0,0 +1,3 @@ +let ys = Array.concat([1], [2]) +let zs = [1]->Array.concat([1], [2]) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_BigInt.res.expected b/tests/tools_tests/src/expected/StdlibMigration_BigInt.res.expected new file mode 100644 index 0000000000..f6ef79a8fa --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_BigInt.res.expected @@ -0,0 +1,49 @@ +let fromStringExn1 = "123"->BigInt.fromStringOrThrow +let fromStringExn2 = BigInt.fromStringOrThrow("123") + +let land1 = 7n & 4n +let land2 = 7n & 4n +let land3 = 7n->BigInt.toString->BigInt.fromStringOrThrow->BigInt.bitwiseAnd(4n) + +let lor1 = 7n->BigInt.bitwiseOr(4n) +let lor2 = BigInt.bitwiseOr(7n, 4n) + +let lxor1 = 7n ^ 4n +let lxor2 = 7n ^ 4n + +let lnot1 = 2n->Js.BigInt.lnot +let lnot2 = Js.BigInt.lnot(2n) + +let lsl1 = 4n << 1n +let lsl2 = 4n << 1n + +let asr1 = 8n >> 1n +let asr2 = 8n >> 1n + +let toString1 = 123n->BigInt.toString +let toString2 = BigInt.toString(123n) + +let toLocaleString1 = 123n->BigInt.toLocaleString +let toLocaleString2 = BigInt.toLocaleString(123n) + +// From the stdlib module +let stdlib_fromStringExn1 = "123"->BigInt.fromStringOrThrow +let stdlib_fromStringExn2 = BigInt.fromStringOrThrow("123") + +let stdlib_land1 = 7n & 4n +let stdlib_land2 = 7n & 4n + +let stdlib_lor1 = BigInt.bitwiseOr(7n, 4n) + +let stdlib_lxor1 = 7n ^ 4n +let stdlib_lxor2 = 7n ^ 4n + +let stdlib_lnot1 = ~2n +let stdlib_lnot2 = ~2n + +let stdlib_lsl1 = 4n << 1n +let stdlib_lsl2 = 4n << 1n + +let stdlib_asr1 = 8n >> 1n +let stdlib_asr2 = 8n >> 1n + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Console.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Console.res.expected new file mode 100644 index 0000000000..472198684f --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Console.res.expected @@ -0,0 +1,29 @@ +let log = Console.log("Hello, World!") +let log2 = Console.log2("Hello", "World") +let log3 = Console.log3("Hello", "World", "!") +let log4 = Console.log4("Hello", "World", "!", "!") +let logMany = Console.logMany(["Hello", "World"]) + +let info = Console.info("Hello, World!") +let info2 = Console.info2("Hello", "World") +let info3 = Console.info3("Hello", "World", "!") +let info4 = Console.info4("Hello", "World", "!", "!") +let infoMany = Console.infoMany(["Hello", "World"]) + +let warn = Console.warn("Hello, World!") +let warn2 = Console.warn2("Hello", "World") +let warn3 = Console.warn3("Hello", "World", "!") +let warn4 = Console.warn4("Hello", "World", "!", "!") +let warnMany = Console.warnMany(["Hello", "World"]) + +let error = Console.error("Hello, World!") +let error2 = Console.error2("Hello", "World") +let error3 = Console.error3("Hello", "World", "!") +let error4 = Console.error4("Hello", "World", "!", "!") +let errorMany = Console.errorMany(["Hello", "World"]) + +let trace = Console.trace() +let timeStart = Console.time("Hello, World!") +let timeEnd = Console.timeEnd("Hello, World!") +let table = Console.table(["Hello", "World"]) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_DataView.res.expected b/tests/tools_tests/src/expected/StdlibMigration_DataView.res.expected new file mode 100644 index 0000000000..8a24759c1c --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_DataView.res.expected @@ -0,0 +1,3 @@ +let a = DataView.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2) +let b = DataView.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2, ~length=4) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Date.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Date.res.expected new file mode 100644 index 0000000000..2b3dd5658b --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Date.res.expected @@ -0,0 +1,191 @@ +let d1 = Date.make() +let d2 = Date.fromString("1973-11-29T21:30:54.321Z") +let d3 = Date.fromTime(123456789.0) + +let msNow = Date.now() + +let v1 = d2->Date.getTime +let v2 = Date.getTime(d2) + +let y = d2->Date.getFullYear +let mo = d2->Date.getMonth +let dayOfMonth = d2->Date.getDate +let dayOfWeek = d2->Date.getDay +let h = d2->Date.getHours +let mi = d2->Date.getMinutes +let s = d2->Date.getSeconds +let ms = d2->Date.getMilliseconds +let tz = d2->Date.getTimezoneOffset + +let uy = d2->Date.getUTCFullYear +let um = d2->Date.getUTCMonth +let ud = d2->Date.getUTCDate +let uday = d2->Date.getUTCDay +let uh = d2->Date.getUTCHours +let umi = d2->Date.getUTCMinutes +let us = d2->Date.getUTCSeconds +let ums = d2->Date.getUTCMilliseconds + +let s1 = d2->Date.toISOString +let s2 = d2->Date.toUTCString +let s3 = d2->Date.toString +let s4 = d2->Date.toTimeString +let s5 = d2->Date.toDateString +let s6 = d2->Date.toLocaleString +let s7 = d2->Date.toLocaleDateString +let s8 = d2->Date.toLocaleTimeString + +/* Additional deprecated APIs to exercise migration */ + +/* getters and legacy variants */ +let t = d2->Date.getTime +let y2 = d2->Date.getFullYear + +/* constructors with components */ +let mym = Date.makeWithYM(~year=Float.toInt(2020.0), ~month=Float.toInt(10.0)) +let mymd = Date.makeWithYMD( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), +) +let mymdh = Date.makeWithYMDH( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), +) +let mymdhm = Date.makeWithYMDHM( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), + ~minutes=Float.toInt(30.0), +) +let mymdhms = Date.makeWithYMDHMS( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), + ~minutes=Float.toInt(30.0), + ~seconds=Float.toInt(54.0), +) + +/* Date.UTC variants */ +let uym = Date.UTC.makeWithYM(~year=Float.toInt(2020.0), ~month=Float.toInt(10.0)) +let uymd = Date.UTC.makeWithYMD( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), +) +let uymdh = Date.UTC.makeWithYMDH( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), +) +let uymdhm = Date.UTC.makeWithYMDHM( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), + ~minutes=Float.toInt(30.0), +) +let uymdhms = Date.UTC.makeWithYMDHMS( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), + ~minutes=Float.toInt(30.0), + ~seconds=Float.toInt(54.0), +) + +/* parse APIs */ +let p = Date.fromString("1973-11-29T21:30:54.321Z") +let pf = Date.getTime(Date.fromString("1973-11-29T21:30:54.321Z")) + +/* setters (local time) */ +let setD = d2->Date.setDate(Float.toInt(15.0)) +let setFY = d2->Date.setFullYear(Float.toInt(1974.0)) + +let setFYM = d2->Date.setFullYearM(~year=Float.toInt(1974.0), ~month=Float.toInt(0.0)) +let setFYMD = + d2->Date.setFullYearMD(~year=Float.toInt(1974.0), ~month=Float.toInt(0.0), ~day=Float.toInt(7.0)) +let setH = d2->Date.setHours(Float.toInt(22.0)) +let setHM = d2->Date.setHoursM(~hours=Float.toInt(22.0), ~minutes=Float.toInt(46.0)) +let setHMS = + d2->Date.setHoursMS( + ~hours=Float.toInt(22.0), + ~minutes=Float.toInt(46.0), + ~seconds=Float.toInt(37.0), + ) +let setHMSMs = + d2->Date.setHoursMSMs( + ~hours=Float.toInt(22.0), + ~minutes=Float.toInt(46.0), + ~seconds=Float.toInt(37.0), + ~milliseconds=Float.toInt(494.0), + ) +let setMs = d2->Date.setMilliseconds(Float.toInt(494.0)) +let setMin = d2->Date.setMinutes(Float.toInt(34.0)) +let setMinS = d2->Date.setMinutesS(~minutes=Float.toInt(34.0), ~seconds=Float.toInt(56.0)) +let setMinSMs = + d2->Date.setMinutesSMs( + ~minutes=Float.toInt(34.0), + ~seconds=Float.toInt(56.0), + ~milliseconds=Float.toInt(789.0), + ) +let setMon = d2->Date.setMonth(Float.toInt(11.0)) +let setMonD = d2->Js.Date.setMonthD(~month=11.0, ~date=8.0, ()) +let setSec = d2->Date.setSeconds(Float.toInt(56.0)) +let setSecMs = d2->Date.setSecondsMs(~seconds=Float.toInt(56.0), ~milliseconds=Float.toInt(789.0)) + +/* setters (UTC) */ +let setUD = d2->Date.setUTCDate(Float.toInt(15.0)) +let setUFY = d2->Date.setUTCFullYear(Float.toInt(1974.0)) +let setUFYM = d2->Date.setUTCFullYearM(~year=Float.toInt(1974.0), ~month=Float.toInt(0.0)) +let setUFYMD = + d2->Date.setUTCFullYearMD( + ~year=Float.toInt(1974.0), + ~month=Float.toInt(0.0), + ~day=Float.toInt(7.0), + ) +let setUH = d2->Date.setUTCHours(Float.toInt(22.0)) +let setUHM = d2->Date.setUTCHoursM(~hours=Float.toInt(22.0), ~minutes=Float.toInt(46.0)) +let setUHMS = + d2->Date.setUTCHoursMS( + ~hours=Float.toInt(22.0), + ~minutes=Float.toInt(46.0), + ~seconds=Float.toInt(37.0), + ) +let setUHMSMs = + d2->Date.setUTCHoursMSMs( + ~hours=Float.toInt(22.0), + ~minutes=Float.toInt(46.0), + ~seconds=Float.toInt(37.0), + ~milliseconds=Float.toInt(494.0), + ) +let setUMs = d2->Date.setUTCMilliseconds(Float.toInt(494.0)) +let setUMin = d2->Date.setUTCMinutes(Float.toInt(34.0)) +let setUMinS = d2->Date.setUTCMinutesS(~minutes=Float.toInt(34.0), ~seconds=Float.toInt(56.0)) +let setUMinSMs = + d2->Date.setUTCMinutesSMs( + ~minutes=Float.toInt(34.0), + ~seconds=Float.toInt(56.0), + ~milliseconds=Float.toInt(789.0), + ) +let setUMon = d2->Date.setUTCMonth(Float.toInt(11.0)) +let setUMonD = d2->Js.Date.setUTCMonthD(~month=11.0, ~date=8.0, ()) +let setUSec = d2->Date.setUTCSeconds(Float.toInt(56.0)) +let setUSecMs = + d2->Date.setUTCSecondsMs(~seconds=Float.toInt(56.0), ~milliseconds=Float.toInt(789.0)) +let setUT = d2->Js.Date.setUTCTime(198765432101.0) +let setYr = d2->Js.Date.setYear(1999.0) + +/* other string conversions */ +let s9 = d2->Date.toUTCString +let j1 = d2->Date.toJSON +let j2 = d2->Date.toJSON + +// Type alias migration +external someDate: Date.t = "someDate" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Dict.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Dict.res.expected new file mode 100644 index 0000000000..2cacd2c0d4 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Dict.res.expected @@ -0,0 +1,34 @@ +let d = Dict.make() + +let get1 = d->Dict.get("k") +let get2 = Dict.get(d, "k") + +let unsafeGet1 = d->Dict.getUnsafe("k") +let unsafeGet2 = Dict.getUnsafe(d, "k") + +let set1 = d->Dict.set("k", 1) +let set2 = Dict.set(d, "k", 1) + +let keys1 = d->Dict.keysToArray +let keys2 = Dict.keysToArray(d) + +let values1 = d->Dict.valuesToArray +let values2 = Dict.valuesToArray(d) + +let entries1 = d->Dict.toArray +let entries2 = Dict.toArray(d) + +let dStr: dict = Dict.make() +let del1 = dStr->Dict.delete("k") +let del2 = Dict.delete(dStr, "k") + +let empty1: dict = Dict.make() + +let fromArray1 = [("a", 1), ("b", 2)]->Dict.fromArray +let fromArray2 = Dict.fromArray([("a", 1), ("b", 2)]) + +let fromList1 = list{("a", 1), ("b", 2)}->Js.Dict.fromList +let fromList2 = Js.Dict.fromList(list{("a", 1), ("b", 2)}) + +let map2 = Dict.mapValues(d, x => x + 1) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Error.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Error.res.expected new file mode 100644 index 0000000000..c2ee710bca --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Error.res.expected @@ -0,0 +1,35 @@ +// Use deprecated Error APIs to validate migration to JsError/JsExn + +external someExn: exn = "whatever" + +let fromExn1 = someExn->JsExn.fromException +let fromExn2 = JsExn.fromException(someExn) + +let err = JsError.make("Some message here") + +let stack1 = err->JsError.stack +let stack2 = JsError.stack(err) + +let message1 = err->JsError.message +let message2 = JsError.message(err) + +let name1 = err->JsError.name +let name2 = JsError.name(err) + +let fileName1 = err->JsError.fileName +let fileName2 = JsError.fileName(err) + +// Type alias migration +let errT: JsError.t = JsError.make("Another message") + +// Sub-error constructors +let evalErr = JsError.EvalError.make("eval error") +let rangeErr = JsError.RangeError.make("range error") +let refErr = JsError.ReferenceError.make("reference error") +let synErr = JsError.SyntaxError.make("syntax error") +let typeErr = JsError.TypeError.make("type error") +let uriErr = JsError.URIError.make("uri error") + +let ignore1 = err->JsError.ignore +let ignore2 = JsError.ignore(err) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Exn.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Exn.res.expected new file mode 100644 index 0000000000..32385d7a1b --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Exn.res.expected @@ -0,0 +1,41 @@ +// Use deprecated Exn APIs to validate migration to JsExn/JsError + +external someExn: exn = "whatever" +external someJsExn: JsExn.t = "whatever" + +// fromException (asJsExn) +let fromExn1 = someExn->JsExn.fromException +let fromExn2 = JsExn.fromException(someExn) + +// Property accessors on Exn.t +let stack1 = someJsExn->JsExn.stack +let stack2 = JsExn.stack(someJsExn) + +let message1 = someJsExn->JsExn.message +let message2 = JsExn.message(someJsExn) + +let name1 = someJsExn->JsExn.name +let name2 = JsExn.name(someJsExn) + +let fileName1 = someJsExn->JsExn.fileName +let fileName2 = JsExn.fileName(someJsExn) + +// Type alias migration +let exnT: JsExn.t = someJsExn + +// anyToExnInternal +let _coerced = JsExn.anyToExnInternal(1) + +// ignore +let ignore1 = someJsExn->JsExn.ignore +let ignore2 = JsExn.ignore(someJsExn) + +// Raise helpers +let throws1 = () => JsError.throwWithMessage("err") +let throws2 = () => JsError.EvalError.throwWithMessage("err") +let throws3 = () => JsError.RangeError.throwWithMessage("err") +let throws4 = () => JsError.ReferenceError.throwWithMessage("err") +let throws5 = () => JsError.SyntaxError.throwWithMessage("err") +let throws6 = () => JsError.TypeError.throwWithMessage("err") +let throws7 = () => JsError.URIError.throwWithMessage("err") + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Extern.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Extern.res.expected new file mode 100644 index 0000000000..c28d1259e1 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Extern.res.expected @@ -0,0 +1,7 @@ +// Exercise migrations from Js_extern to new Stdlib APIs + +let isNullish = Nullable.isNullable(%raw("null")) +let n = Nullable.null +let u = Nullable.undefined +let ty = Type.typeof("hello") + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Float.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Float.res.expected new file mode 100644 index 0000000000..1e70760134 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Float.res.expected @@ -0,0 +1,35 @@ +let nan1 = Float.Constants.nan + +let isNaN1 = Float.Constants.nan->Float.isNaN +let isNaN2 = Float.isNaN(Float.Constants.nan) + +let isFinite1 = 1234.0->Float.isFinite +let isFinite2 = Float.isFinite(1234.0) + +let toExponential1 = 77.1234->Float.toExponential +let toExponential2 = Float.toExponential(77.1234) + +let toExponentialWithPrecision1 = 77.1234->Float.toExponential(~digits=2) +let toExponentialWithPrecision2 = Float.toExponential(77.1234, ~digits=2) + +let toFixed1 = 12345.6789->Float.toFixed +let toFixed2 = Float.toFixed(12345.6789) + +let toFixedWithPrecision1 = 12345.6789->Float.toFixed(~digits=1) +let toFixedWithPrecision2 = Float.toFixed(12345.6789, ~digits=1) + +let toPrecision1 = 12345.6789->Float.toPrecision +let toPrecision2 = Float.toPrecision(12345.6789) + +let toPrecisionWithPrecision1 = 12345.6789->Float.toPrecision(~digits=2) +let toPrecisionWithPrecision2 = Float.toPrecision(12345.6789, ~digits=2) + +let toString1 = 12345.6789->Float.toString +let toString2 = Float.toString(12345.6789) + +let toStringWithRadix1 = 6.0->Float.toString(~radix=2) +let toStringWithRadix2 = Float.toString(6.0, ~radix=2) + +let parse1 = "123"->Float.parseFloat +let parse2 = Float.parseFloat("123") + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Global.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Global.res.expected new file mode 100644 index 0000000000..69e573d135 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Global.res.expected @@ -0,0 +1,16 @@ +let t1: timeoutId = setTimeout(() => (), 1000) +let t2: timeoutId = setTimeoutFloat(() => (), 1000.0) + +clearTimeout(t1) + +let i1: intervalId = setInterval(() => (), 2000) +let i2: intervalId = setIntervalFloat(() => (), 2000.0) + +clearInterval(i1) + +let e1 = encodeURI("https://rescript-lang.org?array=[someValue]") +let d1 = decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D") + +let e2 = encodeURIComponent("array=[someValue]") +let d2 = decodeURIComponent("array%3D%5BsomeValue%5D") + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected new file mode 100644 index 0000000000..49289fa30b --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Int.res.expected @@ -0,0 +1,8 @@ +let result1 = Int.bitwiseAnd(1, 2) +let result2 = Int.bitwiseOr(1, 2) +let result3 = Int.bitwiseXor(1, 2) +let result4 = Int.shiftLeft(1, 2) +let result5 = Int.shiftRightUnsigned(1, 2) +let result6 = Int.shiftRight(1, 2) +let result7 = Int.bitwiseNot(0) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Interface.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Interface.res.expected new file mode 100644 index 0000000000..7906b96b41 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Interface.res.expected @@ -0,0 +1,9 @@ +/* Implementation to satisfy interface build for tests */ + +external arr: array = "arr" +external reT: RegExp.t = "re" +external json: JSON.t = "json" +external nestedArr: array = "nestedArr" + +external useSet: Set.t => unit = "useSet" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Interface.resi.expected b/tests/tools_tests/src/expected/StdlibMigration_Interface.resi.expected new file mode 100644 index 0000000000..d6ce02a731 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Interface.resi.expected @@ -0,0 +1,11 @@ +/* Migration tests for interface (.resi) files using stdlib deprecations */ + +// Type alias migrations exercised via externals +external arr: array = "arr" +external reT: RegExp.t = "re" +external json: JSON.t = "json" +external nestedArr: array = "nestedArr" + +// Function type using a deprecated alias +external useSet: Set.t => unit = "useSet" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_JSON.res.expected b/tests/tools_tests/src/expected/StdlibMigration_JSON.res.expected new file mode 100644 index 0000000000..5f8cd42d0f --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_JSON.res.expected @@ -0,0 +1,23 @@ +external someJson: JSON.t = "someJson" +external strToJson: string => JSON.t = "strToJson" + +let decodeString1 = someJson->JSON.Decode.string +let decodeString2 = JSON.Decode.string(someJson) +let decodeString3 = + [1, 2, 3]->Array.map(v => v->Int.toString)->Array.join(" ")->strToJson->JSON.Decode.string + +let decodeNumber1 = someJson->JSON.Decode.float +let decodeNumber2 = JSON.Decode.float(someJson) + +let decodeObject1 = someJson->JSON.Decode.object +let decodeObject2 = JSON.Decode.object(someJson) + +let decodeArray1 = someJson->JSON.Decode.array +let decodeArray2 = JSON.Decode.array(someJson) + +let decodeBoolean1 = someJson->JSON.Decode.bool +let decodeBoolean2 = JSON.Decode.bool(someJson) + +let decodeNull1 = someJson->JSON.Decode.null +let decodeNull2 = JSON.Decode.null(someJson) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_JSON_ParseStringify.res.expected b/tests/tools_tests/src/expected/StdlibMigration_JSON_ParseStringify.res.expected new file mode 100644 index 0000000000..5711d673ac --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_JSON_ParseStringify.res.expected @@ -0,0 +1,15 @@ +let p1 = JSON.parseExn("{}", ~reviver=(k, v) => v) +let p2 = JSON.parseExnWithReviver("{}", (k, v) => v) + +let s1 = JSON.stringifyWithIndent(JSON.Object(dict{}), 2) +let s2 = JSON.stringifyWithReplacer(JSON.Number(1.), (k, v) => v) +let s3 = JSON.stringifyWithReplacerAndIndent(JSON.Boolean(true), (k, v) => v, 2) +let s4 = JSON.stringifyWithFilter(JSON.Array([JSON.Number(1.)]), ["a"]) +let s5 = JSON.stringifyWithFilterAndIndent(JSON.Array([JSON.Number(1.)]), ["a"], 2) + +let a1 = JSON.stringifyAnyWithIndent(1, 2) +let a2 = JSON.stringifyAnyWithReplacer(1, (k, v) => v) +let a3 = JSON.stringifyAnyWithReplacerAndIndent(1, (k, v) => v, 2) +let a4 = JSON.stringifyAnyWithFilter(1, ["a"]) +let a5 = JSON.stringifyAnyWithFilterAndIndent(1, ["a"], 2) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_JSON_Stdlib.res.expected b/tests/tools_tests/src/expected/StdlibMigration_JSON_Stdlib.res.expected new file mode 100644 index 0000000000..bd246e5cfc --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_JSON_Stdlib.res.expected @@ -0,0 +1,15 @@ +let p1 = JSON.parseExn("{}", ~reviver=(_k, v) => v) +let p2 = JSON.parseExnWithReviver("{}", (_k, v) => v) + +let s1 = JSON.stringifyWithIndent(JSON.Object(dict{}), 2) +let s2 = JSON.stringifyWithReplacer(JSON.Number(1.), (_k, v) => v) +let s3 = JSON.stringifyWithReplacerAndIndent(JSON.Boolean(true), (_k, v) => v, 2) +let s4 = JSON.stringifyWithFilter(JSON.Array([JSON.Number(1.)]), ["a"]) +let s5 = JSON.stringifyWithFilterAndIndent(JSON.Array([JSON.Number(1.)]), ["a"], 2) + +let a1 = JSON.stringifyAnyWithIndent(1, 2) +let a2 = JSON.stringifyAnyWithReplacer(1, (_k, v) => v) +let a3 = JSON.stringifyAnyWithReplacerAndIndent(1, (_k, v) => v, 2) +let a4 = JSON.stringifyAnyWithFilter(1, ["a"]) +let a5 = JSON.stringifyAnyWithFilterAndIndent(1, ["a"], 2) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js.res.expected new file mode 100644 index 0000000000..e87cdd9b25 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js.res.expected @@ -0,0 +1,6 @@ +let consoleLog1 = Console.log("Hello") +let consoleLog2 = Console.log2("Hello", "World") +let consoleLog3 = Console.log3("Hello", "World", "!") +let consoleLog4 = Console.log4("Hello", "World", "!", "!") +let consoleLogMany = Console.logMany(["Hello", "World"]) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_Array.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_Array.res.expected new file mode 100644 index 0000000000..1e95f687c8 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_Array.res.expected @@ -0,0 +1,34 @@ +// Migration tests for Js.Array (old) -> Array module + +external someArrayLike: Array.arrayLike = "whatever" + +let from1 = someArrayLike->Array.fromArrayLike +let from2 = Array.fromArrayLike(someArrayLike) + +let fromMap1 = someArrayLike->Array.fromArrayLikeWithMap(s => s ++ "!") +let fromMap2 = Array.fromArrayLikeWithMap(someArrayLike, s => s ++ "!") + +let isArray1 = [1, 2, 3]->Array.isArray +let isArray2 = Array.isArray([1, 2, 3]) + +let length1 = [1, 2, 3]->Array.length +let length2 = Array.length([1, 2, 3]) + +let pop1 = [1, 2, 3]->Array.pop +let pop2 = Array.pop([1, 2, 3]) + +let reverseInPlace1 = [1, 2, 3]->Array.reverse +let reverseInPlace2 = Array.reverse([1, 2, 3]) + +let shift1 = [1, 2, 3]->Array.shift +let shift2 = Array.shift([1, 2, 3]) + +let toString1 = [1, 2, 3]->Array.toString +let toString2 = Array.toString([1, 2, 3]) + +let toLocaleString1 = [1, 2, 3]->Array.toLocaleString +let toLocaleString2 = Array.toLocaleString([1, 2, 3]) + +// Type alias migration +let arrT: array = [1, 2, 3] + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_Int.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_Int.res.expected new file mode 100644 index 0000000000..2852afd3ba --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_Int.res.expected @@ -0,0 +1,24 @@ +let toExponential1 = 77->Int.toExponential +let toExponential2 = Int.toExponential(77) + +let toExponentialWithPrecision1 = 77->Int.toExponential(~digits=2) +let toExponentialWithPrecision2 = Int.toExponential(77, ~digits=2) + +let toPrecision1 = 123456789->Int.toPrecision +let toPrecision2 = Int.toPrecision(123456789) + +let toPrecisionWithPrecision1 = 123456789->Int.toPrecision(~digits=2) +let toPrecisionWithPrecision2 = Int.toPrecision(123456789, ~digits=2) + +let toString1 = 123456789->Int.toString +let toString2 = Int.toString(123456789) + +let toStringWithRadix1 = 373592855->Int.toString(~radix=16) +let toStringWithRadix2 = Int.toString(373592855, ~radix=16) + +let toFloat1 = 42->Int.toFloat +let toFloat2 = Int.toFloat(42) + +let equal1 = Js.Int.equal(1, 1) +let equal2 = 1->Js.Int.equal(2) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_More.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_More.res.expected new file mode 100644 index 0000000000..4317a49af9 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_More.res.expected @@ -0,0 +1,8 @@ +// Migration tests for new deprecations in packages/@rescript/runtime/Js.res + +// typeof migration +let tyNum = typeof(1) + +// nullToOption +let nToOpt = Null.toOption(Null.make(1)) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_Re.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_Re.res.expected new file mode 100644 index 0000000000..73388f2bed --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_Re.res.expected @@ -0,0 +1,51 @@ +let re1 = RegExp.fromString("foo") +let re2 = RegExp.fromString("foo", ~flags="gi") + +let flags1 = re2->RegExp.flags +let flags2 = RegExp.flags(re2) + +let g1 = re2->RegExp.global +let g2 = RegExp.global(re2) + +let ic1 = re2->RegExp.ignoreCase +let ic2 = RegExp.ignoreCase(re2) + +let m1 = re2->RegExp.multiline +let m2 = RegExp.multiline(re2) + +let u1 = re2->RegExp.unicode +let u2 = RegExp.unicode(re2) + +let y1 = re2->RegExp.sticky +let y2 = RegExp.sticky(re2) + +let src1 = re2->RegExp.source +let src2 = RegExp.source(re2) + +let li1 = re2->RegExp.lastIndex +let () = re2->RegExp.setLastIndex(0) + +let exec1 = re2->RegExp.exec("Foo bar") +let exec2 = RegExp.exec(re2, "Foo bar") + +let test1 = re2->RegExp.test("Foo bar") +let test2 = RegExp.test(re2, "Foo bar") + +// Type alias migration +external reT: RegExp.t = "re" + +let matches_access = switch re2->RegExp.exec("Foo bar") { +| None => 0 +| Some(r) => RegExp.Result.matches(r)->Array.length +} + +let result_index = switch re2->RegExp.exec("Foo bar") { +| None => 0 +| Some(r) => RegExp.Result.index(r) +} + +let result_input = switch re2->RegExp.exec("Foo bar") { +| None => "" +| Some(r) => RegExp.Result.input(r) +} + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_String.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_String.res.expected new file mode 100644 index 0000000000..b2a4f5b63c --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_String.res.expected @@ -0,0 +1,44 @@ +// Migration tests for Js.String (old) -> String module + +let make1 = 1->String.make +let make2 = String.make(1) + +let fromCharCode1 = 65->String.fromCharCode +let fromCharCode2 = String.fromCharCode(65) + +let fromCharCodeMany1 = [65, 66, 67]->String.fromCharCodeMany +let fromCharCodeMany2 = String.fromCharCodeMany([65, 66, 67]) + +let fromCodePoint1 = 65->String.fromCodePoint +let fromCodePoint2 = String.fromCodePoint(65) + +let fromCodePointMany1 = [65, 66, 67]->String.fromCodePointMany +let fromCodePointMany2 = String.fromCodePointMany([65, 66, 67]) + +let length1 = "abcde"->String.length +let length2 = String.length("abcde") + +let get1 = "abcde"->String.get(2) +let get2 = String.get("abcde", 2) + +let normalize1 = "abcde"->String.normalize +let normalize2 = String.normalize("abcde") + +let toLowerCase1 = "ABCDE"->String.toLowerCase +let toLowerCase2 = String.toLowerCase("ABCDE") + +let toUpperCase1 = "abcde"->String.toUpperCase +let toUpperCase2 = String.toUpperCase("abcde") + +let toLocaleLowerCase1 = "ABCDE"->String.toLocaleLowerCase +let toLocaleLowerCase2 = String.toLocaleLowerCase("ABCDE") + +let toLocaleUpperCase1 = "abcde"->String.toLocaleUpperCase +let toLocaleUpperCase2 = String.toLocaleUpperCase("abcde") + +let trim1 = " abcde "->String.trim +let trim2 = String.trim(" abcde ") + +// Type alias migration +let sT: string = "abc" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_Types_Interface.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_Types_Interface.res.expected new file mode 100644 index 0000000000..82501d26c0 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_Types_Interface.res.expected @@ -0,0 +1,10 @@ +/* Implementation to satisfy interface build for tests */ + +external nullT: Null.t = "nullT" +external nullableT: Nullable.t = "nullableT" +external nullUndefT: Nullable.t = "nullUndefT" + +external symbolT: Symbol.t = "symbolT" +external objValT: Type.Classify.object = "objValT" +external functionValT: Type.Classify.function = "functionValT" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_Types_Interface.resi.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_Types_Interface.resi.expected new file mode 100644 index 0000000000..6b4cf7b993 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_Types_Interface.resi.expected @@ -0,0 +1,12 @@ +/* Migration tests for Js.res type deprecations */ + +// Type alias migrations exercised via externals +external nullT: Null.t = "nullT" +external nullableT: Nullable.t = "nullableT" +external nullUndefT: Nullable.t = "nullUndefT" + +// Js.Types migrations +external symbolT: Symbol.t = "symbolT" +external objValT: Type.Classify.object = "objValT" +external functionValT: Type.Classify.function = "functionValT" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_Undefined.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_Undefined.res.expected new file mode 100644 index 0000000000..19289cbc74 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_Undefined.res.expected @@ -0,0 +1,36 @@ +let make1 = "hello"->Nullable.make +let make2 = Nullable.make("hello") + +let empty1 = Nullable.undefined + +let getUnsafe1 = Nullable.make(1)->Nullable.getUnsafe +let getUnsafe2 = Nullable.getUnsafe(Nullable.make(1)) + +let getExn1 = Nullable.make(1)->Nullable.getOrThrow +let getExn2 = Nullable.getOrThrow(Nullable.make(1)) + +let map1 = Nullable.make(2)->Nullable.map(x => x + 1) +let map2 = Nullable.map(Nullable.make(2), x => x + 1) + +let forEach1 = Nullable.make(2)->Nullable.forEach(x => ignore(x)) +let forEach2 = Nullable.forEach(Nullable.make(2), x => ignore(x)) + +let fromOption1 = Some("x")->Nullable.fromOption +let fromOption2 = Nullable.fromOption(None) + +let from_opt1 = Some("y")->Nullable.fromOption +let from_opt2 = Nullable.fromOption(None) + +let toOption1 = Nullable.make(3)->Nullable.toOption +let toOption2 = Nullable.toOption(Nullable.make(3)) + +let to_opt1 = Nullable.make(4)->Nullable.toOption +let to_opt2 = Nullable.toOption(Nullable.make(4)) + +let test1 = Js.Undefined.empty->Js.Undefined.test +let test2 = Js.Undefined.test(Js.Undefined.empty) +let test3 = Js.Undefined.return(5)->Js.Undefined.bind(v => v)->Js.Undefined.test + +let testAny1 = Js.Undefined.testAny(Js.Undefined.empty) +let testAny2 = Js.Undefined.empty->Js.Undefined.testAny + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array.res.expected new file mode 100644 index 0000000000..4f4f598538 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array.res.expected @@ -0,0 +1,8 @@ +let arr1 = Int8Array.fromArray([1, 2, 3]) + +let len = arr1->TypedArray.length + +let bytes = Int8Array.Constants.bytesPerElement +let off = Int8Array.fromBufferToEnd(ArrayBuffer.make(8), ~byteOffset=2) +let range = Int8Array.fromBufferWithRange(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array2.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array2.res.expected new file mode 100644 index 0000000000..35d4cb885e --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array2.res.expected @@ -0,0 +1,19 @@ +let arr = Int8Array.fromArray([1, 2, 3]) + +let len1 = arr->TypedArray.length +let includes1 = arr->TypedArray.includes(2) +let idxFrom1 = arr->TypedArray.indexOfFrom(2, 1) + +let slice1 = arr->TypedArray.slice(~start=1, ~end=2) +let sliceFrom1 = arr->TypedArray.sliceToEnd(~start=1) + +let map1 = arr->TypedArray.map(x => x + 1) +let reduce1 = arr->TypedArray.reduce((acc, x) => acc + x, 0) + +let bytes = Int8Array.Constants.bytesPerElement + +let fromBufToEnd = Int8Array.fromBufferToEnd(ArrayBuffer.make(8), ~byteOffset=2) +let fromBufRange = Int8Array.fromBufferWithRange(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) + +let fromLength = Int8Array.fromLength(3) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array2_Float32.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array2_Float32.res.expected new file mode 100644 index 0000000000..aae0960940 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array2_Float32.res.expected @@ -0,0 +1,19 @@ +let arr = Float32Array.fromArray([1.0, 2.0, 3.0]) + +let len1 = arr->TypedArray.length +let includes1 = arr->TypedArray.includes(2.0) +let idxFrom1 = arr->TypedArray.indexOfFrom(2.0, 1) + +let slice1 = arr->TypedArray.slice(~start=1, ~end=2) +let sliceFrom1 = arr->TypedArray.sliceToEnd(~start=1) + +let map1 = arr->TypedArray.map(x => x +. 1.0) +let reduce1 = arr->TypedArray.reduce((acc, x) => acc +. x, 0.0) + +let bytes = Float32Array.Constants.bytesPerElement + +let fromBufToEnd = Float32Array.fromBufferToEnd(ArrayBuffer.make(8), ~byteOffset=2) +let fromBufRange = Float32Array.fromBufferWithRange(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) + +let fromLength = Float32Array.fromLength(3) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array_Float32_Const.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array_Float32_Const.res.expected new file mode 100644 index 0000000000..770165dc54 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Js_typed_array_Float32_Const.res.expected @@ -0,0 +1,3 @@ +// Float32 constants migration coverage for legacy Js.Typed_array +let bytesF32 = Float32Array.Constants.bytesPerElement + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Map.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Map.res.expected new file mode 100644 index 0000000000..ef71502bff --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Map.res.expected @@ -0,0 +1,3 @@ +// Type alias migration for Js.Map.t +external m: Map.t = "m" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Math.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Math.res.expected new file mode 100644 index 0000000000..ccce8ab209 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Math.res.expected @@ -0,0 +1,82 @@ +// Exercise migrations from Js.Math to Math + +let e = Math.Constants.e +let pi = Math.Constants.pi +let ln2 = Math.Constants.ln2 +let ln10 = Math.Constants.ln10 +let log2e = Math.Constants.log2e +let log10e = Math.Constants.log10e +let sqrt_half = Math.Constants.sqrt1_2 +let sqrt2c = Math.Constants.sqrt2 + +let absInt1 = Math.Int.abs(-5) +let absFloat1 = Math.abs(-3.5) + +let acos1 = Math.acos(1.0) +let acosh1 = Math.acosh(1.5) +let asinh1 = Math.asinh(1.0) +let asin1 = Math.asin(0.5) +let atan1 = Math.atan(1.0) +let atanh1 = Math.atanh(0.5) + +let atan21 = Math.atan2(~y=0.0, ~x=10.0) + +let cbrt1 = Math.cbrt(27.0) + +let ceilInt1 = Math.Int.ceil(3.2) +let ceilInt2 = Math.Int.ceil(3.2) +let ceilFloat1 = Math.ceil(3.2) + +let clz1 = Math.Int.clz32(255) + +let cos1 = Math.cos(0.0) +let cosh1 = Math.cosh(0.0) +let exp1 = Math.exp(1.0) +let expm11 = Math.expm1(1.0) +let log1p1 = Math.log1p(1.0) + +let floorInt1 = Math.Int.floor(3.7) +let floorInt2 = Math.Int.floor(3.7) +let floorFloat1 = Math.floor(3.7) + +let fround1 = Math.fround(5.05) + +let hypot1 = Math.hypot(3.0, 4.0) +let hypotMany1 = Math.hypotMany([3.0, 4.0, 12.0]) + +let imul1 = Math.Int.imul(3, 4) + +let log1 = Math.log(Math.Constants.e) +let log10_1 = Math.log10(1000.0) +let log2_1 = Math.log2(512.0) + +let maxInt1 = Math.Int.max(1, 2) +let maxIntMany1 = Math.Int.maxMany([1, 10, 3]) +let maxFloat1 = Math.max(1.5, 2.5) +let maxFloatMany1 = Math.maxMany([1.5, 2.5, 0.5]) + +let minInt1 = Math.Int.min(1, 2) +let minIntMany1 = Math.Int.minMany([1, 10, 3]) +let minFloat1 = Math.min(1.5, 2.5) +let minFloatMany1 = Math.minMany([1.5, 2.5, 0.5]) + +let powInt1 = Math.Int.pow(3, ~exp=4) +let powFloat1 = Math.pow(3.0, ~exp=4.0) + +let rand1 = Math.random() + +let roundUnsafe1 = Float.toInt(Math.round(3.7)) +let round1 = Math.round(3.7) + +let signInt1 = Math.Int.sign(-5) +let signFloat1 = Math.sign(-5.0) + +let sin1 = Math.sin(0.0) +let sinh1 = Math.sinh(0.0) +let sqrt1 = Math.sqrt(9.0) +let tan1 = Math.tan(0.5) +let tanh1 = Math.tanh(0.0) + +let truncUnsafe1 = Float.toInt(Math.trunc(3.7)) +let trunc1 = Math.trunc(3.7) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Null.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Null.res.expected new file mode 100644 index 0000000000..7e7a2ac5fb --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Null.res.expected @@ -0,0 +1,36 @@ +let make1 = "hello"->Null.make +let make2 = Null.make("hello") + +let empty1 = Null.null + +let getUnsafe1 = Null.make(1)->Null.getUnsafe +let getUnsafe2 = Null.getUnsafe(Null.make(1)) + +let getExn1 = Null.make(1)->Null.getOrThrow +let getExn2 = Null.getOrThrow(Null.make(1)) + +let map1 = Null.make(2)->Null.map(x => x + 1) +let map2 = Null.map(Null.make(2), x => x + 1) + +let forEach1 = Null.make(2)->Null.forEach(x => ignore(x)) +let forEach2 = Null.forEach(Null.make(2), x => ignore(x)) + +let fromOption1 = Some("x")->Null.fromOption +let fromOption2 = Null.fromOption(None) + +let from_opt1 = Some("y")->Null.fromOption +let from_opt2 = Null.fromOption(None) + +let toOption1 = Null.make(3)->Null.toOption +let toOption2 = Null.toOption(Null.make(3)) + +let to_opt1 = Null.make(4)->Null.toOption +let to_opt2 = Null.toOption(Null.make(4)) + +let test1 = Null.null === Null.null +let test2 = Null.null === Null.null +let test3 = Null.make(5)->Null.map(v => v)->Null.equal(Null, (a, b) => a === b) + +// Type alias migration +let nullT: Null.t = Null.make(1) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Nullable.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Nullable.res.expected new file mode 100644 index 0000000000..8412fd909e --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Nullable.res.expected @@ -0,0 +1,35 @@ +let make1 = "hello"->Nullable.make +let make2 = Nullable.make("hello") + +let null1 = Nullable.null +let undefined1 = Nullable.undefined + +let isNullable1 = Nullable.null->Nullable.isNullable +let isNullable2 = Nullable.isNullable(Nullable.null) + +let map1 = Nullable.make(2)->Nullable.map(x => x + 1) +let map2 = Nullable.map(Nullable.make(2), x => x + 1) + +let forEach1 = Nullable.make(2)->Nullable.forEach(x => ignore(x)) +let forEach2 = Nullable.forEach(Nullable.make(2), x => ignore(x)) + +let fromOption1 = Some("x")->Nullable.fromOption +let fromOption2 = Nullable.fromOption(None) + +let from_opt1 = Some("y")->Nullable.fromOption +let from_opt2 = Nullable.fromOption(None) + +let toOption1 = Nullable.make(3)->Nullable.toOption +let toOption2 = Nullable.toOption(Nullable.make(3)) + +let to_opt1 = Nullable.make(4)->Nullable.toOption +let to_opt2 = Nullable.toOption(Nullable.make(4)) + +let optArrayOfNullableToOptArrayOfOpt: option>> => option< + array>, +> = x => + switch x { + | None => None + | Some(arr) => Some(arr->Belt.Array.map(Nullable.toOption)) + } + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Obj.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Obj.res.expected new file mode 100644 index 0000000000..ad86db6537 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Obj.res.expected @@ -0,0 +1,8 @@ +let empty1 = Object.make() + +let assign1 = Object.make()->Object.assign({"a": 1}) +let assign2 = Object.assign(Object.make(), {"a": 1}) + +let keys1 = {"a": 1, "b": 2}->Object.keysToArray +let keys2 = Object.keysToArray({"a": 1, "b": 2}) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Option.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Option.res.expected new file mode 100644 index 0000000000..76a8b69111 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Option.res.expected @@ -0,0 +1,34 @@ +let someCall = Js.Option.some(3) +let somePiped = 3->Js.Option.some + +let isSome1 = Some(1)->Option.isSome +let isSome2 = Option.isSome(None) + +let isNone1 = None->Option.isNone +let isNone2 = Option.isNone(Some(2)) + +let eq = (a: int, b: int) => a == b +// let isSomeValue1 = Js.Option.isSomeValue(eq, 2, Some(2)) + +let getExn1 = Option.getOrThrow(Some(3)) +let getExn2 = Some(3)->Option.getOrThrow + +let equal1 = Option.equal(Some(2), Some(2), eq) + +let f = (x: int) => x > 0 ? Some(x + 1) : None +let andThen1 = Option.flatMap(Some(2), f) + +let map1 = Option.map(Some(2), x => x * 2) + +let getWithDefault1 = Option.getOr(Some(2), 0) + +let default1 = Option.getOr(Some(2), 0) + +let filter1 = Option.filter(Some(1), x => x > 0) + +let firstSome1 = Option.orElse(Some(1), None) +let firstSome2 = Option.orElse(Some(1), None) + +// Type alias migration +let optT: option = Some(1) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Pervasives.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Pervasives.res.expected new file mode 100644 index 0000000000..6e7c36554f --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Pervasives.res.expected @@ -0,0 +1,2 @@ +throw(Failure("test")) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Promise.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Promise.res.expected new file mode 100644 index 0000000000..e4f878cc0f --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Promise.res.expected @@ -0,0 +1,40 @@ +let p1 = Promise.resolve(1) +let p2 = Promise.reject(Failure("err")) + +let all1 = Promise.all([Promise.resolve(1), Promise.resolve(2)]) +let all2 = Promise.all2((Promise.resolve(1), Promise.resolve(2))) +let all3 = Promise.all3((Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))) +let all4 = Promise.all4(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), +)) +let all5 = Promise.all5(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), + Promise.resolve(5), +)) +let all6 = Promise.all6(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), + Promise.resolve(5), + Promise.resolve(6), +)) + +let race1 = Promise.race([Promise.resolve(10), Promise.resolve(20)]) + +// let thenPipe = Js.Promise.resolve(1)->Js.Promise.then_(x => Js.Promise.resolve(x + 1), _) +// let thenDirect = Js.Promise.then_(x => Js.Promise.resolve(x + 1), Js.Promise.resolve(1)) + +// Type alias migration +external p: promise = "p" + +// let catchPipe = Js.Promise.resolve(1)->Js.Promise.catch(_e => Js.Promise.resolve(0), _) +// let catchDirect = Js.Promise.catch(_e => Js.Promise.resolve(0), Js.Promise.resolve(1)) +let make1 = Promise.make((resolve, reject) => resolve(1)) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Promise2.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Promise2.res.expected new file mode 100644 index 0000000000..c582406ff2 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Promise2.res.expected @@ -0,0 +1,43 @@ +let p1 = Promise.resolve(1) +let _p2 = Promise.reject(Failure("err")) + +let all1 = Promise.all([Promise.resolve(1), Promise.resolve(2)]) +let all2 = Promise.all2((Promise.resolve(1), Promise.resolve(2))) +let all3 = Promise.all3((Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))) + +let all4 = Promise.all4(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), +)) +let all5 = Promise.all5(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), + Promise.resolve(5), +)) +let all6 = Promise.all6(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), + Promise.resolve(5), + Promise.resolve(6), +)) + +let race1 = Promise.race([Promise.resolve(10), Promise.resolve(20)]) + +let thenPipe = Promise.resolve(1)->Promise.then(x => Promise.resolve(x + 1)) +let thenDirect = Promise.then(Promise.resolve(1), x => Promise.resolve(x + 1)) + +// Type alias migration +external p2: promise = "p2" + +let catchPipe = Promise.resolve(1)->Promise.catch(_e => Promise.resolve(0)) +let catchDirect = Promise.catch(Promise.resolve(1), _e => Promise.resolve(0)) +let make1 = Promise.make((resolve, _) => resolve(1)) + +let _ = p2->Promise.then(x => Promise.resolve(x + 1)) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Result.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Result.res.expected new file mode 100644 index 0000000000..6451db2701 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Result.res.expected @@ -0,0 +1,3 @@ +type r = result +let res: result = Ok(1) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_Set.res.expected b/tests/tools_tests/src/expected/StdlibMigration_Set.res.expected new file mode 100644 index 0000000000..3abe912e07 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_Set.res.expected @@ -0,0 +1,3 @@ +// Type alias migration for Js.Set.t +external s: Set.t = "s" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_StdlibArray.res.expected b/tests/tools_tests/src/expected/StdlibMigration_StdlibArray.res.expected new file mode 100644 index 0000000000..2acb51183e --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_StdlibArray.res.expected @@ -0,0 +1,21 @@ +let ba1 = [1, 2, 3, 4, 5]->Array.copyWithin(~target=2, ~start=0) +let ba2 = Array.copyWithin([1, 2, 3, 4, 5], ~target=2, ~start=0) + +let b1 = [1, 2, 3, 4]->Array.copyWithin(~target=0, ~start=2) +let b2 = Array.copyWithin([1, 2, 3, 4], ~target=0, ~start=2) + +let c1 = [1, 2, 3]->Array.fill(0) +let c2 = [1, 2, 3, 4]->Array.fill(9, ~start=1) + +let d1 = [1, 2, 1, 2]->Array.indexOf(2, ~from=2) +let d2 = Array.indexOf([1, 2, 1, 2], 2, ~from=2) + +let e1 = ["a", "b"]->Array.join("-") +let e2 = [1, 2]->Array.joinUnsafe(",") + +let f1 = [1, 2, 3, 4]->Array.slice(~start=2) + +let g1 = [1, 2]->Array.lastIndexOf(1, ~from=1) + +let h1 = [1, 2]->Array.getUnsafe(1) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_StdlibListLazyPromise.res.expected b/tests/tools_tests/src/expected/StdlibMigration_StdlibListLazyPromise.res.expected new file mode 100644 index 0000000000..020a7c1a71 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_StdlibListLazyPromise.res.expected @@ -0,0 +1,14 @@ +let l1 = List.headOrThrow(list{1}) +let l2 = List.tailOrThrow(list{1}) +let l3 = List.getOrThrow(list{"a", "b"}, 0) +let l4 = List.shuffle(list{1, 2}) + +let lazy1 = Lazy.make(() => 1) +let lazy2 = Lazy.make(() => 2) +let v1 = Lazy.get(lazy1) +let v2 = Lazy.get(lazy2) +let b1 = Lazy.isEvaluated(lazy1) + +let p = Promise.resolve(5) +let _ = Promise.ignore(p) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_StdlibOptionResultNull.res.expected b/tests/tools_tests/src/expected/StdlibMigration_StdlibOptionResultNull.res.expected new file mode 100644 index 0000000000..7290d990d5 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_StdlibOptionResultNull.res.expected @@ -0,0 +1,16 @@ +let o1 = Option.getOrThrow(Some(3)) +let o2 = Option.mapOr(Some(3), 0, x => x + 1) +let o3 = Option.getOr(None, 0) + +let r1 = Result.getOrThrow(Ok(1)) +let r2 = Result.mapOr(Ok(1), 0, x => x + 1) +let r3 = Result.getOr(Error("e"), 0) + +let n1 = Null.getOrThrow(Null.make(3)) +let n2 = Null.getOr(Null.null, 0) +let n3 = Null.mapOr(Null.make(3), 0, x => x) + +let nb1 = Nullable.getOrThrow(Nullable.make(3)) +let nb2 = Nullable.getOr(Nullable.null, 0) +let nb3 = Nullable.mapOr(Nullable.make(3), 0, x => x) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_StdlibPrimitives.res.expected b/tests/tools_tests/src/expected/StdlibMigration_StdlibPrimitives.res.expected new file mode 100644 index 0000000000..8ff839afe2 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_StdlibPrimitives.res.expected @@ -0,0 +1,19 @@ +let i1 = Int.toExponential(77, ~digits=2) +let i2 = Int.toFixed(300, ~digits=1) +let i3 = Int.toPrecision(100, ~digits=2) +let i4 = Int.toString(6, ~radix=2) +let i5 = Int.range(1, 5, ~options={step: 2}) + +let f1 = Float.parseInt("10.0", ~radix=2) +let f2 = Float.toExponential(77.0, ~digits=2) +let f3 = Float.toFixed(300.0, ~digits=1) +let f4 = Float.toPrecision(100.0, ~digits=2) +let f5 = Float.toString(6.0, ~radix=2) + +let b1 = Bool.fromStringOrThrow("true") + +let buf = ArrayBuffer.make(8) +let ab1 = buf->ArrayBuffer.slice(~start=2) + +let re1 = RegExp.fromString("\\w+", ~flags="g") + diff --git a/tests/tools_tests/src/expected/StdlibMigration_StdlibString.res.expected b/tests/tools_tests/src/expected/StdlibMigration_StdlibString.res.expected new file mode 100644 index 0000000000..02bd480794 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_StdlibString.res.expected @@ -0,0 +1,38 @@ +let s1 = "abcde"->String.slice(~start=1) +let s2 = "abcde"->String.substring(~start=1) + +let r0 = + "vowels"->String.replaceRegExpBy0Unsafe(/a|e|i|o|u/g, (~match, ~offset as _, ~input as _) => + match + ) +let r1 = + "Jony is 40"->String.replaceRegExpBy1Unsafe(/(Jony is )\d+/g, ( + ~match as _, + ~group1, + ~offset as _, + ~input as _, + ) => group1) + +let r2 = "7 times 6"->String.replaceRegExpBy2Unsafe(/(\d+) times (\d+)/, ( + ~match as _, + ~group1, + ~group2, + ~offset as _, + ~input as _, +) => + switch (Int.fromString(group1), Int.fromString(group2)) { + | (Some(x), Some(y)) => Int.toString(x * y) + | _ => "???" + } +) + +let r3 = + "abc"->String.replaceRegExpBy3Unsafe(/(a)(b)(c)/, ( + ~match as _, + ~group1, + ~group2, + ~group3, + ~offset as _, + ~input as _, + ) => group1 ++ group2 ++ group3) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_String.res.expected b/tests/tools_tests/src/expected/StdlibMigration_String.res.expected new file mode 100644 index 0000000000..b867bb3fdf --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_String.res.expected @@ -0,0 +1,130 @@ +let make1 = 1->String.make +let make2 = String.make(1) + +let fromCharCode1 = 65->String.fromCharCode +let fromCharCode2 = String.fromCharCode(65) + +let fromCharCodeMany1 = [65, 66, 67]->String.fromCharCodeMany +let fromCharCodeMany2 = String.fromCharCodeMany([65, 66, 67]) + +let fromCodePoint1 = 65->String.fromCodePoint +let fromCodePoint2 = String.fromCodePoint(65) + +let fromCodePointMany1 = [65, 66, 67]->String.fromCodePointMany +let fromCodePointMany2 = String.fromCodePointMany([65, 66, 67]) + +let length1 = "abcde"->String.length +let length2 = String.length("abcde") + +let get1 = "abcde"->String.getUnsafe(2) +let get2 = String.getUnsafe("abcde", 2) + +let charAt1 = "abcde"->String.charAt(2) +let charAt2 = String.charAt("abcde", 2) + +let charCodeAt1 = "abcde"->String.charCodeAt(2) +let charCodeAt2 = String.charCodeAt("abcde", 2) + +let codePointAt1 = "abcde"->String.codePointAt(2) +let codePointAt2 = String.codePointAt("abcde", 2) + +let concat1 = "abcde"->String.concat("fghij") +let concat2 = String.concat("abcde", "fghij") + +let concatMany1 = "abcde"->String.concatMany(["fghij", "klmno"]) +let concatMany2 = String.concatMany("abcde", ["fghij", "klmno"]) + +let endsWith1 = "abcde"->String.endsWith("de") +let endsWith2 = String.endsWith("abcde", "de") + +let endsWithFrom1 = "abcde"->String.endsWithFrom("d", 2) +let endsWithFrom2 = String.endsWithFrom("abcde", "d", 2) + +let includes1 = "abcde"->String.includes("de") +let includes2 = String.includes("abcde", "de") + +let includesFrom1 = "abcde"->String.includesFrom("d", 2) +let includesFrom2 = String.includesFrom("abcde", "d", 2) + +let indexOf1 = "abcde"->String.indexOf("de") +let indexOf2 = String.indexOf("abcde", "de") + +let indexOfFrom1 = "abcde"->String.indexOfFrom("d", 2) +let indexOfFrom2 = String.indexOfFrom("abcde", "d", 2) + +let lastIndexOf1 = "abcde"->String.lastIndexOf("de") +let lastIndexOf2 = String.lastIndexOf("abcde", "de") + +let lastIndexOfFrom1 = "abcde"->String.lastIndexOfFrom("d", 2) +let lastIndexOfFrom2 = String.lastIndexOfFrom("abcde", "d", 2) + +let localeCompare1 = "abcde"->String.localeCompare("fghij") +let localeCompare2 = String.localeCompare("abcde", "fghij") + +let match1 = "abcde"->String.match(/d/) +let match2 = String.match("abcde", /d/) + +let normalize1 = "abcde"->String.normalize +let normalize2 = String.normalize("abcde") + +let repeat1 = "abcde"->String.repeat(2) +let repeat2 = String.repeat("abcde", 2) + +let replace1 = "abcde"->String.replace("d", "f") +let replace2 = String.replace("abcde", "d", "f") + +let replaceByRe1 = "abcde"->String.replaceRegExp(/d/, "f") +let replaceByRe2 = String.replaceRegExp("abcde", /d/, "f") + +let search1 = "abcde"->String.search(/d/) +let search2 = String.search("abcde", /d/) + +let slice1 = "abcde"->String.slice(~start=1, ~end=3) +let slice2 = String.slice("abcde", ~start=1, ~end=3) + +let sliceToEnd1 = "abcde"->String.slice(~start=1) +let sliceToEnd2 = String.slice("abcde", ~start=1) + +let split1 = "abcde"->String.split("d") +let split2 = String.split("abcde", "d") + +let splitAtMost1 = "abcde"->String.splitAtMost("d", ~limit=2) +let splitAtMost2 = String.splitAtMost("abcde", "d", ~limit=2) + +let splitByRe1 = "abcde"->String.splitByRegExp(/d/) +let splitByRe2 = String.splitByRegExp("abcde", /d/) + +let splitByReAtMost1 = "abcde"->String.splitByRegExpAtMost(/d/, ~limit=2) +let splitByReAtMost2 = String.splitByRegExpAtMost("abcde", /d/, ~limit=2) + +let startsWith1 = "abcde"->String.startsWith("ab") +let startsWith2 = String.startsWith("abcde", "ab") + +let startsWithFrom1 = "abcde"->String.startsWithFrom("b", 1) +let startsWithFrom2 = String.startsWithFrom("abcde", "b", 1) + +let substring1 = "abcde"->String.substring(~start=1, ~end=3) +let substring2 = String.substring("abcde", ~start=1, ~end=3) + +let substringToEnd1 = "abcde"->String.substringToEnd(~start=1) +let substringToEnd2 = String.substringToEnd("abcde", ~start=1) + +let toLowerCase1 = "abcde"->String.toLowerCase +let toLowerCase2 = String.toLowerCase("abcde") + +let toLocaleLowerCase1 = "abcde"->String.toLocaleLowerCase +let toLocaleLowerCase2 = String.toLocaleLowerCase("abcde") + +let toUpperCase1 = "abcde"->String.toUpperCase +let toUpperCase2 = String.toUpperCase("abcde") + +let toLocaleUpperCase1 = "abcde"->String.toLocaleUpperCase +let toLocaleUpperCase2 = String.toLocaleUpperCase("abcde") + +let trim1 = "abcde"->String.trim +let trim2 = String.trim("abcde") + +// Type alias migrations +let sT: string = "abc" +let s2T: string = "def" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_TypedArray_Constructors.res.expected b/tests/tools_tests/src/expected/StdlibMigration_TypedArray_Constructors.res.expected new file mode 100644 index 0000000000..d91e6d05d6 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_TypedArray_Constructors.res.expected @@ -0,0 +1,4 @@ +let a = Uint8Array.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2) +let b = Uint8Array.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) +let c = Uint8Array.fromArrayLikeOrIterable([1, 2], ~map=(v, i) => v) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_TypedArray_Operations.res.expected b/tests/tools_tests/src/expected/StdlibMigration_TypedArray_Operations.res.expected new file mode 100644 index 0000000000..796a3bec95 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_TypedArray_Operations.res.expected @@ -0,0 +1,7 @@ +let ta = Uint8Array.fromArray([1, 2, 3, 4]) + +let a1 = ta->TypedArray.copyWithin(~target=1, ~start=2) +let a2 = ta->TypedArray.fill(9, ~start=1) +let a3 = ta->TypedArray.slice(~start=1) +let a4 = ta->TypedArray.subarray(~start=1) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_TypedArray_Stdlib.res.expected b/tests/tools_tests/src/expected/StdlibMigration_TypedArray_Stdlib.res.expected new file mode 100644 index 0000000000..d4fb049ccb --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_TypedArray_Stdlib.res.expected @@ -0,0 +1,4 @@ +let a = Uint8Array.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2) +let b = Uint8Array.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) +let c = Uint8Array.fromArrayLikeOrIterable([1, 2], ~map=(v, _i) => v) + diff --git a/tests/tools_tests/src/expected/StdlibMigration_WeakMap.res.expected b/tests/tools_tests/src/expected/StdlibMigration_WeakMap.res.expected new file mode 100644 index 0000000000..8dfa5ef102 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_WeakMap.res.expected @@ -0,0 +1,3 @@ +// Type alias migration for Js.WeakMap.t +external wm: WeakMap.t<{..}, int> = "wm" + diff --git a/tests/tools_tests/src/expected/StdlibMigration_WeakSet.res.expected b/tests/tools_tests/src/expected/StdlibMigration_WeakSet.res.expected new file mode 100644 index 0000000000..aa547b1e22 --- /dev/null +++ b/tests/tools_tests/src/expected/StdlibMigration_WeakSet.res.expected @@ -0,0 +1,3 @@ +// Type alias migration for Js.WeakSet.t +external ws: WeakSet.t<{..}> = "ws" + diff --git a/tests/tools_tests/src/migrate/DeprecatedStuff.res b/tests/tools_tests/src/migrate/DeprecatedStuff.res new file mode 100644 index 0000000000..ec1494961e --- /dev/null +++ b/tests/tools_tests/src/migrate/DeprecatedStuff.res @@ -0,0 +1,11 @@ +@send +external slice: (string, ~from: int, ~to_: int) => string = "slice" + +@send +external shift: array<'a> => option<'a> = "shift" + +module Constants = { + let otherThing = [2, 3] +} + +let deprecatedThing = [1, 2] diff --git a/tests/tools_tests/src/migrate/DeprecatedStuff.resi b/tests/tools_tests/src/migrate/DeprecatedStuff.resi new file mode 100644 index 0000000000..1c91c3e439 --- /dev/null +++ b/tests/tools_tests/src/migrate/DeprecatedStuff.resi @@ -0,0 +1,26 @@ +@deprecated({ + reason: "Use `String.slice` instead", + migrate: String.slice( + ~start=%insert.labelledArgument("from"), + ~end=%insert.labelledArgument("to_"), + ), +}) +@send +external slice: (string, ~from: int, ~to_: int) => string = "slice" + +@send +@deprecated({ + reason: "Use `Array.shift` instead.", + migrate: Array.shift(), +}) +external shift: array<'a> => option<'a> = "shift" + +module Constants: { + let otherThing: array +} + +@deprecated({ + reason: "Use `otherThing` instead.", + migrate: DeprecatedStuff.Constants.otherThing, +}) +let deprecatedThing: array diff --git a/tests/tools_tests/src/migrate/FileToMigrate.res b/tests/tools_tests/src/migrate/FileToMigrate.res new file mode 100644 index 0000000000..097d2f5c21 --- /dev/null +++ b/tests/tools_tests/src/migrate/FileToMigrate.res @@ -0,0 +1,14 @@ +let someNiceString = DeprecatedStuff.slice("abcdefg", ~from=2, ~to_=5) + +let someNiceString2 = DeprecatedStuff.slice( + DeprecatedStuff.slice("abcdefg", ~from=0, ~to_=1), + ~from=2, + ~to_=5, +) + +let someNiceString3 = "abcdefg"->DeprecatedStuff.slice(~from=2, ~to_=5) + +let shift1 = DeprecatedStuff.shift([1, 2, 3]) +let shift2 = [1, 2, 3]->DeprecatedStuff.shift + +let deprecatedThing1 = DeprecatedStuff.deprecatedThing diff --git a/tests/tools_tests/src/migrate/OptionalArgRename.res b/tests/tools_tests/src/migrate/OptionalArgRename.res new file mode 100644 index 0000000000..5f8125be41 --- /dev/null +++ b/tests/tools_tests/src/migrate/OptionalArgRename.res @@ -0,0 +1,11 @@ +module Target = { + let doStuff = (~newName: option=?) => { + ignore(newName) + } +} + +let _ = Target.doStuff + +external doStuff: (~oldName: option=?) => unit = "doStuff" + +/* Intentionally no usage here; this test exercises migration config parsing and ensures optional label rename is preserved and doesn’t crash. */ diff --git a/tests/tools_tests/src/migrate/OptionalArgRename.resi b/tests/tools_tests/src/migrate/OptionalArgRename.resi new file mode 100644 index 0000000000..cc6995c020 --- /dev/null +++ b/tests/tools_tests/src/migrate/OptionalArgRename.resi @@ -0,0 +1,5 @@ +@deprecated({ + reason: "Use new label name", + migrate: OptionalArgRename.Target.doStuff(~newName=%insert.labelledArgument("oldName")), +}) +external doStuff: (~oldName: option=?) => unit = "doStuff" diff --git a/tests/tools_tests/src/migrate/PipeAndRecursive.res b/tests/tools_tests/src/migrate/PipeAndRecursive.res new file mode 100644 index 0000000000..cae67949b7 --- /dev/null +++ b/tests/tools_tests/src/migrate/PipeAndRecursive.res @@ -0,0 +1,25 @@ +module Target = { + let a = x => x + 1 + let b = x => x + 2 +} + +@deprecated({ + reason: "test piped vs non-piped", + migrate: PipeAndRecursive.Target.a(), + migrateInPipeChain: PipeAndRecursive.Target.b(), +}) +external dep: int => int = "dep" + +let id = x => x + +/* Should use migrate (Target.a), since lhs has 0 pipes */ +let onePipe = 1->dep + +/* Still migrate (Target.a), since lhs has 1 pipe (< 2) */ +let twoPipes = 1->id->dep + +/* Should use migrateInPipeChain (Target.b), since lhs has 2 pipes */ +let threePipes = 1->id->id->dep + +/* Recursion: all dep steps should migrate */ +let many = 1->dep->dep->dep->dep->dep->dep->dep->dep->dep->dep diff --git a/tests/tools_tests/src/migrate/StdlibMigrationNoCompile_Array.res b/tests/tools_tests/src/migrate/StdlibMigrationNoCompile_Array.res new file mode 100644 index 0000000000..369db964f3 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigrationNoCompile_Array.res @@ -0,0 +1,3 @@ +// Migrations that will not compile after migration (by design) +let sortInPlaceWith1 = [3, 1, 2]->Js.Array2.sortInPlaceWith((a, b) => a - b) +let sortInPlaceWith2 = Js.Array2.sortInPlaceWith([3, 1, 2], (a, b) => a - b) diff --git a/tests/tools_tests/src/migrate/StdlibMigrationNoCompile_Js_Re.res b/tests/tools_tests/src/migrate/StdlibMigrationNoCompile_Js_Re.res new file mode 100644 index 0000000000..a820035008 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigrationNoCompile_Js_Re.res @@ -0,0 +1,10 @@ +let re2 = Js.Re.fromStringWithFlags("foo", ~flags="gi") + +let capture_access = switch re2->Js.Re.exec_("Foo") { +| None => 0 +| Some(r) => + switch Js.Re.captures(r) { + | [Value(full), _] => String.length(full) + | _ => 0 + } +} diff --git a/tests/tools_tests/src/migrate/StdlibMigrationNoCompile_String.res b/tests/tools_tests/src/migrate/StdlibMigrationNoCompile_String.res new file mode 100644 index 0000000000..d377bf2d05 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigrationNoCompile_String.res @@ -0,0 +1,11 @@ +let normalizeByForm1 = "abcde"->Js.String2.normalizeByForm("a") +let normalizeByForm2 = Js.String2.normalizeByForm("abcde", "a") + +let unsafeReplaceBy01 = "abcde"->Js.String2.unsafeReplaceBy0(/d/, (_, _, _) => "f") +let unsafeReplaceBy02 = Js.String2.unsafeReplaceBy0("abcde", /d/, (_, _, _) => "f") + +let unsafeReplaceBy11 = "abcde"->Js.String2.unsafeReplaceBy1(/d/, (_, _, _, _) => "f") +let unsafeReplaceBy12 = Js.String2.unsafeReplaceBy1("abcde", /d/, (_, _, _, _) => "f") + +let unsafeReplaceBy21 = "abcde"->Js.String2.unsafeReplaceBy2(/d/, (_, _, _, _, _) => "f") +let unsafeReplaceBy22 = Js.String2.unsafeReplaceBy2("abcde", /d/, (_, _, _, _, _) => "f") diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Array.res b/tests/tools_tests/src/migrate/StdlibMigration_Array.res new file mode 100644 index 0000000000..c457b93b2e --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Array.res @@ -0,0 +1,179 @@ +let shift1 = [1, 2, 3]->Js.Array2.shift +let shift2 = Js.Array2.shift([1, 2, 3]) + +let slice1 = [1, 2, 3]->Js.Array2.slice(~start=1, ~end_=2) +let slice2 = Js.Array2.slice([1, 2, 3], ~start=1, ~end_=2) + +external someArrayLike: Js_array2.array_like = "whatever" + +let from1 = someArrayLike->Js.Array2.from +let from2 = Js.Array2.from(someArrayLike) + +let fromMap1 = someArrayLike->Js.Array2.fromMap(s => s ++ "!") +let fromMap2 = Js.Array2.fromMap(someArrayLike, s => s ++ "!") + +let isArray1 = [1, 2, 3]->Js.Array2.isArray +let isArray2 = Js.Array2.isArray([1, 2, 3]) + +let length1 = [1, 2, 3]->Js.Array2.length +let length2 = Js.Array2.length([1, 2, 3]) + +let fillInPlace1 = [1, 2, 3]->Js.Array2.fillInPlace(0) +let fillInPlace2 = Js.Array2.fillInPlace([1, 2, 3], 0) + +let fillFromInPlace1 = [1, 2, 3, 4]->Js.Array2.fillFromInPlace(0, ~from=2) +let fillFromInPlace2 = Js.Array2.fillFromInPlace([1, 2, 3, 4], 0, ~from=2) + +let fillRangeInPlace1 = [1, 2, 3, 4]->Js.Array2.fillRangeInPlace(0, ~start=1, ~end_=3) +let fillRangeInPlace2 = Js.Array2.fillRangeInPlace([1, 2, 3, 4], 0, ~start=1, ~end_=3) + +let pop1 = [1, 2, 3]->Js.Array2.pop +let pop2 = Js.Array2.pop([1, 2, 3]) + +let reverseInPlace1 = [1, 2, 3]->Js.Array2.reverseInPlace +let reverseInPlace2 = Js.Array2.reverseInPlace([1, 2, 3]) + +let concat1 = [1, 2]->Js.Array2.concat([3, 4]) +let concat2 = Js.Array2.concat([1, 2], [3, 4]) + +let concatMany1 = [1, 2]->Js.Array2.concatMany([[3, 4], [5, 6]]) +let concatMany2 = Js.Array2.concatMany([1, 2], [[3, 4], [5, 6]]) + +let includes1 = [1, 2, 3]->Js.Array2.includes(2) +let includes2 = Js.Array2.includes([1, 2, 3], 2) + +let indexOf1 = [1, 2, 3]->Js.Array2.indexOf(2) +let indexOf2 = Js.Array2.indexOf([1, 2, 3], 2) + +let indexOfFrom1 = [1, 2, 1, 3]->Js.Array2.indexOfFrom(1, ~from=2) +let indexOfFrom2 = Js.Array2.indexOfFrom([1, 2, 1, 3], 1, ~from=2) + +let joinWith1 = [1, 2, 3]->Js.Array2.joinWith(",") +let joinWith2 = Js.Array2.joinWith([1, 2, 3], ",") + +let lastIndexOf1 = [1, 2, 1, 3]->Js.Array2.lastIndexOf(1) +let lastIndexOf2 = Js.Array2.lastIndexOf([1, 2, 1, 3], 1) + +let lastIndexOfFrom1 = [1, 2, 1, 3, 1]->Js.Array2.lastIndexOfFrom(1, ~from=3) +let lastIndexOfFrom2 = Js.Array2.lastIndexOfFrom([1, 2, 1, 3, 1], 1, ~from=3) + +let copy1 = [1, 2, 3]->Js.Array2.copy +let copy2 = Js.Array2.copy([1, 2, 3]) + +let sliceFrom1 = [1, 2, 3, 4]->Js.Array2.sliceFrom(2) +let sliceFrom2 = Js.Array2.sliceFrom([1, 2, 3, 4], 2) + +let toString1 = [1, 2, 3]->Js.Array2.toString +let toString2 = Js.Array2.toString([1, 2, 3]) + +let toLocaleString1 = [1, 2, 3]->Js.Array2.toLocaleString +let toLocaleString2 = Js.Array2.toLocaleString([1, 2, 3]) + +let every1 = [2, 4, 6]->Js.Array2.every(x => mod(x, 2) == 0) +let every2 = Js.Array2.every([2, 4, 6], x => mod(x, 2) == 0) + +let everyi1 = [0, 1, 2]->Js.Array2.everyi((x, i) => x == i) +let everyi2 = Js.Array2.everyi([0, 1, 2], (x, i) => x == i) + +let filter1 = [1, 2, 3, 4]->Js.Array2.filter(x => x > 2) +let filter2 = Js.Array2.filter([1, 2, 3, 4], x => x > 2) + +let filteri1 = [0, 1, 2, 3]->Js.Array2.filteri((_x, i) => i > 1) +let filteri2 = Js.Array2.filteri([0, 1, 2, 3], (_x, i) => i > 1) + +let find1 = [1, 2, 3, 4]->Js.Array2.find(x => x > 2) +let find2 = Js.Array2.find([1, 2, 3, 4], x => x > 2) + +let findi1 = [0, 1, 2, 3]->Js.Array2.findi((_x, i) => i > 1) +let findi2 = Js.Array2.findi([0, 1, 2, 3], (_x, i) => i > 1) + +let findIndex1 = [1, 2, 3, 4]->Js.Array2.findIndex(x => x > 2) +let findIndex2 = Js.Array2.findIndex([1, 2, 3, 4], x => x > 2) + +let findIndexi1 = [0, 1, 2, 3]->Js.Array2.findIndexi((_x, i) => i > 1) +let findIndexi2 = Js.Array2.findIndexi([0, 1, 2, 3], (_x, i) => i > 1) + +let forEach1 = [1, 2, 3]->Js.Array2.forEach(x => ignore(x)) +let forEach2 = Js.Array2.forEach([1, 2, 3], x => ignore(x)) + +let forEachi1 = [1, 2, 3]->Js.Array2.forEachi((x, i) => ignore(x + i)) +let forEachi2 = Js.Array2.forEachi([1, 2, 3], (x, i) => ignore(x + i)) + +let map1 = [1, 2, 3]->Js.Array2.map(x => x * 2) +let map2 = Js.Array2.map([1, 2, 3], x => x * 2) + +let mapi1 = [1, 2, 3]->Js.Array2.mapi((x, i) => x + i) +let mapi2 = Js.Array2.mapi([1, 2, 3], (x, i) => x + i) + +let some1 = [1, 2, 3, 4]->Js.Array2.some(x => x > 3) +let some2 = Js.Array2.some([1, 2, 3, 4], x => x > 3) + +let somei1 = [0, 1, 2, 3]->Js.Array2.somei((_x, i) => i > 2) +let somei2 = Js.Array2.somei([0, 1, 2, 3], (_x, i) => i > 2) + +let unsafeGet1 = [1, 2, 3]->Js.Array2.unsafe_get(1) +let unsafeGet2 = Js.Array2.unsafe_get([1, 2, 3], 1) + +let unsafeSet1 = [1, 2, 3]->Js.Array2.unsafe_set(1, 5) +let unsafeSet2 = Js.Array2.unsafe_set([1, 2, 3], 1, 5) + +let copyWithin1 = [1, 2, 3, 4, 5]->Js.Array2.copyWithin(~to_=2) +let copyWithin2 = Js.Array2.copyWithin([1, 2, 3, 4, 5], ~to_=2) + +let copyWithinFrom1 = [1, 2, 3, 4, 5]->Js.Array2.copyWithinFrom(~to_=0, ~from=2) +let copyWithinFrom2 = Js.Array2.copyWithinFrom([1, 2, 3, 4, 5], ~to_=0, ~from=2) + +let copyWithinFromRange1 = + [1, 2, 3, 4, 5, 6]->Js.Array2.copyWithinFromRange(~to_=1, ~start=2, ~end_=5) +let copyWithinFromRange2 = Js.Array2.copyWithinFromRange( + [1, 2, 3, 4, 5, 6], + ~to_=1, + ~start=2, + ~end_=5, +) + +let push1 = [1, 2, 3]->Js.Array2.push(4) +let push2 = Js.Array2.push([1, 2, 3], 4) + +let pushMany1 = [1, 2, 3]->Js.Array2.pushMany([4, 5]) +let pushMany2 = Js.Array2.pushMany([1, 2, 3], [4, 5]) + +let sortInPlace1 = ["c", "a", "b"]->Js.Array2.sortInPlace +let sortInPlace2 = Js.Array2.sortInPlace(["c", "a", "b"]) + +let unshift1 = [1, 2, 3]->Js.Array2.unshift(4) +let unshift2 = Js.Array2.unshift([1, 2, 3], 4) + +let unshiftMany1 = [1, 2, 3]->Js.Array2.unshiftMany([4, 5]) +let unshiftMany2 = Js.Array2.unshiftMany([1, 2, 3], [4, 5]) + +let reduce1 = [1, 2, 3]->Js.Array2.reduce((acc, x) => acc + x, 0) +let reduce2 = Js.Array2.reduce([1, 2, 3], (acc, x) => acc + x, 0) + +let spliceInPlace1 = [1, 2, 3]->Js.Array2.spliceInPlace(~pos=1, ~remove=1, ~add=[4, 5]) +let spliceInPlace2 = Js.Array2.spliceInPlace([1, 2, 3], ~pos=1, ~remove=1, ~add=[4, 5]) + +let removeFromInPlace1 = [1, 2, 3]->Js.Array2.removeFromInPlace(~pos=1) +let removeFromInPlace2 = Js.Array2.removeFromInPlace([1, 2, 3], ~pos=1) + +let removeCountInPlace1 = [1, 2, 3]->Js.Array2.removeCountInPlace(~pos=1, ~count=1) +let removeCountInPlace2 = Js.Array2.removeCountInPlace([1, 2, 3], ~pos=1, ~count=1) + +let reducei1 = [1, 2, 3]->Js.Array2.reducei((acc, x, i) => acc + x + i, 0) +let reducei2 = Js.Array2.reducei([1, 2, 3], (acc, x, i) => acc + x + i, 0) + +let reduceRight1 = [1, 2, 3]->Js.Array2.reduceRight((acc, x) => acc + x, 0) +let reduceRight2 = Js.Array2.reduceRight([1, 2, 3], (acc, x) => acc + x, 0) + +let reduceRighti1 = [1, 2, 3]->Js.Array2.reduceRighti((acc, x, i) => acc + x + i, 0) +let reduceRighti2 = Js.Array2.reduceRighti([1, 2, 3], (acc, x, i) => acc + x + i, 0) + +let pipeChain = + [1, 2, 3] + ->Js.Array2.map(x => x * 2) + ->Js.Array2.filter(x => x > 2) + ->Js.Array2.reduce((acc, x) => acc + x, 0) + +// Type alias migrations +let arrT: Js.Array.t = [1, 2, 3] +let arr2T: Js.Array2.t = [1, 2, 3] diff --git a/tests/tools_tests/src/migrate/StdlibMigration_BigInt.res b/tests/tools_tests/src/migrate/StdlibMigration_BigInt.res new file mode 100644 index 0000000000..4503044abc --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_BigInt.res @@ -0,0 +1,48 @@ +let fromStringExn1 = "123"->Js.BigInt.fromStringExn +let fromStringExn2 = Js.BigInt.fromStringExn("123") + +let land1 = 7n->Js.BigInt.land(4n) +let land2 = Js.BigInt.land(7n, 4n) +let land3 = 7n->Js.BigInt.toString->Js.BigInt.fromStringExn->Js.BigInt.land(4n) + +let lor1 = 7n->Js.BigInt.lor(4n) +let lor2 = Js.BigInt.lor(7n, 4n) + +let lxor1 = 7n->Js.BigInt.lxor(4n) +let lxor2 = Js.BigInt.lxor(7n, 4n) + +let lnot1 = 2n->Js.BigInt.lnot +let lnot2 = Js.BigInt.lnot(2n) + +let lsl1 = 4n->Js.BigInt.lsl(1n) +let lsl2 = Js.BigInt.lsl(4n, 1n) + +let asr1 = 8n->Js.BigInt.asr(1n) +let asr2 = Js.BigInt.asr(8n, 1n) + +let toString1 = 123n->Js.BigInt.toString +let toString2 = Js.BigInt.toString(123n) + +let toLocaleString1 = 123n->Js.BigInt.toLocaleString +let toLocaleString2 = Js.BigInt.toLocaleString(123n) + +// From the stdlib module +let stdlib_fromStringExn1 = "123"->BigInt.fromStringExn +let stdlib_fromStringExn2 = BigInt.fromStringExn("123") + +let stdlib_land1 = 7n->BigInt.land(4n) +let stdlib_land2 = BigInt.land(7n, 4n) + +let stdlib_lor1 = BigInt.lor(7n, 4n) + +let stdlib_lxor1 = 7n->BigInt.lxor(4n) +let stdlib_lxor2 = BigInt.lxor(7n, 4n) + +let stdlib_lnot1 = 2n->BigInt.lnot +let stdlib_lnot2 = BigInt.lnot(2n) + +let stdlib_lsl1 = 4n->BigInt.lsl(1n) +let stdlib_lsl2 = BigInt.lsl(4n, 1n) + +let stdlib_asr1 = 8n->BigInt.asr(1n) +let stdlib_asr2 = BigInt.asr(8n, 1n) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Console.res b/tests/tools_tests/src/migrate/StdlibMigration_Console.res new file mode 100644 index 0000000000..0e142a0575 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Console.res @@ -0,0 +1,28 @@ +let log = Js_console.log("Hello, World!") +let log2 = Js_console.log2("Hello", "World") +let log3 = Js_console.log3("Hello", "World", "!") +let log4 = Js_console.log4("Hello", "World", "!", "!") +let logMany = Js_console.logMany(["Hello", "World"]) + +let info = Js_console.info("Hello, World!") +let info2 = Js_console.info2("Hello", "World") +let info3 = Js_console.info3("Hello", "World", "!") +let info4 = Js_console.info4("Hello", "World", "!", "!") +let infoMany = Js_console.infoMany(["Hello", "World"]) + +let warn = Js_console.warn("Hello, World!") +let warn2 = Js_console.warn2("Hello", "World") +let warn3 = Js_console.warn3("Hello", "World", "!") +let warn4 = Js_console.warn4("Hello", "World", "!", "!") +let warnMany = Js_console.warnMany(["Hello", "World"]) + +let error = Js_console.error("Hello, World!") +let error2 = Js_console.error2("Hello", "World") +let error3 = Js_console.error3("Hello", "World", "!") +let error4 = Js_console.error4("Hello", "World", "!", "!") +let errorMany = Js_console.errorMany(["Hello", "World"]) + +let trace = Js_console.trace() +let timeStart = Js_console.timeStart("Hello, World!") +let timeEnd = Js_console.timeEnd("Hello, World!") +let table = Js_console.table(["Hello", "World"]) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_DataView.res b/tests/tools_tests/src/migrate/StdlibMigration_DataView.res new file mode 100644 index 0000000000..21a9969b72 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_DataView.res @@ -0,0 +1,2 @@ +let a = DataView.fromBufferToEnd(ArrayBuffer.make(8), ~byteOffset=2) +let b = DataView.fromBufferWithRange(ArrayBuffer.make(8), ~byteOffset=2, ~length=4) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Date.res b/tests/tools_tests/src/migrate/StdlibMigration_Date.res new file mode 100644 index 0000000000..5621f35480 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Date.res @@ -0,0 +1,139 @@ +let d1 = Js.Date.make() +let d2 = Js.Date.fromString("1973-11-29T21:30:54.321Z") +let d3 = Js.Date.fromFloat(123456789.0) + +let msNow = Js.Date.now() + +let v1 = d2->Js.Date.valueOf +let v2 = Js.Date.valueOf(d2) + +let y = d2->Js.Date.getFullYear +let mo = d2->Js.Date.getMonth +let dayOfMonth = d2->Js.Date.getDate +let dayOfWeek = d2->Js.Date.getDay +let h = d2->Js.Date.getHours +let mi = d2->Js.Date.getMinutes +let s = d2->Js.Date.getSeconds +let ms = d2->Js.Date.getMilliseconds +let tz = d2->Js.Date.getTimezoneOffset + +let uy = d2->Js.Date.getUTCFullYear +let um = d2->Js.Date.getUTCMonth +let ud = d2->Js.Date.getUTCDate +let uday = d2->Js.Date.getUTCDay +let uh = d2->Js.Date.getUTCHours +let umi = d2->Js.Date.getUTCMinutes +let us = d2->Js.Date.getUTCSeconds +let ums = d2->Js.Date.getUTCMilliseconds + +let s1 = d2->Js.Date.toISOString +let s2 = d2->Js.Date.toUTCString +let s3 = d2->Js.Date.toString +let s4 = d2->Js.Date.toTimeString +let s5 = d2->Js.Date.toDateString +let s6 = d2->Js.Date.toLocaleString +let s7 = d2->Js.Date.toLocaleDateString +let s8 = d2->Js.Date.toLocaleTimeString + +/* Additional deprecated APIs to exercise migration */ + +/* getters and legacy variants */ +let t = d2->Js.Date.getTime +let y2 = d2->Js.Date.getYear + +/* constructors with components */ +let mym = Js.Date.makeWithYM(~year=2020.0, ~month=10.0, ()) +let mymd = Js.Date.makeWithYMD(~year=1973.0, ~month=10.0, ~date=29.0, ()) +let mymdh = Js.Date.makeWithYMDH(~year=1973.0, ~month=10.0, ~date=29.0, ~hours=21.0, ()) +let mymdhm = Js.Date.makeWithYMDHM( + ~year=1973.0, + ~month=10.0, + ~date=29.0, + ~hours=21.0, + ~minutes=30.0, + (), +) +let mymdhms = Js.Date.makeWithYMDHMS( + ~year=1973.0, + ~month=10.0, + ~date=29.0, + ~hours=21.0, + ~minutes=30.0, + ~seconds=54.0, + (), +) + +/* Date.UTC variants */ +let uym = Js.Date.utcWithYM(~year=2020.0, ~month=10.0, ()) +let uymd = Js.Date.utcWithYMD(~year=1973.0, ~month=10.0, ~date=29.0, ()) +let uymdh = Js.Date.utcWithYMDH(~year=1973.0, ~month=10.0, ~date=29.0, ~hours=21.0, ()) +let uymdhm = Js.Date.utcWithYMDHM( + ~year=1973.0, + ~month=10.0, + ~date=29.0, + ~hours=21.0, + ~minutes=30.0, + (), +) +let uymdhms = Js.Date.utcWithYMDHMS( + ~year=1973.0, + ~month=10.0, + ~date=29.0, + ~hours=21.0, + ~minutes=30.0, + ~seconds=54.0, + (), +) + +/* parse APIs */ +let p = Js.Date.parse("1973-11-29T21:30:54.321Z") +let pf = Js.Date.parseAsFloat("1973-11-29T21:30:54.321Z") + +/* setters (local time) */ +let setD = d2->Js.Date.setDate(15.0) +let setFY = d2->Js.Date.setFullYear(1974.0) + +let setFYM = d2->Js.Date.setFullYearM(~year=1974.0, ~month=0.0, ()) +let setFYMD = d2->Js.Date.setFullYearMD(~year=1974.0, ~month=0.0, ~date=7.0, ()) +let setH = d2->Js.Date.setHours(22.0) +let setHM = d2->Js.Date.setHoursM(~hours=22.0, ~minutes=46.0, ()) +let setHMS = d2->Js.Date.setHoursMS(~hours=22.0, ~minutes=46.0, ~seconds=37.0, ()) +let setHMSMs = + d2->Js.Date.setHoursMSMs(~hours=22.0, ~minutes=46.0, ~seconds=37.0, ~milliseconds=494.0, ()) +let setMs = d2->Js.Date.setMilliseconds(494.0) +let setMin = d2->Js.Date.setMinutes(34.0) +let setMinS = d2->Js.Date.setMinutesS(~minutes=34.0, ~seconds=56.0, ()) +let setMinSMs = d2->Js.Date.setMinutesSMs(~minutes=34.0, ~seconds=56.0, ~milliseconds=789.0, ()) +let setMon = d2->Js.Date.setMonth(11.0) +let setMonD = d2->Js.Date.setMonthD(~month=11.0, ~date=8.0, ()) +let setSec = d2->Js.Date.setSeconds(56.0) +let setSecMs = d2->Js.Date.setSecondsMs(~seconds=56.0, ~milliseconds=789.0, ()) + +/* setters (UTC) */ +let setUD = d2->Js.Date.setUTCDate(15.0) +let setUFY = d2->Js.Date.setUTCFullYear(1974.0) +let setUFYM = d2->Js.Date.setUTCFullYearM(~year=1974.0, ~month=0.0, ()) +let setUFYMD = d2->Js.Date.setUTCFullYearMD(~year=1974.0, ~month=0.0, ~date=7.0, ()) +let setUH = d2->Js.Date.setUTCHours(22.0) +let setUHM = d2->Js.Date.setUTCHoursM(~hours=22.0, ~minutes=46.0, ()) +let setUHMS = d2->Js.Date.setUTCHoursMS(~hours=22.0, ~minutes=46.0, ~seconds=37.0, ()) +let setUHMSMs = + d2->Js.Date.setUTCHoursMSMs(~hours=22.0, ~minutes=46.0, ~seconds=37.0, ~milliseconds=494.0, ()) +let setUMs = d2->Js.Date.setUTCMilliseconds(494.0) +let setUMin = d2->Js.Date.setUTCMinutes(34.0) +let setUMinS = d2->Js.Date.setUTCMinutesS(~minutes=34.0, ~seconds=56.0, ()) +let setUMinSMs = d2->Js.Date.setUTCMinutesSMs(~minutes=34.0, ~seconds=56.0, ~milliseconds=789.0, ()) +let setUMon = d2->Js.Date.setUTCMonth(11.0) +let setUMonD = d2->Js.Date.setUTCMonthD(~month=11.0, ~date=8.0, ()) +let setUSec = d2->Js.Date.setUTCSeconds(56.0) +let setUSecMs = d2->Js.Date.setUTCSecondsMs(~seconds=56.0, ~milliseconds=789.0, ()) +let setUT = d2->Js.Date.setUTCTime(198765432101.0) +let setYr = d2->Js.Date.setYear(1999.0) + +/* other string conversions */ +let s9 = d2->Js.Date.toGMTString +let j1 = d2->Js.Date.toJSON +let j2 = d2->Js.Date.toJSONUnsafe + +// Type alias migration +external someDate: Js.Date.t = "someDate" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Dict.res b/tests/tools_tests/src/migrate/StdlibMigration_Dict.res new file mode 100644 index 0000000000..b0f00cd7cb --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Dict.res @@ -0,0 +1,33 @@ +let d = Js.Dict.empty() + +let get1 = d->Js.Dict.get("k") +let get2 = Js.Dict.get(d, "k") + +let unsafeGet1 = d->Js.Dict.unsafeGet("k") +let unsafeGet2 = Js.Dict.unsafeGet(d, "k") + +let set1 = d->Js.Dict.set("k", 1) +let set2 = Js.Dict.set(d, "k", 1) + +let keys1 = d->Js.Dict.keys +let keys2 = Js.Dict.keys(d) + +let values1 = d->Js.Dict.values +let values2 = Js.Dict.values(d) + +let entries1 = d->Js.Dict.entries +let entries2 = Js.Dict.entries(d) + +let dStr: Js.Dict.t = Js.Dict.empty() +let del1 = dStr->Js.Dict.unsafeDeleteKey("k") +let del2 = Js.Dict.unsafeDeleteKey(dStr, "k") + +let empty1: Js.Dict.t = Js.Dict.empty() + +let fromArray1 = [("a", 1), ("b", 2)]->Js.Dict.fromArray +let fromArray2 = Js.Dict.fromArray([("a", 1), ("b", 2)]) + +let fromList1 = list{("a", 1), ("b", 2)}->Js.Dict.fromList +let fromList2 = Js.Dict.fromList(list{("a", 1), ("b", 2)}) + +let map2 = Js.Dict.map(x => x + 1, d) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Error.res b/tests/tools_tests/src/migrate/StdlibMigration_Error.res new file mode 100644 index 0000000000..b4cf75855e --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Error.res @@ -0,0 +1,34 @@ +// Use deprecated Error APIs to validate migration to JsError/JsExn + +external someExn: exn = "whatever" + +let fromExn1 = someExn->Error.fromException +let fromExn2 = Error.fromException(someExn) + +let err = Error.make("Some message here") + +let stack1 = err->Error.stack +let stack2 = Error.stack(err) + +let message1 = err->Error.message +let message2 = Error.message(err) + +let name1 = err->Error.name +let name2 = Error.name(err) + +let fileName1 = err->Error.fileName +let fileName2 = Error.fileName(err) + +// Type alias migration +let errT: Error.t = Error.make("Another message") + +// Sub-error constructors +let evalErr = Error.EvalError.make("eval error") +let rangeErr = Error.RangeError.make("range error") +let refErr = Error.ReferenceError.make("reference error") +let synErr = Error.SyntaxError.make("syntax error") +let typeErr = Error.TypeError.make("type error") +let uriErr = Error.URIError.make("uri error") + +let ignore1 = err->Error.ignore +let ignore2 = Error.ignore(err) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Exn.res b/tests/tools_tests/src/migrate/StdlibMigration_Exn.res new file mode 100644 index 0000000000..dcc9ea3591 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Exn.res @@ -0,0 +1,40 @@ +// Use deprecated Exn APIs to validate migration to JsExn/JsError + +external someExn: exn = "whatever" +external someJsExn: Exn.t = "whatever" + +// fromException (asJsExn) +let fromExn1 = someExn->Exn.asJsExn +let fromExn2 = Exn.asJsExn(someExn) + +// Property accessors on Exn.t +let stack1 = someJsExn->Exn.stack +let stack2 = Exn.stack(someJsExn) + +let message1 = someJsExn->Exn.message +let message2 = Exn.message(someJsExn) + +let name1 = someJsExn->Exn.name +let name2 = Exn.name(someJsExn) + +let fileName1 = someJsExn->Exn.fileName +let fileName2 = Exn.fileName(someJsExn) + +// Type alias migration +let exnT: Exn.t = someJsExn + +// anyToExnInternal +let _coerced = Exn.anyToExnInternal(1) + +// ignore +let ignore1 = someJsExn->Exn.ignore +let ignore2 = Exn.ignore(someJsExn) + +// Raise helpers +let throws1 = () => Exn.raiseError("err") +let throws2 = () => Exn.raiseEvalError("err") +let throws3 = () => Exn.raiseRangeError("err") +let throws4 = () => Exn.raiseReferenceError("err") +let throws5 = () => Exn.raiseSyntaxError("err") +let throws6 = () => Exn.raiseTypeError("err") +let throws7 = () => Exn.raiseUriError("err") diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Extern.res b/tests/tools_tests/src/migrate/StdlibMigration_Extern.res new file mode 100644 index 0000000000..3ff65d4bba --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Extern.res @@ -0,0 +1,6 @@ +// Exercise migrations from Js_extern to new Stdlib APIs + +let isNullish = Js_extern.testAny(%raw("null")) +let n = Js_extern.null +let u = Js_extern.undefined +let ty = Js_extern.typeof("hello") diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Float.res b/tests/tools_tests/src/migrate/StdlibMigration_Float.res new file mode 100644 index 0000000000..e87cfb0e5c --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Float.res @@ -0,0 +1,34 @@ +let nan1 = Js.Float._NaN + +let isNaN1 = Js.Float._NaN->Js.Float.isNaN +let isNaN2 = Js.Float.isNaN(Js.Float._NaN) + +let isFinite1 = 1234.0->Js.Float.isFinite +let isFinite2 = Js.Float.isFinite(1234.0) + +let toExponential1 = 77.1234->Js.Float.toExponential +let toExponential2 = Js.Float.toExponential(77.1234) + +let toExponentialWithPrecision1 = 77.1234->Js.Float.toExponentialWithPrecision(~digits=2) +let toExponentialWithPrecision2 = Js.Float.toExponentialWithPrecision(77.1234, ~digits=2) + +let toFixed1 = 12345.6789->Js.Float.toFixed +let toFixed2 = Js.Float.toFixed(12345.6789) + +let toFixedWithPrecision1 = 12345.6789->Js.Float.toFixedWithPrecision(~digits=1) +let toFixedWithPrecision2 = Js.Float.toFixedWithPrecision(12345.6789, ~digits=1) + +let toPrecision1 = 12345.6789->Js.Float.toPrecision +let toPrecision2 = Js.Float.toPrecision(12345.6789) + +let toPrecisionWithPrecision1 = 12345.6789->Js.Float.toPrecisionWithPrecision(~digits=2) +let toPrecisionWithPrecision2 = Js.Float.toPrecisionWithPrecision(12345.6789, ~digits=2) + +let toString1 = 12345.6789->Js.Float.toString +let toString2 = Js.Float.toString(12345.6789) + +let toStringWithRadix1 = 6.0->Js.Float.toStringWithRadix(~radix=2) +let toStringWithRadix2 = Js.Float.toStringWithRadix(6.0, ~radix=2) + +let parse1 = "123"->Js.Float.fromString +let parse2 = Js.Float.fromString("123") diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Global.res b/tests/tools_tests/src/migrate/StdlibMigration_Global.res new file mode 100644 index 0000000000..e15828838b --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Global.res @@ -0,0 +1,15 @@ +let t1: Js.Global.timeoutId = Js.Global.setTimeout(() => (), 1000) +let t2: Js.Global.timeoutId = Js.Global.setTimeoutFloat(() => (), 1000.0) + +Js.Global.clearTimeout(t1) + +let i1: Js.Global.intervalId = Js.Global.setInterval(() => (), 2000) +let i2: Js.Global.intervalId = Js.Global.setIntervalFloat(() => (), 2000.0) + +Js.Global.clearInterval(i1) + +let e1 = Js.Global.encodeURI("https://rescript-lang.org?array=[someValue]") +let d1 = Js.Global.decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D") + +let e2 = Js.Global.encodeURIComponent("array=[someValue]") +let d2 = Js.Global.decodeURIComponent("array%3D%5BsomeValue%5D") diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Int.res b/tests/tools_tests/src/migrate/StdlibMigration_Int.res new file mode 100644 index 0000000000..b76172c1a1 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Int.res @@ -0,0 +1,7 @@ +let result1 = Int.Bitwise.land(1, 2) +let result2 = Int.Bitwise.lor(1, 2) +let result3 = Int.Bitwise.lxor(1, 2) +let result4 = Int.Bitwise.lsl(1, 2) +let result5 = Int.Bitwise.lsr(1, 2) +let result6 = Int.Bitwise.asr(1, 2) +let result7 = Int.Bitwise.lnot(0) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Interface.res b/tests/tools_tests/src/migrate/StdlibMigration_Interface.res new file mode 100644 index 0000000000..acb6e7ed5c --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Interface.res @@ -0,0 +1,8 @@ +/* Implementation to satisfy interface build for tests */ + +external arr: Js.Array.t = "arr" +external reT: Js.Re.t = "re" +external json: Js.Json.t = "json" +external nestedArr: Js.Array.t = "nestedArr" + +external useSet: Js.Set.t => unit = "useSet" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Interface.resi b/tests/tools_tests/src/migrate/StdlibMigration_Interface.resi new file mode 100644 index 0000000000..f9c987eea5 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Interface.resi @@ -0,0 +1,10 @@ +/* Migration tests for interface (.resi) files using stdlib deprecations */ + +// Type alias migrations exercised via externals +external arr: Js.Array.t = "arr" +external reT: Js.Re.t = "re" +external json: Js.Json.t = "json" +external nestedArr: Js.Array.t = "nestedArr" + +// Function type using a deprecated alias +external useSet: Js.Set.t => unit = "useSet" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_JSON.res b/tests/tools_tests/src/migrate/StdlibMigration_JSON.res new file mode 100644 index 0000000000..ae75c80b96 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_JSON.res @@ -0,0 +1,26 @@ +external someJson: Js_json.t = "someJson" +external strToJson: string => Js_json.t = "strToJson" + +let decodeString1 = someJson->Js_json.decodeString +let decodeString2 = Js_json.decodeString(someJson) +let decodeString3 = + [1, 2, 3] + ->Array.map(v => v->Int.toString) + ->Array.join(" ") + ->strToJson + ->Js_json.decodeString + +let decodeNumber1 = someJson->Js_json.decodeNumber +let decodeNumber2 = Js_json.decodeNumber(someJson) + +let decodeObject1 = someJson->Js_json.decodeObject +let decodeObject2 = Js_json.decodeObject(someJson) + +let decodeArray1 = someJson->Js_json.decodeArray +let decodeArray2 = Js_json.decodeArray(someJson) + +let decodeBoolean1 = someJson->Js_json.decodeBoolean +let decodeBoolean2 = Js_json.decodeBoolean(someJson) + +let decodeNull1 = someJson->Js_json.decodeNull +let decodeNull2 = Js_json.decodeNull(someJson) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_JSON_Stdlib.res b/tests/tools_tests/src/migrate/StdlibMigration_JSON_Stdlib.res new file mode 100644 index 0000000000..70f0686c61 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_JSON_Stdlib.res @@ -0,0 +1,14 @@ +let p1 = JSON.parseExn("{}", ~reviver=(_k, v) => v) +let p2 = JSON.parseExnWithReviver("{}", (_k, v) => v) + +let s1 = JSON.stringifyWithIndent(JSON.Object(dict{}), 2) +let s2 = JSON.stringifyWithReplacer(JSON.Number(1.), (_k, v) => v) +let s3 = JSON.stringifyWithReplacerAndIndent(JSON.Boolean(true), (_k, v) => v, 2) +let s4 = JSON.stringifyWithFilter(JSON.Array([JSON.Number(1.)]), ["a"]) +let s5 = JSON.stringifyWithFilterAndIndent(JSON.Array([JSON.Number(1.)]), ["a"], 2) + +let a1 = JSON.stringifyAnyWithIndent(1, 2) +let a2 = JSON.stringifyAnyWithReplacer(1, (_k, v) => v) +let a3 = JSON.stringifyAnyWithReplacerAndIndent(1, (_k, v) => v, 2) +let a4 = JSON.stringifyAnyWithFilter(1, ["a"]) +let a5 = JSON.stringifyAnyWithFilterAndIndent(1, ["a"], 2) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js.res b/tests/tools_tests/src/migrate/StdlibMigration_Js.res new file mode 100644 index 0000000000..39deedf002 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js.res @@ -0,0 +1,5 @@ +let consoleLog1 = Js.log("Hello") +let consoleLog2 = Js.log2("Hello", "World") +let consoleLog3 = Js.log3("Hello", "World", "!") +let consoleLog4 = Js.log4("Hello", "World", "!", "!") +let consoleLogMany = Js.logMany(["Hello", "World"]) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_Array.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_Array.res new file mode 100644 index 0000000000..76dbf95b97 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_Array.res @@ -0,0 +1,33 @@ +// Migration tests for Js.Array (old) -> Array module + +external someArrayLike: Js_array.array_like = "whatever" + +let from1 = someArrayLike->Js.Array.from +let from2 = Js.Array.from(someArrayLike) + +let fromMap1 = someArrayLike->Js.Array.fromMap(s => s ++ "!") +let fromMap2 = Js.Array.fromMap(someArrayLike, s => s ++ "!") + +let isArray1 = [1, 2, 3]->Js.Array.isArray +let isArray2 = Js.Array.isArray([1, 2, 3]) + +let length1 = [1, 2, 3]->Js.Array.length +let length2 = Js.Array.length([1, 2, 3]) + +let pop1 = [1, 2, 3]->Js.Array.pop +let pop2 = Js.Array.pop([1, 2, 3]) + +let reverseInPlace1 = [1, 2, 3]->Js.Array.reverseInPlace +let reverseInPlace2 = Js.Array.reverseInPlace([1, 2, 3]) + +let shift1 = [1, 2, 3]->Js.Array.shift +let shift2 = Js.Array.shift([1, 2, 3]) + +let toString1 = [1, 2, 3]->Js.Array.toString +let toString2 = Js.Array.toString([1, 2, 3]) + +let toLocaleString1 = [1, 2, 3]->Js.Array.toLocaleString +let toLocaleString2 = Js.Array.toLocaleString([1, 2, 3]) + +// Type alias migration +let arrT: Js.Array.t = [1, 2, 3] diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_Int.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_Int.res new file mode 100644 index 0000000000..b120c23691 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_Int.res @@ -0,0 +1,23 @@ +let toExponential1 = 77->Js.Int.toExponential +let toExponential2 = Js.Int.toExponential(77) + +let toExponentialWithPrecision1 = 77->Js.Int.toExponentialWithPrecision(~digits=2) +let toExponentialWithPrecision2 = Js.Int.toExponentialWithPrecision(77, ~digits=2) + +let toPrecision1 = 123456789->Js.Int.toPrecision +let toPrecision2 = Js.Int.toPrecision(123456789) + +let toPrecisionWithPrecision1 = 123456789->Js.Int.toPrecisionWithPrecision(~digits=2) +let toPrecisionWithPrecision2 = Js.Int.toPrecisionWithPrecision(123456789, ~digits=2) + +let toString1 = 123456789->Js.Int.toString +let toString2 = Js.Int.toString(123456789) + +let toStringWithRadix1 = 373592855->Js.Int.toStringWithRadix(~radix=16) +let toStringWithRadix2 = Js.Int.toStringWithRadix(373592855, ~radix=16) + +let toFloat1 = 42->Js.Int.toFloat +let toFloat2 = Js.Int.toFloat(42) + +let equal1 = Js.Int.equal(1, 1) +let equal2 = 1->Js.Int.equal(2) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_More.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_More.res new file mode 100644 index 0000000000..f589739aa5 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_More.res @@ -0,0 +1,7 @@ +// Migration tests for new deprecations in packages/@rescript/runtime/Js.res + +// typeof migration +let tyNum = Js.typeof(1) + +// nullToOption +let nToOpt = Js.nullToOption(Js.Null.return(1)) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_Re.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_Re.res new file mode 100644 index 0000000000..818abba994 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_Re.res @@ -0,0 +1,50 @@ +let re1 = Js.Re.fromString("foo") +let re2 = Js.Re.fromStringWithFlags("foo", ~flags="gi") + +let flags1 = re2->Js.Re.flags +let flags2 = Js.Re.flags(re2) + +let g1 = re2->Js.Re.global +let g2 = Js.Re.global(re2) + +let ic1 = re2->Js.Re.ignoreCase +let ic2 = Js.Re.ignoreCase(re2) + +let m1 = re2->Js.Re.multiline +let m2 = Js.Re.multiline(re2) + +let u1 = re2->Js.Re.unicode +let u2 = Js.Re.unicode(re2) + +let y1 = re2->Js.Re.sticky +let y2 = Js.Re.sticky(re2) + +let src1 = re2->Js.Re.source +let src2 = Js.Re.source(re2) + +let li1 = re2->Js.Re.lastIndex +let () = re2->Js.Re.setLastIndex(0) + +let exec1 = re2->Js.Re.exec_("Foo bar") +let exec2 = Js.Re.exec_(re2, "Foo bar") + +let test1 = re2->Js.Re.test_("Foo bar") +let test2 = Js.Re.test_(re2, "Foo bar") + +// Type alias migration +external reT: Js.Re.t = "re" + +let matches_access = switch re2->Js.Re.exec_("Foo bar") { +| None => 0 +| Some(r) => Js.Re.matches(r)->Array.length +} + +let result_index = switch re2->Js.Re.exec_("Foo bar") { +| None => 0 +| Some(r) => Js.Re.index(r) +} + +let result_input = switch re2->Js.Re.exec_("Foo bar") { +| None => "" +| Some(r) => Js.Re.input(r) +} diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_String.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_String.res new file mode 100644 index 0000000000..67f8145323 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_String.res @@ -0,0 +1,43 @@ +// Migration tests for Js.String (old) -> String module + +let make1 = 1->Js.String.make +let make2 = Js.String.make(1) + +let fromCharCode1 = 65->Js.String.fromCharCode +let fromCharCode2 = Js.String.fromCharCode(65) + +let fromCharCodeMany1 = [65, 66, 67]->Js.String.fromCharCodeMany +let fromCharCodeMany2 = Js.String.fromCharCodeMany([65, 66, 67]) + +let fromCodePoint1 = 65->Js.String.fromCodePoint +let fromCodePoint2 = Js.String.fromCodePoint(65) + +let fromCodePointMany1 = [65, 66, 67]->Js.String.fromCodePointMany +let fromCodePointMany2 = Js.String.fromCodePointMany([65, 66, 67]) + +let length1 = "abcde"->Js.String.length +let length2 = Js.String.length("abcde") + +let get1 = "abcde"->Js.String.get(2) +let get2 = Js.String.get("abcde", 2) + +let normalize1 = "abcde"->Js.String.normalize +let normalize2 = Js.String.normalize("abcde") + +let toLowerCase1 = "ABCDE"->Js.String.toLowerCase +let toLowerCase2 = Js.String.toLowerCase("ABCDE") + +let toUpperCase1 = "abcde"->Js.String.toUpperCase +let toUpperCase2 = Js.String.toUpperCase("abcde") + +let toLocaleLowerCase1 = "ABCDE"->Js.String.toLocaleLowerCase +let toLocaleLowerCase2 = Js.String.toLocaleLowerCase("ABCDE") + +let toLocaleUpperCase1 = "abcde"->Js.String.toLocaleUpperCase +let toLocaleUpperCase2 = Js.String.toLocaleUpperCase("abcde") + +let trim1 = " abcde "->Js.String.trim +let trim2 = Js.String.trim(" abcde ") + +// Type alias migration +let sT: Js.String.t = "abc" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_Types_Interface.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_Types_Interface.res new file mode 100644 index 0000000000..01bd0b8f48 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_Types_Interface.res @@ -0,0 +1,9 @@ +/* Implementation to satisfy interface build for tests */ + +external nullT: Js.null = "nullT" +external nullableT: Js.nullable = "nullableT" +external nullUndefT: Js.null_undefined = "nullUndefT" + +external symbolT: Js.Types.symbol = "symbolT" +external objValT: Js.Types.obj_val = "objValT" +external functionValT: Js.Types.function_val = "functionValT" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_Types_Interface.resi b/tests/tools_tests/src/migrate/StdlibMigration_Js_Types_Interface.resi new file mode 100644 index 0000000000..541b256025 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_Types_Interface.resi @@ -0,0 +1,11 @@ +/* Migration tests for Js.res type deprecations */ + +// Type alias migrations exercised via externals +external nullT: Js.null = "nullT" +external nullableT: Js.nullable = "nullableT" +external nullUndefT: Js.null_undefined = "nullUndefT" + +// Js.Types migrations +external symbolT: Js.Types.symbol = "symbolT" +external objValT: Js.Types.obj_val = "objValT" +external functionValT: Js.Types.function_val = "functionValT" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_Undefined.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_Undefined.res new file mode 100644 index 0000000000..66cc08ae7c --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_Undefined.res @@ -0,0 +1,35 @@ +let make1 = "hello"->Js.Undefined.return +let make2 = Js.Undefined.return("hello") + +let empty1 = Js.Undefined.empty + +let getUnsafe1 = Js.Undefined.return(1)->Js.Undefined.getUnsafe +let getUnsafe2 = Js.Undefined.getUnsafe(Js.Undefined.return(1)) + +let getExn1 = Js.Undefined.return(1)->Js.Undefined.getExn +let getExn2 = Js.Undefined.getExn(Js.Undefined.return(1)) + +let map1 = Js.Undefined.return(2)->Js.Undefined.bind(x => x + 1) +let map2 = Js.Undefined.bind(Js.Undefined.return(2), x => x + 1) + +let forEach1 = Js.Undefined.return(2)->Js.Undefined.iter(x => ignore(x)) +let forEach2 = Js.Undefined.iter(Js.Undefined.return(2), x => ignore(x)) + +let fromOption1 = Some("x")->Js.Undefined.fromOption +let fromOption2 = Js.Undefined.fromOption(None) + +let from_opt1 = Some("y")->Js.Undefined.from_opt +let from_opt2 = Js.Undefined.from_opt(None) + +let toOption1 = Js.Undefined.return(3)->Js.Undefined.toOption +let toOption2 = Js.Undefined.toOption(Js.Undefined.return(3)) + +let to_opt1 = Js.Undefined.return(4)->Js.Undefined.to_opt +let to_opt2 = Js.Undefined.to_opt(Js.Undefined.return(4)) + +let test1 = Js.Undefined.empty->Js.Undefined.test +let test2 = Js.Undefined.test(Js.Undefined.empty) +let test3 = Js.Undefined.return(5)->Js.Undefined.bind(v => v)->Js.Undefined.test + +let testAny1 = Js.Undefined.testAny(Js.Undefined.empty) +let testAny2 = Js.Undefined.empty->Js.Undefined.testAny diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array.res new file mode 100644 index 0000000000..fbc29713c2 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array.res @@ -0,0 +1,7 @@ +let arr1 = Js.Typed_array.Int8Array.make([1, 2, 3]) + +let len = arr1->Js.Typed_array.Int8Array.length + +let bytes = Js.Typed_array.Int8Array._BYTES_PER_ELEMENT +let off = Js.Typed_array.Int8Array.fromBufferOffset(ArrayBuffer.make(8), 2) +let range = Js.Typed_array.Int8Array.fromBufferRange(ArrayBuffer.make(8), ~offset=2, ~length=2) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array2.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array2.res new file mode 100644 index 0000000000..636d79123a --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array2.res @@ -0,0 +1,22 @@ +let arr = Js.TypedArray2.Int8Array.make([1, 2, 3]) + +let len1 = arr->Js.TypedArray2.Int8Array.length +let includes1 = arr->Js.TypedArray2.Int8Array.includes(2) +let idxFrom1 = arr->Js.TypedArray2.Int8Array.indexOfFrom(2, ~from=1) + +let slice1 = arr->Js.TypedArray2.Int8Array.slice(~start=1, ~end_=2) +let sliceFrom1 = arr->Js.TypedArray2.Int8Array.sliceFrom(1) + +let map1 = arr->Js.TypedArray2.Int8Array.map(x => x + 1) +let reduce1 = arr->Js.TypedArray2.Int8Array.reduce((acc, x) => acc + x, 0) + +let bytes = Js.TypedArray2.Int8Array._BYTES_PER_ELEMENT + +let fromBufToEnd = Js.TypedArray2.Int8Array.fromBufferOffset(ArrayBuffer.make(8), 2) +let fromBufRange = Js.TypedArray2.Int8Array.fromBufferRange( + ArrayBuffer.make(8), + ~offset=2, + ~length=2, +) + +let fromLength = Js.TypedArray2.Int8Array.fromLength(3) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array2_Float32.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array2_Float32.res new file mode 100644 index 0000000000..f7b4d6fa5d --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array2_Float32.res @@ -0,0 +1,22 @@ +let arr = Js.TypedArray2.Float32Array.make([1.0, 2.0, 3.0]) + +let len1 = arr->Js.TypedArray2.Float32Array.length +let includes1 = arr->Js.TypedArray2.Float32Array.includes(2.0) +let idxFrom1 = arr->Js.TypedArray2.Float32Array.indexOfFrom(2.0, ~from=1) + +let slice1 = arr->Js.TypedArray2.Float32Array.slice(~start=1, ~end_=2) +let sliceFrom1 = arr->Js.TypedArray2.Float32Array.sliceFrom(1) + +let map1 = arr->Js.TypedArray2.Float32Array.map(x => x +. 1.0) +let reduce1 = arr->Js.TypedArray2.Float32Array.reduce((acc, x) => acc +. x, 0.0) + +let bytes = Js.TypedArray2.Float32Array._BYTES_PER_ELEMENT + +let fromBufToEnd = Js.TypedArray2.Float32Array.fromBufferOffset(ArrayBuffer.make(8), 2) +let fromBufRange = Js.TypedArray2.Float32Array.fromBufferRange( + ArrayBuffer.make(8), + ~offset=2, + ~length=2, +) + +let fromLength = Js.TypedArray2.Float32Array.fromLength(3) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array_Float32_Const.res b/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array_Float32_Const.res new file mode 100644 index 0000000000..f541cfdeaf --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Js_typed_array_Float32_Const.res @@ -0,0 +1,2 @@ +// Float32 constants migration coverage for legacy Js.Typed_array +let bytesF32 = Js.Typed_array.Float32Array._BYTES_PER_ELEMENT diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Map.res b/tests/tools_tests/src/migrate/StdlibMigration_Map.res new file mode 100644 index 0000000000..942aea0246 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Map.res @@ -0,0 +1,2 @@ +// Type alias migration for Js.Map.t +external m: Js.Map.t = "m" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Math.res b/tests/tools_tests/src/migrate/StdlibMigration_Math.res new file mode 100644 index 0000000000..4d9e9427bc --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Math.res @@ -0,0 +1,81 @@ +// Exercise migrations from Js.Math to Math + +let e = Js.Math._E +let pi = Js.Math._PI +let ln2 = Js.Math._LN2 +let ln10 = Js.Math._LN10 +let log2e = Js.Math._LOG2E +let log10e = Js.Math._LOG10E +let sqrt_half = Js.Math._SQRT1_2 +let sqrt2c = Js.Math._SQRT2 + +let absInt1 = Js.Math.abs_int(-5) +let absFloat1 = Js.Math.abs_float(-3.5) + +let acos1 = Js.Math.acos(1.0) +let acosh1 = Js.Math.acosh(1.5) +let asinh1 = Js.Math.asinh(1.0) +let asin1 = Js.Math.asin(0.5) +let atan1 = Js.Math.atan(1.0) +let atanh1 = Js.Math.atanh(0.5) + +let atan21 = Js.Math.atan2(~y=0.0, ~x=10.0, ()) + +let cbrt1 = Js.Math.cbrt(27.0) + +let ceilInt1 = Js.Math.unsafe_ceil_int(3.2) +let ceilInt2 = Js.Math.unsafe_ceil_int(3.2) +let ceilFloat1 = Js.Math.ceil_float(3.2) + +let clz1 = Js.Math.clz32(255) + +let cos1 = Js.Math.cos(0.0) +let cosh1 = Js.Math.cosh(0.0) +let exp1 = Js.Math.exp(1.0) +let expm11 = Js.Math.expm1(1.0) +let log1p1 = Js.Math.log1p(1.0) + +let floorInt1 = Js.Math.unsafe_floor_int(3.7) +let floorInt2 = Js.Math.unsafe_floor_int(3.7) +let floorFloat1 = Js.Math.floor_float(3.7) + +let fround1 = Js.Math.fround(5.05) + +let hypot1 = Js.Math.hypot(3.0, 4.0) +let hypotMany1 = Js.Math.hypotMany([3.0, 4.0, 12.0]) + +let imul1 = Js.Math.imul(3, 4) + +let log1 = Js.Math.log(Js.Math._E) +let log10_1 = Js.Math.log10(1000.0) +let log2_1 = Js.Math.log2(512.0) + +let maxInt1 = Js.Math.max_int(1, 2) +let maxIntMany1 = Js.Math.maxMany_int([1, 10, 3]) +let maxFloat1 = Js.Math.max_float(1.5, 2.5) +let maxFloatMany1 = Js.Math.maxMany_float([1.5, 2.5, 0.5]) + +let minInt1 = Js.Math.min_int(1, 2) +let minIntMany1 = Js.Math.minMany_int([1, 10, 3]) +let minFloat1 = Js.Math.min_float(1.5, 2.5) +let minFloatMany1 = Js.Math.minMany_float([1.5, 2.5, 0.5]) + +let powInt1 = Js.Math.pow_int(~base=3, ~exp=4) +let powFloat1 = Js.Math.pow_float(~base=3.0, ~exp=4.0) + +let rand1 = Js.Math.random() + +let roundUnsafe1 = Js.Math.unsafe_round(3.7) +let round1 = Js.Math.round(3.7) + +let signInt1 = Js.Math.sign_int(-5) +let signFloat1 = Js.Math.sign_float(-5.0) + +let sin1 = Js.Math.sin(0.0) +let sinh1 = Js.Math.sinh(0.0) +let sqrt1 = Js.Math.sqrt(9.0) +let tan1 = Js.Math.tan(0.5) +let tanh1 = Js.Math.tanh(0.0) + +let truncUnsafe1 = Js.Math.unsafe_trunc(3.7) +let trunc1 = Js.Math.trunc(3.7) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Null.res b/tests/tools_tests/src/migrate/StdlibMigration_Null.res new file mode 100644 index 0000000000..f88c148f5c --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Null.res @@ -0,0 +1,35 @@ +let make1 = "hello"->Js.Null.return +let make2 = Js.Null.return("hello") + +let empty1 = Js.Null.empty + +let getUnsafe1 = Js.Null.return(1)->Js.Null.getUnsafe +let getUnsafe2 = Js.Null.getUnsafe(Js.Null.return(1)) + +let getExn1 = Js.Null.return(1)->Js.Null.getExn +let getExn2 = Js.Null.getExn(Js.Null.return(1)) + +let map1 = Js.Null.return(2)->Js.Null.bind(x => x + 1) +let map2 = Js.Null.bind(Js.Null.return(2), x => x + 1) + +let forEach1 = Js.Null.return(2)->Js.Null.iter(x => ignore(x)) +let forEach2 = Js.Null.iter(Js.Null.return(2), x => ignore(x)) + +let fromOption1 = Some("x")->Js.Null.fromOption +let fromOption2 = Js.Null.fromOption(None) + +let from_opt1 = Some("y")->Js.Null.from_opt +let from_opt2 = Js.Null.from_opt(None) + +let toOption1 = Js.Null.return(3)->Js.Null.toOption +let toOption2 = Js.Null.toOption(Js.Null.return(3)) + +let to_opt1 = Js.Null.return(4)->Js.Null.to_opt +let to_opt2 = Js.Null.to_opt(Js.Null.return(4)) + +let test1 = Js.Null.empty->Js.Null.test +let test2 = Js.Null.test(Js.Null.empty) +let test3 = Js.Null.return(5)->Js.Null.bind(v => v)->Js.Null.test + +// Type alias migration +let nullT: Js.Null.t = Js.Null.return(1) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Nullable.res b/tests/tools_tests/src/migrate/StdlibMigration_Nullable.res new file mode 100644 index 0000000000..e709b1b41d --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Nullable.res @@ -0,0 +1,34 @@ +let make1 = "hello"->Js.Null_undefined.return +let make2 = Js.Null_undefined.return("hello") + +let null1 = Js.Null_undefined.null +let undefined1 = Js.Null_undefined.undefined + +let isNullable1 = Js.Null_undefined.null->Js.Null_undefined.isNullable +let isNullable2 = Js.Null_undefined.isNullable(Js.Null_undefined.null) + +let map1 = Js.Null_undefined.return(2)->Js.Null_undefined.bind(x => x + 1) +let map2 = Js.Null_undefined.bind(Js.Null_undefined.return(2), x => x + 1) + +let forEach1 = Js.Null_undefined.return(2)->Js.Null_undefined.iter(x => ignore(x)) +let forEach2 = Js.Null_undefined.iter(Js.Null_undefined.return(2), x => ignore(x)) + +let fromOption1 = Some("x")->Js.Null_undefined.fromOption +let fromOption2 = Js.Null_undefined.fromOption(None) + +let from_opt1 = Some("y")->Js.Null_undefined.from_opt +let from_opt2 = Js.Null_undefined.from_opt(None) + +let toOption1 = Js.Null_undefined.return(3)->Js.Null_undefined.toOption +let toOption2 = Js.Null_undefined.toOption(Js.Null_undefined.return(3)) + +let to_opt1 = Js.Null_undefined.return(4)->Js.Null_undefined.to_opt +let to_opt2 = Js.Null_undefined.to_opt(Js.Null_undefined.return(4)) + +let optArrayOfNullableToOptArrayOfOpt: option>> => option< + array>, +> = x => + switch x { + | None => None + | Some(arr) => Some(arr->Belt.Array.map(Js.Nullable.toOption)) + } diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Obj.res b/tests/tools_tests/src/migrate/StdlibMigration_Obj.res new file mode 100644 index 0000000000..b7ecb2e6cb --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Obj.res @@ -0,0 +1,7 @@ +let empty1 = Js.Obj.empty() + +let assign1 = Js.Obj.empty()->Js.Obj.assign({"a": 1}) +let assign2 = Js.Obj.assign(Js.Obj.empty(), {"a": 1}) + +let keys1 = {"a": 1, "b": 2}->Js.Obj.keys +let keys2 = Js.Obj.keys({"a": 1, "b": 2}) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Option.res b/tests/tools_tests/src/migrate/StdlibMigration_Option.res new file mode 100644 index 0000000000..b781219ed3 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Option.res @@ -0,0 +1,33 @@ +let someCall = Js.Option.some(3) +let somePiped = 3->Js.Option.some + +let isSome1 = Some(1)->Js.Option.isSome +let isSome2 = Js.Option.isSome(None) + +let isNone1 = None->Js.Option.isNone +let isNone2 = Js.Option.isNone(Some(2)) + +let eq = (a: int, b: int) => a == b +// let isSomeValue1 = Js.Option.isSomeValue(eq, 2, Some(2)) + +let getExn1 = Js.Option.getExn(Some(3)) +let getExn2 = Some(3)->Js.Option.getExn + +let equal1 = Js.Option.equal(eq, Some(2), Some(2)) + +let f = (x: int) => x > 0 ? Some(x + 1) : None +let andThen1 = Js.Option.andThen(f, Some(2)) + +let map1 = Js.Option.map(x => x * 2, Some(2)) + +let getWithDefault1 = Js.Option.getWithDefault(0, Some(2)) + +let default1 = Js.Option.default(0, Some(2)) + +let filter1 = Js.Option.filter(x => x > 0, Some(1)) + +let firstSome1 = Js.Option.firstSome(Some(1), None) +let firstSome2 = Some(1)->Js.Option.firstSome(None) + +// Type alias migration +let optT: Js.Option.t = Some(1) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Pervasives.res b/tests/tools_tests/src/migrate/StdlibMigration_Pervasives.res new file mode 100644 index 0000000000..fe8195cbc8 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Pervasives.res @@ -0,0 +1 @@ +raise(Failure("test")) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Promise.res b/tests/tools_tests/src/migrate/StdlibMigration_Promise.res new file mode 100644 index 0000000000..29f244c002 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Promise.res @@ -0,0 +1,39 @@ +let p1 = Js.Promise.resolve(1) +let p2 = Js.Promise.reject(Failure("err")) + +let all1 = Js.Promise.all([Js.Promise.resolve(1), Js.Promise.resolve(2)]) +let all2 = Js.Promise.all2((Js.Promise.resolve(1), Js.Promise.resolve(2))) +let all3 = Js.Promise.all3((Js.Promise.resolve(1), Js.Promise.resolve(2), Js.Promise.resolve(3))) +let all4 = Js.Promise.all4(( + Js.Promise.resolve(1), + Js.Promise.resolve(2), + Js.Promise.resolve(3), + Js.Promise.resolve(4), +)) +let all5 = Js.Promise.all5(( + Js.Promise.resolve(1), + Js.Promise.resolve(2), + Js.Promise.resolve(3), + Js.Promise.resolve(4), + Js.Promise.resolve(5), +)) +let all6 = Js.Promise.all6(( + Js.Promise.resolve(1), + Js.Promise.resolve(2), + Js.Promise.resolve(3), + Js.Promise.resolve(4), + Js.Promise.resolve(5), + Js.Promise.resolve(6), +)) + +let race1 = Js.Promise.race([Js.Promise.resolve(10), Js.Promise.resolve(20)]) + +// let thenPipe = Js.Promise.resolve(1)->Js.Promise.then_(x => Js.Promise.resolve(x + 1), _) +// let thenDirect = Js.Promise.then_(x => Js.Promise.resolve(x + 1), Js.Promise.resolve(1)) + +// Type alias migration +external p: Js.Promise.t = "p" + +// let catchPipe = Js.Promise.resolve(1)->Js.Promise.catch(_e => Js.Promise.resolve(0), _) +// let catchDirect = Js.Promise.catch(_e => Js.Promise.resolve(0), Js.Promise.resolve(1)) +let make1 = Js.Promise.make((~resolve, ~reject) => resolve(1)) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Promise2.res b/tests/tools_tests/src/migrate/StdlibMigration_Promise2.res new file mode 100644 index 0000000000..bb47a1e595 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Promise2.res @@ -0,0 +1,46 @@ +let p1 = Js.Promise2.resolve(1) +let _p2 = Js.Promise2.reject(Failure("err")) + +let all1 = Js.Promise2.all([Js.Promise2.resolve(1), Js.Promise2.resolve(2)]) +let all2 = Js.Promise2.all2((Js.Promise2.resolve(1), Js.Promise2.resolve(2))) +let all3 = Js.Promise2.all3(( + Js.Promise2.resolve(1), + Js.Promise2.resolve(2), + Js.Promise2.resolve(3), +)) + +let all4 = Js.Promise2.all4(( + Js.Promise2.resolve(1), + Js.Promise2.resolve(2), + Js.Promise2.resolve(3), + Js.Promise2.resolve(4), +)) +let all5 = Js.Promise2.all5(( + Js.Promise2.resolve(1), + Js.Promise2.resolve(2), + Js.Promise2.resolve(3), + Js.Promise2.resolve(4), + Js.Promise2.resolve(5), +)) +let all6 = Js.Promise2.all6(( + Js.Promise2.resolve(1), + Js.Promise2.resolve(2), + Js.Promise2.resolve(3), + Js.Promise2.resolve(4), + Js.Promise2.resolve(5), + Js.Promise2.resolve(6), +)) + +let race1 = Js.Promise2.race([Js.Promise2.resolve(10), Js.Promise2.resolve(20)]) + +let thenPipe = Js.Promise2.resolve(1)->Js.Promise2.then(x => Js.Promise2.resolve(x + 1)) +let thenDirect = Js.Promise2.then(Js.Promise2.resolve(1), x => Js.Promise2.resolve(x + 1)) + +// Type alias migration +external p2: Js.Promise2.t = "p2" + +let catchPipe = Js.Promise2.resolve(1)->Js.Promise2.catch(_e => Js.Promise2.resolve(0)) +let catchDirect = Js.Promise2.catch(Js.Promise2.resolve(1), _e => Js.Promise2.resolve(0)) +let make1 = Js.Promise2.make((~resolve, ~reject as _) => resolve(1)) + +let _ = p2->Js.Promise2.then(x => Js.Promise2.resolve(x + 1)) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Result.res b/tests/tools_tests/src/migrate/StdlibMigration_Result.res new file mode 100644 index 0000000000..ed79392944 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Result.res @@ -0,0 +1,2 @@ +type r = Js.Result.t +let res: Js.Result.t = Ok(1) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_Set.res b/tests/tools_tests/src/migrate/StdlibMigration_Set.res new file mode 100644 index 0000000000..f8818cde87 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_Set.res @@ -0,0 +1,2 @@ +// Type alias migration for Js.Set.t +external s: Js.Set.t = "s" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_StdlibArray.res b/tests/tools_tests/src/migrate/StdlibMigration_StdlibArray.res new file mode 100644 index 0000000000..c54b9d4781 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_StdlibArray.res @@ -0,0 +1,20 @@ +let ba1 = [1, 2, 3, 4, 5]->Array.copyAllWithin(~target=2) +let ba2 = Array.copyAllWithin([1, 2, 3, 4, 5], ~target=2) + +let b1 = [1, 2, 3, 4]->Array.copyWithinToEnd(~target=0, ~start=2) +let b2 = Array.copyWithinToEnd([1, 2, 3, 4], ~target=0, ~start=2) + +let c1 = [1, 2, 3]->Array.fillAll(0) +let c2 = [1, 2, 3, 4]->Array.fillToEnd(9, ~start=1) + +let d1 = [1, 2, 1, 2]->Array.indexOfFrom(2, 2) +let d2 = Array.indexOfFrom([1, 2, 1, 2], 2, 2) + +let e1 = ["a", "b"]->Array.joinWith("-") +let e2 = [1, 2]->Array.joinWithUnsafe(",") + +let f1 = [1, 2, 3, 4]->Array.sliceToEnd(~start=2) + +let g1 = [1, 2]->Array.lastIndexOfFrom(1, 1) + +let h1 = [1, 2]->Array.unsafe_get(1) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_StdlibListLazyPromise.res b/tests/tools_tests/src/migrate/StdlibMigration_StdlibListLazyPromise.res new file mode 100644 index 0000000000..a1b091ee23 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_StdlibListLazyPromise.res @@ -0,0 +1,13 @@ +let l1 = List.headExn(list{1}) +let l2 = List.tailExn(list{1}) +let l3 = List.getExn(list{"a", "b"}, 0) +let l4 = List.toShuffled(list{1, 2}) + +let lazy1 = Lazy.from_fun(() => 1) +let lazy2 = Lazy.from_val(2) +let v1 = Lazy.force(lazy1) +let v2 = Lazy.force_val(lazy2) +let b1 = Lazy.is_val(lazy1) + +let p = Promise.resolve(5) +let _ = Promise.done(p) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_StdlibOptionResultNull.res b/tests/tools_tests/src/migrate/StdlibMigration_StdlibOptionResultNull.res new file mode 100644 index 0000000000..119d8fcb4a --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_StdlibOptionResultNull.res @@ -0,0 +1,15 @@ +let o1 = Option.getExn(Some(3)) +let o2 = Option.mapWithDefault(Some(3), 0, x => x + 1) +let o3 = Option.getWithDefault(None, 0) + +let r1 = Result.getExn(Ok(1)) +let r2 = Result.mapWithDefault(Ok(1), 0, x => x + 1) +let r3 = Result.getWithDefault(Error("e"), 0) + +let n1 = Null.getExn(Null.make(3)) +let n2 = Null.getWithDefault(Null.null, 0) +let n3 = Null.mapWithDefault(Null.make(3), 0, x => x) + +let nb1 = Nullable.getExn(Nullable.make(3)) +let nb2 = Nullable.getWithDefault(Nullable.null, 0) +let nb3 = Nullable.mapWithDefault(Nullable.make(3), 0, x => x) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_StdlibPrimitives.res b/tests/tools_tests/src/migrate/StdlibMigration_StdlibPrimitives.res new file mode 100644 index 0000000000..d3ef05d364 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_StdlibPrimitives.res @@ -0,0 +1,18 @@ +let i1 = Int.toExponentialWithPrecision(77, ~digits=2) +let i2 = Int.toFixedWithPrecision(300, ~digits=1) +let i3 = Int.toPrecisionWithPrecision(100, ~digits=2) +let i4 = Int.toStringWithRadix(6, ~radix=2) +let i5 = Int.rangeWithOptions(1, 5, {step: 2}) + +let f1 = Float.parseIntWithRadix("10.0", ~radix=2) +let f2 = Float.toExponentialWithPrecision(77.0, ~digits=2) +let f3 = Float.toFixedWithPrecision(300.0, ~digits=1) +let f4 = Float.toPrecisionWithPrecision(100.0, ~digits=2) +let f5 = Float.toStringWithRadix(6.0, ~radix=2) + +let b1 = Bool.fromStringExn("true") + +let buf = ArrayBuffer.make(8) +let ab1 = buf->ArrayBuffer.sliceToEnd(~start=2) + +let re1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") diff --git a/tests/tools_tests/src/migrate/StdlibMigration_StdlibString.res b/tests/tools_tests/src/migrate/StdlibMigration_StdlibString.res new file mode 100644 index 0000000000..bffbb86235 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_StdlibString.res @@ -0,0 +1,37 @@ +let s1 = "abcde"->String.sliceToEnd(~start=1) +let s2 = "abcde"->String.substringToEnd(~start=1) + +let r0 = + "vowels"->String.unsafeReplaceRegExpBy0(/a|e|i|o|u/g, (~match, ~offset as _, ~input as _) => + match + ) +let r1 = + "Jony is 40"->String.unsafeReplaceRegExpBy1(/(Jony is )\d+/g, ( + ~match as _, + ~group1, + ~offset as _, + ~input as _, + ) => group1) + +let r2 = "7 times 6"->String.unsafeReplaceRegExpBy2(/(\d+) times (\d+)/, ( + ~match as _, + ~group1, + ~group2, + ~offset as _, + ~input as _, +) => + switch (Int.fromString(group1), Int.fromString(group2)) { + | (Some(x), Some(y)) => Int.toString(x * y) + | _ => "???" + } +) + +let r3 = + "abc"->String.unsafeReplaceRegExpBy3(/(a)(b)(c)/, ( + ~match as _, + ~group1, + ~group2, + ~group3, + ~offset as _, + ~input as _, + ) => group1 ++ group2 ++ group3) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_String.res b/tests/tools_tests/src/migrate/StdlibMigration_String.res new file mode 100644 index 0000000000..edf01733c7 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_String.res @@ -0,0 +1,129 @@ +let make1 = 1->Js.String2.make +let make2 = Js.String2.make(1) + +let fromCharCode1 = 65->Js.String2.fromCharCode +let fromCharCode2 = Js.String2.fromCharCode(65) + +let fromCharCodeMany1 = [65, 66, 67]->Js.String2.fromCharCodeMany +let fromCharCodeMany2 = Js.String2.fromCharCodeMany([65, 66, 67]) + +let fromCodePoint1 = 65->Js.String2.fromCodePoint +let fromCodePoint2 = Js.String2.fromCodePoint(65) + +let fromCodePointMany1 = [65, 66, 67]->Js.String2.fromCodePointMany +let fromCodePointMany2 = Js.String2.fromCodePointMany([65, 66, 67]) + +let length1 = "abcde"->Js.String2.length +let length2 = Js.String2.length("abcde") + +let get1 = "abcde"->Js.String2.get(2) +let get2 = Js.String2.get("abcde", 2) + +let charAt1 = "abcde"->Js.String2.charAt(2) +let charAt2 = Js.String2.charAt("abcde", 2) + +let charCodeAt1 = "abcde"->Js.String2.charCodeAt(2) +let charCodeAt2 = Js.String2.charCodeAt("abcde", 2) + +let codePointAt1 = "abcde"->Js.String2.codePointAt(2) +let codePointAt2 = Js.String2.codePointAt("abcde", 2) + +let concat1 = "abcde"->Js.String2.concat("fghij") +let concat2 = Js.String2.concat("abcde", "fghij") + +let concatMany1 = "abcde"->Js.String2.concatMany(["fghij", "klmno"]) +let concatMany2 = Js.String2.concatMany("abcde", ["fghij", "klmno"]) + +let endsWith1 = "abcde"->Js.String2.endsWith("de") +let endsWith2 = Js.String2.endsWith("abcde", "de") + +let endsWithFrom1 = "abcde"->Js.String2.endsWithFrom("d", 2) +let endsWithFrom2 = Js.String2.endsWithFrom("abcde", "d", 2) + +let includes1 = "abcde"->Js.String2.includes("de") +let includes2 = Js.String2.includes("abcde", "de") + +let includesFrom1 = "abcde"->Js.String2.includesFrom("d", 2) +let includesFrom2 = Js.String2.includesFrom("abcde", "d", 2) + +let indexOf1 = "abcde"->Js.String2.indexOf("de") +let indexOf2 = Js.String2.indexOf("abcde", "de") + +let indexOfFrom1 = "abcde"->Js.String2.indexOfFrom("d", 2) +let indexOfFrom2 = Js.String2.indexOfFrom("abcde", "d", 2) + +let lastIndexOf1 = "abcde"->Js.String2.lastIndexOf("de") +let lastIndexOf2 = Js.String2.lastIndexOf("abcde", "de") + +let lastIndexOfFrom1 = "abcde"->Js.String2.lastIndexOfFrom("d", 2) +let lastIndexOfFrom2 = Js.String2.lastIndexOfFrom("abcde", "d", 2) + +let localeCompare1 = "abcde"->Js.String2.localeCompare("fghij") +let localeCompare2 = Js.String2.localeCompare("abcde", "fghij") + +let match1 = "abcde"->Js.String2.match_(/d/) +let match2 = Js.String2.match_("abcde", /d/) + +let normalize1 = "abcde"->Js.String2.normalize +let normalize2 = Js.String2.normalize("abcde") + +let repeat1 = "abcde"->Js.String2.repeat(2) +let repeat2 = Js.String2.repeat("abcde", 2) + +let replace1 = "abcde"->Js.String2.replace("d", "f") +let replace2 = Js.String2.replace("abcde", "d", "f") + +let replaceByRe1 = "abcde"->Js.String2.replaceByRe(/d/, "f") +let replaceByRe2 = Js.String2.replaceByRe("abcde", /d/, "f") + +let search1 = "abcde"->Js.String2.search(/d/) +let search2 = Js.String2.search("abcde", /d/) + +let slice1 = "abcde"->Js.String2.slice(~from=1, ~to_=3) +let slice2 = Js.String2.slice("abcde", ~from=1, ~to_=3) + +let sliceToEnd1 = "abcde"->Js.String2.sliceToEnd(~from=1) +let sliceToEnd2 = Js.String2.sliceToEnd("abcde", ~from=1) + +let split1 = "abcde"->Js.String2.split("d") +let split2 = Js.String2.split("abcde", "d") + +let splitAtMost1 = "abcde"->Js.String2.splitAtMost("d", ~limit=2) +let splitAtMost2 = Js.String2.splitAtMost("abcde", "d", ~limit=2) + +let splitByRe1 = "abcde"->Js.String2.splitByRe(/d/) +let splitByRe2 = Js.String2.splitByRe("abcde", /d/) + +let splitByReAtMost1 = "abcde"->Js.String2.splitByReAtMost(/d/, ~limit=2) +let splitByReAtMost2 = Js.String2.splitByReAtMost("abcde", /d/, ~limit=2) + +let startsWith1 = "abcde"->Js.String2.startsWith("ab") +let startsWith2 = Js.String2.startsWith("abcde", "ab") + +let startsWithFrom1 = "abcde"->Js.String2.startsWithFrom("b", 1) +let startsWithFrom2 = Js.String2.startsWithFrom("abcde", "b", 1) + +let substring1 = "abcde"->Js.String2.substring(~from=1, ~to_=3) +let substring2 = Js.String2.substring("abcde", ~from=1, ~to_=3) + +let substringToEnd1 = "abcde"->Js.String2.substringToEnd(~from=1) +let substringToEnd2 = Js.String2.substringToEnd("abcde", ~from=1) + +let toLowerCase1 = "abcde"->Js.String2.toLowerCase +let toLowerCase2 = Js.String2.toLowerCase("abcde") + +let toLocaleLowerCase1 = "abcde"->Js.String2.toLocaleLowerCase +let toLocaleLowerCase2 = Js.String2.toLocaleLowerCase("abcde") + +let toUpperCase1 = "abcde"->Js.String2.toUpperCase +let toUpperCase2 = Js.String2.toUpperCase("abcde") + +let toLocaleUpperCase1 = "abcde"->Js.String2.toLocaleUpperCase +let toLocaleUpperCase2 = Js.String2.toLocaleUpperCase("abcde") + +let trim1 = "abcde"->Js.String2.trim +let trim2 = Js.String2.trim("abcde") + +// Type alias migrations +let sT: Js.String.t = "abc" +let s2T: Js.String2.t = "def" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_TypedArray_Operations.res b/tests/tools_tests/src/migrate/StdlibMigration_TypedArray_Operations.res new file mode 100644 index 0000000000..1be692eae0 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_TypedArray_Operations.res @@ -0,0 +1,6 @@ +let ta = Uint8Array.fromArray([1, 2, 3, 4]) + +let a1 = ta->TypedArray.copyWithinToEnd(~target=1, ~start=2) +let a2 = ta->TypedArray.fillToEnd(9, ~start=1) +let a3 = ta->TypedArray.sliceToEnd(~start=1) +let a4 = ta->TypedArray.subarrayToEnd(~start=1) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_TypedArray_Stdlib.res b/tests/tools_tests/src/migrate/StdlibMigration_TypedArray_Stdlib.res new file mode 100644 index 0000000000..10a4e6fb95 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_TypedArray_Stdlib.res @@ -0,0 +1,3 @@ +let a = Uint8Array.fromBufferToEnd(ArrayBuffer.make(8), ~byteOffset=2) +let b = Uint8Array.fromBufferWithRange(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) +let c = Uint8Array.fromArrayLikeOrIterableWithMap([1, 2], (v, _i) => v) diff --git a/tests/tools_tests/src/migrate/StdlibMigration_WeakMap.res b/tests/tools_tests/src/migrate/StdlibMigration_WeakMap.res new file mode 100644 index 0000000000..0b4cd98ad2 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_WeakMap.res @@ -0,0 +1,2 @@ +// Type alias migration for Js.WeakMap.t +external wm: Js.WeakMap.t<{..}, int> = "wm" diff --git a/tests/tools_tests/src/migrate/StdlibMigration_WeakSet.res b/tests/tools_tests/src/migrate/StdlibMigration_WeakSet.res new file mode 100644 index 0000000000..35d811fc18 --- /dev/null +++ b/tests/tools_tests/src/migrate/StdlibMigration_WeakSet.res @@ -0,0 +1,2 @@ +// Type alias migration for Js.WeakSet.t +external ws: Js.WeakSet.t<{..}> = "ws" diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Array.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Array.res new file mode 100644 index 0000000000..8349d0dfa5 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Array.res @@ -0,0 +1,177 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Array.res. +let shift1 = [1, 2, 3]->Array.shift +let shift2 = Array.shift([1, 2, 3]) + +let slice1 = [1, 2, 3]->Array.slice(~start=1, ~end=2) +let slice2 = Array.slice([1, 2, 3], ~start=1, ~end=2) + +external someArrayLike: Array.arrayLike = "whatever" + +let from1 = someArrayLike->Array.fromArrayLike +let from2 = Array.fromArrayLike(someArrayLike) + +let fromMap1 = someArrayLike->Array.fromArrayLikeWithMap(s => s ++ "!") +let fromMap2 = Array.fromArrayLikeWithMap(someArrayLike, s => s ++ "!") + +let isArray1 = [1, 2, 3]->Array.isArray +let isArray2 = Array.isArray([1, 2, 3]) + +let length1 = [1, 2, 3]->Array.length +let length2 = Array.length([1, 2, 3]) + +let fillInPlace1 = [1, 2, 3]->Array.fillAll(0) +let fillInPlace2 = Array.fillAll([1, 2, 3], 0) + +let fillFromInPlace1 = [1, 2, 3, 4]->Array.fillToEnd(0, ~start=2) +let fillFromInPlace2 = Array.fillToEnd([1, 2, 3, 4], 0, ~start=2) + +let fillRangeInPlace1 = [1, 2, 3, 4]->Array.fill(0, ~start=1, ~end=3) +let fillRangeInPlace2 = Array.fill([1, 2, 3, 4], 0, ~start=1, ~end=3) + +let pop1 = [1, 2, 3]->Array.pop +let pop2 = Array.pop([1, 2, 3]) + +let reverseInPlace1 = [1, 2, 3]->Array.reverse +let reverseInPlace2 = Array.reverse([1, 2, 3]) + +let concat1 = [1, 2]->Array.concat([3, 4]) +let concat2 = Array.concat([1, 2], [3, 4]) + +let concatMany1 = [1, 2]->Array.concatMany([[3, 4], [5, 6]]) +let concatMany2 = Array.concatMany([1, 2], [[3, 4], [5, 6]]) + +let includes1 = [1, 2, 3]->Array.includes(2) +let includes2 = Array.includes([1, 2, 3], 2) + +let indexOf1 = [1, 2, 3]->Array.indexOf(2) +let indexOf2 = Array.indexOf([1, 2, 3], 2) + +let indexOfFrom1 = [1, 2, 1, 3]->Array.indexOfFrom(1, 2) +let indexOfFrom2 = Array.indexOfFrom([1, 2, 1, 3], 1, 2) + +let joinWith1 = [1, 2, 3]->Array.joinUnsafe(",") +let joinWith2 = Array.joinUnsafe([1, 2, 3], ",") + +let lastIndexOf1 = [1, 2, 1, 3]->Array.lastIndexOf(1) +let lastIndexOf2 = Array.lastIndexOf([1, 2, 1, 3], 1) + +let lastIndexOfFrom1 = [1, 2, 1, 3, 1]->Array.lastIndexOfFrom(1, 3) +let lastIndexOfFrom2 = Array.lastIndexOfFrom([1, 2, 1, 3, 1], 1, 3) + +let copy1 = [1, 2, 3]->Array.copy +let copy2 = Array.copy([1, 2, 3]) + +let sliceFrom1 = [1, 2, 3, 4]->Array.slice(~start=2) +let sliceFrom2 = Array.slice([1, 2, 3, 4], ~start=2) + +let toString1 = [1, 2, 3]->Array.toString +let toString2 = Array.toString([1, 2, 3]) + +let toLocaleString1 = [1, 2, 3]->Array.toLocaleString +let toLocaleString2 = Array.toLocaleString([1, 2, 3]) + +let every1 = [2, 4, 6]->Array.every(x => mod(x, 2) == 0) +let every2 = Array.every([2, 4, 6], x => mod(x, 2) == 0) + +let everyi1 = [0, 1, 2]->Array.everyWithIndex((x, i) => x == i) +let everyi2 = Array.everyWithIndex([0, 1, 2], (x, i) => x == i) + +let filter1 = [1, 2, 3, 4]->Array.filter(x => x > 2) +let filter2 = Array.filter([1, 2, 3, 4], x => x > 2) + +let filteri1 = [0, 1, 2, 3]->Array.filterWithIndex((_x, i) => i > 1) +let filteri2 = Array.filterWithIndex([0, 1, 2, 3], (_x, i) => i > 1) + +let find1 = [1, 2, 3, 4]->Array.find(x => x > 2) +let find2 = Array.find([1, 2, 3, 4], x => x > 2) + +let findi1 = [0, 1, 2, 3]->Array.findWithIndex((_x, i) => i > 1) +let findi2 = Array.findWithIndex([0, 1, 2, 3], (_x, i) => i > 1) + +let findIndex1 = [1, 2, 3, 4]->Array.findIndex(x => x > 2) +let findIndex2 = Array.findIndex([1, 2, 3, 4], x => x > 2) + +let findIndexi1 = [0, 1, 2, 3]->Array.findIndexWithIndex((_x, i) => i > 1) +let findIndexi2 = Array.findIndexWithIndex([0, 1, 2, 3], (_x, i) => i > 1) + +let forEach1 = [1, 2, 3]->Array.forEach(x => ignore(x)) +let forEach2 = Array.forEach([1, 2, 3], x => ignore(x)) + +let forEachi1 = [1, 2, 3]->Array.forEachWithIndex((x, i) => ignore(x + i)) +let forEachi2 = Array.forEachWithIndex([1, 2, 3], (x, i) => ignore(x + i)) + +let map1 = [1, 2, 3]->Array.map(x => x * 2) +let map2 = Array.map([1, 2, 3], x => x * 2) + +let mapi1 = [1, 2, 3]->Array.mapWithIndex((x, i) => x + i) +let mapi2 = Array.mapWithIndex([1, 2, 3], (x, i) => x + i) + +let some1 = [1, 2, 3, 4]->Array.some(x => x > 3) +let some2 = Array.some([1, 2, 3, 4], x => x > 3) + +let somei1 = [0, 1, 2, 3]->Array.someWithIndex((_x, i) => i > 2) +let somei2 = Array.someWithIndex([0, 1, 2, 3], (_x, i) => i > 2) + +let unsafeGet1 = [1, 2, 3]->Array.getUnsafe(1) +let unsafeGet2 = Array.getUnsafe([1, 2, 3], 1) + +let unsafeSet1 = [1, 2, 3]->Array.setUnsafe(1, 5) +let unsafeSet2 = Array.setUnsafe([1, 2, 3], 1, 5) + +let copyWithin1 = [1, 2, 3, 4, 5]->Array.copyAllWithin(~target=2) +let copyWithin2 = Array.copyAllWithin([1, 2, 3, 4, 5], ~target=2) + +let copyWithinFrom1 = [1, 2, 3, 4, 5]->Array.copyWithinToEnd(~target=0, ~start=2) +let copyWithinFrom2 = Array.copyWithinToEnd([1, 2, 3, 4, 5], ~target=0, ~start=2) + +let copyWithinFromRange1 = [1, 2, 3, 4, 5, 6]->Array.copyWithin(~start=2, ~target=1, ~end=5) +let copyWithinFromRange2 = Array.copyWithin([1, 2, 3, 4, 5, 6], ~start=2, ~target=1, ~end=5) + +let push1 = [1, 2, 3]->Array.push(4) +let push2 = Array.push([1, 2, 3], 4) + +let pushMany1 = [1, 2, 3]->Array.pushMany([4, 5]) +let pushMany2 = Array.pushMany([1, 2, 3], [4, 5]) + +let sortInPlace1 = + ["c", "a", "b"]->Array.toSorted((_a, _b) => + %todo("This needs a comparator function. Use `String.compare` for strings, etc.") + ) +let sortInPlace2 = Array.toSorted(["c", "a", "b"], (_a, _b) => + %todo("This needs a comparator function. Use `String.compare` for strings, etc.") +) + +let unshift1 = [1, 2, 3]->Array.unshift(4) +let unshift2 = Array.unshift([1, 2, 3], 4) + +let unshiftMany1 = [1, 2, 3]->Array.unshiftMany([4, 5]) +let unshiftMany2 = Array.unshiftMany([1, 2, 3], [4, 5]) + +let reduce1 = [1, 2, 3]->Array.reduce(0, (acc, x) => acc + x) +let reduce2 = Array.reduce([1, 2, 3], 0, (acc, x) => acc + x) + +let spliceInPlace1 = [1, 2, 3]->Array.splice(~start=1, ~remove=1, ~insert=[4, 5]) +let spliceInPlace2 = Array.splice([1, 2, 3], ~start=1, ~remove=1, ~insert=[4, 5]) + +let removeFromInPlace1 = [1, 2, 3]->Array.removeInPlace(1) +let removeFromInPlace2 = Array.removeInPlace([1, 2, 3], 1) + +let removeCountInPlace1 = [1, 2, 3]->Array.splice(~start=1, ~remove=1, ~insert=[]) +let removeCountInPlace2 = Array.splice([1, 2, 3], ~start=1, ~remove=1, ~insert=[]) + +let reducei1 = [1, 2, 3]->Array.reduceWithIndex(0, (acc, x, i) => acc + x + i) +let reducei2 = Array.reduceWithIndex([1, 2, 3], 0, (acc, x, i) => acc + x + i) + +let reduceRight1 = [1, 2, 3]->Array.reduceRight(0, (acc, x) => acc + x) +let reduceRight2 = Array.reduceRight([1, 2, 3], 0, (acc, x) => acc + x) + +let reduceRighti1 = [1, 2, 3]->Array.reduceRightWithIndex(0, (acc, x, i) => acc + x + i) +let reduceRighti2 = Array.reduceRightWithIndex([1, 2, 3], 0, (acc, x, i) => acc + x + i) + +let pipeChain = + [1, 2, 3]->Array.map(x => x * 2)->Array.filter(x => x > 2)->Array.reduce(0, (acc, x) => acc + x) + +// Type alias migrations +let arrT: array = [1, 2, 3] +let arr2T: array = [1, 2, 3] diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_BigInt.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_BigInt.res new file mode 100644 index 0000000000..ead6d51481 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_BigInt.res @@ -0,0 +1,50 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_BigInt.res. +let fromStringExn1 = "123"->BigInt.fromStringOrThrow +let fromStringExn2 = BigInt.fromStringOrThrow("123") + +let land1 = 7n & 4n +let land2 = 7n & 4n +let land3 = 7n->BigInt.toString->BigInt.fromStringOrThrow->BigInt.bitwiseAnd(4n) + +let lor1 = 7n->BigInt.bitwiseOr(4n) +let lor2 = BigInt.bitwiseOr(7n, 4n) + +let lxor1 = 7n ^ 4n +let lxor2 = 7n ^ 4n + +let lnot1 = 2n->Js.BigInt.lnot +let lnot2 = Js.BigInt.lnot(2n) + +let lsl1 = 4n << 1n +let lsl2 = 4n << 1n + +let asr1 = 8n >> 1n +let asr2 = 8n >> 1n + +let toString1 = 123n->BigInt.toString +let toString2 = BigInt.toString(123n) + +let toLocaleString1 = 123n->BigInt.toLocaleString +let toLocaleString2 = BigInt.toLocaleString(123n) + +// From the stdlib module +let stdlib_fromStringExn1 = "123"->BigInt.fromStringOrThrow +let stdlib_fromStringExn2 = BigInt.fromStringOrThrow("123") + +let stdlib_land1 = 7n & 4n +let stdlib_land2 = 7n & 4n + +let stdlib_lor1 = BigInt.bitwiseOr(7n, 4n) + +let stdlib_lxor1 = 7n ^ 4n +let stdlib_lxor2 = 7n ^ 4n + +let stdlib_lnot1 = ~2n +let stdlib_lnot2 = ~2n + +let stdlib_lsl1 = 4n << 1n +let stdlib_lsl2 = 4n << 1n + +let stdlib_asr1 = 8n >> 1n +let stdlib_asr2 = 8n >> 1n diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Console.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Console.res new file mode 100644 index 0000000000..d539a85560 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Console.res @@ -0,0 +1,30 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Console.res. +let log = Console.log("Hello, World!") +let log2 = Console.log2("Hello", "World") +let log3 = Console.log3("Hello", "World", "!") +let log4 = Console.log4("Hello", "World", "!", "!") +let logMany = Console.logMany(["Hello", "World"]) + +let info = Console.info("Hello, World!") +let info2 = Console.info2("Hello", "World") +let info3 = Console.info3("Hello", "World", "!") +let info4 = Console.info4("Hello", "World", "!", "!") +let infoMany = Console.infoMany(["Hello", "World"]) + +let warn = Console.warn("Hello, World!") +let warn2 = Console.warn2("Hello", "World") +let warn3 = Console.warn3("Hello", "World", "!") +let warn4 = Console.warn4("Hello", "World", "!", "!") +let warnMany = Console.warnMany(["Hello", "World"]) + +let error = Console.error("Hello, World!") +let error2 = Console.error2("Hello", "World") +let error3 = Console.error3("Hello", "World", "!") +let error4 = Console.error4("Hello", "World", "!", "!") +let errorMany = Console.errorMany(["Hello", "World"]) + +let trace = Console.trace() +let timeStart = Console.time("Hello, World!") +let timeEnd = Console.timeEnd("Hello, World!") +let table = Console.table(["Hello", "World"]) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_DataView.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_DataView.res new file mode 100644 index 0000000000..a0ddcc6d1a --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_DataView.res @@ -0,0 +1,4 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_DataView.res. +let a = DataView.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2) +let b = DataView.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2, ~length=4) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Date.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Date.res new file mode 100644 index 0000000000..2df5dd3ff5 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Date.res @@ -0,0 +1,192 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Date.res. +let d1 = Date.make() +let d2 = Date.fromString("1973-11-29T21:30:54.321Z") +let d3 = Date.fromTime(123456789.0) + +let msNow = Date.now() + +let v1 = d2->Date.getTime +let v2 = Date.getTime(d2) + +let y = d2->Date.getFullYear +let mo = d2->Date.getMonth +let dayOfMonth = d2->Date.getDate +let dayOfWeek = d2->Date.getDay +let h = d2->Date.getHours +let mi = d2->Date.getMinutes +let s = d2->Date.getSeconds +let ms = d2->Date.getMilliseconds +let tz = d2->Date.getTimezoneOffset + +let uy = d2->Date.getUTCFullYear +let um = d2->Date.getUTCMonth +let ud = d2->Date.getUTCDate +let uday = d2->Date.getUTCDay +let uh = d2->Date.getUTCHours +let umi = d2->Date.getUTCMinutes +let us = d2->Date.getUTCSeconds +let ums = d2->Date.getUTCMilliseconds + +let s1 = d2->Date.toISOString +let s2 = d2->Date.toUTCString +let s3 = d2->Date.toString +let s4 = d2->Date.toTimeString +let s5 = d2->Date.toDateString +let s6 = d2->Date.toLocaleString +let s7 = d2->Date.toLocaleDateString +let s8 = d2->Date.toLocaleTimeString + +/* Additional deprecated APIs to exercise migration */ + +/* getters and legacy variants */ +let t = d2->Date.getTime +let y2 = d2->Date.getFullYear + +/* constructors with components */ +let mym = Date.makeWithYM(~year=Float.toInt(2020.0), ~month=Float.toInt(10.0)) +let mymd = Date.makeWithYMD( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), +) +let mymdh = Date.makeWithYMDH( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), +) +let mymdhm = Date.makeWithYMDHM( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), + ~minutes=Float.toInt(30.0), +) +let mymdhms = Date.makeWithYMDHMS( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), + ~minutes=Float.toInt(30.0), + ~seconds=Float.toInt(54.0), +) + +/* Date.UTC variants */ +let uym = Date.UTC.makeWithYM(~year=Float.toInt(2020.0), ~month=Float.toInt(10.0)) +let uymd = Date.UTC.makeWithYMD( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), +) +let uymdh = Date.UTC.makeWithYMDH( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), +) +let uymdhm = Date.UTC.makeWithYMDHM( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), + ~minutes=Float.toInt(30.0), +) +let uymdhms = Date.UTC.makeWithYMDHMS( + ~year=Float.toInt(1973.0), + ~month=Float.toInt(10.0), + ~day=Float.toInt(29.0), + ~hours=Float.toInt(21.0), + ~minutes=Float.toInt(30.0), + ~seconds=Float.toInt(54.0), +) + +/* parse APIs */ +let p = Date.fromString("1973-11-29T21:30:54.321Z") +let pf = Date.getTime(Date.fromString("1973-11-29T21:30:54.321Z")) + +/* setters (local time) */ +let setD = d2->Date.setDate(Float.toInt(15.0)) +let setFY = d2->Date.setFullYear(Float.toInt(1974.0)) + +let setFYM = d2->Date.setFullYearM(~year=Float.toInt(1974.0), ~month=Float.toInt(0.0)) +let setFYMD = + d2->Date.setFullYearMD(~year=Float.toInt(1974.0), ~month=Float.toInt(0.0), ~day=Float.toInt(7.0)) +let setH = d2->Date.setHours(Float.toInt(22.0)) +let setHM = d2->Date.setHoursM(~hours=Float.toInt(22.0), ~minutes=Float.toInt(46.0)) +let setHMS = + d2->Date.setHoursMS( + ~hours=Float.toInt(22.0), + ~minutes=Float.toInt(46.0), + ~seconds=Float.toInt(37.0), + ) +let setHMSMs = + d2->Date.setHoursMSMs( + ~hours=Float.toInt(22.0), + ~minutes=Float.toInt(46.0), + ~seconds=Float.toInt(37.0), + ~milliseconds=Float.toInt(494.0), + ) +let setMs = d2->Date.setMilliseconds(Float.toInt(494.0)) +let setMin = d2->Date.setMinutes(Float.toInt(34.0)) +let setMinS = d2->Date.setMinutesS(~minutes=Float.toInt(34.0), ~seconds=Float.toInt(56.0)) +let setMinSMs = + d2->Date.setMinutesSMs( + ~minutes=Float.toInt(34.0), + ~seconds=Float.toInt(56.0), + ~milliseconds=Float.toInt(789.0), + ) +let setMon = d2->Date.setMonth(Float.toInt(11.0)) +let setMonD = d2->Js.Date.setMonthD(~month=11.0, ~date=8.0, ()) +let setSec = d2->Date.setSeconds(Float.toInt(56.0)) +let setSecMs = d2->Date.setSecondsMs(~seconds=Float.toInt(56.0), ~milliseconds=Float.toInt(789.0)) + +/* setters (UTC) */ +let setUD = d2->Date.setUTCDate(Float.toInt(15.0)) +let setUFY = d2->Date.setUTCFullYear(Float.toInt(1974.0)) +let setUFYM = d2->Date.setUTCFullYearM(~year=Float.toInt(1974.0), ~month=Float.toInt(0.0)) +let setUFYMD = + d2->Date.setUTCFullYearMD( + ~year=Float.toInt(1974.0), + ~month=Float.toInt(0.0), + ~day=Float.toInt(7.0), + ) +let setUH = d2->Date.setUTCHours(Float.toInt(22.0)) +let setUHM = d2->Date.setUTCHoursM(~hours=Float.toInt(22.0), ~minutes=Float.toInt(46.0)) +let setUHMS = + d2->Date.setUTCHoursMS( + ~hours=Float.toInt(22.0), + ~minutes=Float.toInt(46.0), + ~seconds=Float.toInt(37.0), + ) +let setUHMSMs = + d2->Date.setUTCHoursMSMs( + ~hours=Float.toInt(22.0), + ~minutes=Float.toInt(46.0), + ~seconds=Float.toInt(37.0), + ~milliseconds=Float.toInt(494.0), + ) +let setUMs = d2->Date.setUTCMilliseconds(Float.toInt(494.0)) +let setUMin = d2->Date.setUTCMinutes(Float.toInt(34.0)) +let setUMinS = d2->Date.setUTCMinutesS(~minutes=Float.toInt(34.0), ~seconds=Float.toInt(56.0)) +let setUMinSMs = + d2->Date.setUTCMinutesSMs( + ~minutes=Float.toInt(34.0), + ~seconds=Float.toInt(56.0), + ~milliseconds=Float.toInt(789.0), + ) +let setUMon = d2->Date.setUTCMonth(Float.toInt(11.0)) +let setUMonD = d2->Js.Date.setUTCMonthD(~month=11.0, ~date=8.0, ()) +let setUSec = d2->Date.setUTCSeconds(Float.toInt(56.0)) +let setUSecMs = + d2->Date.setUTCSecondsMs(~seconds=Float.toInt(56.0), ~milliseconds=Float.toInt(789.0)) +let setUT = d2->Js.Date.setUTCTime(198765432101.0) +let setYr = d2->Js.Date.setYear(1999.0) + +/* other string conversions */ +let s9 = d2->Date.toUTCString +let j1 = d2->Date.toJSON +let j2 = d2->Date.toJSON + +// Type alias migration +external someDate: Date.t = "someDate" diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Dict.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Dict.res new file mode 100644 index 0000000000..990ab3b5e0 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Dict.res @@ -0,0 +1,35 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Dict.res. +let d = Dict.make() + +let get1 = d->Dict.get("k") +let get2 = Dict.get(d, "k") + +let unsafeGet1 = d->Dict.getUnsafe("k") +let unsafeGet2 = Dict.getUnsafe(d, "k") + +let set1 = d->Dict.set("k", 1) +let set2 = Dict.set(d, "k", 1) + +let keys1 = d->Dict.keysToArray +let keys2 = Dict.keysToArray(d) + +let values1 = d->Dict.valuesToArray +let values2 = Dict.valuesToArray(d) + +let entries1 = d->Dict.toArray +let entries2 = Dict.toArray(d) + +let dStr: dict = Dict.make() +let del1 = dStr->Dict.delete("k") +let del2 = Dict.delete(dStr, "k") + +let empty1: dict = Dict.make() + +let fromArray1 = [("a", 1), ("b", 2)]->Dict.fromArray +let fromArray2 = Dict.fromArray([("a", 1), ("b", 2)]) + +let fromList1 = list{("a", 1), ("b", 2)}->Js.Dict.fromList +let fromList2 = Js.Dict.fromList(list{("a", 1), ("b", 2)}) + +let map2 = Dict.mapValues(d, x => x + 1) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Error.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Error.res new file mode 100644 index 0000000000..114ac55b78 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Error.res @@ -0,0 +1,36 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Error.res. +// Use deprecated Error APIs to validate migration to JsError/JsExn + +external someExn: exn = "whatever" + +let fromExn1 = someExn->JsExn.fromException +let fromExn2 = JsExn.fromException(someExn) + +let err = JsError.make("Some message here") + +let stack1 = err->JsError.stack +let stack2 = JsError.stack(err) + +let message1 = err->JsError.message +let message2 = JsError.message(err) + +let name1 = err->JsError.name +let name2 = JsError.name(err) + +let fileName1 = err->JsError.fileName +let fileName2 = JsError.fileName(err) + +// Type alias migration +let errT: JsError.t = JsError.make("Another message") + +// Sub-error constructors +let evalErr = JsError.EvalError.make("eval error") +let rangeErr = JsError.RangeError.make("range error") +let refErr = JsError.ReferenceError.make("reference error") +let synErr = JsError.SyntaxError.make("syntax error") +let typeErr = JsError.TypeError.make("type error") +let uriErr = JsError.URIError.make("uri error") + +let ignore1 = err->JsError.ignore +let ignore2 = JsError.ignore(err) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Exn.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Exn.res new file mode 100644 index 0000000000..7ebdde655f --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Exn.res @@ -0,0 +1,42 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Exn.res. +// Use deprecated Exn APIs to validate migration to JsExn/JsError + +external someExn: exn = "whatever" +external someJsExn: JsExn.t = "whatever" + +// fromException (asJsExn) +let fromExn1 = someExn->JsExn.fromException +let fromExn2 = JsExn.fromException(someExn) + +// Property accessors on Exn.t +let stack1 = someJsExn->JsExn.stack +let stack2 = JsExn.stack(someJsExn) + +let message1 = someJsExn->JsExn.message +let message2 = JsExn.message(someJsExn) + +let name1 = someJsExn->JsExn.name +let name2 = JsExn.name(someJsExn) + +let fileName1 = someJsExn->JsExn.fileName +let fileName2 = JsExn.fileName(someJsExn) + +// Type alias migration +let exnT: JsExn.t = someJsExn + +// anyToExnInternal +let _coerced = JsExn.anyToExnInternal(1) + +// ignore +let ignore1 = someJsExn->JsExn.ignore +let ignore2 = JsExn.ignore(someJsExn) + +// Raise helpers +let throws1 = () => JsError.throwWithMessage("err") +let throws2 = () => JsError.EvalError.throwWithMessage("err") +let throws3 = () => JsError.RangeError.throwWithMessage("err") +let throws4 = () => JsError.ReferenceError.throwWithMessage("err") +let throws5 = () => JsError.SyntaxError.throwWithMessage("err") +let throws6 = () => JsError.TypeError.throwWithMessage("err") +let throws7 = () => JsError.URIError.throwWithMessage("err") diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Extern.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Extern.res new file mode 100644 index 0000000000..fc60d7b0c0 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Extern.res @@ -0,0 +1,8 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Extern.res. +// Exercise migrations from Js_extern to new Stdlib APIs + +let isNullish = Nullable.isNullable(%raw("null")) +let n = Nullable.null +let u = Nullable.undefined +let ty = Type.typeof("hello") diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Float.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Float.res new file mode 100644 index 0000000000..d4bdcc1a15 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Float.res @@ -0,0 +1,36 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Float.res. +let nan1 = Float.Constants.nan + +let isNaN1 = Float.Constants.nan->Float.isNaN +let isNaN2 = Float.isNaN(Float.Constants.nan) + +let isFinite1 = 1234.0->Float.isFinite +let isFinite2 = Float.isFinite(1234.0) + +let toExponential1 = 77.1234->Float.toExponential +let toExponential2 = Float.toExponential(77.1234) + +let toExponentialWithPrecision1 = 77.1234->Float.toExponential(~digits=2) +let toExponentialWithPrecision2 = Float.toExponential(77.1234, ~digits=2) + +let toFixed1 = 12345.6789->Float.toFixed +let toFixed2 = Float.toFixed(12345.6789) + +let toFixedWithPrecision1 = 12345.6789->Float.toFixed(~digits=1) +let toFixedWithPrecision2 = Float.toFixed(12345.6789, ~digits=1) + +let toPrecision1 = 12345.6789->Float.toPrecision +let toPrecision2 = Float.toPrecision(12345.6789) + +let toPrecisionWithPrecision1 = 12345.6789->Float.toPrecision(~digits=2) +let toPrecisionWithPrecision2 = Float.toPrecision(12345.6789, ~digits=2) + +let toString1 = 12345.6789->Float.toString +let toString2 = Float.toString(12345.6789) + +let toStringWithRadix1 = 6.0->Float.toString(~radix=2) +let toStringWithRadix2 = Float.toString(6.0, ~radix=2) + +let parse1 = "123"->Float.parseFloat +let parse2 = Float.parseFloat("123") diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Global.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Global.res new file mode 100644 index 0000000000..80e8767e68 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Global.res @@ -0,0 +1,17 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Global.res. +let t1: timeoutId = setTimeout(() => (), 1000) +let t2: timeoutId = setTimeoutFloat(() => (), 1000.0) + +clearTimeout(t1) + +let i1: intervalId = setInterval(() => (), 2000) +let i2: intervalId = setIntervalFloat(() => (), 2000.0) + +clearInterval(i1) + +let e1 = encodeURI("https://rescript-lang.org?array=[someValue]") +let d1 = decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D") + +let e2 = encodeURIComponent("array=[someValue]") +let d2 = decodeURIComponent("array%3D%5BsomeValue%5D") diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res new file mode 100644 index 0000000000..43b70137c8 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Int.res @@ -0,0 +1,9 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Int.res. +let result1 = Int.bitwiseAnd(1, 2) +let result2 = Int.bitwiseOr(1, 2) +let result3 = Int.bitwiseXor(1, 2) +let result4 = Int.shiftLeft(1, 2) +let result5 = Int.shiftRightUnsigned(1, 2) +let result6 = Int.shiftRight(1, 2) +let result7 = Int.bitwiseNot(0) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Interface.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Interface.res new file mode 100644 index 0000000000..5c10829b6d --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Interface.res @@ -0,0 +1,10 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Interface.res. +/* Implementation to satisfy interface build for tests */ + +external arr: array = "arr" +external reT: RegExp.t = "re" +external json: JSON.t = "json" +external nestedArr: array = "nestedArr" + +external useSet: Set.t => unit = "useSet" diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_JSON.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_JSON.res new file mode 100644 index 0000000000..54e72a78ce --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_JSON.res @@ -0,0 +1,24 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_JSON.res. +external someJson: JSON.t = "someJson" +external strToJson: string => JSON.t = "strToJson" + +let decodeString1 = someJson->JSON.Decode.string +let decodeString2 = JSON.Decode.string(someJson) +let decodeString3 = + [1, 2, 3]->Array.map(v => v->Int.toString)->Array.join(" ")->strToJson->JSON.Decode.string + +let decodeNumber1 = someJson->JSON.Decode.float +let decodeNumber2 = JSON.Decode.float(someJson) + +let decodeObject1 = someJson->JSON.Decode.object +let decodeObject2 = JSON.Decode.object(someJson) + +let decodeArray1 = someJson->JSON.Decode.array +let decodeArray2 = JSON.Decode.array(someJson) + +let decodeBoolean1 = someJson->JSON.Decode.bool +let decodeBoolean2 = JSON.Decode.bool(someJson) + +let decodeNull1 = someJson->JSON.Decode.null +let decodeNull2 = JSON.Decode.null(someJson) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_JSON_Stdlib.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_JSON_Stdlib.res new file mode 100644 index 0000000000..a5c3e925c8 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_JSON_Stdlib.res @@ -0,0 +1,16 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_JSON_Stdlib.res. +let p1 = JSON.parseExn("{}", ~reviver=(_k, v) => v) +let p2 = JSON.parseExnWithReviver("{}", (_k, v) => v) + +let s1 = JSON.stringifyWithIndent(JSON.Object(dict{}), 2) +let s2 = JSON.stringifyWithReplacer(JSON.Number(1.), (_k, v) => v) +let s3 = JSON.stringifyWithReplacerAndIndent(JSON.Boolean(true), (_k, v) => v, 2) +let s4 = JSON.stringifyWithFilter(JSON.Array([JSON.Number(1.)]), ["a"]) +let s5 = JSON.stringifyWithFilterAndIndent(JSON.Array([JSON.Number(1.)]), ["a"], 2) + +let a1 = JSON.stringifyAnyWithIndent(1, 2) +let a2 = JSON.stringifyAnyWithReplacer(1, (_k, v) => v) +let a3 = JSON.stringifyAnyWithReplacerAndIndent(1, (_k, v) => v, 2) +let a4 = JSON.stringifyAnyWithFilter(1, ["a"]) +let a5 = JSON.stringifyAnyWithFilterAndIndent(1, ["a"], 2) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js.res new file mode 100644 index 0000000000..87922b7521 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js.res @@ -0,0 +1,7 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js.res. +let consoleLog1 = Console.log("Hello") +let consoleLog2 = Console.log2("Hello", "World") +let consoleLog3 = Console.log3("Hello", "World", "!") +let consoleLog4 = Console.log4("Hello", "World", "!", "!") +let consoleLogMany = Console.logMany(["Hello", "World"]) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Array.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Array.res new file mode 100644 index 0000000000..f5f2bf86c2 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Array.res @@ -0,0 +1,35 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_Array.res. +// Migration tests for Js.Array (old) -> Array module + +external someArrayLike: Array.arrayLike = "whatever" + +let from1 = someArrayLike->Array.fromArrayLike +let from2 = Array.fromArrayLike(someArrayLike) + +let fromMap1 = someArrayLike->Array.fromArrayLikeWithMap(s => s ++ "!") +let fromMap2 = Array.fromArrayLikeWithMap(someArrayLike, s => s ++ "!") + +let isArray1 = [1, 2, 3]->Array.isArray +let isArray2 = Array.isArray([1, 2, 3]) + +let length1 = [1, 2, 3]->Array.length +let length2 = Array.length([1, 2, 3]) + +let pop1 = [1, 2, 3]->Array.pop +let pop2 = Array.pop([1, 2, 3]) + +let reverseInPlace1 = [1, 2, 3]->Array.reverse +let reverseInPlace2 = Array.reverse([1, 2, 3]) + +let shift1 = [1, 2, 3]->Array.shift +let shift2 = Array.shift([1, 2, 3]) + +let toString1 = [1, 2, 3]->Array.toString +let toString2 = Array.toString([1, 2, 3]) + +let toLocaleString1 = [1, 2, 3]->Array.toLocaleString +let toLocaleString2 = Array.toLocaleString([1, 2, 3]) + +// Type alias migration +let arrT: array = [1, 2, 3] diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Int.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Int.res new file mode 100644 index 0000000000..379b142ce9 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Int.res @@ -0,0 +1,25 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_Int.res. +let toExponential1 = 77->Int.toExponential +let toExponential2 = Int.toExponential(77) + +let toExponentialWithPrecision1 = 77->Int.toExponential(~digits=2) +let toExponentialWithPrecision2 = Int.toExponential(77, ~digits=2) + +let toPrecision1 = 123456789->Int.toPrecision +let toPrecision2 = Int.toPrecision(123456789) + +let toPrecisionWithPrecision1 = 123456789->Int.toPrecision(~digits=2) +let toPrecisionWithPrecision2 = Int.toPrecision(123456789, ~digits=2) + +let toString1 = 123456789->Int.toString +let toString2 = Int.toString(123456789) + +let toStringWithRadix1 = 373592855->Int.toString(~radix=16) +let toStringWithRadix2 = Int.toString(373592855, ~radix=16) + +let toFloat1 = 42->Int.toFloat +let toFloat2 = Int.toFloat(42) + +let equal1 = Js.Int.equal(1, 1) +let equal2 = 1->Js.Int.equal(2) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_More.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_More.res new file mode 100644 index 0000000000..816136577f --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_More.res @@ -0,0 +1,9 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_More.res. +// Migration tests for new deprecations in packages/@rescript/runtime/Js.res + +// typeof migration +let tyNum = typeof(1) + +// nullToOption +let nToOpt = Null.toOption(Null.make(1)) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Re.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Re.res new file mode 100644 index 0000000000..d059c10e9c --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Re.res @@ -0,0 +1,52 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_Re.res. +let re1 = RegExp.fromString("foo") +let re2 = RegExp.fromString("foo", ~flags="gi") + +let flags1 = re2->RegExp.flags +let flags2 = RegExp.flags(re2) + +let g1 = re2->RegExp.global +let g2 = RegExp.global(re2) + +let ic1 = re2->RegExp.ignoreCase +let ic2 = RegExp.ignoreCase(re2) + +let m1 = re2->RegExp.multiline +let m2 = RegExp.multiline(re2) + +let u1 = re2->RegExp.unicode +let u2 = RegExp.unicode(re2) + +let y1 = re2->RegExp.sticky +let y2 = RegExp.sticky(re2) + +let src1 = re2->RegExp.source +let src2 = RegExp.source(re2) + +let li1 = re2->RegExp.lastIndex +let () = re2->RegExp.setLastIndex(0) + +let exec1 = re2->RegExp.exec("Foo bar") +let exec2 = RegExp.exec(re2, "Foo bar") + +let test1 = re2->RegExp.test("Foo bar") +let test2 = RegExp.test(re2, "Foo bar") + +// Type alias migration +external reT: RegExp.t = "re" + +let matches_access = switch re2->RegExp.exec("Foo bar") { +| None => 0 +| Some(r) => RegExp.Result.matches(r)->Array.length +} + +let result_index = switch re2->RegExp.exec("Foo bar") { +| None => 0 +| Some(r) => RegExp.Result.index(r) +} + +let result_input = switch re2->RegExp.exec("Foo bar") { +| None => "" +| Some(r) => RegExp.Result.input(r) +} diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_String.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_String.res new file mode 100644 index 0000000000..ac0d02099f --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_String.res @@ -0,0 +1,45 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_String.res. +// Migration tests for Js.String (old) -> String module + +let make1 = 1->String.make +let make2 = String.make(1) + +let fromCharCode1 = 65->String.fromCharCode +let fromCharCode2 = String.fromCharCode(65) + +let fromCharCodeMany1 = [65, 66, 67]->String.fromCharCodeMany +let fromCharCodeMany2 = String.fromCharCodeMany([65, 66, 67]) + +let fromCodePoint1 = 65->String.fromCodePoint +let fromCodePoint2 = String.fromCodePoint(65) + +let fromCodePointMany1 = [65, 66, 67]->String.fromCodePointMany +let fromCodePointMany2 = String.fromCodePointMany([65, 66, 67]) + +let length1 = "abcde"->String.length +let length2 = String.length("abcde") + +let get1 = "abcde"->String.get(2) +let get2 = String.get("abcde", 2) + +let normalize1 = "abcde"->String.normalize +let normalize2 = String.normalize("abcde") + +let toLowerCase1 = "ABCDE"->String.toLowerCase +let toLowerCase2 = String.toLowerCase("ABCDE") + +let toUpperCase1 = "abcde"->String.toUpperCase +let toUpperCase2 = String.toUpperCase("abcde") + +let toLocaleLowerCase1 = "ABCDE"->String.toLocaleLowerCase +let toLocaleLowerCase2 = String.toLocaleLowerCase("ABCDE") + +let toLocaleUpperCase1 = "abcde"->String.toLocaleUpperCase +let toLocaleUpperCase2 = String.toLocaleUpperCase("abcde") + +let trim1 = " abcde "->String.trim +let trim2 = String.trim(" abcde ") + +// Type alias migration +let sT: string = "abc" diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Types_Interface.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Types_Interface.res new file mode 100644 index 0000000000..ee622cfb46 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Types_Interface.res @@ -0,0 +1,11 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_Types_Interface.res. +/* Implementation to satisfy interface build for tests */ + +external nullT: Null.t = "nullT" +external nullableT: Nullable.t = "nullableT" +external nullUndefT: Nullable.t = "nullUndefT" + +external symbolT: Symbol.t = "symbolT" +external objValT: Type.Classify.object = "objValT" +external functionValT: Type.Classify.function = "functionValT" diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Undefined.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Undefined.res new file mode 100644 index 0000000000..47a7a23687 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_Undefined.res @@ -0,0 +1,37 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_Undefined.res. +let make1 = "hello"->Nullable.make +let make2 = Nullable.make("hello") + +let empty1 = Nullable.undefined + +let getUnsafe1 = Nullable.make(1)->Nullable.getUnsafe +let getUnsafe2 = Nullable.getUnsafe(Nullable.make(1)) + +let getExn1 = Nullable.make(1)->Nullable.getOrThrow +let getExn2 = Nullable.getOrThrow(Nullable.make(1)) + +let map1 = Nullable.make(2)->Nullable.map(x => x + 1) +let map2 = Nullable.map(Nullable.make(2), x => x + 1) + +let forEach1 = Nullable.make(2)->Nullable.forEach(x => ignore(x)) +let forEach2 = Nullable.forEach(Nullable.make(2), x => ignore(x)) + +let fromOption1 = Some("x")->Nullable.fromOption +let fromOption2 = Nullable.fromOption(None) + +let from_opt1 = Some("y")->Nullable.fromOption +let from_opt2 = Nullable.fromOption(None) + +let toOption1 = Nullable.make(3)->Nullable.toOption +let toOption2 = Nullable.toOption(Nullable.make(3)) + +let to_opt1 = Nullable.make(4)->Nullable.toOption +let to_opt2 = Nullable.toOption(Nullable.make(4)) + +let test1 = Js.Undefined.empty->Js.Undefined.test +let test2 = Js.Undefined.test(Js.Undefined.empty) +let test3 = Js.Undefined.return(5)->Js.Undefined.bind(v => v)->Js.Undefined.test + +let testAny1 = Js.Undefined.testAny(Js.Undefined.empty) +let testAny2 = Js.Undefined.empty->Js.Undefined.testAny diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array.res new file mode 100644 index 0000000000..3020b2501f --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array.res @@ -0,0 +1,9 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_typed_array.res. +let arr1 = Int8Array.fromArray([1, 2, 3]) + +let len = arr1->TypedArray.length + +let bytes = Int8Array.Constants.bytesPerElement +let off = Int8Array.fromBufferToEnd(ArrayBuffer.make(8), ~byteOffset=2) +let range = Int8Array.fromBufferWithRange(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array2.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array2.res new file mode 100644 index 0000000000..5b48a43624 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array2.res @@ -0,0 +1,20 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_typed_array2.res. +let arr = Int8Array.fromArray([1, 2, 3]) + +let len1 = arr->TypedArray.length +let includes1 = arr->TypedArray.includes(2) +let idxFrom1 = arr->TypedArray.indexOfFrom(2, 1) + +let slice1 = arr->TypedArray.slice(~start=1, ~end=2) +let sliceFrom1 = arr->TypedArray.sliceToEnd(~start=1) + +let map1 = arr->TypedArray.map(x => x + 1) +let reduce1 = arr->TypedArray.reduce((acc, x) => acc + x, 0) + +let bytes = Int8Array.Constants.bytesPerElement + +let fromBufToEnd = Int8Array.fromBufferToEnd(ArrayBuffer.make(8), ~byteOffset=2) +let fromBufRange = Int8Array.fromBufferWithRange(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) + +let fromLength = Int8Array.fromLength(3) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array2_Float32.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array2_Float32.res new file mode 100644 index 0000000000..086550b6c5 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array2_Float32.res @@ -0,0 +1,20 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_typed_array2_Float32.res. +let arr = Float32Array.fromArray([1.0, 2.0, 3.0]) + +let len1 = arr->TypedArray.length +let includes1 = arr->TypedArray.includes(2.0) +let idxFrom1 = arr->TypedArray.indexOfFrom(2.0, 1) + +let slice1 = arr->TypedArray.slice(~start=1, ~end=2) +let sliceFrom1 = arr->TypedArray.sliceToEnd(~start=1) + +let map1 = arr->TypedArray.map(x => x +. 1.0) +let reduce1 = arr->TypedArray.reduce((acc, x) => acc +. x, 0.0) + +let bytes = Float32Array.Constants.bytesPerElement + +let fromBufToEnd = Float32Array.fromBufferToEnd(ArrayBuffer.make(8), ~byteOffset=2) +let fromBufRange = Float32Array.fromBufferWithRange(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) + +let fromLength = Float32Array.fromLength(3) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array_Float32_Const.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array_Float32_Const.res new file mode 100644 index 0000000000..38edff9781 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Js_typed_array_Float32_Const.res @@ -0,0 +1,4 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Js_typed_array_Float32_Const.res. +// Float32 constants migration coverage for legacy Js.Typed_array +let bytesF32 = Float32Array.Constants.bytesPerElement diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Map.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Map.res new file mode 100644 index 0000000000..5100bef070 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Map.res @@ -0,0 +1,4 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Map.res. +// Type alias migration for Js.Map.t +external m: Map.t = "m" diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Math.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Math.res new file mode 100644 index 0000000000..e6cda4a09a --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Math.res @@ -0,0 +1,83 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Math.res. +// Exercise migrations from Js.Math to Math + +let e = Math.Constants.e +let pi = Math.Constants.pi +let ln2 = Math.Constants.ln2 +let ln10 = Math.Constants.ln10 +let log2e = Math.Constants.log2e +let log10e = Math.Constants.log10e +let sqrt_half = Math.Constants.sqrt1_2 +let sqrt2c = Math.Constants.sqrt2 + +let absInt1 = Math.Int.abs(-5) +let absFloat1 = Math.abs(-3.5) + +let acos1 = Math.acos(1.0) +let acosh1 = Math.acosh(1.5) +let asinh1 = Math.asinh(1.0) +let asin1 = Math.asin(0.5) +let atan1 = Math.atan(1.0) +let atanh1 = Math.atanh(0.5) + +let atan21 = Math.atan2(~y=0.0, ~x=10.0) + +let cbrt1 = Math.cbrt(27.0) + +let ceilInt1 = Math.Int.ceil(3.2) +let ceilInt2 = Math.Int.ceil(3.2) +let ceilFloat1 = Math.ceil(3.2) + +let clz1 = Math.Int.clz32(255) + +let cos1 = Math.cos(0.0) +let cosh1 = Math.cosh(0.0) +let exp1 = Math.exp(1.0) +let expm11 = Math.expm1(1.0) +let log1p1 = Math.log1p(1.0) + +let floorInt1 = Math.Int.floor(3.7) +let floorInt2 = Math.Int.floor(3.7) +let floorFloat1 = Math.floor(3.7) + +let fround1 = Math.fround(5.05) + +let hypot1 = Math.hypot(3.0, 4.0) +let hypotMany1 = Math.hypotMany([3.0, 4.0, 12.0]) + +let imul1 = Math.Int.imul(3, 4) + +let log1 = Math.log(Math.Constants.e) +let log10_1 = Math.log10(1000.0) +let log2_1 = Math.log2(512.0) + +let maxInt1 = Math.Int.max(1, 2) +let maxIntMany1 = Math.Int.maxMany([1, 10, 3]) +let maxFloat1 = Math.max(1.5, 2.5) +let maxFloatMany1 = Math.maxMany([1.5, 2.5, 0.5]) + +let minInt1 = Math.Int.min(1, 2) +let minIntMany1 = Math.Int.minMany([1, 10, 3]) +let minFloat1 = Math.min(1.5, 2.5) +let minFloatMany1 = Math.minMany([1.5, 2.5, 0.5]) + +let powInt1 = Math.Int.pow(3, ~exp=4) +let powFloat1 = Math.pow(3.0, ~exp=4.0) + +let rand1 = Math.random() + +let roundUnsafe1 = Float.toInt(Math.round(3.7)) +let round1 = Math.round(3.7) + +let signInt1 = Math.Int.sign(-5) +let signFloat1 = Math.sign(-5.0) + +let sin1 = Math.sin(0.0) +let sinh1 = Math.sinh(0.0) +let sqrt1 = Math.sqrt(9.0) +let tan1 = Math.tan(0.5) +let tanh1 = Math.tanh(0.0) + +let truncUnsafe1 = Float.toInt(Math.trunc(3.7)) +let trunc1 = Math.trunc(3.7) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Null.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Null.res new file mode 100644 index 0000000000..d521447c8f --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Null.res @@ -0,0 +1,37 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Null.res. +let make1 = "hello"->Null.make +let make2 = Null.make("hello") + +let empty1 = Null.null + +let getUnsafe1 = Null.make(1)->Null.getUnsafe +let getUnsafe2 = Null.getUnsafe(Null.make(1)) + +let getExn1 = Null.make(1)->Null.getOrThrow +let getExn2 = Null.getOrThrow(Null.make(1)) + +let map1 = Null.make(2)->Null.map(x => x + 1) +let map2 = Null.map(Null.make(2), x => x + 1) + +let forEach1 = Null.make(2)->Null.forEach(x => ignore(x)) +let forEach2 = Null.forEach(Null.make(2), x => ignore(x)) + +let fromOption1 = Some("x")->Null.fromOption +let fromOption2 = Null.fromOption(None) + +let from_opt1 = Some("y")->Null.fromOption +let from_opt2 = Null.fromOption(None) + +let toOption1 = Null.make(3)->Null.toOption +let toOption2 = Null.toOption(Null.make(3)) + +let to_opt1 = Null.make(4)->Null.toOption +let to_opt2 = Null.toOption(Null.make(4)) + +let test1 = Null.null === Null.null +let test2 = Null.null === Null.null +let test3 = Null.make(5)->Null.map(v => v)->Null.equal(Null, (a, b) => a === b) + +// Type alias migration +let nullT: Null.t = Null.make(1) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Nullable.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Nullable.res new file mode 100644 index 0000000000..a22592aa5e --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Nullable.res @@ -0,0 +1,36 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Nullable.res. +let make1 = "hello"->Nullable.make +let make2 = Nullable.make("hello") + +let null1 = Nullable.null +let undefined1 = Nullable.undefined + +let isNullable1 = Nullable.null->Nullable.isNullable +let isNullable2 = Nullable.isNullable(Nullable.null) + +let map1 = Nullable.make(2)->Nullable.map(x => x + 1) +let map2 = Nullable.map(Nullable.make(2), x => x + 1) + +let forEach1 = Nullable.make(2)->Nullable.forEach(x => ignore(x)) +let forEach2 = Nullable.forEach(Nullable.make(2), x => ignore(x)) + +let fromOption1 = Some("x")->Nullable.fromOption +let fromOption2 = Nullable.fromOption(None) + +let from_opt1 = Some("y")->Nullable.fromOption +let from_opt2 = Nullable.fromOption(None) + +let toOption1 = Nullable.make(3)->Nullable.toOption +let toOption2 = Nullable.toOption(Nullable.make(3)) + +let to_opt1 = Nullable.make(4)->Nullable.toOption +let to_opt2 = Nullable.toOption(Nullable.make(4)) + +let optArrayOfNullableToOptArrayOfOpt: option>> => option< + array>, +> = x => + switch x { + | None => None + | Some(arr) => Some(arr->Belt.Array.map(Nullable.toOption)) + } diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Obj.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Obj.res new file mode 100644 index 0000000000..8a9f1f5ad1 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Obj.res @@ -0,0 +1,9 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Obj.res. +let empty1 = Object.make() + +let assign1 = Object.make()->Object.assign({"a": 1}) +let assign2 = Object.assign(Object.make(), {"a": 1}) + +let keys1 = {"a": 1, "b": 2}->Object.keysToArray +let keys2 = Object.keysToArray({"a": 1, "b": 2}) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Option.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Option.res new file mode 100644 index 0000000000..ecd5f7f4a9 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Option.res @@ -0,0 +1,35 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Option.res. +let someCall = Js.Option.some(3) +let somePiped = 3->Js.Option.some + +let isSome1 = Some(1)->Option.isSome +let isSome2 = Option.isSome(None) + +let isNone1 = None->Option.isNone +let isNone2 = Option.isNone(Some(2)) + +let eq = (a: int, b: int) => a == b +// let isSomeValue1 = Js.Option.isSomeValue(eq, 2, Some(2)) + +let getExn1 = Option.getOrThrow(Some(3)) +let getExn2 = Some(3)->Option.getOrThrow + +let equal1 = Option.equal(Some(2), Some(2), eq) + +let f = (x: int) => x > 0 ? Some(x + 1) : None +let andThen1 = Option.flatMap(Some(2), f) + +let map1 = Option.map(Some(2), x => x * 2) + +let getWithDefault1 = Option.getOr(Some(2), 0) + +let default1 = Option.getOr(Some(2), 0) + +let filter1 = Option.filter(Some(1), x => x > 0) + +let firstSome1 = Option.orElse(Some(1), None) +let firstSome2 = Option.orElse(Some(1), None) + +// Type alias migration +let optT: option = Some(1) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Pervasives.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Pervasives.res new file mode 100644 index 0000000000..fef6b587c9 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Pervasives.res @@ -0,0 +1,3 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Pervasives.res. +throw(Failure("test")) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Promise.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Promise.res new file mode 100644 index 0000000000..3c811ac007 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Promise.res @@ -0,0 +1,41 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Promise.res. +let p1 = Promise.resolve(1) +let p2 = Promise.reject(Failure("err")) + +let all1 = Promise.all([Promise.resolve(1), Promise.resolve(2)]) +let all2 = Promise.all2((Promise.resolve(1), Promise.resolve(2))) +let all3 = Promise.all3((Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))) +let all4 = Promise.all4(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), +)) +let all5 = Promise.all5(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), + Promise.resolve(5), +)) +let all6 = Promise.all6(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), + Promise.resolve(5), + Promise.resolve(6), +)) + +let race1 = Promise.race([Promise.resolve(10), Promise.resolve(20)]) + +// let thenPipe = Js.Promise.resolve(1)->Js.Promise.then_(x => Js.Promise.resolve(x + 1), _) +// let thenDirect = Js.Promise.then_(x => Js.Promise.resolve(x + 1), Js.Promise.resolve(1)) + +// Type alias migration +external p: promise = "p" + +// let catchPipe = Js.Promise.resolve(1)->Js.Promise.catch(_e => Js.Promise.resolve(0), _) +// let catchDirect = Js.Promise.catch(_e => Js.Promise.resolve(0), Js.Promise.resolve(1)) +let make1 = Promise.make((resolve, reject) => resolve(1)) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Promise2.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Promise2.res new file mode 100644 index 0000000000..79860dd1c2 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Promise2.res @@ -0,0 +1,44 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Promise2.res. +let p1 = Promise.resolve(1) +let _p2 = Promise.reject(Failure("err")) + +let all1 = Promise.all([Promise.resolve(1), Promise.resolve(2)]) +let all2 = Promise.all2((Promise.resolve(1), Promise.resolve(2))) +let all3 = Promise.all3((Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))) + +let all4 = Promise.all4(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), +)) +let all5 = Promise.all5(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), + Promise.resolve(5), +)) +let all6 = Promise.all6(( + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3), + Promise.resolve(4), + Promise.resolve(5), + Promise.resolve(6), +)) + +let race1 = Promise.race([Promise.resolve(10), Promise.resolve(20)]) + +let thenPipe = Promise.resolve(1)->Promise.then(x => Promise.resolve(x + 1)) +let thenDirect = Promise.then(Promise.resolve(1), x => Promise.resolve(x + 1)) + +// Type alias migration +external p2: promise = "p2" + +let catchPipe = Promise.resolve(1)->Promise.catch(_e => Promise.resolve(0)) +let catchDirect = Promise.catch(Promise.resolve(1), _e => Promise.resolve(0)) +let make1 = Promise.make((resolve, _) => resolve(1)) + +let _ = p2->Promise.then(x => Promise.resolve(x + 1)) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Result.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Result.res new file mode 100644 index 0000000000..8047545816 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Result.res @@ -0,0 +1,4 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Result.res. +type r = result +let res: result = Ok(1) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Set.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Set.res new file mode 100644 index 0000000000..7d1576ebee --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_Set.res @@ -0,0 +1,4 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_Set.res. +// Type alias migration for Js.Set.t +external s: Set.t = "s" diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibArray.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibArray.res new file mode 100644 index 0000000000..03c5b7c14a --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibArray.res @@ -0,0 +1,22 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_StdlibArray.res. +let ba1 = [1, 2, 3, 4, 5]->Array.copyWithin(~target=2, ~start=0) +let ba2 = Array.copyWithin([1, 2, 3, 4, 5], ~target=2, ~start=0) + +let b1 = [1, 2, 3, 4]->Array.copyWithin(~target=0, ~start=2) +let b2 = Array.copyWithin([1, 2, 3, 4], ~target=0, ~start=2) + +let c1 = [1, 2, 3]->Array.fill(0) +let c2 = [1, 2, 3, 4]->Array.fill(9, ~start=1) + +let d1 = [1, 2, 1, 2]->Array.indexOf(2, ~from=2) +let d2 = Array.indexOf([1, 2, 1, 2], 2, ~from=2) + +let e1 = ["a", "b"]->Array.join("-") +let e2 = [1, 2]->Array.joinUnsafe(",") + +let f1 = [1, 2, 3, 4]->Array.slice(~start=2) + +let g1 = [1, 2]->Array.lastIndexOf(1, ~from=1) + +let h1 = [1, 2]->Array.getUnsafe(1) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibListLazyPromise.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibListLazyPromise.res new file mode 100644 index 0000000000..297dce36f7 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibListLazyPromise.res @@ -0,0 +1,15 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_StdlibListLazyPromise.res. +let l1 = List.headOrThrow(list{1}) +let l2 = List.tailOrThrow(list{1}) +let l3 = List.getOrThrow(list{"a", "b"}, 0) +let l4 = List.shuffle(list{1, 2}) + +let lazy1 = Lazy.make(() => 1) +let lazy2 = Lazy.make(() => 2) +let v1 = Lazy.get(lazy1) +let v2 = Lazy.get(lazy2) +let b1 = Lazy.isEvaluated(lazy1) + +let p = Promise.resolve(5) +let _ = Promise.ignore(p) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibOptionResultNull.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibOptionResultNull.res new file mode 100644 index 0000000000..79f981af5d --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibOptionResultNull.res @@ -0,0 +1,17 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_StdlibOptionResultNull.res. +let o1 = Option.getOrThrow(Some(3)) +let o2 = Option.mapOr(Some(3), 0, x => x + 1) +let o3 = Option.getOr(None, 0) + +let r1 = Result.getOrThrow(Ok(1)) +let r2 = Result.mapOr(Ok(1), 0, x => x + 1) +let r3 = Result.getOr(Error("e"), 0) + +let n1 = Null.getOrThrow(Null.make(3)) +let n2 = Null.getOr(Null.null, 0) +let n3 = Null.mapOr(Null.make(3), 0, x => x) + +let nb1 = Nullable.getOrThrow(Nullable.make(3)) +let nb2 = Nullable.getOr(Nullable.null, 0) +let nb3 = Nullable.mapOr(Nullable.make(3), 0, x => x) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibPrimitives.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibPrimitives.res new file mode 100644 index 0000000000..54758d538c --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibPrimitives.res @@ -0,0 +1,20 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_StdlibPrimitives.res. +let i1 = Int.toExponential(77, ~digits=2) +let i2 = Int.toFixed(300, ~digits=1) +let i3 = Int.toPrecision(100, ~digits=2) +let i4 = Int.toString(6, ~radix=2) +let i5 = Int.range(1, 5, ~options={step: 2}) + +let f1 = Float.parseInt("10.0", ~radix=2) +let f2 = Float.toExponential(77.0, ~digits=2) +let f3 = Float.toFixed(300.0, ~digits=1) +let f4 = Float.toPrecision(100.0, ~digits=2) +let f5 = Float.toString(6.0, ~radix=2) + +let b1 = Bool.fromStringOrThrow("true") + +let buf = ArrayBuffer.make(8) +let ab1 = buf->ArrayBuffer.slice(~start=2) + +let re1 = RegExp.fromString("\\w+", ~flags="g") diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibString.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibString.res new file mode 100644 index 0000000000..3bc9c59b26 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_StdlibString.res @@ -0,0 +1,39 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_StdlibString.res. +let s1 = "abcde"->String.slice(~start=1) +let s2 = "abcde"->String.substring(~start=1) + +let r0 = + "vowels"->String.replaceRegExpBy0Unsafe(/a|e|i|o|u/g, (~match, ~offset as _, ~input as _) => + match + ) +let r1 = + "Jony is 40"->String.replaceRegExpBy1Unsafe(/(Jony is )\d+/g, ( + ~match as _, + ~group1, + ~offset as _, + ~input as _, + ) => group1) + +let r2 = "7 times 6"->String.replaceRegExpBy2Unsafe(/(\d+) times (\d+)/, ( + ~match as _, + ~group1, + ~group2, + ~offset as _, + ~input as _, +) => + switch (Int.fromString(group1), Int.fromString(group2)) { + | (Some(x), Some(y)) => Int.toString(x * y) + | _ => "???" + } +) + +let r3 = + "abc"->String.replaceRegExpBy3Unsafe(/(a)(b)(c)/, ( + ~match as _, + ~group1, + ~group2, + ~group3, + ~offset as _, + ~input as _, + ) => group1 ++ group2 ++ group3) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_String.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_String.res new file mode 100644 index 0000000000..8b1b6b7ddf --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_String.res @@ -0,0 +1,131 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_String.res. +let make1 = 1->String.make +let make2 = String.make(1) + +let fromCharCode1 = 65->String.fromCharCode +let fromCharCode2 = String.fromCharCode(65) + +let fromCharCodeMany1 = [65, 66, 67]->String.fromCharCodeMany +let fromCharCodeMany2 = String.fromCharCodeMany([65, 66, 67]) + +let fromCodePoint1 = 65->String.fromCodePoint +let fromCodePoint2 = String.fromCodePoint(65) + +let fromCodePointMany1 = [65, 66, 67]->String.fromCodePointMany +let fromCodePointMany2 = String.fromCodePointMany([65, 66, 67]) + +let length1 = "abcde"->String.length +let length2 = String.length("abcde") + +let get1 = "abcde"->String.getUnsafe(2) +let get2 = String.getUnsafe("abcde", 2) + +let charAt1 = "abcde"->String.charAt(2) +let charAt2 = String.charAt("abcde", 2) + +let charCodeAt1 = "abcde"->String.charCodeAt(2) +let charCodeAt2 = String.charCodeAt("abcde", 2) + +let codePointAt1 = "abcde"->String.codePointAt(2) +let codePointAt2 = String.codePointAt("abcde", 2) + +let concat1 = "abcde"->String.concat("fghij") +let concat2 = String.concat("abcde", "fghij") + +let concatMany1 = "abcde"->String.concatMany(["fghij", "klmno"]) +let concatMany2 = String.concatMany("abcde", ["fghij", "klmno"]) + +let endsWith1 = "abcde"->String.endsWith("de") +let endsWith2 = String.endsWith("abcde", "de") + +let endsWithFrom1 = "abcde"->String.endsWithFrom("d", 2) +let endsWithFrom2 = String.endsWithFrom("abcde", "d", 2) + +let includes1 = "abcde"->String.includes("de") +let includes2 = String.includes("abcde", "de") + +let includesFrom1 = "abcde"->String.includesFrom("d", 2) +let includesFrom2 = String.includesFrom("abcde", "d", 2) + +let indexOf1 = "abcde"->String.indexOf("de") +let indexOf2 = String.indexOf("abcde", "de") + +let indexOfFrom1 = "abcde"->String.indexOfFrom("d", 2) +let indexOfFrom2 = String.indexOfFrom("abcde", "d", 2) + +let lastIndexOf1 = "abcde"->String.lastIndexOf("de") +let lastIndexOf2 = String.lastIndexOf("abcde", "de") + +let lastIndexOfFrom1 = "abcde"->String.lastIndexOfFrom("d", 2) +let lastIndexOfFrom2 = String.lastIndexOfFrom("abcde", "d", 2) + +let localeCompare1 = "abcde"->String.localeCompare("fghij") +let localeCompare2 = String.localeCompare("abcde", "fghij") + +let match1 = "abcde"->String.match(/d/) +let match2 = String.match("abcde", /d/) + +let normalize1 = "abcde"->String.normalize +let normalize2 = String.normalize("abcde") + +let repeat1 = "abcde"->String.repeat(2) +let repeat2 = String.repeat("abcde", 2) + +let replace1 = "abcde"->String.replace("d", "f") +let replace2 = String.replace("abcde", "d", "f") + +let replaceByRe1 = "abcde"->String.replaceRegExp(/d/, "f") +let replaceByRe2 = String.replaceRegExp("abcde", /d/, "f") + +let search1 = "abcde"->String.search(/d/) +let search2 = String.search("abcde", /d/) + +let slice1 = "abcde"->String.slice(~start=1, ~end=3) +let slice2 = String.slice("abcde", ~start=1, ~end=3) + +let sliceToEnd1 = "abcde"->String.slice(~start=1) +let sliceToEnd2 = String.slice("abcde", ~start=1) + +let split1 = "abcde"->String.split("d") +let split2 = String.split("abcde", "d") + +let splitAtMost1 = "abcde"->String.splitAtMost("d", ~limit=2) +let splitAtMost2 = String.splitAtMost("abcde", "d", ~limit=2) + +let splitByRe1 = "abcde"->String.splitByRegExp(/d/) +let splitByRe2 = String.splitByRegExp("abcde", /d/) + +let splitByReAtMost1 = "abcde"->String.splitByRegExpAtMost(/d/, ~limit=2) +let splitByReAtMost2 = String.splitByRegExpAtMost("abcde", /d/, ~limit=2) + +let startsWith1 = "abcde"->String.startsWith("ab") +let startsWith2 = String.startsWith("abcde", "ab") + +let startsWithFrom1 = "abcde"->String.startsWithFrom("b", 1) +let startsWithFrom2 = String.startsWithFrom("abcde", "b", 1) + +let substring1 = "abcde"->String.substring(~start=1, ~end=3) +let substring2 = String.substring("abcde", ~start=1, ~end=3) + +let substringToEnd1 = "abcde"->String.substringToEnd(~start=1) +let substringToEnd2 = String.substringToEnd("abcde", ~start=1) + +let toLowerCase1 = "abcde"->String.toLowerCase +let toLowerCase2 = String.toLowerCase("abcde") + +let toLocaleLowerCase1 = "abcde"->String.toLocaleLowerCase +let toLocaleLowerCase2 = String.toLocaleLowerCase("abcde") + +let toUpperCase1 = "abcde"->String.toUpperCase +let toUpperCase2 = String.toUpperCase("abcde") + +let toLocaleUpperCase1 = "abcde"->String.toLocaleUpperCase +let toLocaleUpperCase2 = String.toLocaleUpperCase("abcde") + +let trim1 = "abcde"->String.trim +let trim2 = String.trim("abcde") + +// Type alias migrations +let sT: string = "abc" +let s2T: string = "def" diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_TypedArray_Operations.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_TypedArray_Operations.res new file mode 100644 index 0000000000..9f689ac2fd --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_TypedArray_Operations.res @@ -0,0 +1,8 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_TypedArray_Operations.res. +let ta = Uint8Array.fromArray([1, 2, 3, 4]) + +let a1 = ta->TypedArray.copyWithin(~target=1, ~start=2) +let a2 = ta->TypedArray.fill(9, ~start=1) +let a3 = ta->TypedArray.slice(~start=1) +let a4 = ta->TypedArray.subarray(~start=1) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_TypedArray_Stdlib.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_TypedArray_Stdlib.res new file mode 100644 index 0000000000..fd28700022 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_TypedArray_Stdlib.res @@ -0,0 +1,5 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_TypedArray_Stdlib.res. +let a = Uint8Array.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2) +let b = Uint8Array.fromBuffer(ArrayBuffer.make(8), ~byteOffset=2, ~length=2) +let c = Uint8Array.fromArrayLikeOrIterable([1, 2], ~map=(v, _i) => v) diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_WeakMap.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_WeakMap.res new file mode 100644 index 0000000000..afb50c990c --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_WeakMap.res @@ -0,0 +1,4 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_WeakMap.res. +// Type alias migration for Js.WeakMap.t +external wm: WeakMap.t<{..}, int> = "wm" diff --git a/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_WeakSet.res b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_WeakSet.res new file mode 100644 index 0000000000..af9ad046c2 --- /dev/null +++ b/tests/tools_tests/src/migrate/migrated/Migrated_StdlibMigration_WeakSet.res @@ -0,0 +1,4 @@ +// This file is autogenerated so it can be type checked. +// It's the migrated version of src/migrate/StdlibMigration_WeakSet.res. +// Type alias migration for Js.WeakSet.t +external ws: WeakSet.t<{..}> = "ws" diff --git a/tests/tools_tests/test.sh b/tests/tools_tests/test.sh index 73e42acfd6..4e44f42170 100755 --- a/tests/tools_tests/test.sh +++ b/tests/tools_tests/test.sh @@ -33,6 +33,24 @@ for file in src/docstrings-format/*.{res,resi,md}; do fi done +# Test migrate command +for file in src/migrate/*.{res,resi}; do + output="src/expected/$(basename $file).expected" + ../../_build/install/default/bin/rescript-tools migrate "$file" --stdout > $output + if [ "$RUNNER_OS" == "Windows" ]; then + perl -pi -e 's/\r\n/\n/g' -- $output + fi +done + +# Move migrated files to expected directory so they can be compiled in the project +for file in src/migrate/StdlibMigration_*.res; do + expected_file="src/expected/$(basename $file).expected" + output="src/migrate/migrated/Migrated_$(basename $file)" + echo "// This file is autogenerated so it can be type checked. +// It's the migrated version of $file." > "$output" && cat "$expected_file" >> "$output" + ../../cli/rescript.js format "$output" +done + warningYellow='\033[0;33m' successGreen='\033[0;32m' reset='\033[0m' diff --git a/tools/bin/main.ml b/tools/bin/main.ml index 88f7ffa575..cd810b5309 100644 --- a/tools/bin/main.ml +++ b/tools/bin/main.ml @@ -32,6 +32,8 @@ Usage: rescript-tools [command] Commands: +migrate [--stdout] Runs the migration tool on the given file +migrate-all Runs migrations for all project sources under doc Generate documentation format-codeblocks Format ReScript code blocks [--stdout] Output to stdout @@ -66,6 +68,72 @@ let main () = in logAndExit (Tools.extractDocs ~entryPointFile:path ~debug:false) | _ -> logAndExit (Error docHelp)) + | "migrate" :: file :: opts -> ( + let isStdout = List.mem "--stdout" opts in + let outputMode = if isStdout then `Stdout else `File in + match + (Tools.Migrate.migrate ~entryPointFile:file ~outputMode, outputMode) + with + | Ok content, `Stdout -> print_endline content + | result, `File -> logAndExit result + | Error e, _ -> logAndExit (Error e)) + | "migrate-all" :: root :: _opts -> ( + let rootPath = + if Filename.is_relative root then Unix.realpath root else root + in + match Analysis.Packages.newBsPackage ~rootPath with + | None -> + logAndExit + (Error + (Printf.sprintf + "error: failed to load ReScript project at %s (missing \ + bsconfig.json/rescript.json?)" + rootPath)) + | Some package -> + let moduleNames = + Analysis.SharedTypes.FileSet.elements package.projectFiles + in + let files = + moduleNames + |> List.filter_map (fun modName -> + Hashtbl.find_opt package.pathsForModule modName + |> Option.map Analysis.SharedTypes.getSrc) + |> List.concat + |> List.filter (fun path -> + Filename.check_suffix path ".res" + || Filename.check_suffix path ".resi") + in + let total = List.length files in + if total = 0 then logAndExit (Ok "No source files found to migrate") + else + let process_one file = + (file, Tools.Migrate.migrate ~entryPointFile:file ~outputMode:`File) + in + let results = List.map process_one files in + let migrated, unchanged, failures = + results + |> List.fold_left + (fun (migrated, unchanged, failures) (file, res) -> + match res with + | Ok msg -> + let base = Filename.basename file in + if msg = base ^ ": File migrated successfully" then + (migrated + 1, unchanged, failures) + else if msg = base ^ ": File did not need migration" then + (migrated, unchanged + 1, failures) + else + (* Unknown OK message, count as unchanged *) + (migrated, unchanged + 1, failures) + | Error _ -> (migrated, unchanged, failures + 1)) + (0, 0, 0) + in + let summary = + Printf.sprintf + "Migration summary: migrated %d, unchanged %d, failed %d, total %d" + migrated unchanged failures total + in + if failures > 0 then logAndExit (Error summary) + else logAndExit (Ok summary)) | "format-codeblocks" :: rest -> ( match rest with | ["-h"] | ["--help"] -> logAndExit (Ok formatCodeblocksHelp) diff --git a/tools/src/migrate.md b/tools/src/migrate.md new file mode 100644 index 0000000000..340432bcc0 --- /dev/null +++ b/tools/src/migrate.md @@ -0,0 +1,82 @@ +# Migration Framework – Current Capabilities + +This document captures what the migration framework currently supports, based on `tools/src/migrate.ml` (and helpers in `tools/src/transforms.ml`, `compiler/ml/builtin_attributes.ml`, and `analysis/src/Cmt.ml`). + +## Inputs & Preconditions + +- Targets: `*.res` and `*.resi` files. +- Requires build artifacts for the file’s module (CMT/CMTI). If not found, migration aborts with an error message asking to build the project. +- Output modes: write back to file or print to stdout. + +## Deprecation Sources + +- Migration data is harvested from `@deprecated({ reason, migrate, migrateInPipeChain })` attributes recorded in CMT extras. +- Captured context where deprecation was used: + - `FunctionCall` – a function call site + - `Reference` – a value/identifier reference (non‑call) + +## Supported Rewrites + +- Direct function calls (non‑pipe): + - If `migrate` is an application expression, the call is rewritten according to the template (see Templates & Placeholders). +- Pipe calls using `->`: + - If `migrateInPipeChain` is provided, it is used for piped form. Special handling for single‑step chains (see Pipe Semantics). +- Identifier references (non‑call): + - If `migrate` is provided, the reference is replaced by that expression. + - Special case: if the template is `f()` (unit call), treat it as `f` to avoid adding a spurious unit application. +- Type constructor references: + - If `migrate` is `%replace.type(: )`, type constructor occurrences within the deprecation’s location range are replaced by ``. + - If the template is a constructor with its own type arguments, original type arguments are appended; otherwise original arguments are dropped. +- Extension rename: + - Extension `todo_` is remapped to `todo`. + +## Templates & Placeholders + +- Template form: application expressions only for call‑site rewrites; arbitrary expressions for reference rewrites. +- Placeholders inside template expressions: + - `%insert.unlabelledArgument()` + - 0‑based index into the source call’s unlabelled arguments. + - `%insert.labelledArgument("")` + - Refers to a labelled or optional source argument by name. +- Placeholder replacement occurs anywhere inside the template expression, not only as direct arguments. +- Consumed arguments are dropped from the original call; remaining arguments keep order. +- Label renaming: + - If a template argument has a label and its expression is a labelled placeholder, the corresponding source argument is emitted under the template’s label (rename). + +## Pipe Semantics + +- For piped calls, the pipe LHS is considered unlabelled argument index 0 for placeholder resolution. +- When constructing the inner call, unlabelled drop positions are adjusted to account for the fact that the LHS does not appear as an inner argument. +- Single‑step collapse: + - If the LHS is not itself a pipe and `migrateInPipeChain` exists: + - If `migrate` exists, prefer collapsing the step by applying `migrate` with the LHS inserted as unlabelled argument index 0. + - Otherwise use `migrateInPipeChain` in piped form. +- Empty‑args piped form: + - If piping into a bare identifier and the chosen piped template inserts no arguments, the result remains `lhs -> newFn` (no extra parentheses). + +## Transforms (`@apply.transforms`) + +- Attribute name: `@apply.transforms(["", ...])` on expressions. +- Resolution: IDs map to functions in `tools/src/transforms.ml`. Unknown IDs are ignored. +- Application: + - Attributes attached to template or placeholder expressions are preserved on replacements and applied in a second pass over `.res` implementations. + - Currently implemented transform: `dropUnitArgumentsInApply` (drops only unlabelled unit arguments from application nodes). + - Other registry entries are stubs and currently no‑ops. +- Note: The second pass runs for `.res` (implementations). Interfaces (`.resi`) do not contain expression bodies; transform pass is not applied there. + +## Limitations / Not Supported (Today) + +- Call‑site rewrite requires the template to be an application expression; non‑application templates for calls are ignored. +- Placeholders with negative indices are ignored (no replacement, no drop). +- No special handling for method sends beyond normal call/pipe matching. +- Transforms run only in `.res`. Attachments in `.resi` will be carried in attrs but not executed. +- Only type constructor occurrences are replaced via `%replace.type`; no pattern matching over other type forms. +- Transform registry is minimal; most listed transforms are placeholders. + +## Summary of Behavior + +1. Collect deprecated uses from CMT (with optional templates and contexts). +2. Rewrite references/calls/pipes according to provided templates and placeholder rules. +3. Adjust labels, drop consumed args, and append inserted template args. +4. For `.res`, run a second pass applying any `@apply.transforms` attributes that were attached to expressions during rewriting. +5. Print updated AST; write file or stdout. diff --git a/tools/src/migrate.ml b/tools/src/migrate.ml new file mode 100644 index 0000000000..8a1b4b0140 --- /dev/null +++ b/tools/src/migrate.ml @@ -0,0 +1,746 @@ +open Analysis + +module StringMap = Map.Make (String) +module StringSet = Set.Make (String) +module IntSet = Set.Make (Int) + +(* Public API: migrate ~entryPointFile ~outputMode *) + +let is_unit_expr (e : Parsetree.expression) = + match e.pexp_desc with + | Pexp_construct ({txt = Lident "()"}, None) -> true + | _ -> false + +module InsertExt = struct + type placeholder = Labelled of string | Unlabelled of int + + let ext_labelled = "insert.labelledArgument" + let ext_unlabelled = "insert.unlabelledArgument" + + (* + Unlabelled argument placeholders use 0-based indexing. + Pipe semantics: the pipe LHS occupies index 0 when resolving placeholders + in piped templates. For inner calls that exclude the LHS (e.g. `lhs->f(x)`), + we adjust drop positions at the call site to keep the generated call correct. + *) + let placeholder_of_expr = function + | { + Parsetree.pexp_desc = + Pexp_extension + ( {txt}, + PStr [{pstr_desc = Pstr_eval ({pexp_desc = Pexp_constant c}, _)}] + ); + } -> + if txt = ext_labelled then + match c with + | Pconst_string (name, _) -> Some (Labelled name) + | _ -> None + else if txt = ext_unlabelled then + match c with + | Pconst_integer (s, _) -> ( + match int_of_string_opt s with + | Some i -> Some (Unlabelled i) + | None -> None) + | _ -> None + else None + | _ -> None +end + +module ArgUtils = struct + let map_expr_args mapper args = + args + |> List.map (fun (label, arg) -> (label, mapper.Ast_mapper.expr mapper arg)) +end + +module ExprUtils = struct + let rec is_pipe_apply (e : Parsetree.expression) = + match e.pexp_desc with + | Pexp_apply {funct = {pexp_desc = Pexp_ident {txt = Lident "->"}}; _} -> + true + | Pexp_construct (_, Some e) + | Pexp_constraint (e, _) + | Pexp_coerce (e, _, _) + | Pexp_let (_, _, e) + | Pexp_sequence (e, _) + | Pexp_letmodule (_, _, e) + | Pexp_open (_, _, e) -> + is_pipe_apply e + | _ -> false +end + +type args = (Asttypes.arg_label * Parsetree.expression) list + +module MapperUtils = struct + module ApplyTransforms = struct + let attr_name = "apply.transforms" + + let split_attrs (attrs : Parsetree.attributes) = + List.partition (fun ({Location.txt}, _) -> txt = attr_name) attrs + + let names_of_payload (payload : Parsetree.payload) : string list = + match payload with + | Parsetree.PStr + [ + {pstr_desc = Parsetree.Pstr_eval ({pexp_desc = Pexp_array elems}, _)}; + ] -> + elems + |> List.filter_map (fun (e : Parsetree.expression) -> + match e.pexp_desc with + | Pexp_constant (Pconst_string (s, _)) -> Some s + | _ -> None) + | _ -> [] + + let apply_names (names : string list) (e : Parsetree.expression) : + Parsetree.expression = + List.fold_left + (fun acc name -> + match Transforms.get name with + | Some f -> f acc + | None -> acc) + e names + + let attach_to_replacement ~(attrs : Parsetree.attributes) + (e : Parsetree.expression) : Parsetree.expression = + if Ext_list.is_empty attrs then e + else {e with pexp_attributes = attrs @ e.pexp_attributes} + + (* Apply transforms attached to an expression itself and drop the + transform attributes afterwards. *) + let apply_on_self (e : Parsetree.expression) : Parsetree.expression = + let transform_attrs, other_attrs = split_attrs e.pexp_attributes in + if Ext_list.is_empty transform_attrs then e + else + let names = + transform_attrs + |> List.concat_map (fun (_id, payload) -> names_of_payload payload) + in + let e' = {e with pexp_attributes = other_attrs} in + apply_names names e' + end + + (* Collect placeholder usages anywhere inside an expression. *) + let collect_placeholders (expr : Parsetree.expression) = + let labelled = ref StringSet.empty in + let unlabelled = ref IntSet.empty in + let open Ast_iterator in + let iter = + { + default_iterator with + expr = + (fun self e -> + (match InsertExt.placeholder_of_expr e with + | Some (InsertExt.Labelled name) -> + labelled := StringSet.add name !labelled + | Some (InsertExt.Unlabelled i) when i >= 0 -> + unlabelled := IntSet.add i !unlabelled + | _ -> ()); + default_iterator.expr self e); + } + in + iter.expr iter expr; + (!labelled, !unlabelled) + + (* Build lookup tables for labelled and unlabelled source args. *) + let build_source_arg_tables (source_args : args) = + let labelled = Hashtbl.create 8 in + let unlabelled = Hashtbl.create 8 in + let idx = ref 0 in + source_args + |> List.iter (fun (lbl, arg) -> + match lbl with + | Asttypes.Nolabel -> + Hashtbl.replace unlabelled !idx arg; + incr idx + | Asttypes.Labelled {txt} | Optional {txt} -> + Hashtbl.replace labelled txt arg); + (labelled, unlabelled) + + (* Replace placeholders anywhere inside an expression using the given + source arguments. *) + let replace_placeholders_in_expr (expr : Parsetree.expression) + (source_args : args) = + let labelled, unlabelled = build_source_arg_tables source_args in + let mapper = + { + Ast_mapper.default_mapper with + expr = + (fun mapper exp -> + match InsertExt.placeholder_of_expr exp with + | Some (InsertExt.Labelled name) -> ( + match Hashtbl.find_opt labelled name with + | Some arg -> + ApplyTransforms.attach_to_replacement ~attrs:exp.pexp_attributes + arg + | None -> exp) + | Some (InsertExt.Unlabelled i) -> ( + match Hashtbl.find_opt unlabelled i with + | Some arg -> + ApplyTransforms.attach_to_replacement ~attrs:exp.pexp_attributes + arg + | None -> exp) + | None -> Ast_mapper.default_mapper.expr mapper exp); + } + in + mapper.expr mapper expr + + let build_labelled_args_map (template_args : args) = + template_args + |> List.filter_map (fun (label, arg) -> + match (label, InsertExt.placeholder_of_expr arg) with + | ( (Asttypes.Labelled {txt = label} | Optional {txt = label}), + Some (InsertExt.Labelled arg_name) ) -> + Some (arg_name, label) + | _ -> None) + |> List.fold_left (fun map (k, v) -> StringMap.add k v map) StringMap.empty + + (* + Pure computation of which template args to insert and which source args + are consumed by placeholders. + + Indexing is 0-based everywhere. + For piped application, the pipe LHS occupies index 0 in the source list + used for placeholder resolution. If the inner call excludes the LHS + (e.g. `lhs -> f(args)`), adjust drop positions accordingly at the call site. + + Returns: + - template_args_to_insert: args to append to the final call + - labelled_names_to_drop: names of labelled source args consumed + - unlabelled_positions_to_drop: 0-based indices of unlabelled source args to drop + *) + type template_resolution = { + args_to_insert: args; + labelled_to_drop: StringSet.t; + unlabelled_to_drop: IntSet.t; + } + + let get_template_args_to_insert mapper (template_args : args) + (source_args : args) : template_resolution = + (* For each template argument, decide whether it is a placeholder that + should be substituted from the source call, or a concrete argument which + should be preserved (after mapping through the mapper). + Accumulator: + - rev_args: arguments to append to the final call (in reverse order) + - used_labelled: names of labelled args consumed from the source call + - used_unlabelled: 0-based positions of unlabelled args consumed. *) + let accumulate_template_arg (rev_args, used_labelled, used_unlabelled) + (label, arg) = + (* Always perform nested replacement inside the argument expression, + and collect which placeholders were used so we can drop them from the + original call's arguments. *) + let labelled_used_here, unlabelled_used_here = collect_placeholders arg in + let arg_replaced = replace_placeholders_in_expr arg source_args in + ( (label, mapper.Ast_mapper.expr mapper arg_replaced) :: rev_args, + StringSet.union used_labelled labelled_used_here, + IntSet.union used_unlabelled unlabelled_used_here ) + in + let rev_args, labelled_set, unlabelled_set = + List.fold_left accumulate_template_arg + ([], StringSet.empty, IntSet.empty) + template_args + in + { + args_to_insert = List.rev rev_args; + labelled_to_drop = labelled_set; + unlabelled_to_drop = unlabelled_set; + } + + (* Drop consumed source arguments. + - unlabelled_positions_to_drop: 0-based indices of Nolabel args to drop + - labelled_names_to_drop: names of labelled/optional args to drop *) + let drop_args (source_args : args) ~unlabelled_positions_to_drop + ~labelled_names_to_drop = + let _, rev = + List.fold_left + (fun (idx, acc) (label, arg) -> + match label with + | Asttypes.Nolabel -> + let drop = IntSet.mem idx unlabelled_positions_to_drop in + let idx' = idx + 1 in + if drop then (idx', acc) else (idx', (label, arg) :: acc) + | Asttypes.Labelled {txt} | Optional {txt} -> + if StringSet.mem txt labelled_names_to_drop then (idx, acc) + else (idx, (label, arg) :: acc)) + (0, []) source_args + in + List.rev rev + + let rename_labels (source_args : args) ~labelled_args_map = + source_args + |> List.map (fun (label, arg) -> + match label with + | Asttypes.Labelled ({loc; txt} as l) -> ( + match StringMap.find_opt txt labelled_args_map with + | Some mapped -> (Asttypes.Labelled {loc; txt = mapped}, arg) + | None -> (Asttypes.Labelled l, arg)) + | Optional ({loc; txt} as l) -> ( + match StringMap.find_opt txt labelled_args_map with + | Some mapped -> (Optional {loc; txt = mapped}, arg) + | None -> (Optional l, arg)) + | _ -> (label, arg)) + + let apply_migration_template mapper (template_args : args) + (source_args : args) = + let labelled_args_map = build_labelled_args_map template_args in + let resolution = + get_template_args_to_insert mapper template_args source_args + in + let dropped = + drop_args source_args + ~unlabelled_positions_to_drop:resolution.unlabelled_to_drop + ~labelled_names_to_drop:resolution.labelled_to_drop + in + let renamed = rename_labels dropped ~labelled_args_map in + renamed @ resolution.args_to_insert + + (* Adjust unlabelled drop positions for piped calls where the LHS occupies + position 0 in placeholder resolution, but is not part of the inner call's + argument list. *) + let shift_unlabelled_drop_for_piped set = + IntSet.fold + (fun i acc -> if i > 0 then IntSet.add (i - 1) acc else acc) + set IntSet.empty + + let migrate_piped_args mapper ~template_args ~lhs ~pipe_args = + let full_source_args = lhs :: pipe_args in + let resolution = + get_template_args_to_insert mapper template_args full_source_args + in + let labelled_args_map = build_labelled_args_map template_args in + let adjusted_unlabelled_to_drop = + shift_unlabelled_drop_for_piped resolution.unlabelled_to_drop + in + let dropped = + drop_args pipe_args + ~unlabelled_positions_to_drop:adjusted_unlabelled_to_drop + ~labelled_names_to_drop:resolution.labelled_to_drop + in + let renamed = rename_labels dropped ~labelled_args_map in + renamed @ resolution.args_to_insert +end + +module TypeReplace = struct + let ext_replace_type = "replace.type" + + (* Extract a core_type payload from an expression extension of the form + %replace.type(: ) *) + let core_type_of_expr_extension (expr : Parsetree.expression) = + match expr.pexp_desc with + | Pexp_extension ({txt}, payload) when txt = ext_replace_type -> ( + match payload with + | PTyp ct -> Some ct + | _ -> None) + | _ -> None +end + +let remap_needed_extensions (mapper : Ast_mapper.mapper) + (ext : Parsetree.extension) : Parsetree.extension = + match ext with + | ({txt = "todo_"} as e), payload -> + Ast_mapper.default_mapper.extension mapper ({e with txt = "todo"}, payload) + | e -> Ast_mapper.default_mapper.extension mapper e + +let migrate_reference_from_info (deprecated_info : Cmt_utils.deprecated_used) + exp = + match deprecated_info.migration_template with + | None -> exp + | Some e -> ( + (* For identifier references, treat templates of the form `f()` as the + function reference `f` to avoid inserting a spurious unit call. *) + match e.pexp_desc with + | Pexp_apply + {funct; args = [(_lbl, unit_arg)]; partial = _; transformed_jsx = _} + when is_unit_expr unit_arg -> + MapperUtils.ApplyTransforms.attach_to_replacement ~attrs:e.pexp_attributes + funct + | _ -> e) + +module Template = struct + type t = + | Apply of { + funct: Parsetree.expression; + args: args; + partial: bool; + transformed_jsx: bool; + } + + let attach attrs e = + MapperUtils.ApplyTransforms.attach_to_replacement ~attrs e + + let of_expr = function + | {Parsetree.pexp_desc = Pexp_apply {funct; args; partial; transformed_jsx}} + -> + (* Normalize templates like `f()` to just `f` by dropping a single unit + argument. This treats `String.concat()` as the function reference + `String.concat`, not a call with a unit argument. *) + let args' = + match args with + | [(_lbl, e)] when is_unit_expr e -> [] + | _ -> args + in + Some (Apply {funct; args = args'; partial; transformed_jsx}) + | _ -> None + + let of_expr_with_attrs (e : Parsetree.expression) : + (t * Parsetree.attributes) option = + match of_expr e with + | Some t -> Some (t, e.pexp_attributes) + | None -> None + + let mk_apply (exp : Parsetree.expression) ~funct ~args ~partial + ~transformed_jsx = + {exp with pexp_desc = Pexp_apply {funct; args; partial; transformed_jsx}} + + let apply_direct ~mapper ~template ~template_attrs ~call_args + (exp : Parsetree.expression) = + match template with + | Apply + {funct = template_funct; args = template_args; partial; transformed_jsx} + -> + let migrated_args = + MapperUtils.apply_migration_template mapper template_args call_args + in + let res = + mk_apply exp ~funct:template_funct ~args:migrated_args ~partial + ~transformed_jsx + in + attach template_attrs res + + let apply_piped ~mapper ~template ~template_attrs ~lhs ~pipe_args ~funct + (exp : Parsetree.expression) = + match template with + | Apply + {funct = template_funct; args = template_args; partial; transformed_jsx} + -> + let pipe_args_mapped = ArgUtils.map_expr_args mapper pipe_args in + let migrated_args = + MapperUtils.migrate_piped_args mapper ~template_args ~lhs + ~pipe_args:pipe_args_mapped + in + let inner = Ast_helper.Exp.apply template_funct migrated_args in + let inner_with_attrs = attach template_attrs inner in + mk_apply exp ~funct + ~args:[lhs; (Asttypes.Nolabel, inner_with_attrs)] + ~partial ~transformed_jsx + + let apply_piped_maybe_empty ~mapper ~template ~template_attrs ~lhs ~pipe_args + ~funct (exp : Parsetree.expression) = + match template with + | Apply + {funct = template_funct; args = template_args; partial; transformed_jsx} + -> + if Ext_list.is_empty pipe_args then + let resolution = + MapperUtils.get_template_args_to_insert mapper template_args [] + in + if Ext_list.is_empty resolution.args_to_insert then + let res = + mk_apply exp ~funct + ~args: + [lhs; (Asttypes.Nolabel, attach template_attrs template_funct)] + ~partial ~transformed_jsx + in + res + else + let inner = + Ast_helper.Exp.apply template_funct resolution.args_to_insert + in + let inner_with_attrs = attach template_attrs inner in + mk_apply exp ~funct + ~args:[lhs; (Asttypes.Nolabel, inner_with_attrs)] + ~partial ~transformed_jsx + else + apply_piped ~mapper ~template ~template_attrs ~lhs ~pipe_args ~funct exp + + let apply_single_pipe_collapse ~mapper ~template ~template_attrs ~lhs_exp + ~pipe_args (exp : Parsetree.expression) = + match template with + | Apply + { + funct = templ_f; + args = templ_args; + partial = tpartial; + transformed_jsx = tjsx; + } -> + let pipe_args_mapped = ArgUtils.map_expr_args mapper pipe_args in + let migrated_args = + MapperUtils.apply_migration_template mapper templ_args + ((Asttypes.Nolabel, lhs_exp) :: pipe_args_mapped) + in + let res = + mk_apply exp ~funct:templ_f ~args:migrated_args ~partial:tpartial + ~transformed_jsx:tjsx + in + attach template_attrs res +end + +(* Apply a direct-call migration template to a call site. *) +let apply_template_direct mapper template_expr call_args exp = + match Template.of_expr template_expr with + | Some template -> + Template.apply_direct ~mapper ~template + ~template_attrs:template_expr.pexp_attributes ~call_args exp + | None -> exp + +(* Helper removed: inline selection logic where needed for clarity. *) + +(* Apply migration for a single-step pipe if possible, else use the piped + template. Mirrors the previous inline logic from the mapper. *) +let apply_single_step_or_piped ~mapper + ~(deprecated_info : Cmt_utils.deprecated_used) ~lhs ~lhs_exp ~pipe_args + ~funct exp = + let is_single_pipe_step = not (ExprUtils.is_pipe_apply lhs_exp) in + let in_pipe_template = + match deprecated_info.migration_in_pipe_chain_template with + | Some e -> Template.of_expr_with_attrs e + | None -> None + in + let direct_template = + match deprecated_info.migration_template with + | Some e -> Template.of_expr_with_attrs e + | None -> None + in + if is_single_pipe_step && Option.is_some in_pipe_template then + match direct_template with + | Some (t, attrs) -> + Template.apply_single_pipe_collapse ~mapper ~template:t + ~template_attrs:attrs ~lhs_exp ~pipe_args exp + | None -> ( + match in_pipe_template with + | Some (t, attrs) -> + Template.apply_piped ~mapper ~template:t ~template_attrs:attrs ~lhs + ~pipe_args ~funct exp + | None -> exp) + else + let chosen = + match in_pipe_template with + | None -> direct_template + | some_tpl -> some_tpl + in + match chosen with + | Some (t, attrs) -> + Template.apply_piped_maybe_empty ~mapper ~template:t ~template_attrs:attrs + ~lhs ~pipe_args ~funct exp + | None -> exp + +let makeMapper (deprecated_used : Cmt_utils.deprecated_used list) = + let deprecated_function_calls = + deprecated_used + |> List.filter (fun (d : Cmt_utils.deprecated_used) -> + match d.context with + | Some FunctionCall -> true + | _ -> false) + in + let loc_to_deprecated_fn_call = + Hashtbl.create (List.length deprecated_function_calls) + in + deprecated_function_calls + |> List.iter (fun ({Cmt_utils.source_loc} as d) -> + Hashtbl.replace loc_to_deprecated_fn_call source_loc d); + + let deprecated_references = + deprecated_used + |> List.filter (fun (d : Cmt_utils.deprecated_used) -> + match d.context with + | Some Reference -> true + | _ -> false) + in + let loc_to_deprecated_reference = + Hashtbl.create (List.length deprecated_references) + in + deprecated_references + |> List.iter (fun ({Cmt_utils.source_loc} as d) -> + Hashtbl.replace loc_to_deprecated_reference source_loc d); + + (* Helpers for type replacement lookups *) + let loc_contains (a : Location.t) (b : Location.t) = + let a_start = a.Location.loc_start.pos_cnum in + let a_end = a.Location.loc_end.pos_cnum in + let b_start = b.Location.loc_start.pos_cnum in + let b_end = b.Location.loc_end.pos_cnum in + a_start <= b_start && a_end >= b_end + in + (* Prefilter deprecations that have a %replace.type(: ) payload. *) + let type_replace_deprecations : + (Cmt_utils.deprecated_used * Parsetree.core_type) list = + deprecated_used + |> List.filter_map (fun (d : Cmt_utils.deprecated_used) -> + match d.migration_template with + | Some e -> ( + match TypeReplace.core_type_of_expr_extension e with + | Some ct -> Some (d, ct) + | None -> None) + | None -> None) + in + let find_type_replace_template (loc : Location.t) : Parsetree.core_type option + = + type_replace_deprecations + |> List.find_map (fun ((d : Cmt_utils.deprecated_used), ct) -> + if loc_contains loc d.source_loc || loc_contains d.source_loc loc + then Some ct + else None) + in + + let mapper = + { + Ast_mapper.default_mapper with + extension = remap_needed_extensions; + (* Replace deprecated type references when a %replace.type(: ...) template + is provided. *) + typ = + (fun mapper (ct : Parsetree.core_type) -> + match ct.ptyp_desc with + | Ptyp_constr ({loc}, args) -> ( + match find_type_replace_template loc with + | Some template_ct -> ( + (* Transfer all source type arguments as-is. *) + let mapped_args = List.map (mapper.Ast_mapper.typ mapper) args in + match template_ct.ptyp_desc with + | Ptyp_constr (new_lid, templ_args) -> + let new_args = templ_args @ mapped_args in + let ct' = + {ct with ptyp_desc = Ptyp_constr (new_lid, new_args)} + in + mapper.Ast_mapper.typ mapper ct' + | _ -> + (* If the template isn't a constructor, fall back to the + template itself and drop the original args. *) + let ct' = {template_ct with ptyp_loc = ct.ptyp_loc} in + mapper.Ast_mapper.typ mapper ct') + | None -> Ast_mapper.default_mapper.typ mapper ct) + | _ -> Ast_mapper.default_mapper.typ mapper ct); + expr = + (fun mapper exp -> + match exp with + | {pexp_desc = Pexp_ident {loc}} + when Hashtbl.mem loc_to_deprecated_reference loc -> + let deprecated_info = + Hashtbl.find loc_to_deprecated_reference loc + in + migrate_reference_from_info deprecated_info exp + | { + pexp_desc = + Pexp_apply {funct = {pexp_loc = fn_loc}; args = call_args}; + } + when Hashtbl.mem loc_to_deprecated_fn_call fn_loc -> ( + let deprecated_info = + Hashtbl.find loc_to_deprecated_fn_call fn_loc + in + let call_args = ArgUtils.map_expr_args mapper call_args in + match deprecated_info.migration_template with + | Some e -> apply_template_direct mapper e call_args exp + | None -> exp) + | { + pexp_desc = + Pexp_apply + { + funct = {pexp_desc = Pexp_ident {txt = Lident "->"}} as funct; + args = (lhs_label, lhs_exp) :: (Nolabel, rhs) :: _; + }; + } -> ( + let lhs_exp = mapper.expr mapper lhs_exp in + let lhs = (lhs_label, lhs_exp) in + let fn_loc_opt, pipe_args = + match rhs with + | {pexp_loc = fn_loc; pexp_desc = Pexp_ident _} -> + (Some fn_loc, []) + | { + pexp_desc = + Pexp_apply + { + funct = {pexp_loc = fn_loc; pexp_desc = Pexp_ident _}; + args = pipe_args; + }; + } -> + (Some fn_loc, pipe_args) + | _ -> (None, []) + in + match fn_loc_opt with + | None -> Ast_mapper.default_mapper.expr mapper exp + | Some fn_loc when Hashtbl.mem loc_to_deprecated_fn_call fn_loc -> + let deprecated_info = + Hashtbl.find loc_to_deprecated_fn_call fn_loc + in + apply_single_step_or_piped ~mapper ~deprecated_info ~lhs ~lhs_exp + ~pipe_args ~funct exp + | Some _ -> Ast_mapper.default_mapper.expr mapper exp) + | _ -> Ast_mapper.default_mapper.expr mapper exp); + } + in + mapper + +let migrate ~entryPointFile ~outputMode = + let path = + match Filename.is_relative entryPointFile with + | true -> Unix.realpath entryPointFile + | false -> entryPointFile + in + let result = + if Filename.check_suffix path ".res" then + let parser = + Res_driver.parsing_engine.parse_implementation ~for_printer:true + in + let {Res_driver.parsetree; comments; source} = parser ~filename:path in + match Cmt.loadCmtInfosFromPath ~path with + | None -> + Error + (Printf.sprintf + "error: failed to run migration for %s because build artifacts \ + could not be found. try to build the project" + path) + | Some {cmt_extra_info = {deprecated_used}} -> + let mapper = makeMapper deprecated_used in + let astMapped = mapper.structure mapper parsetree in + (* Second pass: apply any post-migration transforms signaled via @apply.transforms *) + let apply_transforms = + let expr mapper (e : Parsetree.expression) = + let e = Ast_mapper.default_mapper.expr mapper e in + MapperUtils.ApplyTransforms.apply_on_self e + in + {Ast_mapper.default_mapper with expr} + in + let astTransformed = + apply_transforms.structure apply_transforms astMapped + in + Ok + ( Res_printer.print_implementation + ~width:Res_printer.default_print_width astTransformed ~comments, + source ) + else if Filename.check_suffix path ".resi" then + let parser = + Res_driver.parsing_engine.parse_interface ~for_printer:true + in + let {Res_driver.parsetree = signature; comments; source} = + parser ~filename:path + in + + match Cmt.loadCmtInfosFromPath ~path with + | None -> + Error + (Printf.sprintf + "error: failed to run migration for %s because build artifacts \ + could not be found. try to build the project" + path) + | Some {cmt_extra_info = {deprecated_used}} -> + let mapper = makeMapper deprecated_used in + let astMapped = mapper.signature mapper signature in + Ok (Res_printer.print_interface astMapped ~comments, source) + else + Error + (Printf.sprintf + "File extension not supported. This command accepts .res and .resi \ + files") + in + match result with + | Error e -> Error e + | Ok (contents, source) when contents <> source -> ( + match outputMode with + | `Stdout -> Ok contents + | `File -> + let oc = open_out path in + Printf.fprintf oc "%s" contents; + close_out oc; + Ok (Filename.basename path ^ ": File migrated successfully")) + | Ok (contents, _) -> ( + match outputMode with + | `Stdout -> Ok contents + | `File -> Ok (Filename.basename path ^ ": File did not need migration")) diff --git a/tools/src/migrate.mli b/tools/src/migrate.mli new file mode 100644 index 0000000000..1831a90b30 --- /dev/null +++ b/tools/src/migrate.mli @@ -0,0 +1,4 @@ +val migrate : + entryPointFile:string -> + outputMode:[`File | `Stdout] -> + (string, string) result diff --git a/tools/src/tools.ml b/tools/src/tools.ml index 1722fdda07..eb591aa912 100644 --- a/tools/src/tools.ml +++ b/tools/src/tools.ml @@ -1292,3 +1292,5 @@ module ExtractCodeblocks = struct ]) |> Protocol.array) end + +module Migrate = Migrate diff --git a/tools/src/transforms.ml b/tools/src/transforms.ml new file mode 100644 index 0000000000..694a5c4e4b --- /dev/null +++ b/tools/src/transforms.ml @@ -0,0 +1,83 @@ +let labelledToUnlabelledArgumentsInFnDefinition (e : Parsetree.expression) : + Parsetree.expression = + (* `(~a, ~b, ~c) => ...` to `(a, b, c) => ...` *) + let rec dropLabels (e : Parsetree.expression) : Parsetree.expression = + match e.pexp_desc with + | Pexp_fun + {arg_label = Labelled _ | Optional _; default; lhs; rhs; arity; async} + -> + { + e with + pexp_desc = + Pexp_fun + { + arg_label = Nolabel; + default; + lhs; + rhs = dropLabels rhs; + arity; + async; + }; + } + | Pexp_fun {arg_label; default; lhs; rhs; arity; async} -> + { + e with + pexp_desc = + Pexp_fun {arg_label; default; lhs; rhs = dropLabels rhs; arity; async}; + } + | _ -> e + in + dropLabels e + +let makerFnToRecord (e : Parsetree.expression) : Parsetree.expression = + (* `ReactDOM.Style.make(~width="12px", ~height="12px", ())` to `{height: "12px", width: "12px"}` *) + e + +let dictFromArrayToDictLiteralSyntax (e : Parsetree.expression) : + Parsetree.expression = + (* `Dict.fromArray([("a", 1), ("b", 2)])` to `dict{"a": 1, "b": 2}` *) + (* Elgible if all keys are strings *) + e + +let convertedLiteralToPureLiteral (e : Parsetree.expression) : + Parsetree.expression = + (* `Float.fromInt(1)` to `1.`, *) + e + +let dropUnitArgumentsInApply (e : Parsetree.expression) : Parsetree.expression = + (* Drop only unlabelled unit arguments from an application expression. *) + let is_unit_expr (e : Parsetree.expression) = + match e.pexp_desc with + | Pexp_construct ({txt = Lident "()"}, None) -> true + | _ -> false + in + match e.pexp_desc with + | Pexp_apply {funct; args; partial; transformed_jsx} -> + let args' = + List.filter + (fun (label, arg) -> + match label with + | Asttypes.Nolabel -> not (is_unit_expr arg) + | _ -> true) + args + in + { + e with + pexp_desc = Pexp_apply {funct; args = args'; partial; transformed_jsx}; + } + | _ -> e + +(* Registry of available transforms *) +type transform = Parsetree.expression -> Parsetree.expression + +let registry : (string * transform) list = + [ + ( "labelledToUnlabelledArgumentsInFnDefinition", + labelledToUnlabelledArgumentsInFnDefinition ); + ("makerFnToRecord", makerFnToRecord); + ("dictFromArrayToDictLiteralSyntax", dictFromArrayToDictLiteralSyntax); + ("convertedLiteralToPureLiteral", convertedLiteralToPureLiteral); + ("dropUnitArgumentsInApply", dropUnitArgumentsInApply); + ] + +let get (id : string) : transform option = List.assoc_opt id registry