diff --git a/compiler/core/lam.ml b/compiler/core/lam.ml index 1c20bb2e8e..d7c6d6c6cc 100644 --- a/compiler/core/lam.ml +++ b/compiler/core/lam.ml @@ -298,8 +298,8 @@ let rec apply ?(ap_transformed_jsx = false) fn args (ap_info : ap_info) : t = Lprim { primitive = - ( Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt - | Pis_null | Pis_null_undefined | Ptypeof ) as wrap; + ( Pnull_to_opt | Pnull_undefined_to_opt | Pis_null + | Pis_null_undefined | Ptypeof ) as wrap; args = [Lprim ({primitive = _; args = inner_args} as primitive_call)]; }; @@ -442,11 +442,7 @@ let rec seq (a : t) b : t = match a with | Lprim {primitive = Pmakeblock _; args = x :: xs} -> seq (Ext_list.fold_left xs x seq) b - | Lprim - { - primitive = Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt; - args = [a]; - } -> + | Lprim {primitive = Pnull_to_opt | Pnull_undefined_to_opt; args = [a]} -> seq a b | _ -> Lsequence (a, b) @@ -719,8 +715,6 @@ let result_wrap loc (result_type : External_ffi_types.return_wrapper) result = | Return_null_to_opt -> prim ~primitive:Pnull_to_opt ~args:[result] loc | Return_null_undefined_to_opt -> prim ~primitive:Pnull_undefined_to_opt ~args:[result] loc - | Return_undefined_to_opt -> - prim ~primitive:Pundefined_to_opt ~args:[result] loc | Return_unset | Return_identity -> result let handle_bs_non_obj_ffi ?(transformed_jsx = false) diff --git a/compiler/core/lam_analysis.ml b/compiler/core/lam_analysis.ml index 9ad08cee97..a4b78bea0e 100644 --- a/compiler/core/lam_analysis.ml +++ b/compiler/core/lam_analysis.ml @@ -46,8 +46,8 @@ let rec no_side_effects (lam : Lam.t) : bool = | _ -> false) | Pcreate_extension _ | Ptypeof | Pis_null | Pis_not_none | Psome | Psome_not_nest | Pis_undefined | Pis_null_undefined | Pnull_to_opt - | Pundefined_to_opt | Pnull_undefined_to_opt | Pjs_fn_make _ - | Pjs_fn_make_unit | Pjs_object_create _ | Pimport + | Pnull_undefined_to_opt | Pjs_fn_make _ | Pjs_fn_make_unit + | Pjs_object_create _ | Pimport (* TODO: check *) | Pmakeblock _ (* whether it's mutable or not *) diff --git a/compiler/core/lam_compile_primitive.ml b/compiler/core/lam_compile_primitive.ml index 80f27b764a..e7c377e97a 100644 --- a/compiler/core/lam_compile_primitive.ml +++ b/compiler/core/lam_compile_primitive.ml @@ -95,13 +95,6 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) | Var _ | Undefined _ | Null -> Js_of_lam_option.null_to_opt e | _ -> E.runtime_call Primitive_modules.option "fromNull" args) | _ -> assert false) - | Pundefined_to_opt -> ( - match args with - | [e] -> ( - match e.expression_desc with - | Var _ | Undefined _ | Null -> Js_of_lam_option.undef_to_opt e - | _ -> E.runtime_call Primitive_modules.option "fromUndefined" args) - | _ -> assert false) | Pnull_undefined_to_opt -> ( match args with | [e] -> ( diff --git a/compiler/core/lam_convert.ml b/compiler/core/lam_convert.ml index a12b25ac57..544bf033d2 100644 --- a/compiler/core/lam_convert.ml +++ b/compiler/core/lam_convert.ml @@ -220,7 +220,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = | Pisnullable -> prim ~primitive:Pis_null_undefined ~args loc | Pnull_to_opt -> prim ~primitive:Pnull_to_opt ~args loc | Pnullable_to_opt -> prim ~primitive:Pnull_undefined_to_opt ~args loc - | Pundefined_to_opt -> prim ~primitive:Pundefined_to_opt ~args loc | Pis_not_none -> prim ~primitive:Pis_not_none ~args loc | Pval_from_option -> prim ~primitive:Pval_from_option ~args loc | Pval_from_option_not_nest -> diff --git a/compiler/core/lam_pass_collect.ml b/compiler/core/lam_pass_collect.ml index 5f4a0d46e5..f37d74cb6a 100644 --- a/compiler/core/lam_pass_collect.ml +++ b/compiler/core/lam_pass_collect.ml @@ -73,8 +73,6 @@ let collect_info (meta : Lam_stats.t) (lam : Lam.t) = (FunctionId {arity = Lam_arity.info [arity] false; lambda = None}) | Lprim {primitive = Pnull_to_opt; args = [(Lvar _ as l)]; _} -> Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Null)) - | Lprim {primitive = Pundefined_to_opt; args = [(Lvar _ as l)]; _} -> - Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Undefined)) | Lprim {primitive = Pnull_undefined_to_opt; args = [(Lvar _ as l)]} -> Hash_ident.replace meta.ident_tbl ident (OptionalBlock (l, Null_undefined)) diff --git a/compiler/core/lam_pass_deep_flatten.ml b/compiler/core/lam_pass_deep_flatten.ml index 0eddcb1a9d..11258e6a12 100644 --- a/compiler/core/lam_pass_deep_flatten.ml +++ b/compiler/core/lam_pass_deep_flatten.ml @@ -123,8 +123,7 @@ let deep_flatten (lam : Lam.t) : Lam.t = id, (Lprim { - primitive = - Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt; + primitive = Pnull_to_opt | Pnull_undefined_to_opt; args = [Lvar _]; } as arg), body ) -> @@ -134,9 +133,7 @@ let deep_flatten (lam : Lam.t) : Lam.t = id, Lprim { - primitive = - (Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt) as - primitive; + primitive = (Pnull_to_opt | Pnull_undefined_to_opt) as primitive; args = [arg]; }, body ) -> diff --git a/compiler/core/lam_primitive.ml b/compiler/core/lam_primitive.ml index 831555f848..2135293c85 100644 --- a/compiler/core/lam_primitive.ml +++ b/compiler/core/lam_primitive.ml @@ -161,7 +161,6 @@ type t = play safe first *) | Pjs_fn_method - | Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt | Pis_null @@ -224,12 +223,12 @@ let eq_primitive_approx (lhs : t) (rhs : t) = | Pawait (* etc *) | Pjs_apply | Pjs_runtime_apply | Pval_from_option | Pval_from_option_not_nest - | Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt | Pis_null - | Pis_not_none | Psome | Psome_not_nest | Pis_undefined | Pis_null_undefined - | Pimport | Ptypeof | Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod - | Pupdate_mod | Pduprecord | Pmakearray | Parraylength | Parrayrefu - | Parraysetu | Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method - | Phash | Phash_mixstring | Phash_mixint | Phash_finalmix -> + | Pnull_to_opt | Pnull_undefined_to_opt | Pis_null | Pis_not_none | Psome + | Psome_not_nest | Pis_undefined | Pis_null_undefined | Pimport | Ptypeof + | Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod | Pupdate_mod + | Pduprecord | Pmakearray | Parraylength | Parrayrefu | Parraysetu + | Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method | Phash + | Phash_mixstring | Phash_mixint | Phash_finalmix -> rhs = lhs | Pcreate_extension a -> ( match rhs with diff --git a/compiler/core/lam_primitive.mli b/compiler/core/lam_primitive.mli index a4445ceff1..879f03a412 100644 --- a/compiler/core/lam_primitive.mli +++ b/compiler/core/lam_primitive.mli @@ -152,7 +152,6 @@ type t = | Pjs_fn_make of int | Pjs_fn_make_unit | Pjs_fn_method - | Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt | Pis_null diff --git a/compiler/core/lam_print.ml b/compiler/core/lam_print.ml index afc50d10d6..172e219abb 100644 --- a/compiler/core/lam_print.ml +++ b/compiler/core/lam_print.ml @@ -61,7 +61,6 @@ let primitive ppf (prim : Lam_primitive.t) = | Praw_js_code _ -> fprintf ppf "[raw]" | Ptypeof -> fprintf ppf "typeof" | Pnull_to_opt -> fprintf ppf "[null->opt]" - | Pundefined_to_opt -> fprintf ppf "[undefined->opt]" | Pnull_undefined_to_opt -> fprintf ppf "[null/undefined->opt]" | Pis_null -> fprintf ppf "[?null]" | Pis_not_none -> fprintf ppf "[?is-not-none]" diff --git a/compiler/frontend/ast_attributes.ml b/compiler/frontend/ast_attributes.ml index cd5af1db95..8a3eee2b91 100644 --- a/compiler/frontend/ast_attributes.ml +++ b/compiler/frontend/ast_attributes.ml @@ -279,24 +279,6 @@ let set : attr = ({txt = "set"; loc = locg}, Ast_payload.empty) let internal_expansive : attr = ({txt = "internal.expansive"; loc = locg}, Ast_payload.empty) -let bs_return_undefined : attr = - ( {txt = "return"; loc = locg}, - PStr - [ - { - pstr_desc = - Pstr_eval - ( { - pexp_desc = - Pexp_ident {txt = Lident "undefined_to_opt"; loc = locg}; - pexp_loc = locg; - pexp_attributes = []; - }, - [] ); - pstr_loc = locg; - }; - ] ) - let is_gentype (attr : attr) = match attr with | {Location.txt = "genType" | "gentype"; _}, _ -> true diff --git a/compiler/frontend/ast_attributes.mli b/compiler/frontend/ast_attributes.mli index 16892aba0b..1fae9799ea 100644 --- a/compiler/frontend/ast_attributes.mli +++ b/compiler/frontend/ast_attributes.mli @@ -59,8 +59,6 @@ val get_index : attr val set : attr -val bs_return_undefined : attr - val internal_expansive : attr (* val deprecated : string -> attr *) diff --git a/compiler/frontend/ast_derive_abstract.ml b/compiler/frontend/ast_derive_abstract.ml index 064d4f1f17..e59f007618 100644 --- a/compiler/frontend/ast_derive_abstract.ml +++ b/compiler/frontend/ast_derive_abstract.ml @@ -54,8 +54,7 @@ let is_abstract (xs : Ast_payload.action list) = (** For this attributes, its type was wrapped as an option, so we can still reuse existing frame work *) -let get_optional_attrs = - [Ast_attributes.get; Ast_attributes.bs_return_undefined] +let get_optional_attrs = [Ast_attributes.get] let get_attrs = [] diff --git a/compiler/frontend/ast_external_process.ml b/compiler/frontend/ast_external_process.ml index e916e4bc69..7a2cf5926d 100644 --- a/compiler/frontend/ast_external_process.ml +++ b/compiler/frontend/ast_external_process.ml @@ -190,7 +190,6 @@ let init_st = let return_wrapper loc (txt : string) : External_ffi_types.return_wrapper = match txt with - | "undefined_to_opt" -> Return_undefined_to_opt | "null_to_opt" -> Return_null_to_opt | "nullable" | "null_undefined_to_opt" -> Return_null_undefined_to_opt | "identity" -> Return_identity @@ -407,8 +406,7 @@ let check_return_wrapper loc (wrapper : External_ffi_types.return_wrapper) | Return_unset -> if Ast_core_type.is_unit result_type then Return_replaced_with_unit else wrapper - | Return_undefined_to_opt | Return_null_to_opt | Return_null_undefined_to_opt - -> + | Return_null_to_opt | Return_null_undefined_to_opt -> if Ast_core_type.is_user_option result_type then wrapper else Bs_syntaxerr.err loc Expect_opt_in_bs_return_to_opt | Return_replaced_with_unit -> assert false diff --git a/compiler/frontend/external_ffi_types.ml b/compiler/frontend/external_ffi_types.ml index 9016341603..55c93b89e4 100644 --- a/compiler/frontend/external_ffi_types.ml +++ b/compiler/frontend/external_ffi_types.ml @@ -98,7 +98,6 @@ type external_spec = type return_wrapper = | Return_unset | Return_identity - | Return_undefined_to_opt | Return_null_to_opt | Return_null_undefined_to_opt | Return_replaced_with_unit diff --git a/compiler/frontend/external_ffi_types.mli b/compiler/frontend/external_ffi_types.mli index b661c3124b..4a0a87c59f 100644 --- a/compiler/frontend/external_ffi_types.mli +++ b/compiler/frontend/external_ffi_types.mli @@ -74,7 +74,6 @@ type external_spec = type return_wrapper = | Return_unset | Return_identity - | Return_undefined_to_opt | Return_null_to_opt | Return_null_undefined_to_opt | Return_replaced_with_unit diff --git a/compiler/ml/lambda.ml b/compiler/ml/lambda.ml index 2046977019..fa161af920 100644 --- a/compiler/ml/lambda.ml +++ b/compiler/ml/lambda.ml @@ -298,7 +298,6 @@ type primitive = (* js *) | Pcurry_apply of int | Pjscomp of comparison - | Pundefined_to_opt | Pnull_to_opt | Pnullable_to_opt | Pis_not_none diff --git a/compiler/ml/lambda.mli b/compiler/ml/lambda.mli index ecd5db632d..51fd3008b5 100644 --- a/compiler/ml/lambda.mli +++ b/compiler/ml/lambda.mli @@ -265,7 +265,6 @@ type primitive = (* js *) | Pcurry_apply of int | Pjscomp of comparison - | Pundefined_to_opt | Pnull_to_opt | Pnullable_to_opt | Pis_not_none diff --git a/compiler/ml/printlambda.ml b/compiler/ml/printlambda.ml index 27f8873df1..12de80e897 100644 --- a/compiler/ml/printlambda.ml +++ b/compiler/ml/printlambda.ml @@ -253,7 +253,6 @@ let primitive ppf = function | Pjscomp Cle -> fprintf ppf "<=" | Pjscomp Cgt -> fprintf ppf ">" | Pjscomp Cge -> fprintf ppf ">=" - | Pundefined_to_opt -> fprintf ppf "undefined_to_opt" | Pnull_to_opt -> fprintf ppf "null_to_opt" | Pnullable_to_opt -> fprintf ppf "nullable_to_opt" | Pis_not_none -> fprintf ppf "#is_not_none" diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index e9f2400c1f..6609fe553e 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -372,7 +372,6 @@ let primitives_table = ("%null", Pnull); ("%undefined", Pundefined); ("%is_nullable", Pisnullable); - ("%undefined_to_opt", Pundefined_to_opt); ("%null_to_opt", Pnull_to_opt); ("%nullable_to_opt", Pnullable_to_opt); ("%function_arity", Pfn_arity); @@ -397,7 +396,6 @@ let primitives_table = ("#is_nullable", Pisnullable); ("#null_to_opt", Pnull_to_opt); ("#nullable_to_opt", Pnullable_to_opt); - ("#undefined_to_opt", Pundefined_to_opt); ("#makemutablelist", Pmakelist Mutable); ("#import", Pimport); (* FIXME: Deprecated *) diff --git a/lib/es6/Js_array.js b/lib/es6/Js_array.js index 53b53dd109..8c5f4beca9 100644 --- a/lib/es6/Js_array.js +++ b/lib/es6/Js_array.js @@ -1,6 +1,5 @@ -import * as Primitive_option from "./Primitive_option.js"; function copyWithin(to_, obj) { return obj.copyWithin(to_); @@ -115,11 +114,11 @@ function filteri(arg1, obj) { } function find(arg1, obj) { - return Primitive_option.fromUndefined(obj.find(arg1)); + return obj.find(arg1); } function findi(arg1, obj) { - return Primitive_option.fromUndefined(obj.find(arg1)); + return obj.find(arg1); } function findIndex(arg1, obj) { diff --git a/lib/es6/Js_undefined.js b/lib/es6/Js_undefined.js index bd095b530a..19ad8c43a5 100644 --- a/lib/es6/Js_undefined.js +++ b/lib/es6/Js_undefined.js @@ -12,21 +12,21 @@ function testAny(x) { function getExn(f) { if (f !== undefined) { - return f; + return Primitive_option.valFromOption(f); } throw new Error("Js.Undefined.getExn"); } function bind(x, f) { if (x !== undefined) { - return f(x); + return f(Primitive_option.valFromOption(x)); } } function iter(x, f) { if (x !== undefined) { - return f(x); + return f(Primitive_option.valFromOption(x)); } } diff --git a/lib/js/Js_array.js b/lib/js/Js_array.js index 6579f2c2a5..a9c75f24c4 100644 --- a/lib/js/Js_array.js +++ b/lib/js/Js_array.js @@ -1,6 +1,5 @@ 'use strict'; -let Primitive_option = require("./Primitive_option.js"); function copyWithin(to_, obj) { return obj.copyWithin(to_); @@ -115,11 +114,11 @@ function filteri(arg1, obj) { } function find(arg1, obj) { - return Primitive_option.fromUndefined(obj.find(arg1)); + return obj.find(arg1); } function findi(arg1, obj) { - return Primitive_option.fromUndefined(obj.find(arg1)); + return obj.find(arg1); } function findIndex(arg1, obj) { diff --git a/lib/js/Js_undefined.js b/lib/js/Js_undefined.js index 9e915f935d..4a39d516c1 100644 --- a/lib/js/Js_undefined.js +++ b/lib/js/Js_undefined.js @@ -12,21 +12,21 @@ function testAny(x) { function getExn(f) { if (f !== undefined) { - return f; + return Primitive_option.valFromOption(f); } throw new Error("Js.Undefined.getExn"); } function bind(x, f) { if (x !== undefined) { - return f(x); + return f(Primitive_option.valFromOption(x)); } } function iter(x, f) { if (x !== undefined) { - return f(x); + return f(Primitive_option.valFromOption(x)); } } diff --git a/runtime/Belt_internalBucketsType.res b/runtime/Belt_internalBucketsType.res index 2cb648b3dc..73bc602719 100644 --- a/runtime/Belt_internalBucketsType.res +++ b/runtime/Belt_internalBucketsType.res @@ -31,7 +31,7 @@ type container<'hash, 'eq, 'c> = { } module A = Belt_Array -external toOpt: opt<'a> => option<'a> = "%undefined_to_opt" +external toOpt: opt<'a> => option<'a> = "%identity" external return: 'a => opt<'a> = "%identity" let emptyOpt = Js.undefined diff --git a/runtime/Belt_internalBucketsType.resi b/runtime/Belt_internalBucketsType.resi index d8eff6d858..71498b86c9 100644 --- a/runtime/Belt_internalBucketsType.resi +++ b/runtime/Belt_internalBucketsType.resi @@ -30,7 +30,7 @@ type container<'hash, 'eq, 'c> = { eq: 'eq, } -external toOpt: opt<'a> => option<'a> = "%undefined_to_opt" +external toOpt: opt<'a> => option<'a> = "%identity" external return: 'a => opt<'a> = "%identity" let emptyOpt: Js.undefined<'a> diff --git a/runtime/Js.res b/runtime/Js.res index e1bfdcd334..20cc70c2fe 100644 --- a/runtime/Js.res +++ b/runtime/Js.res @@ -190,7 +190,7 @@ type nullable<+'a> = Js_null_undefined.t<'a> = Value('a) | @as(null) Null | @as( type null_undefined<+'a> = nullable<'a> external toOption: nullable<'a> => option<'a> = "%nullable_to_opt" -external undefinedToOption: undefined<'a> => option<'a> = "%undefined_to_opt" +external undefinedToOption: undefined<'a> => option<'a> = "%identity" external nullToOption: null<'a> => option<'a> = "%null_to_opt" external isNullable: nullable<'a> => bool = "%is_nullable" external import: 'a => promise<'a> = "%import" diff --git a/runtime/Js_array.res b/runtime/Js_array.res index 2d6bc43f1d..548e4a1f62 100644 --- a/runtime/Js_array.res +++ b/runtime/Js_array.res @@ -245,7 +245,6 @@ Js.Array.pop(empty) == None ``` */ @send -@return(undefined_to_opt) external pop: t<'a> => option<'a> = "pop" /** @@ -308,7 +307,6 @@ Js.Array.shift(empty) == None ``` */ @send -@return(undefined_to_opt) external shift: t<'a> => option<'a> = "shift" /** @@ -781,7 +779,6 @@ Js.Array.find(x => x < 0, [33, 22, 55, 77, 44]) == None ``` */ @send -@return(undefined_to_opt) external find: (t<'a>, 'a => bool) => option<'a> = "find" let find = (arg1, obj) => find(obj, arg1) @@ -799,7 +796,6 @@ Js.Array.findi(positiveOddElement, [66, -33, 55, -88, 22]) == None ``` */ @send -@return(undefined_to_opt) external findi: (t<'a>, ('a, int) => bool) => option<'a> = "find" let findi = (arg1, obj) => findi(obj, arg1) diff --git a/runtime/Js_array2.res b/runtime/Js_array2.res index c4239dc7a2..aa6bec9eae 100644 --- a/runtime/Js_array2.res +++ b/runtime/Js_array2.res @@ -249,7 +249,6 @@ external fillRangeInPlace: (t<'a>, 'a, ~start: int, ~end_: int) => t<'a> = "fill /* ES2015 */ @send -@return(undefined_to_opt) /** If the array is not empty, removes the last element and returns it as `Some(value)`; returns `None` if the array is empty. *This function modifies @@ -324,7 +323,6 @@ arr == ["cat", "bee", "ant"] external reverseInPlace: t<'a> => t<'a> = "reverse" @send -@return(undefined_to_opt) /** If the array is not empty, removes the first element and returns it as `Some(value)`; returns `None` if the array is empty. *This function modifies @@ -803,7 +801,6 @@ Js.Array2.filteri([6, 3, 5, 8, 7, -4, 1], positiveOddElement) == [3, 8] external filteri: (t<'a>, ('a, int) => bool) => t<'a> = "filter" @send -@return({undefined_to_opt: undefined_to_opt}) /** Returns `Some(value)` for the first element in the array that satisifies the given predicate function, or `None` if no element satisifies the predicate. See @@ -823,7 +820,6 @@ external find: (t<'a>, 'a => bool) => option<'a> = "find" /* ES2015 */ @send -@return({undefined_to_opt: undefined_to_opt}) /** Returns `Some(value)` for the first element in the array that satisifies the given predicate function, or `None` if no element satisifies the predicate. The diff --git a/runtime/Js_undefined.res b/runtime/Js_undefined.res index 8a518b1ce8..996e6cd542 100644 --- a/runtime/Js_undefined.res +++ b/runtime/Js_undefined.res @@ -26,8 +26,8 @@ type t<+'a> = Primitive_js_extern.undefined<'a> -external to_opt: t<'a> => option<'a> = "%undefined_to_opt" -external toOption: t<'a> => option<'a> = "%undefined_to_opt" +external to_opt: t<'a> => option<'a> = "%identity" +external toOption: t<'a> => option<'a> = "%identity" external return: 'a => t<'a> = "%identity" external empty: t<'a> = "%undefined" diff --git a/runtime/Js_undefined.resi b/runtime/Js_undefined.resi index 6b379c62f2..655a86b066 100644 --- a/runtime/Js_undefined.resi +++ b/runtime/Js_undefined.resi @@ -90,6 +90,6 @@ Maps `Js.undefined<'a>` to `option<'a>` `a` => `Some(a)` `empty` => `None` */ -external toOption: t<'a> => option<'a> = "%undefined_to_opt" +external toOption: t<'a> => option<'a> = "%identity" -@deprecated("use toOption instead") external to_opt: t<'a> => option<'a> = "%undefined_to_opt" +@deprecated("use toOption instead") external to_opt: t<'a> => option<'a> = "%identity" diff --git a/tests/tests/src/functor_ffi.mjs b/tests/tests/src/functor_ffi.mjs index 8ea2c8aafe..252d80f93c 100644 --- a/tests/tests/src/functor_ffi.mjs +++ b/tests/tests/src/functor_ffi.mjs @@ -1,16 +1,15 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; function Make(S) { - let opt_get = (f, i) => Primitive_option.fromUndefined(f[i]); + let opt_get = (f, i) => f[i]; return { opt_get: opt_get }; } function opt_get(f, i) { - return Primitive_option.fromUndefined(f[i]); + return f[i]; } let Int_arr = { @@ -20,7 +19,7 @@ let Int_arr = { function f(v) { return [ v[0], - Primitive_option.fromUndefined(v[1]) + v[1] ]; } diff --git a/tests/tests/src/gpr_2614_test.mjs b/tests/tests/src/gpr_2614_test.mjs index 27235a950b..4a52ad1442 100644 --- a/tests/tests/src/gpr_2614_test.mjs +++ b/tests/tests/src/gpr_2614_test.mjs @@ -1,6 +1,5 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; let v = { "Content-Type": 3, @@ -35,7 +34,7 @@ let h2 = { function hh(x) { x["lo-x"] = "3"; - return Primitive_option.fromUndefined(x["lo-x"]); + return x["lo-x"]; } function hh2(x) { diff --git a/tests/tests/src/gpr_974_test.mjs b/tests/tests/src/gpr_974_test.mjs index b3db25c414..fd7ade6d65 100644 --- a/tests/tests/src/gpr_974_test.mjs +++ b/tests/tests/src/gpr_974_test.mjs @@ -15,7 +15,7 @@ if (!Primitive_object.equal(Primitive_option.fromNullable(""), "")) { }; } -if (!Primitive_object.equal(Primitive_option.fromUndefined(""), "")) { +if (!Primitive_object.equal("", "")) { throw { RE_EXN_ID: "Assert_failure", _1: [ diff --git a/tests/tests/src/js_array_test.mjs b/tests/tests/src/js_array_test.mjs index 9b14eaf969..02202f12d9 100644 --- a/tests/tests/src/js_array_test.mjs +++ b/tests/tests/src/js_array_test.mjs @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Mt from "./mt.mjs"; -import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; let suites_0 = [ "isArray_array", @@ -154,11 +153,11 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 3, - _1: Primitive_option.fromUndefined([ + _1: [ 1, 2, 3 - ].pop()) + ].pop() }) ], tl: { @@ -167,7 +166,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: undefined, - _1: Primitive_option.fromUndefined([].pop()) + _1: [].pop() }) ], tl: { @@ -219,11 +218,11 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 1, - _1: Primitive_option.fromUndefined([ + _1: [ 1, 2, 3 - ].shift()) + ].shift() }) ], tl: { @@ -232,7 +231,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: undefined, - _1: Primitive_option.fromUndefined([].shift()) + _1: [].shift() }) ], tl: { @@ -693,12 +692,12 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 2, - _1: Primitive_option.fromUndefined([ + _1: [ 1, 2, 3, 4 - ].find(n => n % 2 === 0)) + ].find(n => n % 2 === 0) }) ], tl: { @@ -707,12 +706,12 @@ let suites_1 = { param => ({ TAG: "Eq", _0: undefined, - _1: Primitive_option.fromUndefined([ + _1: [ 1, 2, 3, 4 - ].find(n => n % 2 === 5)) + ].find(n => n % 2 === 5) }) ], tl: { @@ -721,12 +720,12 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 1, - _1: Primitive_option.fromUndefined([ + _1: [ 1, 2, 3, 4 - ].find((param, i) => i % 2 === 0)) + ].find((param, i) => i % 2 === 0) }) ], tl: { @@ -735,12 +734,12 @@ let suites_1 = { param => ({ TAG: "Eq", _0: undefined, - _1: Primitive_option.fromUndefined([ + _1: [ 1, 2, 3, 4 - ].find((param, i) => i % 2 === 5)) + ].find((param, i) => i % 2 === 5) }) ], tl: { diff --git a/tests/tests/src/js_undefined_test.mjs b/tests/tests/src/js_undefined_test.mjs index 37f280b9c5..2a856ce821 100644 --- a/tests/tests/src/js_undefined_test.mjs +++ b/tests/tests/src/js_undefined_test.mjs @@ -2,7 +2,6 @@ import * as Mt from "./mt.mjs"; import * as Js_undefined from "rescript/lib/es6/Js_undefined.js"; -import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; let suites_0 = [ "toOption - empty", @@ -28,7 +27,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: "something", - _1: Primitive_option.fromUndefined("something") + _1: "something" }) ], tl: { diff --git a/tests/tests/src/optional_regression_test.mjs b/tests/tests/src/optional_regression_test.mjs index a3baf11fc1..f83ebc77f5 100644 --- a/tests/tests/src/optional_regression_test.mjs +++ b/tests/tests/src/optional_regression_test.mjs @@ -35,11 +35,11 @@ let hh = { i: 0 }; -eq("File \"optional_regression_test.res\", line 16, characters 3-10", Primitive_option.fromUndefined(hh.s), ""); +eq("File \"optional_regression_test.res\", line 16, characters 3-10", hh.s, ""); -eq("File \"optional_regression_test.res\", line 17, characters 3-10", Primitive_option.fromUndefined(hh.b), false); +eq("File \"optional_regression_test.res\", line 17, characters 3-10", hh.b, false); -eq("File \"optional_regression_test.res\", line 18, characters 3-10", Primitive_option.fromUndefined(hh.i), 0); +eq("File \"optional_regression_test.res\", line 18, characters 3-10", hh.i, 0); console.log(hh); diff --git a/tests/tests/src/return_check.mjs b/tests/tests/src/return_check.mjs index de09f71e8f..e8a1fc418c 100644 --- a/tests/tests/src/return_check.mjs +++ b/tests/tests/src/return_check.mjs @@ -1,6 +1,5 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; function test(dom) { let elem = dom.getElementById("haha"); @@ -50,7 +49,7 @@ function f_escaped_1(xs, i) { } function f_escaped_2(xs, i) { - console.log(Primitive_option.fromUndefined(xs[i])); + console.log(xs[i]); } function f_null(xs, i) { diff --git a/tests/tests/src/return_check.res b/tests/tests/src/return_check.res index 78f1b15adb..8447e4d4de 100644 --- a/tests/tests/src/return_check.res +++ b/tests/tests/src/return_check.res @@ -16,7 +16,7 @@ let test = dom => { /* external getElementById2 : dom -> string -> element option = "" [@@return null_to_opt] */ -@get_index @return(undefined_to_opt) external get_undefined: (array, int) => option = "" +@get_index external get_undefined: (array, int) => option = "" let f_undefined = (xs, i) => switch get_undefined(xs, i) { diff --git a/tests/tests/src/test_zero_nullable.mjs b/tests/tests/src/test_zero_nullable.mjs index 1cf2904609..743aed2485 100644 --- a/tests/tests/src/test_zero_nullable.mjs +++ b/tests/tests/src/test_zero_nullable.mjs @@ -156,7 +156,7 @@ function f7$1(x) { function f8$1(x) { if (x !== undefined) { - if (x !== undefined) { + if (Primitive_option.valFromOption(x) !== undefined) { return 0; } else { return 1; @@ -169,11 +169,7 @@ function f8$1(x) { let u$1 = f8$1(undefined); function f9$1(x) { - if (x === undefined) { - return; - } else { - return Primitive_option.some(x); - } + return x; } function f10$1(x) { diff --git a/tests/tests/src/undef_regression_test.mjs b/tests/tests/src/undef_regression_test.mjs index 7508734332..361a287dca 100644 --- a/tests/tests/src/undef_regression_test.mjs +++ b/tests/tests/src/undef_regression_test.mjs @@ -1,5 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; function f(obj) { if (typeof obj === "function") { @@ -7,7 +8,7 @@ function f(obj) { } let size = obj.length; if (size !== undefined) { - console.log(size); + console.log(Primitive_option.valFromOption(size)); return; }