diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ece1e0846..1b99798dca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,27 @@ - Make the `--help` arg be prioritized in the CLI, so correctly prints help message and skip other commands. https://github.com/rescript-lang/rescript-compiler/pull/6667 +# 11.1.0-rc.5 + +#### :bug: Bug Fix + +- Fix misparsing in/after JSX. https://github.com/rescript-lang/rescript-compiler/pull/6686 +- Fix `@deriving(accessors)` outputting curried functions in uncurried mode. https://github.com/rescript-lang/rescript-compiler/pull/6687 + +# 11.1.0-rc.4 + +#### :bug: Bug Fix + +- Fix emitting static import instead of dynamic import. https://github.com/rescript-lang/rescript-compiler/pull/6664 +- Fix local type variables breaking react components. https://github.com/rescript-lang/rescript-compiler/pull/6665 +- Fix remove redundant branches in generated switch body. https://github.com/rescript-lang/rescript-compiler/pull/6672 +- Fix issue in partial application when the last named arg is provided. https://github.com/rescript-lang/rescript-compiler/pull/6681 + +#### :nail-care: Polish + +- Omit `undefined` in external function calls for trailing optional arguments when not supplied. https://github.com/rescript-lang/rescript-compiler/pull/6653 +- Make pattern match suggestions to be easier to copy-paste. https://github.com/rescript-lang/rescript-compiler/pull/6656 + # 11.1.0-rc.3 #### :nail_care: Polish diff --git a/docs/docson/build-schema.json b/docs/docson/build-schema.json index 09d2d4923a..32702d9cd5 100644 --- a/docs/docson/build-schema.json +++ b/docs/docson/build-schema.json @@ -439,7 +439,7 @@ "properties": { "number": { "type": "string", - "description": "Default: -40+6+7+27+32..39+44+45 [Here](https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec270) for the meanings of the warning flags" + "description": "Default: \"+a-4-9-20-40-41-42-50-61-102\". Go [here](https://rescript-lang.org/docs/manual/latest/warning-numbers) for the meanings of the warning flags" }, "error": { "oneOf": [ diff --git a/jscomp/build_tests/super_errors/expected/warnings4.res.expected b/jscomp/build_tests/super_errors/expected/warnings4.res.expected index dfa23450b8..8591875997 100644 --- a/jscomp/build_tests/super_errors/expected/warnings4.res.expected +++ b/jscomp/build_tests/super_errors/expected/warnings4.res.expected @@ -10,4 +10,4 @@ 14 │ You forgot to handle a possible case here, for example: - #second(_) | #fourth | #third \ No newline at end of file + | #second(_) | #fourth | #third diff --git a/jscomp/build_tests/super_errors/expected/warnings5.res.expected b/jscomp/build_tests/super_errors/expected/warnings5.res.expected index 91026741ff..1cb0e9757d 100644 --- a/jscomp/build_tests/super_errors/expected/warnings5.res.expected +++ b/jscomp/build_tests/super_errors/expected/warnings5.res.expected @@ -24,7 +24,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 15 │ switch y { You forgot to handle a possible case here, for example: - {otherValue: true, _} + | {otherValue: true, _} Warning number 9 @@ -52,7 +52,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 19 │ let arr = [1] You forgot to handle a possible case here, for example: - {typ: WithPayload(false), _} + | {typ: WithPayload(false), _} | {typ: Variant | One | Two | Three | Four | Five | Six | Seven(_), _} @@ -68,7 +68,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 25 │ switch arr { You forgot to handle a possible case here, for example: - [_] + | [_] Warning number 8 @@ -83,7 +83,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 29 │ switch arr { You forgot to handle a possible case here, for example: - [] + | [] Warning number 8 @@ -98,7 +98,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 33 │ let lst = list{} You forgot to handle a possible case here, for example: - [1, 0] | [0, _] | [] + | [1, 0] | [0, _] | [] Warning number 8 @@ -113,7 +113,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 39 │ switch lst { You forgot to handle a possible case here, for example: - list{_, ..._} + | list{_, ..._} Warning number 8 @@ -128,7 +128,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 43 │ switch lst { You forgot to handle a possible case here, for example: - list{1, 2, _, ..._} | list{1, 0, ..._} | list{1} | list{0, ..._} | list{} + | list{1, 2, _, ..._} | list{1, 0, ..._} | list{1} | list{0, ..._} | list{} Warning number 8 @@ -143,7 +143,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 47 │ switch "abc" { You forgot to handle a possible case here, for example: - list{1, _, ..._} | list{0, ..._} | list{} + | list{1, _, ..._} | list{0, ..._} | list{} Warning number 8 @@ -158,7 +158,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 51 │ switch 0 { You forgot to handle a possible case here, for example: - "*" + | "*" Warning number 8 @@ -173,7 +173,7 @@ Either bind these labels explicitly or add ', _' to the pattern. 55 │ let tuple = (1, true) You forgot to handle a possible case here, for example: - 0 + | 0 Warning number 8 @@ -187,4 +187,4 @@ Either bind these labels explicitly or add ', _' to the pattern. 60 │ You forgot to handle a possible case here, for example: - (_, true) \ No newline at end of file + | (_, true) diff --git a/jscomp/core/lam.ml b/jscomp/core/lam.ml index 7eb7881d44..8aa5fe17bd 100644 --- a/jscomp/core/lam.ml +++ b/jscomp/core/lam.ml @@ -788,13 +788,13 @@ let rec transform_uncurried_arg_type loc (arg_types : External_arg_spec.params) | ([], [] | _ :: _, [] | [], _ :: _) as ok -> ok let handle_bs_non_obj_ffi (arg_types : External_arg_spec.params) - (result_type : External_ffi_types.return_wrapper) ffi args loc prim_name = + (result_type : External_ffi_types.return_wrapper) ffi args loc prim_name ~dynamic_import = if no_auto_uncurried_arg_types arg_types then result_wrap loc result_type - (prim ~primitive:(Pjs_call { prim_name; arg_types; ffi }) ~args loc) + (prim ~primitive:(Pjs_call { prim_name; arg_types; ffi; dynamic_import }) ~args loc) else let n_arg_types, n_args = transform_uncurried_arg_type loc arg_types args in result_wrap loc result_type (prim - ~primitive:(Pjs_call { prim_name; arg_types = n_arg_types; ffi }) + ~primitive:(Pjs_call { prim_name; arg_types = n_arg_types; ffi; dynamic_import }) ~args:n_args loc) diff --git a/jscomp/core/lam.mli b/jscomp/core/lam.mli index d57bdcb316..cc76e5b05b 100644 --- a/jscomp/core/lam.mli +++ b/jscomp/core/lam.mli @@ -91,6 +91,7 @@ val handle_bs_non_obj_ffi : t list -> Location.t -> string -> + dynamic_import: bool -> t (**************************************************************) diff --git a/jscomp/core/lam_compile.ml b/jscomp/core/lam_compile.ml index ed5a704cef..1c68d766df 100644 --- a/jscomp/core/lam_compile.ml +++ b/jscomp/core/lam_compile.ml @@ -573,6 +573,11 @@ and compile_general_cases : break still should not be printed (it will be continuned) TOOD: disabled temporarily since it's not perfect yet *) morph_declare_to_assign cxt (fun cxt declaration -> + (* Exclude cases that are the same as the default if the default is defined *) + let cases = match default with + | Default lam -> List.filter (fun (_, lam1) -> not (Lam.eq_approx lam lam1)) cases + | _ -> cases + in let default = match default with | Complete -> None diff --git a/jscomp/core/lam_compile_env.ml b/jscomp/core/lam_compile_env.ml index 7d86349178..ff1dadb0af 100644 --- a/jscomp/core/lam_compile_env.ml +++ b/jscomp/core/lam_compile_env.ml @@ -60,7 +60,7 @@ let reset () = be escaped quite ugly *) let add_js_module ?import_attributes (hint_name : External_ffi_types.module_bind_name) - (module_name : string) default : Ident.t = + (module_name : string) default ~dynamic_import : Ident.t = let id = Ident.create (match hint_name with @@ -71,7 +71,7 @@ let add_js_module ?import_attributes (hint_name : External_ffi_types.module_bind | Phint_nothing -> Ext_modulename.js_id_name_of_hint_name module_name) in let lam_module_ident : J.module_id = - { id; kind = External { name = module_name; default; import_attributes }; dynamic_import = false } + { id; kind = External { name = module_name; default; import_attributes }; dynamic_import } in match Lam_module_ident.Hash.find_key_opt cached_tbl lam_module_ident with | None -> diff --git a/jscomp/core/lam_compile_env.mli b/jscomp/core/lam_compile_env.mli index 632162faac..c9cfd374b7 100644 --- a/jscomp/core/lam_compile_env.mli +++ b/jscomp/core/lam_compile_env.mli @@ -27,7 +27,7 @@ val reset : unit -> unit val add_js_module : - ?import_attributes:External_ffi_types.import_attributes -> External_ffi_types.module_bind_name -> string -> bool -> Ident.t + ?import_attributes:External_ffi_types.import_attributes -> External_ffi_types.module_bind_name -> string -> bool -> dynamic_import:bool -> Ident.t (** [add_js_module hint_name module_name] Given a js module name and hint name, assign an id to it diff --git a/jscomp/core/lam_compile_external_call.ml b/jscomp/core/lam_compile_external_call.ml index db03d15a2a..9a7a92190e 100644 --- a/jscomp/core/lam_compile_external_call.ml +++ b/jscomp/core/lam_compile_external_call.ml @@ -50,8 +50,8 @@ let splice_obj_apply obj name args = bundle *) let external_var - ({ bundle; module_bind_name; import_attributes } : External_ffi_types.external_module_name) = - let id = Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle false in + ({ bundle; module_bind_name; import_attributes } : External_ffi_types.external_module_name) ~dynamic_import = + let id = Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle false ~dynamic_import in E.external_var ?import_attributes ~external_name:bundle id (* let handle_external_opt @@ -216,21 +216,22 @@ let assemble_args_has_splice (arg_types : specs) (args : exprs) : let translate_scoped_module_val (module_name : External_ffi_types.external_module_name option) (fn : string) - (scopes : string list) = + (scopes : string list) + ~dynamic_import = match module_name with | Some { bundle; module_bind_name; import_attributes } -> ( match scopes with | [] -> let default = fn = "default" in let id = - Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle default + Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle default ~dynamic_import in E.external_var_field ?import_attributes ~external_name:bundle ~field:fn ~default id | x :: rest -> (* TODO: what happens when scope contains "default" ?*) let default = false in let id = - Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle default + Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle default ~dynamic_import in let start = E.external_var_field ?import_attributes ~external_name:bundle ~field:x ~default id @@ -250,10 +251,10 @@ let translate_scoped_access scopes obj = | x :: xs -> Ext_list.fold_left xs (E.dot obj x) E.dot let translate_ffi (cxt : Lam_compile_context.t) arg_types - (ffi : External_ffi_types.external_spec) (args : J.expression list) = + (ffi : External_ffi_types.external_spec) (args : J.expression list) ~dynamic_import = match ffi with | Js_call { external_module_name; name; splice: _; scopes; tagged_template = true } -> - let fn = translate_scoped_module_val external_module_name name scopes in + let fn = translate_scoped_module_val external_module_name name scopes ~dynamic_import in (match args with | [ {expression_desc = Array (strings, _); _}; {expression_desc = Array (values, _); _} ] -> E.tagged_template fn strings values @@ -262,7 +263,7 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types (if dynamic then splice_apply fn args else E.call ~info:{ arity = Full; call_info = Call_na } fn args)) | Js_call { external_module_name = module_name; name = fn; splice; scopes; tagged_template = false } -> - let fn = translate_scoped_module_val module_name fn scopes in + let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in if splice then let args, eff, dynamic = assemble_args_has_splice arg_types args in add_eff eff @@ -270,10 +271,20 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types else E.call ~info:{ arity = Full; call_info = Call_na } fn args) else let args, eff = assemble_args_no_splice arg_types args in + let rec keepNonUndefinedArgs argsList (argTypes : specs) = + match (argsList, argTypes) with + | ( {J.expression_desc = Undefined {isUnit = false}; _} :: rest, + {External_arg_spec.arg_label = Arg_optional; _} :: argTypes ) -> + keepNonUndefinedArgs rest argTypes + | _ -> argsList + in + let args = + keepNonUndefinedArgs (List.rev args) (List.rev arg_types) |> List.rev + in add_eff eff @@ E.call ~info:{ arity = Full; call_info = Call_na } fn args | Js_module_as_fn { external_module_name; splice } -> - let fn = external_var external_module_name in + let fn = external_var external_module_name ~dynamic_import in if splice then let args, eff, dynamic = assemble_args_has_splice arg_types args in (* TODO: fix in rest calling convention *) @@ -303,14 +314,14 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types in if splice then let args, eff, dynamic = assemble_args_has_splice arg_types args in - let fn = translate_scoped_module_val module_name fn scopes in + let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in add_eff eff (mark (); if dynamic then splice_new_apply fn args else E.new_ fn args) else let args, eff = assemble_args_no_splice arg_types args in - let fn = translate_scoped_module_val module_name fn scopes in + let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in add_eff eff (mark (); E.new_ fn args) | Js_send { splice; name; js_send_scopes } -> ( @@ -336,16 +347,16 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types ~info:{ arity = Full; call_info = Call_na } (E.dot self name) args) | _ -> assert false) - | Js_module_as_var module_name -> external_var module_name + | Js_module_as_var module_name -> external_var module_name ~dynamic_import | Js_var { name; external_module_name; scopes } -> (* TODO #11 1. check args -- error checking 2. support [@@scope "window"] we need know whether we should call [add_js_module] or not *) - translate_scoped_module_val external_module_name name scopes + translate_scoped_module_val external_module_name name scopes ~dynamic_import | Js_module_as_class module_name -> - let fn = external_var module_name in + let fn = external_var module_name ~dynamic_import in let args, eff = assemble_args_no_splice arg_types args in (* TODO: fix in rest calling convention *) add_eff eff diff --git a/jscomp/core/lam_compile_external_call.mli b/jscomp/core/lam_compile_external_call.mli index 51d50fbcc9..e8c974f10a 100644 --- a/jscomp/core/lam_compile_external_call.mli +++ b/jscomp/core/lam_compile_external_call.mli @@ -34,6 +34,7 @@ val translate_ffi : External_arg_spec.params -> External_ffi_types.external_spec -> J.expression list -> + dynamic_import:bool -> J.expression (** TODO: document supported attributes diff --git a/jscomp/core/lam_compile_primitive.ml b/jscomp/core/lam_compile_primitive.ml index b25269aaec..2afd22338e 100644 --- a/jscomp/core/lam_compile_primitive.ml +++ b/jscomp/core/lam_compile_primitive.ml @@ -337,8 +337,8 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) (* Lam_compile_external_call.translate loc cxt prim args *) (* Test if the argument is a block or an immediate integer *) | Pjs_object_create _ -> assert false - | Pjs_call { arg_types; ffi } -> - Lam_compile_external_call.translate_ffi cxt arg_types ffi args + | Pjs_call { arg_types; ffi; dynamic_import } -> + Lam_compile_external_call.translate_ffi cxt arg_types ffi args ~dynamic_import (* FIXME, this can be removed later *) | Pisint -> E.is_type_number (Ext_list.singleton_exn args) | Pis_poly_var_block -> E.is_type_object (Ext_list.singleton_exn args) diff --git a/jscomp/core/lam_convert.ml b/jscomp/core/lam_convert.ml index 922184e3a1..dd376230a1 100644 --- a/jscomp/core/lam_convert.ml +++ b/jscomp/core/lam_convert.ml @@ -380,7 +380,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : let may_depends = Lam_module_ident.Hash_set.create 0 in let rec convert_ccall (a_prim : Primitive.description) - (args : Lambda.lambda list) loc : Lam.t = + (args : Lambda.lambda list) loc ~dynamic_import : Lam.t = let prim_name = a_prim.prim_name in let prim_name_len = String.length prim_name in match External_ffi_types.from_string a_prim.prim_native_name with @@ -400,7 +400,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : | Param_number i -> Ext_list.init i (fun _ -> External_arg_spec.dummy) in let args = Ext_list.map args convert_aux in - Lam.handle_bs_non_obj_ffi arg_types result_type ffi args loc prim_name + Lam.handle_bs_non_obj_ffi arg_types result_type ffi args loc prim_name ~dynamic_import | Ffi_inline_const i -> Lam.const i and convert_js_primitive (p : Primitive.description) (args : Lambda.lambda list) loc : Lam.t = @@ -542,7 +542,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : convert_pipe f x outer_loc | Lprim (Prevapply, _, _) -> assert false | Lprim (Pdirapply, _, _) -> assert false - | Lprim (Pccall a, args, loc) -> convert_ccall a args loc + | Lprim (Pccall a, args, loc) -> convert_ccall a args loc ~dynamic_import | Lprim (Pgetglobal id, args, _) -> let args = Ext_list.map args convert_aux in if Ident.is_predef_exn id then diff --git a/jscomp/core/lam_primitive.ml b/jscomp/core/lam_primitive.ml index 26a9f998b2..552906858e 100644 --- a/jscomp/core/lam_primitive.ml +++ b/jscomp/core/lam_primitive.ml @@ -48,6 +48,7 @@ type t = prim_name : string; arg_types : External_arg_spec.params; ffi : External_ffi_types.external_spec; + dynamic_import: bool; } | Pjs_object_create of External_arg_spec.obj_params (* Exceptions *) @@ -249,11 +250,11 @@ let eq_primitive_approx (lhs : t) (rhs : t) = i0 = i1 && flag0 = flag1 && eq_tag_info info0 info1 | _ -> false) | Pduprecord -> rhs = Pduprecord - | Pjs_call { prim_name; arg_types; ffi } -> ( + | Pjs_call { prim_name; arg_types; ffi; dynamic_import } -> ( match rhs with | Pjs_call rhs -> prim_name = rhs.prim_name && arg_types = rhs.arg_types - && ffi = rhs.ffi + && ffi = rhs.ffi && dynamic_import = rhs.dynamic_import | _ -> false) | Pjs_object_create obj_create -> ( match rhs with diff --git a/jscomp/core/lam_primitive.mli b/jscomp/core/lam_primitive.mli index d78dd25e64..4c05d7fe2d 100644 --- a/jscomp/core/lam_primitive.mli +++ b/jscomp/core/lam_primitive.mli @@ -43,6 +43,7 @@ type t = prim_name : string; arg_types : External_arg_spec.params; ffi : External_ffi_types.external_spec; + dynamic_import: bool; } | Pjs_object_create of External_arg_spec.obj_params | Praise diff --git a/jscomp/ext/bsc_warnings.ml b/jscomp/ext/bsc_warnings.ml index 833b46443a..9769142843 100644 --- a/jscomp/ext/bsc_warnings.ml +++ b/jscomp/ext/bsc_warnings.ml @@ -69,6 +69,7 @@ - 102 Bs_polymorphic_comparison *) +(* If you change this, don't forget to adapt docs/docson/build-schema.json as well. *) let defaults_w = "+a-4-9-20-40-41-42-50-61-102" let defaults_warn_error = "-a+5+6+101+109" diff --git a/jscomp/frontend/ast_derive_projector.ml b/jscomp/frontend/ast_derive_projector.ml index ca63811c6f..352aaeb177 100644 --- a/jscomp/frontend/ast_derive_projector.ml +++ b/jscomp/frontend/ast_derive_projector.ml @@ -14,6 +14,13 @@ let init () = { structure_gen = (fun (tdcls : tdcls) _explict_nonrec -> + let handle_uncurried_accessor_tranform ~loc ~arity accessor = + (* Accessors with no params (arity of 0) are simply values and not functions *) + match Config.uncurried.contents with + | Uncurried when arity > 0 -> + Ast_uncurried.uncurriedFun ~loc ~arity accessor + | _ -> accessor + in let handle_tdcl tdcl = let core_type = Ast_derive_util.core_type_of_type_declaration tdcl @@ -39,7 +46,9 @@ let init () = (Pat.constraint_ (Pat.var {txt; loc}) core_type) (Exp.field (Exp.ident {txt = Lident txt; loc}) - {txt = Longident.Lident pld_label; loc}))) + {txt = Longident.Lident pld_label; loc}) + (*arity will alwys be 1 since these are single param functions*) + |> handle_uncurried_accessor_tranform ~arity:1 ~loc)) | Ptype_variant constructor_declarations -> Ext_list.map constructor_declarations (fun @@ -94,7 +103,8 @@ let init () = annotate_type in Ext_list.fold_right vars exp (fun var b -> - Ast_compatible.fun_ (Pat.var {loc; txt = var}) b))) + Ast_compatible.fun_ (Pat.var {loc; txt = var}) b) + |> handle_uncurried_accessor_tranform ~loc ~arity)) | Ptype_abstract | Ptype_open -> Ast_derive_util.notApplicable tdcl.ptype_loc derivingName; [] @@ -103,6 +113,13 @@ let init () = Ext_list.flat_map tdcls handle_tdcl); signature_gen = (fun (tdcls : Parsetree.type_declaration list) _explict_nonrec -> + let handle_uncurried_type_tranform ~loc ~arity t = + match Config.uncurried.contents with + (* Accessors with no params (arity of 0) are simply values and not functions *) + | Uncurried when arity > 0 -> + Ast_uncurried.uncurriedType ~loc ~arity t + | _ -> t + in let handle_tdcl tdcl = let core_type = Ast_derive_util.core_type_of_type_declaration tdcl @@ -119,7 +136,10 @@ let init () = | Ptype_record label_declarations -> Ext_list.map label_declarations (fun {pld_name; pld_type} -> Ast_comb.single_non_rec_val ?attrs:gentype_attrs pld_name - (Ast_compatible.arrow core_type pld_type)) + (Ast_compatible.arrow core_type pld_type + (*arity will alwys be 1 since these are single param functions*) + |> handle_uncurried_type_tranform ~arity:1 + ~loc:pld_name.loc)) | Ptype_variant constructor_declarations -> Ext_list.map constructor_declarations (fun @@ -135,6 +155,7 @@ let init () = | Pcstr_tuple pcd_args -> pcd_args | Pcstr_record _ -> assert false in + let arity = pcd_args |> List.length in let annotate_type = match pcd_res with | Some x -> x @@ -143,7 +164,8 @@ let init () = Ast_comb.single_non_rec_val ?attrs:gentype_attrs {loc; txt = Ext_string.uncapitalize_ascii con_name} (Ext_list.fold_right pcd_args annotate_type (fun x acc -> - Ast_compatible.arrow x acc))) + Ast_compatible.arrow x acc) + |> handle_uncurried_type_tranform ~arity ~loc)) | Ptype_open | Ptype_abstract -> Ast_derive_util.notApplicable tdcl.ptype_loc derivingName; [] diff --git a/jscomp/ml/parmatch.ml b/jscomp/ml/parmatch.ml index e06991290b..d93f1a63df 100644 --- a/jscomp/ml/parmatch.ml +++ b/jscomp/ml/parmatch.ml @@ -2099,6 +2099,7 @@ let do_check_partial ?pred exhaust loc casel pss = match pss with let errmsg = try let buf = Buffer.create 16 in + Buffer.add_string buf "| "; Buffer.add_string buf (!print_res_pat v); begin match check_partial_all v casel with | None -> () diff --git a/jscomp/ml/translcore.ml b/jscomp/ml/translcore.ml index 7033cd5405..512940c72e 100644 --- a/jscomp/ml/translcore.ml +++ b/jscomp/ml/translcore.ml @@ -763,10 +763,18 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda = Translattribute.get_and_remove_inlined_attribute funct in let uncurried_partial_application = + (* In case of partial application foo(args, ...) when some args are missing, + get the arity *) let uncurried_partial_app = Ext_list.exists e.exp_attributes (fun ({txt },_) -> txt = "res.partial") in if uncurried_partial_app then - let arity_opt = Ast_uncurried.uncurried_type_get_arity_opt ~env:funct.exp_env funct.exp_type in - arity_opt + let arity_opt = Ast_uncurried.uncurried_type_get_arity_opt ~env:funct.exp_env funct.exp_type in + match arity_opt with + | Some arity -> + let real_args = List.filter (fun (_, x) -> Option.is_some x) oargs in + if arity > List.length real_args then + Some arity + else None + | None -> None else None in transl_apply ~inlined ~uncurried_partial_application (transl_exp funct) oargs e.exp_loc @@ -1036,7 +1044,7 @@ and transl_apply ?(inlined = Default_inline) ?(uncurried_partial_application=Non | [] -> lapply lam (List.rev_map fst args) in match uncurried_partial_application with - | Some arity when arity > List.length sargs -> + | Some arity -> let extra_arity = arity - List.length sargs in let none_ids = ref [] in let args = Ext_list.filter_map sargs (function diff --git a/jscomp/syntax/src/jsx_common.ml b/jscomp/syntax/src/jsx_common.ml index 4281f0580a..5dd8d2f090 100644 --- a/jscomp/syntax/src/jsx_common.ml +++ b/jscomp/syntax/src/jsx_common.ml @@ -58,6 +58,8 @@ let removeArity binding = match expr.pexp_desc with | _ when Ast_uncurried.exprIsUncurriedFun expr -> Ast_uncurried.exprExtractUncurriedFun expr + | Pexp_newtype (label, e) -> + {expr with pexp_desc = Pexp_newtype (label, removeArityRecord e)} | Pexp_apply (forwardRef, [(label, e)]) -> { expr with diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index cf8c4fe474..6215bb0cc2 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -2602,6 +2602,7 @@ and parseJsxOpeningOrSelfClosingElement ~startPos p = let childrenStartPos = p.Parser.startPos in Parser.next p; let childrenEndPos = p.Parser.startPos in + Scanner.popMode p.scanner Jsx; Parser.expect GreaterThan p; let loc = mkLoc childrenStartPos childrenEndPos in makeListExpression loc [] None (* no children *) @@ -2611,8 +2612,6 @@ and parseJsxOpeningOrSelfClosingElement ~startPos p = Parser.next p; let spread, children = parseJsxChildren p in let childrenEndPos = p.Parser.startPos in - Scanner.popMode p.scanner Jsx; - Scanner.setJsxMode p.scanner; let () = match p.token with | LessThanSlash -> Parser.next p @@ -2624,12 +2623,14 @@ and parseJsxOpeningOrSelfClosingElement ~startPos p = in match p.Parser.token with | (Lident _ | Uident _) when verifyJsxOpeningClosingName p name -> ( + Scanner.popMode p.scanner Jsx; Parser.expect GreaterThan p; let loc = mkLoc childrenStartPos childrenEndPos in match (spread, children) with | true, child :: _ -> child | _ -> makeListExpression loc children None) | token -> ( + Scanner.popMode p.scanner Jsx; let () = if Grammar.isStructureItemStart token then let closing = "" in @@ -2650,6 +2651,7 @@ and parseJsxOpeningOrSelfClosingElement ~startPos p = | true, child :: _ -> child | _ -> makeListExpression loc children None)) | token -> + Scanner.popMode p.scanner Jsx; Parser.err p (Diagnostics.unexpected token p.breadcrumbs); makeListExpression Location.none [] None in @@ -2677,7 +2679,6 @@ and parseJsxOpeningOrSelfClosingElement ~startPos p = * jsx-children ::= primary-expr* * => 0 or more *) and parseJsx p = - Scanner.popMode p.scanner Jsx; Scanner.setJsxMode p.Parser.scanner; Parser.leaveBreadcrumb p Grammar.Jsx; let startPos = p.Parser.startPos in @@ -2690,7 +2691,6 @@ and parseJsx p = parseJsxFragment p | _ -> parseJsxName p in - Scanner.popMode p.scanner Jsx; Parser.eatBreadcrumb p; {jsxExpr with pexp_attributes = [jsxAttr]} @@ -2704,9 +2704,10 @@ and parseJsxFragment p = Parser.expect GreaterThan p; let _spread, children = parseJsxChildren p in let childrenEndPos = p.Parser.startPos in + if p.token = LessThan then p.token <- Scanner.reconsiderLessThan p.scanner; Parser.expect LessThanSlash p; - Parser.expect GreaterThan p; Scanner.popMode p.scanner Jsx; + Parser.expect GreaterThan p; let loc = mkLoc childrenStartPos childrenEndPos in makeListExpression loc children None @@ -2758,6 +2759,7 @@ and parseJsxProp p = Some (label, attrExpr)) (* {...props} *) | Lbrace -> ( + Scanner.popMode p.scanner Jsx; Parser.next p; match p.Parser.token with | DotDotDot -> ( @@ -2776,6 +2778,7 @@ and parseJsxProp p = match p.Parser.token with | Rbrace -> Parser.next p; + Scanner.setJsxMode p.scanner; Some (label, attrExpr) | _ -> None) | _ -> None) @@ -2785,6 +2788,7 @@ and parseJsxProps p = parseRegion ~grammar:Grammar.JsxAttribute ~f:parseJsxProp p and parseJsxChildren p = + Scanner.popMode p.scanner Jsx; let rec loop p children = match p.Parser.token with | Token.Eof | LessThanSlash -> children @@ -2805,21 +2809,23 @@ and parseJsxChildren p = let () = p.token <- token in children | token when Grammar.isJsxChildStart token -> - let () = Scanner.popMode p.scanner Jsx in let child = parsePrimaryExpr ~operand:(parseAtomicExpr p) ~noCall:true p in loop p (child :: children) | _ -> children in - match p.Parser.token with - | DotDotDot -> - Parser.next p; - (true, [parsePrimaryExpr ~operand:(parseAtomicExpr p) ~noCall:true p]) - | _ -> - let children = List.rev (loop p []) in - Scanner.popMode p.scanner Jsx; - (false, children) + let spread, children = + match p.Parser.token with + | DotDotDot -> + Parser.next p; + (true, [parsePrimaryExpr ~operand:(parseAtomicExpr p) ~noCall:true p]) + | _ -> + let children = List.rev (loop p []) in + (false, children) + in + Scanner.setJsxMode p.scanner; + (spread, children) and parseBracedOrRecordExpr p = let startPos = p.Parser.startPos in diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/jsx.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/jsx.res.txt index fccf7675bd..908cbf768a 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/jsx.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/jsx.res.txt @@ -580,11 +580,13 @@ let _ = ;;((div ~children:((span ~children:[] ())[@JSX ]) ())[@JSX ]) ;;((div ~children:[|a|] ())[@JSX ]) ;;((div ~children:(1, 2) ())[@JSX ]) +;;((div ~children:((array |. f)[@res.braces ]) ())[@JSX ]) ;;(([element])[@JSX ]) ;;(([(((fun a -> 1))[@res.braces ])])[@JSX ]) ;;(([((span ~children:[] ())[@JSX ])])[@JSX ]) ;;(([[|a|]])[@JSX ]) ;;(([(1, 2)])[@JSX ]) +;;(([((array |. f)[@res.braces ])])[@JSX ]) let _ = ((A.createElement ~x:(({js|y|js})[@res.namedArgLoc ]) ~_spreadProps:((str) [@res.namedArgLoc ]) ~children:[] ()) diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/jsx.res b/jscomp/syntax/tests/parsing/grammar/expressions/jsx.res index 78287c37b3..e712324aa0 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/jsx.res +++ b/jscomp/syntax/tests/parsing/grammar/expressions/jsx.res @@ -507,11 +507,13 @@ let _ =
...
...[a]
...(1, 2)
+
...{array->f}
<> ...element <> ...{(a) => 1} <> ... <> ...[a] <> ...(1, 2) +<> ...{array->f} let _ = \ No newline at end of file diff --git a/jscomp/syntax/tests/ppx/react/expected/newtype.res.txt b/jscomp/syntax/tests/ppx/react/expected/newtype.res.txt index 7d09fa4528..ca23fe5ad2 100644 --- a/jscomp/syntax/tests/ppx/react/expected/newtype.res.txt +++ b/jscomp/syntax/tests/ppx/react/expected/newtype.res.txt @@ -99,3 +99,16 @@ let make = { \"Newtype" } + +@@uncurried + +module Uncurried = { + type props<'foo> = {foo?: 'foo} + + let make = (type a, {?foo, _}: props<_>) => React.null + let make = { + let \"Newtype$Uncurried" = (props: props<_>) => make(props) + + \"Newtype$Uncurried" + } +} diff --git a/jscomp/syntax/tests/ppx/react/newtype.res b/jscomp/syntax/tests/ppx/react/newtype.res index aab1935456..e1d859a8d4 100644 --- a/jscomp/syntax/tests/ppx/react/newtype.res +++ b/jscomp/syntax/tests/ppx/react/newtype.res @@ -45,4 +45,10 @@ module V4A3 = { } @react.component -let make =(~x : ('a,'b), ~q:'a ) => [fst(x), q] \ No newline at end of file +let make =(~x : ('a,'b), ~q:'a ) => [fst(x), q] + +@@uncurried + +module Uncurried = { + @react.component + let make = (type a, ~foo=?) => React.null} diff --git a/jscomp/syntax/tests/printer/expr/expected/jsx.res.txt b/jscomp/syntax/tests/printer/expr/expected/jsx.res.txt index 30eae4bc43..f63ffeac15 100644 --- a/jscomp/syntax/tests/printer/expr/expected/jsx.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/jsx.res.txt @@ -427,3 +427,34 @@ let x = props => {...props} className="inline-block px-6 py-2.5 bg-blue-600 text-white font-medium text-xs leading-tight" /> + +let x = ...{() => msg->React.string} + +let x = ...{array->Array.map(React.string)} + +let x = <> {array->Array.map(React.string)} + +let x = { + let _ =
+ msg->React.string +} + +let x = { + let _ =
{children}
+ msg->React.string +} + +let x = { + let _ = <> {children} + msg->React.string +} + +let x = { + let _ = + msg->React.string +} + +let x = { + let _ = {children} + msg->React.string +} diff --git a/jscomp/syntax/tests/printer/expr/jsx.res b/jscomp/syntax/tests/printer/expr/jsx.res index 7387b073e7..2745f5974f 100644 --- a/jscomp/syntax/tests/printer/expr/jsx.res +++ b/jscomp/syntax/tests/printer/expr/jsx.res @@ -412,3 +412,34 @@ let x = props => {...props} className="inline-block px-6 py-2.5 bg-blue-600 text-white font-medium text-xs leading-tight" /> + +let x = ...{() => msg->React.string} + +let x = ...{array->Array.map(React.string)} + +let x = <> ...{array->Array.map(React.string)} + +let x = { + let _ =
+ msg->React.string +} + +let x = { + let _ =
{children}
+ msg->React.string +} + +let x = { + let _ = <> {children} + msg->React.string +} + +let x = { + let _ = + msg->React.string +} + +let x = { + let _ = {children} + msg->React.string +} diff --git a/jscomp/test/DerivingAccessorsCurried.js b/jscomp/test/DerivingAccessorsCurried.js new file mode 100644 index 0000000000..eccd00c518 --- /dev/null +++ b/jscomp/test/DerivingAccessorsCurried.js @@ -0,0 +1,57 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +var Curry = require("../../lib/js/curry.js"); + +function myField(param) { + return param.myField; +} + +function num(param_0) { + return { + TAG: "Num", + _0: param_0 + }; +} + +function doubleNum(param_0, param_1) { + return { + TAG: "DoubleNum", + _0: param_0, + _1: param_1 + }; +} + +function compose(a, accessor) { + return Curry._1(accessor, a); +} + +var _composedMyField = 1; + +var _composedNum = { + TAG: "Num", + _0: 1 +}; + +var noParam = "NoParam"; + +var _myFieldAlias = myField; + +var _noParamAlias = "NoParam"; + +var _numAlias = num; + +var _doubleNumAlias = doubleNum; + +exports.myField = myField; +exports.noParam = noParam; +exports.num = num; +exports.doubleNum = doubleNum; +exports._myFieldAlias = _myFieldAlias; +exports._noParamAlias = _noParamAlias; +exports._numAlias = _numAlias; +exports._doubleNumAlias = _doubleNumAlias; +exports.compose = compose; +exports._composedMyField = _composedMyField; +exports._composedNum = _composedNum; +/* No side effect */ diff --git a/jscomp/test/DerivingAccessorsCurried.res b/jscomp/test/DerivingAccessorsCurried.res new file mode 100644 index 0000000000..80ff7ef476 --- /dev/null +++ b/jscomp/test/DerivingAccessorsCurried.res @@ -0,0 +1,21 @@ +//Assert that deriving accessors does not break +//In curried mode + +@deriving(accessors) +type myRecord = { myField: int } + +@deriving(accessors) +type variant = | NoParam | Num(int) | DoubleNum(int, int) + +//Asserts the correct signature for derived accessor +let _myFieldAlias: myRecord => int = myField +let _noParamAlias: variant = noParam +let _numAlias: int => variant = num +let _doubleNumAlias: (int, int) => variant = doubleNum + +//Asserts that inference works when composing +//with derived functions +let compose = (a, accessor) => accessor(a) +let _composedMyField = compose({ myField: 1 }, myField) +let _composedNum = compose(1, num) + diff --git a/jscomp/test/DerivingAccessorsUncurried.js b/jscomp/test/DerivingAccessorsUncurried.js new file mode 100644 index 0000000000..e4c47c8f17 --- /dev/null +++ b/jscomp/test/DerivingAccessorsUncurried.js @@ -0,0 +1,56 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + + +function myField(param) { + return param.myField; +} + +function num(param_0) { + return { + TAG: "Num", + _0: param_0 + }; +} + +function doubleNum(param_0, param_1) { + return { + TAG: "DoubleNum", + _0: param_0, + _1: param_1 + }; +} + +function compose(a, accessor) { + return accessor(a); +} + +var _composedMyField = 1; + +var _composedNum = { + TAG: "Num", + _0: 1 +}; + +var noParam = "NoParam"; + +var _myFieldAlias = myField; + +var _noParamAlias = "NoParam"; + +var _numAlias = num; + +var _doubleNumAlias = doubleNum; + +exports.myField = myField; +exports.noParam = noParam; +exports.num = num; +exports.doubleNum = doubleNum; +exports._myFieldAlias = _myFieldAlias; +exports._noParamAlias = _noParamAlias; +exports._numAlias = _numAlias; +exports._doubleNumAlias = _doubleNumAlias; +exports.compose = compose; +exports._composedMyField = _composedMyField; +exports._composedNum = _composedNum; +/* No side effect */ diff --git a/jscomp/test/DerivingAccessorsUncurried.res b/jscomp/test/DerivingAccessorsUncurried.res new file mode 100644 index 0000000000..130f82c32d --- /dev/null +++ b/jscomp/test/DerivingAccessorsUncurried.res @@ -0,0 +1,22 @@ +//Assert that deriving accessors does not break +//In uncurried mode +@@uncurried + +@deriving(accessors) +type myRecord = { myField: int } + +@deriving(accessors) +type variant = | NoParam | Num(int) | DoubleNum(int, int) + +//Asserts the correct signature for derived accessor +let _myFieldAlias: myRecord => int = myField +let _noParamAlias: variant = noParam +let _numAlias: int => variant = num +let _doubleNumAlias: (int, int) => variant = doubleNum + +//Asserts that inference works when composing +//with derived functions +let compose = (a, accessor) => accessor(a) +let _composedMyField = compose({ myField: 1 }, myField) +let _composedNum = compose(1, num) + diff --git a/jscomp/test/DerivingAccessorsUnurried.js b/jscomp/test/DerivingAccessorsUnurried.js new file mode 100644 index 0000000000..eccd00c518 --- /dev/null +++ b/jscomp/test/DerivingAccessorsUnurried.js @@ -0,0 +1,57 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +var Curry = require("../../lib/js/curry.js"); + +function myField(param) { + return param.myField; +} + +function num(param_0) { + return { + TAG: "Num", + _0: param_0 + }; +} + +function doubleNum(param_0, param_1) { + return { + TAG: "DoubleNum", + _0: param_0, + _1: param_1 + }; +} + +function compose(a, accessor) { + return Curry._1(accessor, a); +} + +var _composedMyField = 1; + +var _composedNum = { + TAG: "Num", + _0: 1 +}; + +var noParam = "NoParam"; + +var _myFieldAlias = myField; + +var _noParamAlias = "NoParam"; + +var _numAlias = num; + +var _doubleNumAlias = doubleNum; + +exports.myField = myField; +exports.noParam = noParam; +exports.num = num; +exports.doubleNum = doubleNum; +exports._myFieldAlias = _myFieldAlias; +exports._noParamAlias = _noParamAlias; +exports._numAlias = _numAlias; +exports._doubleNumAlias = _doubleNumAlias; +exports.compose = compose; +exports._composedMyField = _composedMyField; +exports._composedNum = _composedNum; +/* No side effect */ diff --git a/jscomp/test/UncurriedAlways.js b/jscomp/test/UncurriedAlways.js index a70b90bcf1..e197d2239d 100644 --- a/jscomp/test/UncurriedAlways.js +++ b/jscomp/test/UncurriedAlways.js @@ -179,6 +179,33 @@ function a$1(__x) { }), 2, __x); } +function f3(x, y, z) { + console.log(x); + return (x + y | 0) + z | 0; +} + +function fx(extra, extra$1) { + return f3(1, extra, extra$1); +} + +function fy(none, extra) { + return f3(none, 1, extra); +} + +function fz(none, none$1) { + return f3(none, none$1, 1); +} + +var fxyz = f3(1, 1, 1); + +var PartialApplication = { + f3: f3, + fx: fx, + fy: fy, + fz: fz, + fxyz: fxyz +}; + exports.foo = foo; exports.z = z; exports.bar = bar; @@ -198,4 +225,5 @@ exports.OptMixed = OptMixed; exports.fn = fn; exports.fn1 = fn1; exports.a = a$1; +exports.PartialApplication = PartialApplication; /* Not a pure module */ diff --git a/jscomp/test/UncurriedAlways.res b/jscomp/test/UncurriedAlways.res index 88264bef79..a8872f689e 100644 --- a/jscomp/test/UncurriedAlways.res +++ b/jscomp/test/UncurriedAlways.res @@ -75,3 +75,18 @@ fn(s => Js.log(#foo(s))) let fn1 = (a, b, ()) => a() + b let a = fn1(() => 1, 2, _) + +module PartialApplication = { + let f3 = (~x, ~y, ~z) => { + Js.log(x) + x + y + z + } + + let fx = f3(~x=1, ...) + + let fy = f3(~y=1, ...) + + let fz = f3(~z=1, ...) + + let fxyz = f3(~x=1, ~y=1, ~z=1, ...) +} diff --git a/jscomp/test/gpr_1438.js b/jscomp/test/gpr_1438.js index 6e286ffb3e..1007c0d56d 100644 --- a/jscomp/test/gpr_1438.js +++ b/jscomp/test/gpr_1438.js @@ -12,22 +12,6 @@ function actionKey(key, a, b, c, d, e) { return e; case 116 : return b; - case 100 : - case 101 : - case 102 : - case 103 : - case 104 : - case 105 : - case 108 : - case 109 : - case 110 : - case 111 : - case 112 : - case 113 : - case 114 : - case 115 : - case 117 : - break; case 99 : case 118 : return a; diff --git a/jscomp/test/gpr_1698_test.js b/jscomp/test/gpr_1698_test.js index 1d14c72e7e..2a0fb865d9 100644 --- a/jscomp/test/gpr_1698_test.js +++ b/jscomp/test/gpr_1698_test.js @@ -168,8 +168,6 @@ function compare(context, state, _a, _b) { switch (b.TAG) { case "Pow" : return 1; - case "Gcd" : - return -1; default: return -1; } diff --git a/jscomp/test/import2.js b/jscomp/test/import2.js new file mode 100644 index 0000000000..00deaef5c0 --- /dev/null +++ b/jscomp/test/import2.js @@ -0,0 +1,14 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +var A = require("a").default; + +var a = import("a").then(function (m) { + return m.default; + }); + +var b = A; + +exports.a = a; +exports.b = b; +/* a Not a pure module */ diff --git a/jscomp/test/import2.res b/jscomp/test/import2.res new file mode 100644 index 0000000000..9130ed5f23 --- /dev/null +++ b/jscomp/test/import2.res @@ -0,0 +1,2 @@ +let a = Js.import(Import_external.makeA) +let b = Import_external.makeA diff --git a/jscomp/test/import_external.js b/jscomp/test/import_external.js new file mode 100644 index 0000000000..595a8b2358 --- /dev/null +++ b/jscomp/test/import_external.js @@ -0,0 +1,10 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + + +var f8 = import("a").then(function (m) { + return m.default; + }); + +exports.f8 = f8; +/* f8 Not a pure module */ diff --git a/jscomp/test/import_external.res b/jscomp/test/import_external.res new file mode 100644 index 0000000000..e3e93b123b --- /dev/null +++ b/jscomp/test/import_external.res @@ -0,0 +1,4 @@ +@module("a") +external makeA: string = "default" + +let f8 = Js.import(makeA) diff --git a/jscomp/test/mario_game.js b/jscomp/test/mario_game.js index 95150eadbc..6983adb8ad 100644 --- a/jscomp/test/mario_game.js +++ b/jscomp/test/mario_game.js @@ -2377,25 +2377,6 @@ function keydown(evt) { case 83 : pressed_keys.down = true; break; - case 67 : - case 69 : - case 70 : - case 71 : - case 72 : - case 73 : - case 74 : - case 75 : - case 76 : - case 77 : - case 78 : - case 79 : - case 80 : - case 81 : - case 82 : - case 84 : - case 85 : - case 86 : - break; case 87 : pressed_keys.up = true; break; diff --git a/jscomp/test/ocaml_re_test.js b/jscomp/test/ocaml_re_test.js index a93a34a8c1..041f35e63e 100644 --- a/jscomp/test/ocaml_re_test.js +++ b/jscomp/test/ocaml_re_test.js @@ -3541,23 +3541,6 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { }); case 90 : return "Last_end_of_line"; - case 58 : - case 59 : - case 60 : - case 61 : - case 62 : - case 63 : - case 64 : - case 91 : - case 92 : - case 93 : - case 94 : - case 95 : - case 96 : - return { - TAG: "Set", - _0: single(c) - }; case 98 : return alt$1({ hd: "Beg_of_word", diff --git a/jscomp/test/omit_trailing_undefined_in_external_calls.js b/jscomp/test/omit_trailing_undefined_in_external_calls.js new file mode 100644 index 0000000000..7a225b6f1d --- /dev/null +++ b/jscomp/test/omit_trailing_undefined_in_external_calls.js @@ -0,0 +1,15 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +'use strict'; + +var SomeModule = require("SomeModule"); + +SomeModule.formatDate(new Date()); + +SomeModule.formatDate(new Date(), { + someOption: true + }); + +var x = SomeModule.formatDate(new Date(), undefined, true); + +exports.x = x; +/* Not a pure module */ diff --git a/jscomp/test/omit_trailing_undefined_in_external_calls.res b/jscomp/test/omit_trailing_undefined_in_external_calls.res new file mode 100644 index 0000000000..4e4fca946d --- /dev/null +++ b/jscomp/test/omit_trailing_undefined_in_external_calls.res @@ -0,0 +1,11 @@ +@@uncurried + +type dateFormatOptions = {someOption?: bool} + +@module("SomeModule") +external formatDate: (Js.Date.t, ~options: dateFormatOptions=?, ~done: bool=?) => string = + "formatDate" + +let x = formatDate(Js.Date.make()) +let x = formatDate(Js.Date.make(), ~options={someOption: true}) +let x = formatDate(Js.Date.make(), ~done=true) diff --git a/jscomp/test/string_test.js b/jscomp/test/string_test.js index 2744674448..30571ddd1b 100644 --- a/jscomp/test/string_test.js +++ b/jscomp/test/string_test.js @@ -46,11 +46,6 @@ function gg(x) { case 4 : a = 6; break; - case 5 : - case 6 : - case 7 : - a = 8; - break; case 8 : a = 7; break; diff --git a/jscomp/test/typeof_test.js b/jscomp/test/typeof_test.js index 44dcf4b821..0985549075 100644 --- a/jscomp/test/typeof_test.js +++ b/jscomp/test/typeof_test.js @@ -8,9 +8,6 @@ function string_or_number(x) { var ty = Js_types.classify(x); if (typeof ty !== "object") { switch (ty) { - case "JSFalse" : - case "JSTrue" : - return false; default: return false; } diff --git a/lib/es6/caml_format.js b/lib/es6/caml_format.js index e0452d321b..a67a4a58fe 100644 --- a/lib/es6/caml_format.js +++ b/lib/es6/caml_format.js @@ -46,8 +46,6 @@ function parse_sign_and_base(s) { case 43 : i = i + 1 | 0; break; - case 44 : - break; case 45 : sign = -1; i = i + 1 | 0; @@ -417,19 +415,6 @@ function parse_format(fmt) { }; _i = j; continue ; - case 33 : - case 34 : - case 36 : - case 37 : - case 38 : - case 39 : - case 40 : - case 41 : - case 42 : - case 44 : - case 47 : - exit = 1; - break; case 48 : f.filter = "0"; _i = i + 1 | 0; diff --git a/lib/es6/genlex.js b/lib/es6/genlex.js index 09a9b041b3..362e36152b 100644 --- a/lib/es6/genlex.js +++ b/lib/es6/genlex.js @@ -240,9 +240,6 @@ function make_lexer(keywords) { case 94 : exit = 3; break; - case 95 : - exit = 2; - break; case 91 : case 93 : case 96 : @@ -535,12 +532,6 @@ function make_lexer(keywords) { case 114 : Stream.junk(strm__); return /* '\r' */13; - case 111 : - case 112 : - case 113 : - case 115 : - Stream.junk(strm__); - return c1; case 116 : Stream.junk(strm__); return /* '\t' */9; @@ -617,9 +608,6 @@ function make_lexer(keywords) { RE_EXN_ID: Stream.Failure, Error: new Error() }; - case 41 : - Stream.junk(strm__); - continue ; case 42 : Stream.junk(strm__); while(true) { diff --git a/lib/js/caml_format.js b/lib/js/caml_format.js index 47e458a5da..bb6e0c34eb 100644 --- a/lib/js/caml_format.js +++ b/lib/js/caml_format.js @@ -46,8 +46,6 @@ function parse_sign_and_base(s) { case 43 : i = i + 1 | 0; break; - case 44 : - break; case 45 : sign = -1; i = i + 1 | 0; @@ -417,19 +415,6 @@ function parse_format(fmt) { }; _i = j; continue ; - case 33 : - case 34 : - case 36 : - case 37 : - case 38 : - case 39 : - case 40 : - case 41 : - case 42 : - case 44 : - case 47 : - exit = 1; - break; case 48 : f.filter = "0"; _i = i + 1 | 0; diff --git a/lib/js/genlex.js b/lib/js/genlex.js index 27b3c7d43d..ff3731e9c6 100644 --- a/lib/js/genlex.js +++ b/lib/js/genlex.js @@ -240,9 +240,6 @@ function make_lexer(keywords) { case 94 : exit = 3; break; - case 95 : - exit = 2; - break; case 91 : case 93 : case 96 : @@ -535,12 +532,6 @@ function make_lexer(keywords) { case 114 : Stream.junk(strm__); return /* '\r' */13; - case 111 : - case 112 : - case 113 : - case 115 : - Stream.junk(strm__); - return c1; case 116 : Stream.junk(strm__); return /* '\t' */9; @@ -617,9 +608,6 @@ function make_lexer(keywords) { RE_EXN_ID: Stream.Failure, Error: new Error() }; - case 41 : - Stream.junk(strm__); - continue ; case 42 : Stream.junk(strm__); while(true) {