From 75f4116657e2f084e9f0905f7da6388a6bea768d Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 8 Aug 2023 20:10:05 +0200 Subject: [PATCH 1/7] Remove some bspack stuff --- jscomp/test/conditional/test.sh | 5 ----- scripts/ninja.js | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100755 jscomp/test/conditional/test.sh diff --git a/jscomp/test/conditional/test.sh b/jscomp/test/conditional/test.sh deleted file mode 100755 index b72867b7e9..0000000000 --- a/jscomp/test/conditional/test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -set -e -B=true bspack.exe -bs-main a.ml -o a_B.ml -C=true bspack.exe -bs-main a.ml -o a_C.ml -bspack.exe -bs-main a.ml -o a_none.ml diff --git a/scripts/ninja.js b/scripts/ninja.js index f3112ca96e..bce31a4465 100755 --- a/scripts/ninja.js +++ b/scripts/ninja.js @@ -1170,7 +1170,8 @@ ${mllList(ninjaCwd, [ return ( x.endsWith(".resi") || x.endsWith(".res") || - ((x.endsWith(".ml") || x.endsWith(".mli")) && !x.endsWith("bspack.ml")) + x.endsWith(".ml") || + x.endsWith(".mli") ); }); From c9ef45b2f21c7fabbf0dcd315420849c9dea219c Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 9 Aug 2023 08:58:30 +0200 Subject: [PATCH 2/7] Remove OCaml stuff that won't work in .res --- jscomp/test/fail/gpr_978.ml | 9 --------- jscomp/test/fail/gpr_978.mli | 6 ------ jscomp/test/tmp/gen.ml | 33 --------------------------------- jscomp/test/tmp/hey.ml | 4 ---- jscomp/test/tmp/hi.ml | 2 -- jscomp/test/tmp/run.sh | 21 --------------------- 6 files changed, 75 deletions(-) delete mode 100644 jscomp/test/fail/gpr_978.ml delete mode 100644 jscomp/test/fail/gpr_978.mli delete mode 100644 jscomp/test/tmp/gen.ml delete mode 100644 jscomp/test/tmp/hey.ml delete mode 100644 jscomp/test/tmp/hi.ml delete mode 100755 jscomp/test/tmp/run.sh diff --git a/jscomp/test/fail/gpr_978.ml b/jscomp/test/fail/gpr_978.ml deleted file mode 100644 index dfb588e7f3..0000000000 --- a/jscomp/test/fail/gpr_978.ml +++ /dev/null @@ -1,9 +0,0 @@ - - -let f x = x + 1 -let f x = x * 1 - - -class f (x : int) = object - method hey = x -end diff --git a/jscomp/test/fail/gpr_978.mli b/jscomp/test/fail/gpr_978.mli deleted file mode 100644 index 23dc291382..0000000000 --- a/jscomp/test/fail/gpr_978.mli +++ /dev/null @@ -1,6 +0,0 @@ -val f : int -> int -val f : int -> int - -class f : int -> object - method hey : int -end diff --git a/jscomp/test/tmp/gen.ml b/jscomp/test/tmp/gen.ml deleted file mode 100644 index 2c905a847d..0000000000 --- a/jscomp/test/tmp/gen.ml +++ /dev/null @@ -1,33 +0,0 @@ - -#directory "+compiler-libs";; -#load "ocamlcommon.cma";; - -open Ast_helper - -let gen loc top files = - files - |> List.map begin fun f -> - Str.module_ - (Mb.mk {loc ; - txt = String.capitalize f} - (Mod.ident {loc; txt = Lident ( top ^ "-" ^ String.capitalize f) })) - end - -type _ kind = - | Ml : Parsetree.structure kind - | Mli : Parsetree.signature kind -let write_ast (type t) ~(fname : string) ~output (kind : t kind) ( pt : t) : unit = - let magic = - match kind with - | Ml -> Config.ast_impl_magic_number - | Mli -> Config.ast_intf_magic_number in - let oc = open_out output in - output_string oc magic ; - output_value oc fname; - output_value oc pt; - close_out oc - -let strs = gen Location.none "Tmp" ["Hey"] - -let () = write_ast ~fname:"Tmp.mlmap" ~output:"Tmp.mlast" Ml strs - diff --git a/jscomp/test/tmp/hey.ml b/jscomp/test/tmp/hey.ml deleted file mode 100644 index aba98b1e01..0000000000 --- a/jscomp/test/tmp/hey.ml +++ /dev/null @@ -1,4 +0,0 @@ - - - -let a = 3 diff --git a/jscomp/test/tmp/hi.ml b/jscomp/test/tmp/hi.ml deleted file mode 100644 index 1573490ccc..0000000000 --- a/jscomp/test/tmp/hi.ml +++ /dev/null @@ -1,2 +0,0 @@ -let b = Hey.a - diff --git a/jscomp/test/tmp/run.sh b/jscomp/test/tmp/run.sh deleted file mode 100755 index afdeedd240..0000000000 --- a/jscomp/test/tmp/run.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -set -e -ocaml gen.ml -bscc -w -49 -no-alias-deps -c -impl Tmp.mlast -bscc -w -24 -open Tmp -o Tmp-Hey.cmi -c hey.ml -bscc -w -24 -open Tmp -o Tmp-Hi.cmi -c hi.ml - -# can we enforce all stdlib comes from -# Std.List? (seems no) - - -# can we create module alias for sub dirs -# module SubDir = Tmp-SubDir - -# Tmp-SubDir.mlast - -# module N1 = SubDir-N1 - -# vs - -# module N1 = Tmp-SubDir-N1 From 90d96b92c1fa43df9d409c2cdc303893e6c99c9e Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 9 Aug 2023 09:15:19 +0200 Subject: [PATCH 3/7] jscomp/test: .ml -> .res --- jscomp/test/acyc/a0_a1.ml | 1 - .../test/{glob/glob_u.ml => acyc/a0_a1.res} | 0 jscomp/test/acyc/a1_a2.mli | 1 - jscomp/test/acyc/{a1_a2.ml => a1_a2.res} | 0 jscomp/test/acyc/a1_a2.resi | 1 + jscomp/test/acyc/{a2_a3.ml => a2_a3.res} | 0 jscomp/test/acyc/{a3_a4.ml => a3_a4.res} | 0 jscomp/test/acyc/{a4_a5.ml => a4_a5.res} | 2 +- jscomp/test/acyc/x.ml | 35 ------------------- jscomp/test/acyc/x.res | 19 ++++++++++ jscomp/test/conditional/a.ml | 9 ----- jscomp/test/conditional/a.res | 1 + jscomp/test/conditional/a_B.ml | 17 --------- jscomp/test/conditional/a_B.res | 6 ++++ jscomp/test/conditional/a_C.ml | 16 --------- jscomp/test/conditional/a_C.res | 6 ++++ jscomp/test/conditional/a_none.ml | 10 ------ jscomp/test/conditional/a_none.res | 3 ++ jscomp/test/conditional/{c.ml => b.res} | 0 jscomp/test/conditional/{b.ml => c.res} | 1 - jscomp/test/cyc/{a_b.ml => a_b.res} | 0 jscomp/test/cyc/{b_a.ml => b_a.res} | 0 jscomp/test/cyc/{c.ml => c.res} | 0 jscomp/test/fail/gpr_978_module.ml | 4 --- jscomp/test/fail/gpr_978_module.res | 4 +++ jscomp/test/glob/glob_test_add.ml | 1 - jscomp/test/glob/glob_test_add.res | 1 + .../glob/{glob_test_u.ml => glob_test_u.res} | 0 jscomp/test/glob/{xlob_x.ml => glob_u.res} | 0 jscomp/test/glob/{glob_x.ml => glob_x.res} | 0 jscomp/test/glob/xlob_x.res | 1 + jscomp/test/slot/test_concat.ml | 5 --- jscomp/test/slot/test_concat.res | 5 +++ 33 files changed, 48 insertions(+), 101 deletions(-) delete mode 100644 jscomp/test/acyc/a0_a1.ml rename jscomp/test/{glob/glob_u.ml => acyc/a0_a1.res} (100%) delete mode 100644 jscomp/test/acyc/a1_a2.mli rename jscomp/test/acyc/{a1_a2.ml => a1_a2.res} (100%) create mode 100644 jscomp/test/acyc/a1_a2.resi rename jscomp/test/acyc/{a2_a3.ml => a2_a3.res} (100%) rename jscomp/test/acyc/{a3_a4.ml => a3_a4.res} (100%) rename jscomp/test/acyc/{a4_a5.ml => a4_a5.res} (53%) delete mode 100644 jscomp/test/acyc/x.ml create mode 100644 jscomp/test/acyc/x.res delete mode 100644 jscomp/test/conditional/a.ml create mode 100644 jscomp/test/conditional/a.res delete mode 100644 jscomp/test/conditional/a_B.ml create mode 100644 jscomp/test/conditional/a_B.res delete mode 100644 jscomp/test/conditional/a_C.ml create mode 100644 jscomp/test/conditional/a_C.res delete mode 100644 jscomp/test/conditional/a_none.ml create mode 100644 jscomp/test/conditional/a_none.res rename jscomp/test/conditional/{c.ml => b.res} (100%) rename jscomp/test/conditional/{b.ml => c.res} (93%) rename jscomp/test/cyc/{a_b.ml => a_b.res} (100%) rename jscomp/test/cyc/{b_a.ml => b_a.res} (100%) rename jscomp/test/cyc/{c.ml => c.res} (100%) delete mode 100644 jscomp/test/fail/gpr_978_module.ml create mode 100644 jscomp/test/fail/gpr_978_module.res delete mode 100644 jscomp/test/glob/glob_test_add.ml create mode 100644 jscomp/test/glob/glob_test_add.res rename jscomp/test/glob/{glob_test_u.ml => glob_test_u.res} (100%) rename jscomp/test/glob/{xlob_x.ml => glob_u.res} (100%) rename jscomp/test/glob/{glob_x.ml => glob_x.res} (100%) create mode 100644 jscomp/test/glob/xlob_x.res delete mode 100644 jscomp/test/slot/test_concat.ml create mode 100644 jscomp/test/slot/test_concat.res diff --git a/jscomp/test/acyc/a0_a1.ml b/jscomp/test/acyc/a0_a1.ml deleted file mode 100644 index 290125b22f..0000000000 --- a/jscomp/test/acyc/a0_a1.ml +++ /dev/null @@ -1 +0,0 @@ -let v = 3 diff --git a/jscomp/test/glob/glob_u.ml b/jscomp/test/acyc/a0_a1.res similarity index 100% rename from jscomp/test/glob/glob_u.ml rename to jscomp/test/acyc/a0_a1.res diff --git a/jscomp/test/acyc/a1_a2.mli b/jscomp/test/acyc/a1_a2.mli deleted file mode 100644 index acfdb4c90b..0000000000 --- a/jscomp/test/acyc/a1_a2.mli +++ /dev/null @@ -1 +0,0 @@ -val v : int diff --git a/jscomp/test/acyc/a1_a2.ml b/jscomp/test/acyc/a1_a2.res similarity index 100% rename from jscomp/test/acyc/a1_a2.ml rename to jscomp/test/acyc/a1_a2.res diff --git a/jscomp/test/acyc/a1_a2.resi b/jscomp/test/acyc/a1_a2.resi new file mode 100644 index 0000000000..19b83dc216 --- /dev/null +++ b/jscomp/test/acyc/a1_a2.resi @@ -0,0 +1 @@ +let v: int diff --git a/jscomp/test/acyc/a2_a3.ml b/jscomp/test/acyc/a2_a3.res similarity index 100% rename from jscomp/test/acyc/a2_a3.ml rename to jscomp/test/acyc/a2_a3.res diff --git a/jscomp/test/acyc/a3_a4.ml b/jscomp/test/acyc/a3_a4.res similarity index 100% rename from jscomp/test/acyc/a3_a4.ml rename to jscomp/test/acyc/a3_a4.res diff --git a/jscomp/test/acyc/a4_a5.ml b/jscomp/test/acyc/a4_a5.res similarity index 53% rename from jscomp/test/acyc/a4_a5.ml rename to jscomp/test/acyc/a4_a5.res index 3a1fa073f9..fe605a8638 100644 --- a/jscomp/test/acyc/a4_a5.ml +++ b/jscomp/test/acyc/a4_a5.res @@ -1,3 +1,3 @@ include A3_a4 -;; Js.log v +Js.log(v) diff --git a/jscomp/test/acyc/x.ml b/jscomp/test/acyc/x.ml deleted file mode 100644 index 6f76aa3e43..0000000000 --- a/jscomp/test/acyc/x.ml +++ /dev/null @@ -1,35 +0,0 @@ -module A0_a1 -= struct -#1 "a0_a1.ml" -let v = 3 - -end -module A1_a2 : sig -#1 "a1_a2.mli" -val v : int - -end = struct -#1 "a1_a2.ml" -let v = A0_a1.v - -end -module A2_a3 -= struct -#1 "a2_a3.ml" -let v = A1_a2.v - -end -module A3_a4 -= struct -#1 "a3_a4.ml" -include A2_a3 - -end -module A4_a5 -= struct -#1 "a4_a5.ml" -include A3_a4 - -;; Js.log v - -end diff --git a/jscomp/test/acyc/x.res b/jscomp/test/acyc/x.res new file mode 100644 index 0000000000..c1e75af08d --- /dev/null +++ b/jscomp/test/acyc/x.res @@ -0,0 +1,19 @@ +module A0_a1 = { + let v = 3 +} +module A1_a2: { + let v: int +} = { + let v = A0_a1.v +} +module A2_a3 = { + let v = A1_a2.v +} +module A3_a4 = { + include A2_a3 +} +module A4_a5 = { + include A3_a4 + + Js.log(v) +} diff --git a/jscomp/test/conditional/a.ml b/jscomp/test/conditional/a.ml deleted file mode 100644 index df06a03090..0000000000 --- a/jscomp/test/conditional/a.ml +++ /dev/null @@ -1,9 +0,0 @@ - -let u = -#if defined B then - B.value -#elif defined C then - C.value -#else - assert false -#end diff --git a/jscomp/test/conditional/a.res b/jscomp/test/conditional/a.res new file mode 100644 index 0000000000..c2f270fd05 --- /dev/null +++ b/jscomp/test/conditional/a.res @@ -0,0 +1 @@ +let u = assert(false) diff --git a/jscomp/test/conditional/a_B.ml b/jscomp/test/conditional/a_B.ml deleted file mode 100644 index 681837e2d6..0000000000 --- a/jscomp/test/conditional/a_B.ml +++ /dev/null @@ -1,17 +0,0 @@ -module B -= struct -#1 "b.ml" -let value = 3 - - -end -module A -= struct -#1 "a.ml" - -let u = - - B.value - - -end diff --git a/jscomp/test/conditional/a_B.res b/jscomp/test/conditional/a_B.res new file mode 100644 index 0000000000..e4d235f354 --- /dev/null +++ b/jscomp/test/conditional/a_B.res @@ -0,0 +1,6 @@ +module B = { + let value = 3 +} +module A = { + let u = B.value +} diff --git a/jscomp/test/conditional/a_C.ml b/jscomp/test/conditional/a_C.ml deleted file mode 100644 index 8f6d3b4693..0000000000 --- a/jscomp/test/conditional/a_C.ml +++ /dev/null @@ -1,16 +0,0 @@ -module C -= struct -#1 "c.ml" -let value = 3 - -end -module A -= struct -#1 "a.ml" - -let u = - - C.value - - -end diff --git a/jscomp/test/conditional/a_C.res b/jscomp/test/conditional/a_C.res new file mode 100644 index 0000000000..fe61d4890d --- /dev/null +++ b/jscomp/test/conditional/a_C.res @@ -0,0 +1,6 @@ +module C = { + let value = 3 +} +module A = { + let u = C.value +} diff --git a/jscomp/test/conditional/a_none.ml b/jscomp/test/conditional/a_none.ml deleted file mode 100644 index d40eabc1ae..0000000000 --- a/jscomp/test/conditional/a_none.ml +++ /dev/null @@ -1,10 +0,0 @@ -module A -= struct -#1 "a.ml" - -let u = - - assert false - - -end diff --git a/jscomp/test/conditional/a_none.res b/jscomp/test/conditional/a_none.res new file mode 100644 index 0000000000..08434a9623 --- /dev/null +++ b/jscomp/test/conditional/a_none.res @@ -0,0 +1,3 @@ +module A = { + let u = assert(false) +} diff --git a/jscomp/test/conditional/c.ml b/jscomp/test/conditional/b.res similarity index 100% rename from jscomp/test/conditional/c.ml rename to jscomp/test/conditional/b.res diff --git a/jscomp/test/conditional/b.ml b/jscomp/test/conditional/c.res similarity index 93% rename from jscomp/test/conditional/b.ml rename to jscomp/test/conditional/c.res index 064954366d..e1b898c188 100644 --- a/jscomp/test/conditional/b.ml +++ b/jscomp/test/conditional/c.res @@ -1,2 +1 @@ let value = 3 - diff --git a/jscomp/test/cyc/a_b.ml b/jscomp/test/cyc/a_b.res similarity index 100% rename from jscomp/test/cyc/a_b.ml rename to jscomp/test/cyc/a_b.res diff --git a/jscomp/test/cyc/b_a.ml b/jscomp/test/cyc/b_a.res similarity index 100% rename from jscomp/test/cyc/b_a.ml rename to jscomp/test/cyc/b_a.res diff --git a/jscomp/test/cyc/c.ml b/jscomp/test/cyc/c.res similarity index 100% rename from jscomp/test/cyc/c.ml rename to jscomp/test/cyc/c.res diff --git a/jscomp/test/fail/gpr_978_module.ml b/jscomp/test/fail/gpr_978_module.ml deleted file mode 100644 index 2a4c814dcc..0000000000 --- a/jscomp/test/fail/gpr_978_module.ml +++ /dev/null @@ -1,4 +0,0 @@ -exception M of int -module M = struct - let x = 3 -end diff --git a/jscomp/test/fail/gpr_978_module.res b/jscomp/test/fail/gpr_978_module.res new file mode 100644 index 0000000000..68133a407d --- /dev/null +++ b/jscomp/test/fail/gpr_978_module.res @@ -0,0 +1,4 @@ +exception M(int) +module M = { + let x = 3 +} diff --git a/jscomp/test/glob/glob_test_add.ml b/jscomp/test/glob/glob_test_add.ml deleted file mode 100644 index 089229ad0b..0000000000 --- a/jscomp/test/glob/glob_test_add.ml +++ /dev/null @@ -1 +0,0 @@ -let add x y = x + y diff --git a/jscomp/test/glob/glob_test_add.res b/jscomp/test/glob/glob_test_add.res new file mode 100644 index 0000000000..1997dd2443 --- /dev/null +++ b/jscomp/test/glob/glob_test_add.res @@ -0,0 +1 @@ +let add = (x, y) => x + y diff --git a/jscomp/test/glob/glob_test_u.ml b/jscomp/test/glob/glob_test_u.res similarity index 100% rename from jscomp/test/glob/glob_test_u.ml rename to jscomp/test/glob/glob_test_u.res diff --git a/jscomp/test/glob/xlob_x.ml b/jscomp/test/glob/glob_u.res similarity index 100% rename from jscomp/test/glob/xlob_x.ml rename to jscomp/test/glob/glob_u.res diff --git a/jscomp/test/glob/glob_x.ml b/jscomp/test/glob/glob_x.res similarity index 100% rename from jscomp/test/glob/glob_x.ml rename to jscomp/test/glob/glob_x.res diff --git a/jscomp/test/glob/xlob_x.res b/jscomp/test/glob/xlob_x.res new file mode 100644 index 0000000000..55f1eb2775 --- /dev/null +++ b/jscomp/test/glob/xlob_x.res @@ -0,0 +1 @@ +let v = 3 diff --git a/jscomp/test/slot/test_concat.ml b/jscomp/test/slot/test_concat.ml deleted file mode 100644 index 2298df2a6b..0000000000 --- a/jscomp/test/slot/test_concat.ml +++ /dev/null @@ -1,5 +0,0 @@ -let v = Pervasives.(^) - -(* local variables: *) -(* compile-command: "ocamlc -drawlambda test_concat.ml" *) -(* end: *) diff --git a/jscomp/test/slot/test_concat.res b/jscomp/test/slot/test_concat.res new file mode 100644 index 0000000000..63c6c8a084 --- /dev/null +++ b/jscomp/test/slot/test_concat.res @@ -0,0 +1,5 @@ +let v = Pervasives.\"^" + +/* local variables: */ +/* compile-command: "ocamlc -drawlambda test_concat.ml" */ +/* end: */ From 76b032afb9548ecddbed6efc181cf8760a1e64b6 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 10 Aug 2023 14:16:07 +0200 Subject: [PATCH 4/7] Fix doc comments in tests --- jscomp/test/a_recursive_type.res | 6 ++-- jscomp/test/a_scope_bug.res | 4 +-- jscomp/test/arith_syntax.res | 12 ++++---- jscomp/test/arity.res | 18 ----------- jscomp/test/bs_auto_uncurry.res | 11 +++---- jscomp/test/bs_rest_test.res | 2 +- jscomp/test/caml_compare_bigint_test.res | 2 +- jscomp/test/condition_compilation_test.res | 4 +-- jscomp/test/const_block_test.res | 8 ++--- jscomp/test/const_block_test.resi | 1 - jscomp/test/demo_int_map.resi | 1 - jscomp/test/demo_page.res | 16 +++++----- jscomp/test/exception_value_test.res | 4 +-- jscomp/test/ext_array_test.res | 6 ++-- jscomp/test/ext_filename_test.res | 24 +++++++-------- jscomp/test/ext_list_test.res | 15 ++++----- jscomp/test/ext_pervasives_test.resi | 10 +++--- jscomp/test/ext_string_test.res | 22 ++++++------- jscomp/test/ext_sys_test.res | 2 +- jscomp/test/external_ppx.res | 4 +-- jscomp/test/ffi_splice_test.res | 4 +-- jscomp/test/flexible_array_test.res | 4 +-- jscomp/test/for_loop_test.res | 4 +-- jscomp/test/gpr_1072.res | 4 +-- jscomp/test/gpr_1072_reg.res | 4 +-- jscomp/test/gpr_1150.res | 6 ++-- jscomp/test/gpr_1245_test.res | 4 +-- jscomp/test/gpr_2614_test.res | 13 ++++---- jscomp/test/gpr_3875_test.res | 8 ++--- jscomp/test/gpr_405_test.res | 2 +- jscomp/test/gpr_405_test.resi | 2 +- jscomp/test/guide_for_ext.res | 4 +-- jscomp/test/mt.res | 4 +-- jscomp/test/mutual_non_recursive_type.res | 2 +- jscomp/test/poly_variant_test.res | 12 ++++---- jscomp/test/prepend_data_ffi.res | 4 +-- jscomp/test/queue_test.res | 6 ++-- jscomp/test/reasonReact.resi | 4 +-- jscomp/test/reasonReactRouter.res | 4 +-- jscomp/test/reasonReactRouter.resi | 22 +++++-------- jscomp/test/record_extension_test.res | 2 +- jscomp/test/set_gen.res | 36 +++++++++++----------- jscomp/test/sexp.resi | 4 +-- jscomp/test/sexpm.res | 4 +-- jscomp/test/sexpm.resi | 12 ++++---- jscomp/test/sexpm_test.res | 4 +-- jscomp/test/stream_parser_test.res | 8 ++--- jscomp/test/string_runtime_test.res | 8 ++--- jscomp/test/test_closure.res | 4 +-- jscomp/test/test_cps.res | 8 ++--- jscomp/test/test_external.res | 2 +- jscomp/test/test_ffi.res | 4 +-- jscomp/test/test_include.res | 4 +-- jscomp/test/test_incomplete.res | 4 +-- jscomp/test/test_js_ffi.res | 4 +-- jscomp/test/test_list.res | 4 +-- jscomp/test/test_literals.res | 2 +- jscomp/test/test_order_tailcall.res | 2 +- jscomp/test/test_react.res | 2 +- jscomp/test/test_react_case.res | 4 +-- jscomp/test/test_seq.res | 6 ++-- jscomp/test/test_trywith.res | 2 +- jscomp/test/test_tuple_destructring.res | 4 +-- jscomp/test/test_type_based_arity.res | 4 +-- jscomp/test/test_unsafe_obj_ffi.res | 7 +++-- jscomp/test/test_while_closure.res | 4 +-- jscomp/test/ticker.res | 14 ++++----- jscomp/test/topsort_test.res | 4 +-- jscomp/test/unboxed_attribute_test.res | 8 ++--- jscomp/test/unboxed_use_case.res | 2 +- jscomp/test/unboxed_use_case.resi | 2 +- 71 files changed, 220 insertions(+), 248 deletions(-) diff --git a/jscomp/test/a_recursive_type.res b/jscomp/test/a_recursive_type.res index 425e52686a..5df8db5136 100644 --- a/jscomp/test/a_recursive_type.res +++ b/jscomp/test/a_recursive_type.res @@ -23,12 +23,12 @@ type rec t1 = A(array) @unboxed type rec t2 = A2(array) -@@ocaml.text(/* let rec h = A [|h|] +/* let rec h = A [|h|] let rec h1 = A [|h1|] // could be relaxed let rec h2 = A2 [|h2|] ;; Js.log (h,h2) */ -" If we inline g's definition -- it will be the same, inline uncarefully +/* If we inline g's definition -- it will be the same, inline uncarefully (inline the inlined result) will make it non-terminating - ") +*/ diff --git a/jscomp/test/a_scope_bug.res b/jscomp/test/a_scope_bug.res index dc6832bfc7..cc91c3201c 100644 --- a/jscomp/test/a_scope_bug.res +++ b/jscomp/test/a_scope_bug.res @@ -1,6 +1,6 @@ -@ocaml.doc(" FIXME: the inner +/** FIXME: the inner [even ] is printed as [even] while global [even] is printed as [even$1] -") +*/ let rec odd = z => { let a = { let even = z diff --git a/jscomp/test/arith_syntax.res b/jscomp/test/arith_syntax.res index 161d49fc1f..0a5820d9c8 100644 --- a/jscomp/test/arith_syntax.res +++ b/jscomp/test/arith_syntax.res @@ -1,10 +1,10 @@ type rec expression = - | @ocaml.doc(" non-negative integer constant ") Numeral(float) - | @ocaml.doc(" Addition [e1 + e2] ") Plus(expression, expression) - | @ocaml.doc(" Difference [e1 - e2] ") Minus(expression, expression) - | @ocaml.doc(" Product [e1 * e2] ") Times(expression, expression) - | @ocaml.doc(" Quotient [e1 / e2] ") Divide(expression, expression) - | @ocaml.doc(" Opposite value [-e] ") Negate(expression) + | /** non-negative integer constant */ Numeral(float) + | /** Addition [e1 + e2] */ Plus(expression, expression) + | /** Difference [e1 - e2] */ Minus(expression, expression) + | /** Product [e1 * e2] */ Times(expression, expression) + | /** Quotient [e1 / e2] */ Divide(expression, expression) + | /** Opposite value [-e] */ Negate(expression) | Variable(string) let rec str = e => diff --git a/jscomp/test/arity.res b/jscomp/test/arity.res index 341ceaf501..18f818e1a1 100644 --- a/jscomp/test/arity.res +++ b/jscomp/test/arity.res @@ -24,24 +24,6 @@ let add = \"+" // let h = add(.1,2); // This function is a curried function where an uncurried function is expected -@ocaml.doc(" -let u = obj => { - obj##hai(1, 2) ; - obj##hai(3, 4,2) -} -") -@ocaml.doc(" -let u = obj => { - obj##hai(1, 2) ; - obj##hai(\"x\",2) -} -") -@ocaml.doc(" -let u = obj => { - obj##hai(1, 2) ; - obj##hai(~x=\"x\",2) -} -") let // This function has arity2 but was expected arity3 // This expression has type string but an expression was expected of type diff --git a/jscomp/test/bs_auto_uncurry.res b/jscomp/test/bs_auto_uncurry.res index 4784e05349..2b7a23cc5b 100644 --- a/jscomp/test/bs_auto_uncurry.res +++ b/jscomp/test/bs_auto_uncurry.res @@ -27,12 +27,11 @@ let xs = map([1, 1, 2], (x, y) => y + x + 1) @val external hi: (@uncurry(1) (unit => unit)) => int = "hi" -@@ocaml.text(" +/* fun (_){ f 0 } - -") +*/ let f_0 = () => hi(() => ()) let f_01 = () => @@ -78,7 +77,7 @@ external optional_cb: ( string, ) => int = "optional_cb" -@@ocaml.text(/* +/* let fishy_unit = fun () -> Js.log 1 let fishy_unit_2 = fun [@bs] (() as x) -> Js.log x @@ -133,10 +132,10 @@ let f : expected = ~lo:3 () */ +/* " we auto-uncurry so the inferred type would be -") - +*/ /* let v = ref 0 diff --git a/jscomp/test/bs_rest_test.res b/jscomp/test/bs_rest_test.res index de70f4b404..b3be3b2fc2 100644 --- a/jscomp/test/bs_rest_test.res +++ b/jscomp/test/bs_rest_test.res @@ -16,5 +16,5 @@ include ( ) let u = xxx(. 3) -@ocaml.doc(" Do we need both [bs.val] and [bs.call]* instead of just one [bs.val] ") +/** Do we need both [bs.val] and [bs.call]* instead of just one [bs.val] */ let xx = xxx(. "3") diff --git a/jscomp/test/caml_compare_bigint_test.res b/jscomp/test/caml_compare_bigint_test.res index 35ce340d43..09693cd038 100644 --- a/jscomp/test/caml_compare_bigint_test.res +++ b/jscomp/test/caml_compare_bigint_test.res @@ -42,7 +42,7 @@ let isEqual = (title, num1, num2) => list{ let five = bigint("5") -@ocaml.doc(" Not comparing floats and Bigint; not sure this is correct since works in JavaScript") +/** Not comparing floats and Bigint; not sure this is correct since works in JavaScript */ let suites: Mt.pair_suites = \"@"( isLessThan("123 and 555555", bigint("123"), bigint("555555")), \"@"( diff --git a/jscomp/test/condition_compilation_test.res b/jscomp/test/condition_compilation_test.res index d498f8fb62..c988eba721 100644 --- a/jscomp/test/condition_compilation_test.res +++ b/jscomp/test/condition_compilation_test.res @@ -41,13 +41,13 @@ let ocaml_veriosn = "unknown" /* #if OCAML_VERSION =~ ">4.02" #then */ /* #else */ /* #end */ -@ocaml.doc(" +/** #if OCAML_VERSION =~ \"4.02.3\" #then #elif OCAML_VERSION =~ \"4.03\" #then gsho #end -") +*/ let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => { diff --git a/jscomp/test/const_block_test.res b/jscomp/test/const_block_test.res index d3c01b10dd..7d6b9fc1cf 100644 --- a/jscomp/test/const_block_test.res +++ b/jscomp/test/const_block_test.res @@ -7,16 +7,16 @@ let f = () => { b[0] = 3 } -@ocaml.doc(" should not be inlined here +/** should not be inlined here everytime we call [h ()], it should share the same copy - ") + */ let h = () => c -@ocaml.doc(" should not be inlined here +/** should not be inlined here everytime we call [h ()], it should share the same copy - ") + */ let g = () => { f() Mt.Eq((a[0], b[0]), (3.0, 3)) diff --git a/jscomp/test/const_block_test.resi b/jscomp/test/const_block_test.resi index 634e11b46c..84dad4b268 100644 --- a/jscomp/test/const_block_test.resi +++ b/jscomp/test/const_block_test.resi @@ -1,4 +1,3 @@ -@ocaml.doc(" ") let a: array let b: array let c: array diff --git a/jscomp/test/demo_int_map.resi b/jscomp/test/demo_int_map.resi index 3f6408d4bf..e69de29bb2 100644 --- a/jscomp/test/demo_int_map.resi +++ b/jscomp/test/demo_int_map.resi @@ -1 +0,0 @@ -@@ocaml.text(" ") diff --git a/jscomp/test/demo_page.res b/jscomp/test/demo_page.res index 73d460fd49..bba7300cb9 100644 --- a/jscomp/test/demo_page.res +++ b/jscomp/test/demo_page.res @@ -1,11 +1,11 @@ -@ocaml.doc(" Imperative style ") +/** Imperative style */ let rec fib = x => switch x { | 1 | 2 => 1 | n => fib(n - 1) + fib(n - 2) } -@ocaml.doc(" Imperative style ") @ocaml.doc(" List map ") +/** Imperative style */ /** List map */ let sum = n => { let v = ref(0) for i in 0 to n { @@ -14,7 +14,7 @@ let sum = n => { v.contents } -@ocaml.doc(" List map ") +/** List map */ type rec list<'a> = | Nil | Cons('a, list<'a>) @@ -25,25 +25,25 @@ let rec map = (f, x) => | Cons(x, xs) => Cons(f(x), map(f, xs)) } -@ocaml.doc(" Test curry and uncurry calling convention ") +/** Test curry and uncurry calling convention */ let test_curry = (x, y) => x + y let f = test_curry(32) -@ocaml.doc(" Create a typed binding for react ") +/** Create a typed binding for react */ type t type element @val external document: t = "document" @send external getElementById: (t, string) => element = "getElementById" -@ocaml.doc(" Phantom types ") +/** Phantom types */ type config type component type attrs type component_class -@obj @ocaml.doc(" make a json object ") +@obj /** make a json object */ external config: (~display_name: string=?, ~render: unit => component, unit) => config = "" -@ocaml.doc(" make a json object ") @obj +/** make a json object */ @obj external attrs: (~alt: string=?, ~autoPlay: bool=?, unit) => attrs = "" external str: string => component = "%identity" diff --git a/jscomp/test/exception_value_test.res b/jscomp/test/exception_value_test.res index a69baf6ac6..38460a461c 100644 --- a/jscomp/test/exception_value_test.res +++ b/jscomp/test/exception_value_test.res @@ -15,8 +15,8 @@ exception A(int) exception B exception C(int, int) let u = A(3) -@ocaml.doc(" note in ocaml, if such exception is not caught, - it will be re-raised ") +/** note in ocaml, if such exception is not caught, + it will be re-raised */ let test_not_found = (f, ()) => try f() catch { | Not_found => 2 diff --git a/jscomp/test/ext_array_test.res b/jscomp/test/ext_array_test.res index 213d2ad4fd..53a71e3894 100644 --- a/jscomp/test/ext_array_test.res +++ b/jscomp/test/ext_array_test.res @@ -149,7 +149,7 @@ let of_list_map = (f, a) => fill(1, tl) } -@ocaml.doc(" +/** {[ # rfind_with_index [|1;2;3|] (=) 2;; - : int = 1 @@ -160,7 +160,7 @@ let of_list_map = (f, a) => # rfind_with_index [|1;2;3|] (=) 4;; - : int = -1 ]} -") +*/ let rfind_with_index = (arr, cmp, v) => { let len = Array.length(arr) let rec aux = i => @@ -206,7 +206,7 @@ let find_and_split = (arr, cmp, v): split<_> => { } } -@@ocaml.text(" TODO: available since 4.03, use {!Array.exists} ") +/* TODO: available since 4.03, use {!Array.exists} */ let exists = (p, a) => { let n = Array.length(a) diff --git a/jscomp/test/ext_filename_test.res b/jscomp/test/ext_filename_test.res index 7962c43c82..fcb80a6da1 100644 --- a/jscomp/test/ext_filename_test.res +++ b/jscomp/test/ext_filename_test.res @@ -22,7 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -@ocaml.doc(" Used when produce node compatible paths ") +/** Used when produce node compatible paths */ let node_sep = "/" let node_parent = ".." let node_current = "." @@ -94,7 +94,7 @@ let chop_extension_if_any = fname => let os_path_separator_char = String.unsafe_get(Filename.dir_sep, 0) -@ocaml.doc(" example +/** example {[ \"/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/external/pervasives.cmj\" \"/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/ocaml_array.ml\" @@ -113,7 +113,7 @@ let os_path_separator_char = String.unsafe_get(Filename.dir_sep, 0) /a/b /c/d ]} -") +*/ let relative_path = (file_or_dir_1, file_or_dir_2) => { let sep_char = os_path_separator_char let relevant_dir1 = switch file_or_dir_1 { @@ -138,7 +138,7 @@ let relative_path = (file_or_dir_1, file_or_dir_2) => { } } -@ocaml.doc(" path2: a/b +/** path2: a/b path1: a result: ./b TODO: [Filename.concat] with care @@ -147,7 +147,7 @@ let relative_path = (file_or_dir_1, file_or_dir_2) => { [file2] is the dependency TODO: this is a hackish function: FIXME -") +*/ let node_relative_path = ( node_modules_shorten, file1: t, @@ -219,9 +219,9 @@ let module_name_of_file = file => let module_name_of_file_if_any = file => String.capitalize_ascii(\"@@"(chop_extension_if_any, Filename.basename(file))) -@@ocaml.text(" For win32 or case insensitve OS +/* For win32 or case insensitve OS [\".cmj\"] is the same as [\".CMJ\"] -") +*/ /* let has_exact_suffix_then_chop fname suf = */ let combine = (p1, p2) => @@ -235,7 +235,7 @@ let combine = (p1, p2) => p2 } -@ocaml.doc(" +/** {[ split_aux \"//ghosg//ghsogh/\";; - : string * string list = (\"/\", [\"ghosg\"; \"ghsogh\"]) @@ -256,7 +256,7 @@ let combine = (p1, p2) => dirname \"\" = \".\" dirname \"\" = \".\" ]} -") +*/ let split_aux = p => { let rec go = (p, acc) => { let dir = Filename.dirname(p) @@ -279,10 +279,10 @@ let split_aux = p => { go(p, list{}) } -@ocaml.doc(" +/** TODO: optimization if [from] and [to] resolve to the same path, a zero-length string is returned -") +*/ let rel_normalized_absolute_path = (from, to_) => { let (root1, paths1) = split_aux(from) let (root2, paths2) = split_aux(to_) @@ -335,7 +335,7 @@ let rel_normalized_absolute_path = (from, to_) => { ]} */ -@ocaml.doc(" See tests in {!Ounit_path_tests} ") +/** See tests in {!Ounit_path_tests} */ let normalize_absolute_path = x => { let drop_if_exist = xs => switch xs { diff --git a/jscomp/test/ext_list_test.res b/jscomp/test/ext_list_test.res index f0abfe1d1f..e9e1dfbec8 100644 --- a/jscomp/test/ext_list_test.res +++ b/jscomp/test/ext_list_test.res @@ -77,7 +77,7 @@ let exclude_with_fact = (p, l) => { ) } -@ocaml.doc(" Make sure [p2 x] and [p1 x] will not hold at the same time ") +/** Make sure [p2 x] and [p1 x] will not hold at the same time */ let exclude_with_fact2 = (p1, p2, l) => { let excluded1 = ref(None) let excluded2 = ref(None) @@ -227,10 +227,10 @@ let try_take = (n, l) => { } } -@ocaml.doc(" +/** {[length xs = length ys + n ]} -") +*/ let rec length_compare = (l, n) => if n < 0 { #Gt @@ -246,10 +246,10 @@ let rec length_compare = (l, n) => } } -@ocaml.doc(" +/** {[length xs = length ys + n ]} -") +*/ let rec length_larger_than_n = (n, xs, ys) => switch (xs, ys) { | (_, list{}) => length_compare(xs, n) == #Eq @@ -495,7 +495,8 @@ let rec assoc_by_int = (def, k: int, lst) => } } -@@ocaml.text(" `modulo [1;2;3;4] [1;2;3]` => [1;2;3], Some [4] ` +/* `modulo [1;2;3;4] [1;2;3]` => [1;2;3], Some [4] ` modulo [1;2;3] [1;2;3;4] => [1;2;3] None modulo [1;2;3] [1;2;3] => [1;2;3] Some [] - ") + */ + \ No newline at end of file diff --git a/jscomp/test/ext_pervasives_test.resi b/jscomp/test/ext_pervasives_test.resi index 68b7ead02f..60ad175c9d 100644 --- a/jscomp/test/ext_pervasives_test.resi +++ b/jscomp/test/ext_pervasives_test.resi @@ -1,4 +1,4 @@ -@@ocaml.text(/* Copyright (C) 2015-2016 Bloomberg Finance L.P. +/* 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 @@ -22,8 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -" Extension to standard library [Pervavives] module, safe to open -") +/*** Extension to standard library [Pervavives] module, safe to open +*/ external reraise: exn => 'a = "%reraise" @@ -33,9 +33,9 @@ let is_pos_pow: Int32.t => int let is_pos_pow_2: Int32.t => int -@ocaml.doc(" Copied from {!Btype.hash_variant}: +/** Copied from {!Btype.hash_variant}: need sync up and add test case -") +*/ let hash_variant: string => int module LargeFile: { diff --git a/jscomp/test/ext_string_test.res b/jscomp/test/ext_string_test.res index e9dc894a95..89dc2b107e 100644 --- a/jscomp/test/ext_string_test.res +++ b/jscomp/test/ext_string_test.res @@ -97,9 +97,9 @@ let starts_with = (s, beg) => { } } -@ocaml.doc(" return an index which is minus when [s] does not +/** return an index which is minus when [s] does not end with [beg] -") +*/ let ends_with_index = (s, end_) => { let s_finish = String.length(s) - 1 let s_beg = String.length(end_) - 1 @@ -149,10 +149,10 @@ let check_any_suffix_case_then_chop = (s, suffixes) => { aux(suffixes) } -@ocaml.doc(" In OCaml 4.02.3, {!String.escaped} is locale senstive, +/** In OCaml 4.02.3, {!String.escaped} is locale senstive, this version try to make it not locale senstive, this bug is fixed in the compiler trunk -") +*/ let escaped = s => { let rec needs_escape = i => if i >= String.length(s) { @@ -236,9 +236,9 @@ let find = (~start=0, ~sub, s) => { let contain_substring = (s, sub) => find(s, ~sub) >= 0 -@ocaml.doc(" TODO: optimize +/** TODO: optimize avoid nonterminating when string is empty -") +*/ let non_overlap_count = (~sub, s) => { let sub_len = String.length(sub) let rec aux = (acc, off) => { @@ -284,11 +284,11 @@ let tail_from = (s, x) => { } } -@ocaml.doc(" +/** {[ digits_of_str \"11_js\" 2 == 11 ]} -") +*/ let digits_of_str = (s, ~offset, x) => { let rec aux = (i, acc, s, x) => if i >= x { @@ -418,10 +418,10 @@ let is_valid_npm_package_name = (s: string) => { type check_result = | Good | Invalid_module_name - | @ocaml.doc(" + | /** TODO: move to another module Make {!Ext_filename_test} not stateful -") +*/ Suffix_mismatch let is_valid_source_name = (name): check_result => @@ -435,7 +435,7 @@ let is_valid_source_name = (name): check_result => } } -@ocaml.doc(" TODO: can be improved to return a positive integer instead ") +/** TODO: can be improved to return a positive integer instead */ let rec unsafe_no_char = (x, ch, i, last_idx) => i > last_idx || (String.unsafe_get(x, i) != ch && unsafe_no_char(x, ch, i + 1, last_idx)) diff --git a/jscomp/test/ext_sys_test.res b/jscomp/test/ext_sys_test.res index 580cab86b8..d224881d0c 100644 --- a/jscomp/test/ext_sys_test.res +++ b/jscomp/test/ext_sys_test.res @@ -22,7 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -@ocaml.doc(" TODO: not exported yet, wait for Windows Fix") +/** TODO: not exported yet, wait for Windows Fix */ let is_directory_no_exn = f => try Sys.is_directory(f) catch { | _ => false diff --git a/jscomp/test/external_ppx.res b/jscomp/test/external_ppx.res index c98458a7a5..28665f702e 100644 --- a/jscomp/test/external_ppx.res +++ b/jscomp/test/external_ppx.res @@ -1,10 +1,10 @@ @obj external make_config: (~length: int, ~width: int) => unit = "" @obj -@ocaml.doc(" Note that +/** Note that {[ 'a . length: 'a -> width:int -> unit ]} is a syntax error -- check where it is allowed -") +*/ external make_config: (~length: 'a, ~width: int) => unit = "" @obj external opt_make: (~length: int, ~width: int=?) => (_ as 'event) = "" diff --git a/jscomp/test/ffi_splice_test.res b/jscomp/test/ffi_splice_test.res index 6fff4bd045..402338227a 100644 --- a/jscomp/test/ffi_splice_test.res +++ b/jscomp/test/ffi_splice_test.res @@ -6,9 +6,9 @@ let eq = (loc, x, y) => { list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} } -@@ocaml.text(" +/* [%%raw [@import \"jscomp/test/xx.js\"]] (* PATH relative to package.json *) -") +*/ %%raw(` function Make (){ diff --git a/jscomp/test/flexible_array_test.res b/jscomp/test/flexible_array_test.res index d763132805..4ffee6666a 100644 --- a/jscomp/test/flexible_array_test.res +++ b/jscomp/test/flexible_array_test.res @@ -47,10 +47,10 @@ let rec delete = (tr: tree<_>, n) => } /* it is the same as [push_front] */ -@ocaml.doc(" proof: +/** proof: left => right right has to be left -") +*/ let rec loext = (tr: tree<_>, w) => switch tr { | Lf => Br(w, Lf, Lf) diff --git a/jscomp/test/for_loop_test.res b/jscomp/test/for_loop_test.res index d170d74daa..8c45dd2c05 100644 --- a/jscomp/test/for_loop_test.res +++ b/jscomp/test/for_loop_test.res @@ -133,7 +133,7 @@ let for_9 = () => { [(vv.contents, get(), vv2.contents)] } -@@ocaml.text(" +/* See how google closure works, in both simple model and advanced model @@ -155,7 +155,7 @@ console.log(result,u) ]} -") +*/ let suites = list{ ("for_loop_test_3", _ => Mt.Eq(90, \"@@"(for_3, Array.make(10, 2)))), diff --git a/jscomp/test/gpr_1072.res b/jscomp/test/gpr_1072.res index 79cb027b96..068d006696 100644 --- a/jscomp/test/gpr_1072.res +++ b/jscomp/test/gpr_1072.res @@ -48,8 +48,8 @@ let v_ice_cream4: list = list{ @obj external label_test: (~x__ignore: int, unit) => _ = "" -@ocaml.doc(" here the type label should be the same, - when get the object, it will be mangled ") +/** here the type label should be the same, + when get the object, it will be mangled */ type label_expect = {"x__ignore": int} let vv: label_expect = label_test(~x__ignore=3, ()) diff --git a/jscomp/test/gpr_1072_reg.res b/jscomp/test/gpr_1072_reg.res index 7cd7769243..1bd34fed78 100644 --- a/jscomp/test/gpr_1072_reg.res +++ b/jscomp/test/gpr_1072_reg.res @@ -33,7 +33,7 @@ let v1 = make( (), ) -@@ocaml.text(" In the future we might allow below cases , issues are [`num] maybe escaped +/* In the future we might allow below cases , issues are [`num] maybe escaped we need prevent its escaping external make2 : @@ -73,4 +73,4 @@ let v2 = ~timeZoneName:`short ~hour:`two_digit () -") +*/ diff --git a/jscomp/test/gpr_1150.res b/jscomp/test/gpr_1150.res index 9c33473f37..5b6b00750f 100644 --- a/jscomp/test/gpr_1150.res +++ b/jscomp/test/gpr_1150.res @@ -116,7 +116,7 @@ let f = children => } } -@@ocaml.text(/* +/* match children with | [] -> [|a0;a1;a2;a3;a4;a5;a6;a7;a8;a9;a10;a11;a12;a13;a14;a15;a16|] | a17::children -> @@ -132,13 +132,13 @@ let f = children => */ -" This function seems to trigger quadratice behavior with the length of [children] +/* This function seems to trigger quadratice behavior with the length of [children] memory consumption is okay 17 -> 4s 18 -> 9s 19 -> 19s 20 -> 40s - ") + */ /* let f children = match children with diff --git a/jscomp/test/gpr_1245_test.res b/jscomp/test/gpr_1245_test.res index b7f8494cfe..db1c15ed6f 100644 --- a/jscomp/test/gpr_1245_test.res +++ b/jscomp/test/gpr_1245_test.res @@ -7,7 +7,7 @@ let f = ((c, d)) => { Js.log2(a, b) } -@@ocaml.text(" escape analysis to avoid allocation +/* escape analysis to avoid allocation {[ let match/xx = [a,b,c] ]} @@ -22,7 +22,7 @@ let f = ((c, d)) => { This also applies to [reference] exception allocation -") +*/ type t = {x: int, y: int} diff --git a/jscomp/test/gpr_2614_test.res b/jscomp/test/gpr_2614_test.res index aa53783d0e..8a942e2422 100644 --- a/jscomp/test/gpr_2614_test.res +++ b/jscomp/test/gpr_2614_test.res @@ -17,10 +17,9 @@ let v = t(~hi=3, ~low=2, ~x=2) let (a, b, c) = (v->hiGet, v->lowGet, v->xGet) -@ocaml.doc(" - +/** v |. (hi, lo) -") +*/ let ff = () => { v->hiSet(3) v->lowSet(2) @@ -32,11 +31,11 @@ type a = { hi: int, } -@ocaml.doc(" +/** external a : ?low:int -> hi:int -> a low: a -> int option [@@bs.return undefined_to_opt] lowSet : a -> int -> unit -") +*/ let h0 = a(~hi=2, ~low="x") let h1 = a(~hi=2, ~low="x", ()) @@ -48,11 +47,11 @@ let hh = x => { x->lowGet } -@@ocaml.text(" should we make the type of +/* should we make the type of lowSet : a -> string option -> unit lowSet : a -> string -> unit -") +*/ let hh2 = x => switch x->lowGet { diff --git a/jscomp/test/gpr_3875_test.res b/jscomp/test/gpr_3875_test.res index c296cdd357..c5edaeb1d3 100644 --- a/jscomp/test/gpr_3875_test.res +++ b/jscomp/test/gpr_3875_test.res @@ -1,14 +1,14 @@ let result = ref("") -@ocaml.doc(" TODO: +/** TODO: pattern match over (Some \"xx\") could be simplified -") +*/ module Xx = { let log = x => result := x } -@ocaml.doc(" TODO: +/** TODO: pattern match over (Some \"xx\") could be simplified -") +*/ let compilerBug = (a, b, c, f) => switch (a, b) { | (Some("x"), _) diff --git a/jscomp/test/gpr_405_test.res b/jscomp/test/gpr_405_test.res index bdb3867636..f779235afd 100644 --- a/jscomp/test/gpr_405_test.res +++ b/jscomp/test/gpr_405_test.res @@ -1,7 +1,7 @@ module type G = { type t module V: { - @@ocaml.text(" Vertices are {!COMPARABLE}. ") + /*** Vertices are {!COMPARABLE}. */ type t diff --git a/jscomp/test/gpr_405_test.resi b/jscomp/test/gpr_405_test.resi index d93f6d81b0..9167fc839c 100644 --- a/jscomp/test/gpr_405_test.resi +++ b/jscomp/test/gpr_405_test.resi @@ -1,7 +1,7 @@ module type G = { type t module V: { - @@ocaml.text(" Vertices are {!COMPARABLE}. ") + /*** Vertices are {!COMPARABLE}. */ type t diff --git a/jscomp/test/guide_for_ext.res b/jscomp/test/guide_for_ext.res index dac407e1df..e419672dbb 100644 --- a/jscomp/test/guide_for_ext.res +++ b/jscomp/test/guide_for_ext.res @@ -1,7 +1,7 @@ -@@ocaml.text(" +/* [%js{ text : 32 ; label : \"hel\" }] Attention: also ok for nested case -") +*/ let mk = () => { module N = { diff --git a/jscomp/test/mt.res b/jscomp/test/mt.res index 8e6c354a45..5810bfac2a 100644 --- a/jscomp/test/mt.res +++ b/jscomp/test/mt.res @@ -20,9 +20,9 @@ @val @module("assert") -@ocaml.doc(" There is a problem -- +/** There is a problem -- it does not return [unit] -") +*/ external throws: (unit => unit) => unit = "throws" let assert_equal = eq diff --git a/jscomp/test/mutual_non_recursive_type.res b/jscomp/test/mutual_non_recursive_type.res index 908df44636..9f5cc15f0b 100644 --- a/jscomp/test/mutual_non_recursive_type.res +++ b/jscomp/test/mutual_non_recursive_type.res @@ -8,6 +8,6 @@ open U type t = | Ta(t) /* * u compilation error [nonrec applices to all] */ | Tb(int) -and u = | @ocaml.doc(" one attribute nonrecursive will affect all ") H(t) /* refers to old t */ +and u = | /** one attribute nonrecursive will affect all */ H(t) /* refers to old t */ let v: u = H(OT) diff --git a/jscomp/test/poly_variant_test.res b/jscomp/test/poly_variant_test.res index 995672ead1..1eaa3f4501 100644 --- a/jscomp/test/poly_variant_test.res +++ b/jscomp/test/poly_variant_test.res @@ -27,7 +27,7 @@ function hey_int (option){ } `) -@ocaml.doc(" when marshall, make sure location does not matter ") +/** when marshall, make sure location does not matter */ type u = [ | #on_closed | #on_open @@ -38,7 +38,7 @@ type u = [ /* TODO: add warning test */ -@ocaml.doc(" when marshall, make sure location does not matter ") @val +/** when marshall, make sure location does not matter */ @val external test_string_type: (~flag: @string [#on_closed | #on_open | @as("in") #in_]) => string = "hey_string" @@ -114,7 +114,7 @@ module N = { @module("fs") external readFileSync: (string, [#utf8 | #ascii]) => string = "readFileSync" let read = name => readFileSync(name, #utf8) } -@ocaml.doc(" +/** let register readline = readline |> on (`line begin fun [@bs] s -> Js.log s end) @@ -126,10 +126,10 @@ let register readline = on (`close begin fun [@bs] () -> Js.log \"finished\" end) readline ]} -") +*/ let readN = N.read -@ocaml.doc(" +/** let register readline = readline |> on (`line begin fun [@bs] s -> Js.log s end) @@ -141,7 +141,7 @@ let register readline = on (`close begin fun [@bs] () -> Js.log \"finished\" end) readline ]} -") +*/ let test = (readline, x) => on(readline, x) let p_is_int_test = x => diff --git a/jscomp/test/prepend_data_ffi.res b/jscomp/test/prepend_data_ffi.res index 7e73329dd8..4dac705a5e 100644 --- a/jscomp/test/prepend_data_ffi.res +++ b/jscomp/test/prepend_data_ffi.res @@ -65,9 +65,9 @@ external on_exit_slice5: ( array, ) => unit = "xx" -@ocaml.doc(" +/** TODO: bs.send conflicts with bs.val: better error message -") +*/ let f = (x: t) => { x->on_exit_slice1(__LINE__, [1, 2, 3]) x->on_exit_slice2(__LINE__, [1, 2, 3]) diff --git a/jscomp/test/queue_test.res b/jscomp/test/queue_test.res index 6a8ba7d2ea..128527366a 100644 --- a/jscomp/test/queue_test.res +++ b/jscomp/test/queue_test.res @@ -17,10 +17,10 @@ module Test = (Queue: module type of Queue) => { to_array(q) } - @@ocaml.text( - " TODO: Note it needs need recursive values support " + /* + TODO: Note it needs need recursive values support */ /* let _ = queue_1 [|38|] */ - ) + } module T1 = Test(Queue) diff --git a/jscomp/test/reasonReact.resi b/jscomp/test/reasonReact.resi index f4ca15aaa7..89d3b7f58a 100644 --- a/jscomp/test/reasonReact.resi +++ b/jscomp/test/reasonReact.resi @@ -199,10 +199,10 @@ Were you using this because you needed to pass a children array reference to a D Alternatively, if you're using this because the prop name contains a hyphen, please use `ReactDOMRe.createElementVariadic` instead.") let createDomElement: (string, ~props: {..}, array) => reactElement -@ocaml.doc(" +/** * Wrap props into a JS component * Use for interop when Reason components use JS components - ") + */ let wrapJsForReason: ( ~reactClass: reactClass, ~props: 'a, diff --git a/jscomp/test/reasonReactRouter.res b/jscomp/test/reasonReactRouter.res index 0536f3cd5e..cd70c75ee8 100644 --- a/jscomp/test/reasonReactRouter.res +++ b/jscomp/test/reasonReactRouter.res @@ -167,10 +167,10 @@ let useUrl = (~serverUrl=?, ()) => { React.useEffect0(() => { let watcherId = watchUrl(url => setUrl(_ => url)) - @ocaml.doc(" + /* * check for updates that may have occured between * the initial state and the subscribe above - ") + */ let newUrl = dangerouslyGetInitialUrl() if urlNotEqual(newUrl, url) { setUrl(_ => newUrl) diff --git a/jscomp/test/reasonReactRouter.resi b/jscomp/test/reasonReactRouter.resi index 84800e0e6c..65c9baed35 100644 --- a/jscomp/test/reasonReactRouter.resi +++ b/jscomp/test/reasonReactRouter.resi @@ -1,10 +1,6 @@ -@ocaml.doc( - " update the url with the string path. Example: `push(\"/book/1\")`, `push(\"/books#title\")` " -) +/** update the url with the string path. Example: `push(\"/book/1\")`, `push(\"/books#title\")` */ let push: string => unit -@ocaml.doc( - " update the url with the string path. modifies the current history entry instead of creating a new one. Example: `replace(\"/book/1\")`, `replace(\"/books#title\")` " -) +/** update the url with the string path. modifies the current history entry instead of creating a new one. Example: `replace(\"/book/1\")`, `replace(\"/books#title\")` */ let replace: string => unit type watcherID type url = { @@ -15,13 +11,11 @@ type url = { /* the url's query params, if any. The ? symbol is stripped out for you */ search: string, } -@ocaml.doc( - " start watching for URL changes. Returns a subscription token. Upon url change, calls the callback and passes it the url record " -) +/** start watching for URL changes. Returns a subscription token. Upon url change, calls the callback and passes it the url record */ let watchUrl: (url => unit) => watcherID -@ocaml.doc(" stop watching for URL changes ") +/** stop watching for URL changes */ let unwatchUrl: watcherID => unit -@ocaml.doc(" this is marked as \"dangerous\" because you technically shouldn't be accessing the URL outside of watchUrl's callback; +/** this is marked as \"dangerous\" because you technically shouldn't be accessing the URL outside of watchUrl's callback; you'd read a potentially stale url, instead of the fresh one inside watchUrl. But this helper is sometimes needed, if you'd like to initialize a page whose display/state depends on the URL, @@ -31,9 +25,9 @@ let unwatchUrl: watcherID => unit So, the correct (and idiomatic) usage of this helper is to only use it in a component that's also subscribed to watchUrl. Please see https://github.com/reasonml-community/reason-react-example/blob/master/src/todomvc/TodoItem.re for an example. - ") + */ let dangerouslyGetInitialUrl: unit => url -@ocaml.doc(" hook for watching url changes. +/** hook for watching url changes. * serverUrl is used for ssr. it allows you to specify the url without relying on browser apis existing/working as expected - ") + */ let useUrl: (~serverUrl: url=?, unit) => url diff --git a/jscomp/test/record_extension_test.res b/jscomp/test/record_extension_test.res index 22c5b8f713..a8e73d73a3 100644 --- a/jscomp/test/record_extension_test.res +++ b/jscomp/test/record_extension_test.res @@ -18,7 +18,7 @@ let v0 = Inline_record({x: 3, y: "4"}) eq(__LOC__, f(v0), Some(7)) /* Record_unboxed */ -type t1 = | @ocaml.unboxed A({x: int}) +type t1 = | @unboxed A({x: int}) /* Record_inlined */ type t2 = diff --git a/jscomp/test/set_gen.res b/jscomp/test/set_gen.res index eee26c1da5..bd743ec4dd 100644 --- a/jscomp/test/set_gen.res +++ b/jscomp/test/set_gen.res @@ -1,19 +1,19 @@ -@@ocaml.text( - /* ********************************************************************* */ - /* */ - /* OCaml */ - /* */ - /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ - /* */ - /* Copyright 1996 Institut National de Recherche en Informatique et */ - /* en Automatique. All rights reserved. This file is distributed */ - /* under the terms of the GNU Library General Public License, with */ - /* the special exception on linking described in file ../LICENSE. */ - /* */ - /* ********************************************************************* */ - - " balanced tree based on stdlib distribution " -) +/* ********************************************************************* */ +/* */ +/* OCaml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/* ********************************************************************* */ + +/*** + balanced tree based on stdlib distribution +*/ type rec t<'a> = | Empty @@ -363,7 +363,7 @@ let rec add_max_element = (v, x) => | Node(l, x, r, h) => internal_bal(l, x, add_max_element(v, r)) } -@ocaml.doc(" +/** Invariants: 1. l < v < r 2. l and r are balanced @@ -371,7 +371,7 @@ let rec add_max_element = (v, x) => Proof by induction The height of output will be ~~ (max (height l) (height r) + 2) Also use the lemma from [bal] -") +*/ let rec internal_join = (l, v, r) => switch (l, r) { | (Empty, _) => add_min_element(v, r) diff --git a/jscomp/test/sexp.resi b/jscomp/test/sexp.resi index f885d0fa37..ffb85e6343 100644 --- a/jscomp/test/sexp.resi +++ b/jscomp/test/sexp.resi @@ -43,7 +43,7 @@ let of_field: (string, t) => t /** Represent a record by its named fields */ let of_record: list<(string, t)> => t -@@ocaml.text(" {6 Traversal of S-exp} +/* {6 Traversal of S-exp} Example: serializing 2D points {[ @@ -65,7 +65,7 @@ let of_record: list<(string, t)> => t Sexp.Traverse.list_all pt_of_sexp sexp;; ]} -") +*/ module Traverse: { /** A converter from S-expressions to 'a is a function [sexp -> 'a option]. diff --git a/jscomp/test/sexpm.res b/jscomp/test/sexpm.res index d392590b27..24c82f8ce6 100644 --- a/jscomp/test/sexpm.res +++ b/jscomp/test/sexpm.res @@ -11,7 +11,7 @@ type rec t = [ ] type sexp = t -@@ocaml.text(" {2 Serialization (encoding)} ") +/* {2 Serialization (encoding)} */ /* shall we escape the string because of one of its chars? */ let _must_escape = s => @@ -55,7 +55,7 @@ let to_string = t => { Buffer.contents(b) } -@@ocaml.text(" {2 Deserialization (decoding)} ") +/* {2 Deserialization (decoding)} */ module type MONAD = { type t<'a> diff --git a/jscomp/test/sexpm.resi b/jscomp/test/sexpm.resi index 27b2471bd0..645d0c9ade 100644 --- a/jscomp/test/sexpm.resi +++ b/jscomp/test/sexpm.resi @@ -1,14 +1,14 @@ -@@ocaml.text(/* This file is free software, part of containers. See file "license" for more details. */ +/* This file is free software, part of containers. See file "license" for more details. */ -" {1 Simple and efficient S-expression parsing/printing} +/* {1 Simple and efficient S-expression parsing/printing} - @since 0.7 ") + @since 0.7 " */ type or_error<'a> = [#Ok('a) | #Error(string)] type sequence<'a> = ('a => unit) => unit type gen<'a> = unit => option<'a> -@@ocaml.text(" {2 Basics} ") +/* {2 Basics} */ type rec t = [ | #Atom(string) @@ -16,11 +16,11 @@ type rec t = [ ] type sexp = t -@@ocaml.text(" {2 Serialization (encoding)} ") +/* {2 Serialization (encoding)} */ let to_buf: (Buffer.t, t) => unit let to_string: t => string -@ocaml.doc(" Parse a string ") +/** Parse a string */ let parse_string: string => or_error diff --git a/jscomp/test/sexpm_test.res b/jscomp/test/sexpm_test.res index d6b63bb11b..591b402f0a 100644 --- a/jscomp/test/sexpm_test.res +++ b/jscomp/test/sexpm_test.res @@ -20,6 +20,6 @@ let () = { let () = Mt.from_pair_suites(__MODULE__, suites.contents) -@@ocaml.text(" +/* [%bs.internal.test ] -") +*/ diff --git a/jscomp/test/stream_parser_test.res b/jscomp/test/stream_parser_test.res index c5b86d7d72..bf6f82113f 100644 --- a/jscomp/test/stream_parser_test.res +++ b/jscomp/test/stream_parser_test.res @@ -1,6 +1,6 @@ exception Parse_error(string) -@ocaml.doc(" +/** expr | expr1 expr_aux @@ -15,7 +15,7 @@ expr2 | Int | ( expr ) -") +*/ let parse = (token: unit => Genlex.token) => { let look_ahead = Queue.create() let token = () => @@ -68,7 +68,7 @@ let token = chars => { () => Stream.next(strm) } -@@ocaml.text(" +/* http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm @@ -80,7 +80,7 @@ F | Int | (E) -") +*/ let l_parse = (token: unit => Genlex.token) => { let look_ahead = Queue.create() diff --git a/jscomp/test/string_runtime_test.res b/jscomp/test/string_runtime_test.res index d3bc229d80..112b92acbc 100644 --- a/jscomp/test/string_runtime_test.res +++ b/jscomp/test/string_runtime_test.res @@ -1,12 +1,12 @@ module S = Caml_string -@ocaml.doc(" TODO: performance could be improved, however, +/** TODO: performance could be improved, however, this function is not in critical Path - ") + */ module B = Caml_bytes -@ocaml.doc(" TODO: performance could be improved, however, +/** TODO: performance could be improved, however, this function is not in critical Path - ") + */ let suites = { open Mt list{ diff --git a/jscomp/test/test_closure.res b/jscomp/test/test_closure.res index 37f1468ada..8feacb1ad4 100644 --- a/jscomp/test/test_closure.res +++ b/jscomp/test/test_closure.res @@ -1,6 +1,6 @@ let v = ref(0) -@ocaml.doc(" Test when i is captured +/** Test when i is captured {[ ((fun _ -> j = i; (fun _ -> v := !v + j)) ()) ]} @@ -36,7 +36,7 @@ This means inline is tricky in javascript, here we try to inline [_loop]? - ") + */ let f = () => { let n = 10 let arr = Array.make(10, _ => ()) diff --git a/jscomp/test/test_cps.res b/jscomp/test/test_cps.res index e3336df963..c7eb46f664 100644 --- a/jscomp/test/test_cps.res +++ b/jscomp/test/test_cps.res @@ -1,4 +1,4 @@ -@@ocaml.text(" +/* To do the right [tail call] conversion when the arguments are functions which captures some variables, we need create a scope to capture it @@ -63,7 +63,7 @@ ]} with [let] -") +*/ let rec f = (n, acc) => if n == 0 { @@ -75,7 +75,7 @@ let rec f = (n, acc) => }) } -@ocaml.doc(" +/** Here a naive version would be {[ for(var i = 0;i<=n;++i) @@ -87,7 +87,7 @@ let rec f = (n, acc) => for(var i = 0;i<=n;++i) {arr[i]= (function(){ var i$1 = i; function(){return i$1;};}()) ]} - ") + */ let test_closure = () => { let n = 6 let arr = Array.make(n, x => x) diff --git a/jscomp/test/test_external.res b/jscomp/test/test_external.res index 86b06b8907..0baaa3b734 100644 --- a/jscomp/test/test_external.res +++ b/jscomp/test/test_external.res @@ -1,7 +1,7 @@ type any /* just pass it through -- we need find an elegant way to walk around ocaml's type system */ -@ocaml.doc(" It's okay to do this in javascript, you will never get segfault") +/** It's okay to do this in javascript, you will never get segfault" */ external \"~~": 'a => 'b = "%identity" type document diff --git a/jscomp/test/test_ffi.res b/jscomp/test/test_ffi.res index bbf4c982f3..2b32373d80 100644 --- a/jscomp/test/test_ffi.res +++ b/jscomp/test/test_ffi.res @@ -1,7 +1,7 @@ @val("console.log") -@ocaml.doc(" we should also allow js function call from an external js module +/** we should also allow js function call from an external js module -") +*/ external log: 'a => unit = "?ignore" @scope("console") external log2: 'a => unit = "log" diff --git a/jscomp/test/test_include.res b/jscomp/test/test_include.res index 88ab3d4599..118142503d 100644 --- a/jscomp/test/test_include.res +++ b/jscomp/test/test_include.res @@ -1,6 +1,6 @@ -@ocaml.doc(" luckily we have module alias +/** luckily we have module alias so global module alias is fine -") +*/ include List module N = List let v = N.length diff --git a/jscomp/test/test_incomplete.res b/jscomp/test/test_incomplete.res index 5a68a886d3..f8c4a7d72a 100644 --- a/jscomp/test/test_incomplete.res +++ b/jscomp/test/test_incomplete.res @@ -18,7 +18,7 @@ let f2 = x => | None => 1 } -@ocaml.doc(" if there is [default] in [Lswitch] it means +/** if there is [default] in [Lswitch] it means its patten match are complete, in that case we can transform @@ -41,7 +41,7 @@ let f2 = x => { return v[1] + 1 } else {return v[1] + 2 } ]} - ") + */ let f3 = x => switch x { | A(v) => v + 1 diff --git a/jscomp/test/test_js_ffi.res b/jscomp/test/test_js_ffi.res index 8069c8fe5b..e33cf3139a 100644 --- a/jscomp/test/test_js_ffi.res +++ b/jscomp/test/test_js_ffi.res @@ -1,7 +1,7 @@ @val("console.log") -@ocaml.doc(" we should also allow js function call from an external js module +/** we should also allow js function call from an external js module -") +*/ external log: 'a => unit = "?ignore" let v = u => { diff --git a/jscomp/test/test_list.res b/jscomp/test/test_list.res index 050cccb89a..acda86ce68 100644 --- a/jscomp/test/test_list.res +++ b/jscomp/test/test_list.res @@ -320,7 +320,7 @@ let rec combine = (l1, l2) => | (_, _) => invalid_arg("List.combine") } -@@ocaml.text(" sorting ") +/* sorting */ let rec merge = (cmp, l1, l2) => switch (l1, l2) { @@ -445,7 +445,7 @@ let stable_sort = (cmp, l) => { let sort = stable_sort let fast_sort = stable_sort -@@ocaml.text(" sorting + removing duplicates ") +/* sorting + removing duplicates */ let sort_uniq = (cmp, l) => { let rec rev_merge = (l1, l2, accu) => diff --git a/jscomp/test/test_literals.res b/jscomp/test/test_literals.res index 15aab3ea80..1ce0973ff6 100644 --- a/jscomp/test/test_literals.res +++ b/jscomp/test/test_literals.res @@ -1,4 +1,4 @@ -@ocaml.doc(" nodejs ") +/** nodejs */ let node_modules = "node_modules" let node_modules_length = String.length("node_modules") diff --git a/jscomp/test/test_order_tailcall.res b/jscomp/test/test_order_tailcall.res index 2e5605fc28..1a4ac646c3 100644 --- a/jscomp/test/test_order_tailcall.res +++ b/jscomp/test/test_order_tailcall.res @@ -13,7 +13,7 @@ let rec f4 = (x, y) => f4(x + 10, y + x) let rec f5 = (x, y, z) => f5(y + 10, z + 20, z) -@ocaml.doc(" tail call as well ") +/** tail call as well */ let rec f6 = b => b && f6(b) let rec f7 = b => b || f7(b) diff --git a/jscomp/test/test_react.res b/jscomp/test/test_react.res index da39a5f703..f740f87f91 100644 --- a/jscomp/test/test_react.res +++ b/jscomp/test/test_react.res @@ -1,4 +1,4 @@ -@@ocaml.text(" TODO: binding -- document.getElementById -- to mount node ") +/* TODO: binding -- document.getElementById -- to mount node */ type html_element diff --git a/jscomp/test/test_react_case.res b/jscomp/test/test_react_case.res index 13add19c5c..70b7a1e0d9 100644 --- a/jscomp/test/test_react_case.res +++ b/jscomp/test/test_react_case.res @@ -1,4 +1,4 @@ -@ocaml.doc(" +/** var CommentBox = React.createClass({ render: function() { return ( @@ -8,7 +8,7 @@ var CommentBox = React.createClass({ ); } }); -") +*/ type obj_spec type react_dom_element @val diff --git a/jscomp/test/test_seq.res b/jscomp/test/test_seq.res index 8eb900540d..753ef98b43 100644 --- a/jscomp/test/test_seq.res +++ b/jscomp/test/test_seq.res @@ -93,7 +93,5 @@ let add_help = speclist => { \"@"(speclist, \"@"(add1, add2)) } -@@ocaml.text( - " FIXME- not compatible with strict mode " - /* let f x x = x */ -) +/* FIXME- not compatible with strict mode */ +/* let f x x = x */ diff --git a/jscomp/test/test_trywith.res b/jscomp/test/test_trywith.res index cc28560e6c..271fc25bbc 100644 --- a/jscomp/test/test_trywith.res +++ b/jscomp/test/test_trywith.res @@ -46,7 +46,7 @@ let u = () => { let u1 = "bad character decimal encoding \\" let v = "bad character decimal encoding \\%c%c%c" -@ocaml.doc(" test default branch ") +/** test default branch */ type u = A | B | C | D(int) | E(char) let f = (x: u) => diff --git a/jscomp/test/test_tuple_destructring.res b/jscomp/test/test_tuple_destructring.res index c17e674cdb..bfafa715cd 100644 --- a/jscomp/test/test_tuple_destructring.res +++ b/jscomp/test/test_tuple_destructring.res @@ -4,8 +4,8 @@ module N = { let v = N.b -@ocaml.doc(" TODO: +/** TODO: (3,4) belongs to ImmutableBlock - ") + */ let (u, h) = (3, 4) let (g, gg) = (u, h) diff --git a/jscomp/test/test_type_based_arity.res b/jscomp/test/test_type_based_arity.res index 4f34b02712..ff4dc45e8a 100644 --- a/jscomp/test/test_type_based_arity.res +++ b/jscomp/test/test_type_based_arity.res @@ -1,9 +1,9 @@ -@@ocaml.text(" Checkout [Ctype.arity] [Btype.repr] +/* Checkout [Ctype.arity] [Btype.repr] [Predef] Note that [f g x] can also be [(f g) x] even though we get a non-function return type - ") + */ let f0 = (g, x) => g(x) diff --git a/jscomp/test/test_unsafe_obj_ffi.res b/jscomp/test/test_unsafe_obj_ffi.res index b738cd5e9c..36e3d36115 100644 --- a/jscomp/test/test_unsafe_obj_ffi.res +++ b/jscomp/test/test_unsafe_obj_ffi.res @@ -6,10 +6,11 @@ let h = (x): unit => { x["height"] = 3 x["width"] = 3 } -@@ocaml.text(/* can not write set api without syntax extension, any more + +/* can not write set api without syntax extension, any more */ -" +/* imagine you have {[ let h = x ##_set_height in @@ -59,4 +60,4 @@ if it is already a property read, there ? how about {[ x #.property_fun 1 2 ]} this is mostly an error in FFI binding -") +*/ \ No newline at end of file diff --git a/jscomp/test/test_while_closure.res b/jscomp/test/test_while_closure.res index a345d4fead..a0981d3976 100644 --- a/jscomp/test/test_while_closure.res +++ b/jscomp/test/test_while_closure.res @@ -1,4 +1,4 @@ -@@ocaml.text(" Test when i is captured +/* Test when i is captured {[ ((fun _ -> j = i; (fun _ -> v := !v + j)) ()) ]} @@ -34,7 +34,7 @@ This means inline is tricky in javascript, here we try to inline [_loop]? - ") + */ let v = ref(0) let count = 10 diff --git a/jscomp/test/ticker.res b/jscomp/test/ticker.res index ab6e27af26..e81690e5e8 100644 --- a/jscomp/test/ticker.res +++ b/jscomp/test/ticker.res @@ -1,5 +1,5 @@ -@ocaml.doc(" General purpose utility functions - ") +/** General purpose utility functions + */ module Util = { let split = (~delim, s) => { let rec loop = (l, x) => @@ -33,7 +33,7 @@ module Util = { } } -@@ocaml.text(" AST for the tickers ") +/* AST for the tickers */ type binary_op = | PLUS @@ -87,7 +87,7 @@ module Ticker_map = Map.Make({ let compare = Pervasives.compare }) -@ocaml.doc(" For each market tickers, this function will compute +/** For each market tickers, this function will compute the associated list of tickers value to be updated based on the correct graph ordering @@ -98,7 +98,7 @@ module Ticker_map = Map.Make({ market tickers and finally we `sort_uniq` that list by rank to guarantee that a composite ticker is update only once and in the correct order. - ") + */ let compute_update_sequences = all_tickers => { /* Ranking */ @@ -162,8 +162,8 @@ let compute_update_sequences = all_tickers => { }, map, map) } -@ocaml.doc(" Process a new quote for a market ticker - ") +/** Process a new quote for a market ticker + */ let process_quote = (ticker_map, new_ticker, new_value) => { let update_sequence = Ticker_map.find(new_ticker, ticker_map) diff --git a/jscomp/test/topsort_test.res b/jscomp/test/topsort_test.res index 102d571d7b..54e132c6cc 100644 --- a/jscomp/test/topsort_test.res +++ b/jscomp/test/topsort_test.res @@ -75,9 +75,9 @@ let () = { assert (dfs1(list{"b"}, list{("f", "d"), ...graph}) == list{"b", "e", "g", "f", "d"}) } -@@ocaml.text(" since [x] is recorded before visiting its successors, so even with +/* since [x] is recorded before visiting its successors, so even with cycles, it is still terminating -") +*/ let grwork = list{ ("wake", "shower"), diff --git a/jscomp/test/unboxed_attribute_test.res b/jscomp/test/unboxed_attribute_test.res index 7b7ec41d10..f8d62e4a84 100644 --- a/jscomp/test/unboxed_attribute_test.res +++ b/jscomp/test/unboxed_attribute_test.res @@ -2,7 +2,7 @@ let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) -@ocaml.unboxed type t = A(int) +@unboxed type t = A(int) let v0 = A(3) @@ -11,7 +11,7 @@ let make = x => A(x) let get = (A(x)) => x /* For concrete types */ -@ocaml.unboxed type t1 = A(string) +@unboxed type t1 = A(string) { let x = A("foo") @@ -27,7 +27,7 @@ let get = (A(x)) => x } /* For records */ -@ocaml.unboxed type t2 = {f: string} +@unboxed type t2 = {f: string} { let x = {f: "foo"} @@ -35,7 +35,7 @@ let get = (A(x)) => x } /* For inline records */ -@ocaml.unboxed type t3 = B({g: string}) +@unboxed type t3 = B({g: string}) { let x = B({g: "foo"}) diff --git a/jscomp/test/unboxed_use_case.res b/jscomp/test/unboxed_use_case.res index 4f70d54abf..d05f2af98e 100644 --- a/jscomp/test/unboxed_use_case.res +++ b/jscomp/test/unboxed_use_case.res @@ -28,7 +28,7 @@ type rec t3<'a, 'b> = [ | #A(t3_aux) | #B ] -@ocaml.unboxed and t3_aux<'a, 'b> = {field: t3<'a, 'b>} +@unboxed and t3_aux<'a, 'b> = {field: t3<'a, 'b>} let rec v0: t3<_> = #A({field: v0}) let rec v1: t3<_> = #A({field: #B}) diff --git a/jscomp/test/unboxed_use_case.resi b/jscomp/test/unboxed_use_case.resi index f2dbccb922..32fe5d4143 100644 --- a/jscomp/test/unboxed_use_case.resi +++ b/jscomp/test/unboxed_use_case.resi @@ -11,7 +11,7 @@ type rec t3<'a, 'b> = [ | #A(t3_aux) | #B ] -@ocaml.unboxed and t3_aux<'a, 'b> = {field: t3<'a, 'b>} +@unboxed and t3_aux<'a, 'b> = {field: t3<'a, 'b>} let v0: t3<'a, 'b> let v1: t3<'a, 'b> From 96bf93c1cc6bd6e1b5f4fc03f54578514351ded7 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 9 Aug 2023 14:30:16 +0200 Subject: [PATCH 5/7] Convert Js.Dict and Js.String to .res --- jscomp/others/js_dict.ml | 114 --- jscomp/others/js_dict.res | 122 +++ jscomp/others/{js_dict.mli => js_dict.resi} | 117 +-- jscomp/others/{js_string.ml => js_string.res} | 734 +++++++++--------- jscomp/others/release.ninja | 6 +- lib/es6/js_dict.js | 10 +- lib/js/js_dict.js | 10 +- 7 files changed, 562 insertions(+), 551 deletions(-) delete mode 100644 jscomp/others/js_dict.ml create mode 100644 jscomp/others/js_dict.res rename jscomp/others/{js_dict.mli => js_dict.resi} (59%) rename jscomp/others/{js_string.ml => js_string.res} (61%) diff --git a/jscomp/others/js_dict.ml b/jscomp/others/js_dict.ml deleted file mode 100644 index a54bde508a..0000000000 --- a/jscomp/others/js_dict.ml +++ /dev/null @@ -1,114 +0,0 @@ -(* 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. *) - -(** Provides a simple key-value dictionary abstraction over native JavaScript objects *) - -(** The dict type *) -type 'a t - -(** The key type, an alias of string *) -type key = string - -(** - `unsafeGet dict key` returns the value associated with `key` in `dict` - - This function will return an invalid value (`undefined`) if `key` does not exist in `dict`. It - will not throw an error. -*) -external unsafeGet : 'a t -> key -> 'a = "" [@@bs.get_index] -let (.!()) = unsafeGet - -(** `get dict key` returns the value associated with `key` in `dict` *) -let get (type u) (dict : u t) (k : key) : u option = - if [%raw {|k in dict|}] then - Some dict.!(k) - else None - -(** `set dict key value` sets the value of `key` in `dict` to `value` *) -external set : 'a t -> key -> 'a -> unit = "" [@@bs.set_index] - -(** `keys dict` returns an array of all the keys in `dict` *) -external keys : 'a t -> key array = "Object.keys" [@@bs.val] - -(** `empty ()` creates an empty dictionary *) -external empty : unit -> 'a t = "" [@@bs.obj] - - -let unsafeDeleteKey : string t -> string -> unit [@bs] = - [%raw {| function (dict,key){ - delete dict[key]; - } - |}] - - -external unsafeCreate : int -> 'a array = "Array" [@@bs.new] -(* external entries : 'a t -> (key * 'a) array = "Object.entries" [@@bs.val] (* ES2017 *) *) -let entries dict = - let keys = keys dict in - let l = Js_array2.length keys in - let values = unsafeCreate l in - for i = 0 to l - 1 do - let key = Js_array2.unsafe_get keys i in - Js_array2.unsafe_set values i (key, dict.!(key)) - done; - values - -(* external values : 'a t -> 'a array = "Object.values" [@@bs.val] (* ES2017 *) *) -let values dict = - let keys = keys dict in - let l = Js_array2.length keys in - let values = unsafeCreate l in - for i = 0 to l - 1 do - Js_array2.unsafe_set values i dict.!(Js_array2.unsafe_get keys i) - done; - values - -let fromList entries = - let dict = empty () in - let rec loop = function - | [] -> dict - | (key, value) :: rest -> - set dict key value; - loop rest - in - loop entries - -let fromArray entries = - let dict = empty () in - let l = Js_array2.length entries in - for i = 0 to l - 1 do - let (key, value) = Js_array2.unsafe_get entries i in - set dict key value - done; - dict - -let map f source = - let target = empty () in - let keys = keys source in - let l = Js_array2.length keys in - for i = 0 to l - 1 do - let key = Js_array2.unsafe_get keys i in - set target key (f (unsafeGet source key) [@bs]) - done; - target diff --git a/jscomp/others/js_dict.res b/jscomp/others/js_dict.res new file mode 100644 index 0000000000..01caed7e7a --- /dev/null +++ b/jscomp/others/js_dict.res @@ -0,0 +1,122 @@ +@@ocaml.text( + /* 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. */ + + " Provides a simple key-value dictionary abstraction over native JavaScript objects " +) + +@ocaml.doc(" The dict type ") +type t<'a> + +@ocaml.doc(" The key type, an alias of string ") +type key = string + +@ocaml.doc(" + `unsafeGet dict key` returns the value associated with `key` in `dict` + + This function will return an invalid value (`undefined`) if `key` does not exist in `dict`. It + will not throw an error. +") +@get_index +external unsafeGet: (t<'a>, key) => 'a = "" +let \".!()" = unsafeGet + +@ocaml.doc(" `get dict key` returns the value associated with `key` in `dict` ") +let get = (type u, dict: t, k: key): option => + if %raw(`k in dict`) { + Some(\".!()"(dict, k)) + } else { + None + } + +@ocaml.doc(" `set dict key value` sets the value of `key` in `dict` to `value` ") @set_index +external set: (t<'a>, key, 'a) => unit = "" + +@ocaml.doc(" `keys dict` returns an array of all the keys in `dict` ") @val +external keys: t<'a> => array = "Object.keys" + +@ocaml.doc(" `empty ()` creates an empty dictionary ") @obj external empty: unit => t<'a> = "" + +let unsafeDeleteKey: (. t, string) => unit = %raw(` function (dict,key){ + delete dict[key]; + } + `) + +@new external unsafeCreate: int => array<'a> = "Array" +/* external entries : 'a t -> (key * 'a) array = "Object.entries" [@@bs.val] (* ES2017 *) */ +let entries = dict => { + let keys = keys(dict) + let l = Js_array2.length(keys) + let values = unsafeCreate(l) + for i in 0 to l - 1 { + let key = Js_array2.unsafe_get(keys, i) + Js_array2.unsafe_set(values, i, (key, \".!()"(dict, key))) + } + values +} + +/* external values : 'a t -> 'a array = "Object.values" [@@bs.val] (* ES2017 *) */ +let values = dict => { + let keys = keys(dict) + let l = Js_array2.length(keys) + let values = unsafeCreate(l) + for i in 0 to l - 1 { + Js_array2.unsafe_set(values, i, \".!()"(dict, Js_array2.unsafe_get(keys, i))) + } + values +} + +let fromList = entries => { + let dict = empty() + let rec loop = x => + switch x { + | list{} => dict + | list{(key, value), ...rest} => + set(dict, key, value) + loop(rest) + } + + loop(entries) +} + +let fromArray = entries => { + let dict = empty() + let l = Js_array2.length(entries) + for i in 0 to l - 1 { + let (key, value) = Js_array2.unsafe_get(entries, i) + set(dict, key, value) + } + dict +} + +let map = (f, source) => { + let target = empty() + let keys = keys(source) + let l = Js_array2.length(keys) + for i in 0 to l - 1 { + let key = Js_array2.unsafe_get(keys, i) + set(target, key, f(. unsafeGet(source, key))) + } + target +} diff --git a/jscomp/others/js_dict.mli b/jscomp/others/js_dict.resi similarity index 59% rename from jscomp/others/js_dict.mli rename to jscomp/others/js_dict.resi index ea2d91c355..28f36b7754 100644 --- a/jscomp/others/js_dict.mli +++ b/jscomp/others/js_dict.resi @@ -1,4 +1,4 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. +@@ocaml.text(/* 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 @@ -20,133 +20,134 @@ * * 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. *) + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -(** +" Provide utilities for JS dictionary object. **Note:** This module's examples will assume this predeclared dictionary: ```res prelude -let ages = Js.Dict.fromList(list{("Maria", 30), ("Vinh", 22), ("Fred", 49)}) +let ages = Js.Dict.fromList(list{(\"Maria\", 30), (\"Vinh\", 22), (\"Fred\", 49)}) ``` -*) +") -type 'a t -(** +@ocaml.doc(" 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. -*) +") +type t<'a> +@ocaml.doc( + " The type for dictionary keys. This means that dictionaries *must* use `string`s as their keys. " +) type key = string -(** The type for dictionary keys. This means that dictionaries *must* use `string`s as their keys. *) -val get : 'a t -> key -> 'a option -(** +@ocaml.doc(" `Js.Dict.get(key)` returns `None` if the key is not found in the dictionary, `Some(value)` otherwise. ```res example -Js.Dict.get(ages, "Vinh") == Some(22) -Js.Dict.get(ages, "Paul") == None +Js.Dict.get(ages, \"Vinh\") == Some(22) +Js.Dict.get(ages, \"Paul\") == None ``` -*) +") +let get: (t<'a>, key) => option<'a> -external unsafeGet : 'a t -> key -> 'a = "" - [@@bs.get_index] -(** +@get_index +@ocaml.doc(" `Js.Dict.unsafeGet(key)` returns the value if the key exists, otherwise an `undefined` value is returned. Use this only when you are sure the key exists (i.e. when having used the `keys()` function to check that the key is valid). ```res example -Js.Dict.unsafeGet(ages, "Fred") == 49 -Js.Dict.unsafeGet(ages, "Paul") // returns undefined +Js.Dict.unsafeGet(ages, \"Fred\") == 49 +Js.Dict.unsafeGet(ages, \"Paul\") // returns undefined ``` -*) +") +external unsafeGet: (t<'a>, key) => 'a = "" -external set : 'a t -> key -> 'a -> unit = "" - [@@bs.set_index] -(** +@set_index +@ocaml.doc(" `Js.Dict.set(dict, key, value)` sets the key/value in the dictionary `dict`. If the key does not exist, and entry will be created for it. *This function modifies the original dictionary.* ```res example -Js.Dict.set(ages, "Maria", 31) -Js.log(ages == Js.Dict.fromList(list{("Maria", 31), ("Vinh", 22), ("Fred", 49)})) +Js.Dict.set(ages, \"Maria\", 31) +Js.log(ages == Js.Dict.fromList(list{(\"Maria\", 31), (\"Vinh\", 22), (\"Fred\", 49)})) -Js.Dict.set(ages, "David", 66) -Js.log(ages == Js.Dict.fromList(list{("Maria", 31), ("Vinh", 22), ("Fred", 49), ("David", 66)})) +Js.Dict.set(ages, \"David\", 66) +Js.log(ages == Js.Dict.fromList(list{(\"Maria\", 31), (\"Vinh\", 22), (\"Fred\", 49), (\"David\", 66)})) ``` -*) +") +external set: (t<'a>, key, 'a) => unit = "" -external keys : 'a t -> string array = "Object.keys" - [@@bs.val] -(** +@val +@ocaml.doc(" Returns all the keys in the dictionary `dict`. ```res example -Js.Dict.keys(ages) == ["Maria", "Vinh", "Fred"] +Js.Dict.keys(ages) == [\"Maria\", \"Vinh\", \"Fred\"] ``` -*) +") +external keys: t<'a> => array = "Object.keys" -external empty : unit -> 'a t = "" - [@@bs.obj] -(** Returns an empty dictionary. *) +@obj @ocaml.doc(" Returns an empty dictionary. ") +external empty: unit => t<'a> = "" -val unsafeDeleteKey : (string t -> string -> unit[@bs]) -(** Experimental internal function *) +@ocaml.doc(" Experimental internal function ") +let unsafeDeleteKey: (. t, string) => unit -val entries : 'a t -> (key * 'a) array -(** +@ocaml.doc(" Returns an array of key/value pairs in the given dictionary (ES2017). ```res example -Js.Dict.entries(ages) == [("Maria", 30), ("Vinh", 22), ("Fred", 49)] +Js.Dict.entries(ages) == [(\"Maria\", 30), (\"Vinh\", 22), (\"Fred\", 49)] ``` -*) +") +let entries: t<'a> => array<(key, 'a)> -val values : 'a t -> 'a array -(** +@ocaml.doc(" Returns the values in the given dictionary (ES2017). ```res example Js.Dict.values(ages) == [30, 22, 49] ``` -*) +") +let values: t<'a> => array<'a> -val fromList : (key * 'a) list -> 'a t -(** +@ocaml.doc(" Creates a new dictionary containing each (key, value) pair in its list argument. ```res example -let capitals = Js.Dict.fromList(list{("Japan", "Tokyo"), ("France", "Paris"), ("Egypt", "Cairo")}) +let capitals = Js.Dict.fromList(list{(\"Japan\", \"Tokyo\"), (\"France\", \"Paris\"), (\"Egypt\", \"Cairo\")}) ``` -*) +") +let fromList: list<(key, 'a)> => t<'a> -val fromArray : (key * 'a) array -> 'a t -(** +@ocaml.doc(" Creates a new dictionary containing each (key, value) pair in its array argument. ```res example -let capitals2 = Js.Dict.fromArray([("Germany", "Berlin"), ("Burkina Faso", "Ouagadougou")]) +let capitals2 = Js.Dict.fromArray([(\"Germany\", \"Berlin\"), (\"Burkina Faso\", \"Ouagadougou\")]) ``` -*) +") +let fromArray: array<(key, 'a)> => t<'a> -val map : (('a -> 'b)[@bs]) -> 'a t -> 'b t -(** +@ocaml.doc(" `map(f, dict)` maps `dict` to a new dictionary with the same keys, using the function `f` to map each value. ```res example -let prices = Js.Dict.fromList(list{("pen", 1.00), ("book", 5.00), ("stapler", 7.00)}) +let prices = Js.Dict.fromList(list{(\"pen\", 1.00), (\"book\", 5.00), (\"stapler\", 7.00)}) let discount = (. price) => price *. 0.90 let salePrices = Js.Dict.map(discount, prices) -salePrices == Js.Dict.fromList(list{("pen", 0.90), ("book", 4.50), ("stapler", 6.30)}) +salePrices == Js.Dict.fromList(list{(\"pen\", 0.90), (\"book\", 4.50), (\"stapler\", 6.30)}) ``` -*) +") +let map: ((. 'a) => 'b, t<'a>) => t<'b> diff --git a/jscomp/others/js_string.ml b/jscomp/others/js_string.res similarity index 61% rename from jscomp/others/js_string.ml rename to jscomp/others/js_string.res index 60dba98351..9729739e49 100644 --- a/jscomp/others/js_string.ml +++ b/jscomp/others/js_string.res @@ -1,70 +1,72 @@ -(* 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. *) - -(** JavaScript String API *) - -[@@@warning "-103"] +@@ocaml.text( + /* 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. */ + + " JavaScript String API " +) + +@@warning("-103") type t = string -external make : 'a -> t = "String" - [@@bs.val] -(** +@val +@ocaml.doc(" `make(value)` converts the given value to a `string`. ```res example -Js.String2.make(3.5) == "3.5" -Js.String2.make([1, 2, 3]) == "1,2,3" +Js.String2.make(3.5) == \"3.5\" +Js.String2.make([1, 2, 3]) == \"1,2,3\" ``` -*) +") +external make: 'a => t = "String" -external fromCharCode : int -> t = "String.fromCharCode" - [@@bs.val] -(** +@val +@ocaml.doc(" `fromCharCode(n)` creates a `string` containing the character corresponding to that number; `n` ranges from 0 to 65535. If out of range, the lower 16 bits of the value are used. Thus, `fromCharCode(0x1F63A)` gives the same result as `fromCharCode(0xF63A)`. See [`String.fromCharCode`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) on MDN. ```res example -Js.String2.fromCharCode(65) == "A" +Js.String2.fromCharCode(65) == \"A\" Js.String2.fromCharCode(0x3c8) == `ψ` Js.String2.fromCharCode(0xd55c) == `한` Js.String2.fromCharCode(-64568) == `ψ` ``` -*) +") +external fromCharCode: int => t = "String.fromCharCode" -external fromCharCodeMany : int array -> t = "String.fromCharCode" - [@@bs.val] [@@bs.splice] -(** +@val +@variadic +@ocaml.doc(" `fromCharCodeMany([n1, n2, n3])` creates a `string` from the characters 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. -*) +") +external fromCharCodeMany: array => t = "String.fromCharCode" -external fromCodePoint : int -> t = "String.fromCodePoint" - [@@bs.val] -(** +@val +@ocaml.doc(" `fromCodePoint(n)` creates a `string` containing the character corresponding to that numeric code point. If the number is not a valid code point, it raises `RangeError`.Thus, `fromCodePoint(0x1F63A)` will produce a correct value, @@ -75,16 +77,17 @@ See [`String.fromCodePoint`](https://developer.mozilla.org/en-US/docs/Web/JavaSc on MDN. ```res example -Js.String2.fromCodePoint(65) == "A" +Js.String2.fromCodePoint(65) == \"A\" Js.String2.fromCodePoint(0x3c8) == `ψ` Js.String2.fromCodePoint(0xd55c) == `한` Js.String2.fromCodePoint(0x1f63a) == `😺` ``` -*) +") +external fromCodePoint: int => t = "String.fromCodePoint" -external fromCodePointMany : int array -> t = "String.fromCodePoint" - [@@bs.val] [@@bs.splice] -(** +@val +@variadic +@ocaml.doc(" `fromCodePointMany([n1, n2, n3])` creates a `string` from the characters corresponding to the given code point numbers, using the same rules as `fromCodePoint`. @@ -95,39 +98,39 @@ on MDN. ```res example Js.String2.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` ``` -*) +") +external fromCodePointMany: array => t = "String.fromCodePoint" -(* String.raw: ES2015, meant to be used with template strings, not directly *) +/* String.raw: ES2015, meant to be used with template strings, not directly */ -external length : t -> int = "length" - [@@bs.get] -(** +@get +@ocaml.doc(" `length(s)` returns the length of the given `string`. See [`String.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length) on MDN. ```res example -Js.String2.length("abcd") == 4 +Js.String2.length(\"abcd\") == 4 ``` -*) +") +external length: t => int = "length" -external get : t -> int -> t = "" - [@@bs.get_index] -(** +@get_index +@ocaml.doc(" `get(s, n)` returns as a `string` the character at the given index number. If `n` is out of range, this function returns `undefined`, so at some point this function may be modified to return `option(string)`. ```res example -Js.String2.get("Reason", 0) == "R" -Js.String2.get("Reason", 4) == "o" +Js.String2.get(\"Reason\", 0) == \"R\" +Js.String2.get(\"Reason\", 4) == \"o\" Js.String2.get(`Rẽasöń`, 5) == `ń` ``` -*) +") +external get: (t, int) => t = "" -external charAt : int -> t = "charAt" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `charAt(n, s)` gets the character at index `n` within string `s`. If `n` is negative or greater than the length of `s`, it returns the empty string. If the string contains characters outside the range \u0000-\uffff, it will return the @@ -137,15 +140,15 @@ See [`String.charAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.charAt(0, "Reason") == "R" -Js.String.charAt(12, "Reason") == "" +Js.String.charAt(0, \"Reason\") == \"R\" +Js.String.charAt(12, \"Reason\") == \"\" Js.String.charAt(5, `Rẽasöń`) == `ń` ``` -*) +") +external charAt: int => t = "charAt" -external charCodeAt : int -> float = "charCodeAt" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `charCodeAt(n, s)` returns the character code at position `n` in string `s`; the result is in the range 0-65535, unlke `codePointAt`, so it will not work correctly for characters with code points greater than or equal to 0x10000. The @@ -159,11 +162,11 @@ on MDN. Js.String.charCodeAt(0, `😺`) == 0xd83d->Belt.Int.toFloat Js.String.codePointAt(0, `😺`) == Some(0x1f63a) ``` -*) +") +external charCodeAt: int => float = "charCodeAt" -external codePointAt : int -> int option = "codePointAt" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `codePointAt(n, s)` returns the code point at position `n` within string `s` as a `Some(value)`. The return value handles code points greater than or equal to 0x10000. If there is no code point at the given position, the function returns @@ -174,13 +177,13 @@ on MDN. ```res example Js.String.codePointAt(1, `¿😺?`) == Some(0x1f63a) -Js.String.codePointAt(5, "abc") == None +Js.String.codePointAt(5, \"abc\") == None ``` -*) +") +external codePointAt: int => option = "codePointAt" -external concat : t -> t = "concat" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `concat(append, original)` returns a new `string` with `append` added after `original`. @@ -188,13 +191,14 @@ See [`String.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.concat("bell", "cow") == "cowbell" +Js.String.concat(\"bell\", \"cow\") == \"cowbell\" ``` -*) +") +external concat: t => t = "concat" -external concatMany : t array -> t = "concat" - [@@bs.send.pipe: t] [@@bs.splice] -(** +@bs.send.pipe(: t) +@variadic +@ocaml.doc(" `concat(arr, original)` returns a new `string` consisting of each item of an array of strings added to the `original` string. @@ -202,13 +206,13 @@ See [`String.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.concatMany(["2nd", "3rd", "4th"], "1st") == "1st2nd3rd4th" +Js.String.concatMany([\"2nd\", \"3rd\", \"4th\"], \"1st\") == \"1st2nd3rd4th\" ``` -*) +") +external concatMany: array => t = "concat" -external endsWith : t -> bool = "endsWith" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" ES2015: `endsWith(substr, str)` returns `true` if the `str` ends with `substr`, `false` otherwise. @@ -216,14 +220,14 @@ See [`String.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ on MDN. ```res example -Js.String.endsWith("Script", "BuckleScript") == true -Js.String.endsWith("Script", "BuckleShoes") == false +Js.String.endsWith(\"Script\", \"BuckleScript\") == true +Js.String.endsWith(\"Script\", \"BuckleShoes\") == false ``` -*) +") +external endsWith: t => bool = "endsWith" -external endsWithFrom : t -> int -> bool = "endsWith" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `endsWithFrom(ending, len, str)` returns `true` if the first len characters of `str` end with `ending`, `false` otherwise. If `len` is greater than or equal to the length of `str`, then it works like `endsWith`. (Honestly, this should @@ -233,16 +237,16 @@ See [`String.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ on MDN. ```res example -Js.String.endsWithFrom("cd", 4, "abcd") == true -Js.String.endsWithFrom("cd", 3, "abcde") == false -Js.String.endsWithFrom("cde", 99, "abcde") == true -Js.String.endsWithFrom("ple", 7, "example.dat") == true +Js.String.endsWithFrom(\"cd\", 4, \"abcd\") == true +Js.String.endsWithFrom(\"cd\", 3, \"abcde\") == false +Js.String.endsWithFrom(\"cde\", 99, \"abcde\") == true +Js.String.endsWithFrom(\"ple\", 7, \"example.dat\") == true ``` -*) +") +external endsWithFrom: (t, int) => bool = "endsWith" -external includes : t -> bool = "includes" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" ES2015: `includes(searchValue, str)` returns `true` if `searchValue` is found anywhere within `str`, false otherwise. @@ -250,16 +254,16 @@ See [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ on MDN. ```res example -Js.String.includes("gram", "programmer") == true -Js.String.includes("er", "programmer") == true -Js.String.includes("pro", "programmer") == true -Js.String.includes("xyz", "programmer.dat") == false +Js.String.includes(\"gram\", \"programmer\") == true +Js.String.includes(\"er\", \"programmer\") == true +Js.String.includes(\"pro\", \"programmer\") == true +Js.String.includes(\"xyz\", \"programmer.dat\") == false ``` -*) +") +external includes: t => bool = "includes" -external includesFrom : t -> int -> bool = "includes" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" ES2015: `includes(searchValue start, str)` returns `true` if `searchValue` is found anywhere within `str` starting at character number `start` (where 0 is the first character), `false` otherwise. @@ -268,15 +272,15 @@ See [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ on MDN. ```res example -Js.String.includesFrom("gram", 1, "programmer") == true -Js.String.includesFrom("gram", 4, "programmer") == false +Js.String.includesFrom(\"gram\", 1, \"programmer\") == true +Js.String.includesFrom(\"gram\", 4, \"programmer\") == false Js.String.includesFrom(`한`, 1, `대한민국`) == true ``` -*) +") +external includesFrom: (t, int) => bool = "includes" -external indexOf : t -> int = "indexOf" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" ES2015: `indexOf(searchValue, str)` returns the position at which `searchValue` was first found within `str`, or -1 if `searchValue` is not in `str`. @@ -284,16 +288,16 @@ See [`String.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -Js.String.indexOf("ok", "bookseller") == 2 -Js.String.indexOf("sell", "bookseller") == 4 -Js.String.indexOf("ee", "beekeeper") == 1 -Js.String.indexOf("xyz", "bookseller") == -1 +Js.String.indexOf(\"ok\", \"bookseller\") == 2 +Js.String.indexOf(\"sell\", \"bookseller\") == 4 +Js.String.indexOf(\"ee\", \"beekeeper\") == 1 +Js.String.indexOf(\"xyz\", \"bookseller\") == -1 ``` -*) +") +external indexOf: t => int = "indexOf" -external indexOfFrom : t -> int -> int = "indexOf" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `indexOfFrom(searchValue, start, str)` returns the position at which `searchValue` was found within `str` starting at character position `start`, or -1 if `searchValue` is not found in that portion of `str`. The return value is @@ -304,15 +308,15 @@ See [`String.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -Js.String.indexOfFrom("ok", 1, "bookseller") == 2 -Js.String.indexOfFrom("sell", 2, "bookseller") == 4 -Js.String.indexOfFrom("sell", 5, "bookseller") == -1 +Js.String.indexOfFrom(\"ok\", 1, \"bookseller\") == 2 +Js.String.indexOfFrom(\"sell\", 2, \"bookseller\") == 4 +Js.String.indexOfFrom(\"sell\", 5, \"bookseller\") == -1 ``` -*) +") +external indexOfFrom: (t, int) => int = "indexOf" -external lastIndexOf : t -> int = "lastIndexOf" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `lastIndexOf(searchValue, str)` returns the position of the last occurrence of `searchValue` within `str`, searching backwards from the end of the string. Returns -1 if `searchValue` is not in `str`. The return value is always @@ -322,15 +326,15 @@ See [`String.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScri on MDN. ```res example -Js.String.lastIndexOf("ok", "bookseller") == 2 -Js.String.lastIndexOf("ee", "beekeeper") == 4 -Js.String.lastIndexOf("xyz", "abcdefg") == -1 +Js.String.lastIndexOf(\"ok\", \"bookseller\") == 2 +Js.String.lastIndexOf(\"ee\", \"beekeeper\") == 4 +Js.String.lastIndexOf(\"xyz\", \"abcdefg\") == -1 ``` -*) +") +external lastIndexOf: t => int = "lastIndexOf" -external lastIndexOfFrom : t -> int -> int = "lastIndexOf" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `lastIndexOfFrom(searchValue, start, str)` returns the position of the last occurrence of `searchValue` within `str`, searching backwards from the given start position. Returns -1 if `searchValue` is not in `str`. The return value @@ -340,18 +344,18 @@ See [`String.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScri on MDN. ```res example -Js.String.lastIndexOfFrom("ok", 6, "bookseller") == 2 -Js.String.lastIndexOfFrom("ee", 8, "beekeeper") == 4 -Js.String.lastIndexOfFrom("ee", 3, "beekeeper") == 1 -Js.String.lastIndexOfFrom("xyz", 4, "abcdefg") == -1 +Js.String.lastIndexOfFrom(\"ok\", 6, \"bookseller\") == 2 +Js.String.lastIndexOfFrom(\"ee\", 8, \"beekeeper\") == 4 +Js.String.lastIndexOfFrom(\"ee\", 3, \"beekeeper\") == 1 +Js.String.lastIndexOfFrom(\"xyz\", 4, \"abcdefg\") == -1 ``` -*) +") +external lastIndexOfFrom: (t, int) => int = "lastIndexOf" -(* extended by ECMA-402 *) +/* extended by ECMA-402 */ -external localeCompare : t -> float = "localeCompare" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `localeCompare(comparison, reference)` returns - a negative value if reference comes before comparison in sort order - zero if reference and comparison have the same sort order @@ -360,16 +364,17 @@ external localeCompare : t -> float = "localeCompare" See [`String.localeCompare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare) on MDN. ```res example -Js.String.localeCompare("ant", "zebra") > 0.0 -Js.String.localeCompare("zebra", "ant") < 0.0 -Js.String.localeCompare("cat", "cat") == 0.0 -Js.String.localeCompare("cat", "CAT") > 0.0 +Js.String.localeCompare(\"ant\", \"zebra\") > 0.0 +Js.String.localeCompare(\"zebra\", \"ant\") < 0.0 +Js.String.localeCompare(\"cat\", \"cat\") == 0.0 +Js.String.localeCompare(\"cat\", \"CAT\") > 0.0 ``` -*) +") +external localeCompare: t => float = "localeCompare" -external match_ : Js_re.t -> t option array option = "match" - [@@bs.send.pipe: t] [@@bs.return { null_to_opt }] -(** +@bs.send.pipe(: t) +@return({null_to_opt: null_to_opt}) +@ocaml.doc(" `match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: @@ -383,17 +388,17 @@ See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref on MDN. ```res example -Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some(["bet"]) -Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some(["bet", "bat"]) -Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") == - Some(["2018-04-05", "2018", "04", "05"]) -Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None +Js.String.match_(%re(\"/b[aeiou]t/\"), \"The better bats\") == Some([\"bet\"]) +Js.String.match_(%re(\"/b[aeiou]t/g\"), \"The better bats\") == Some([\"bet\", \"bat\"]) +Js.String.match_(%re(\"/(\d+)-(\d+)-(\d+)/\"), \"Today is 2018-04-05.\") == + Some([\"2018-04-05\", \"2018\", \"04\", \"05\"]) +Js.String.match_(%re(\"/b[aeiou]g/\"), \"The large container.\") == None ``` -*) +") +external match_: Js_re.t => option>> = "match" -external normalize : t = "normalize" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `normalize(str)` returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition. Consider the character ã, which can be represented as the single codepoint \u00e3 or the combination of a lower case letter A @@ -405,25 +410,25 @@ on MDN. See also [Unicode technical report #15](https://unicode.org/reports/tr15/) for details. -*) +") +external normalize: t = "normalize" -external normalizeByForm : t -> t = "normalize" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" ES2015: `normalize(form, str)` returns the normalized Unicode string using the specified form of normalization, which may be one of: -- "NFC" — Normalization Form Canonical Composition. -- "NFD" — Normalization Form Canonical Decomposition. -- "NFKC" — Normalization Form Compatibility Composition. -- "NFKD" — Normalization Form Compatibility Decomposition. +- \"NFC\" — Normalization Form Canonical Composition. +- \"NFD\" — Normalization Form Canonical Decomposition. +- \"NFKC\" — Normalization Form Compatibility Composition. +- \"NFKD\" — Normalization Form Compatibility Decomposition. 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. -*) +") +external normalizeByForm: t => t = "normalize" -external repeat : int -> t = "repeat" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `repeat(n, str)` returns a `string` that consists of `n` repetitions of `str`. Raises `RangeError` if `n` is negative. @@ -431,14 +436,14 @@ See [`String.repeat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.repeat(3, "ha") == "hahaha" -Js.String.repeat(0, "empty") == "" +Js.String.repeat(3, \"ha\") == \"hahaha\" +Js.String.repeat(0, \"empty\") == \"\" ``` -*) +") +external repeat: int => t = "repeat" -external replace : t -> t -> t = "replace" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" ES2015: `replace(substr, newSubstr, str)` returns a new `string` which is identical to `str` except with the first matching instance of `substr` replaced by `newSubstr`. `substr` is treated as a verbatim string to match, not a @@ -448,14 +453,14 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -Js.String.replace("old", "new", "old string") == "new string" -Js.String.replace("the", "this", "the cat and the dog") == "this cat and the dog" +Js.String.replace(\"old\", \"new\", \"old string\") == \"new string\" +Js.String.replace(\"the\", \"this\", \"the cat and the dog\") == \"this cat and the dog\" ``` -*) +") +external replace: (t, t) => t = "replace" -external replaceByRe : Js_re.t -> t -> t = "replace" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `replaceByRe(regex, replacement, str)` returns a new `string` where occurrences matching regex have been replaced by `replacement`. @@ -463,15 +468,14 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -Js.String.replaceByRe(%re("/[aeiou]/g"), "x", "vowels be gone") == "vxwxls bx gxnx" -Js.String.replaceByRe(%re("/(\w+) (\w+)/"), "$2, $1", "Juan Fulano") == "Fulano, Juan" +Js.String.replaceByRe(%re(\"/[aeiou]/g\"), \"x\", \"vowels be gone\") == \"vxwxls bx gxnx\" +Js.String.replaceByRe(%re(\"/(\w+) (\w+)/\"), \"$2, $1\", \"Juan Fulano\") == \"Fulano, Juan\" ``` -*) +") +external replaceByRe: (Js_re.t, t) => t = "replace" -external unsafeReplaceBy0 : Js_re.t -> ((t -> int -> t -> t)[@bs.uncurry]) -> t - = "replace" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" Returns a new `string` with some or all matches of a pattern with no capturing parentheses replaced by the value returned from the given function. The function receives as its parameters the matched string, the offset at which the @@ -481,18 +485,17 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -let str = "beautiful vowels" -let re = %re("/[aeiou]/g") +let str = \"beautiful vowels\" +let re = %re(\"/[aeiou]/g\") let matchFn = (matchPart, _offset, _wholeString) => Js.String.toUpperCase(matchPart) -Js.String.unsafeReplaceBy0(re, matchFn, str) == "bEAUtIfUl vOwEls" +Js.String.unsafeReplaceBy0(re, matchFn, str) == \"bEAUtIfUl vOwEls\" ``` -*) +") +external unsafeReplaceBy0: (Js_re.t, @uncurry (t, int, t) => t) => t = "replace" -external unsafeReplaceBy1 : - Js_re.t -> ((t -> t -> int -> t -> t)[@bs.uncurry]) -> t = "replace" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" Returns a new `string` with some or all matches of a pattern with one set of capturing parentheses replaced by the value returned from the given function. The function receives as its parameters the matched string, the captured @@ -503,20 +506,19 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -let str = "Jony is 40" -let re = %re("/(Jony is )\d+/g") +let str = \"Jony is 40\" +let re = %re(\"/(Jony is )\d+/g\") let matchFn = (_match, part1, _offset, _wholeString) => { - part1 ++ "41" + part1 ++ \"41\" } -Js.String.unsafeReplaceBy1(re, matchFn, str) == "Jony is 41" +Js.String.unsafeReplaceBy1(re, matchFn, str) == \"Jony is 41\" ``` -*) +") +external unsafeReplaceBy1: (Js_re.t, @uncurry (t, t, int, t) => t) => t = "replace" -external unsafeReplaceBy2 : - Js_re.t -> ((t -> t -> t -> int -> t -> t)[@bs.uncurry]) -> t = "replace" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" Returns a new `string` with some or all matches of a pattern with two sets of capturing parentheses replaced by the value returned from the given function. The function receives as its parameters the matched string, the captured @@ -527,23 +529,22 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -let str = "7 times 6" -let re = %re("/(\d+) times (\d+)/") +let str = \"7 times 6\" +let re = %re(\"/(\d+) times (\d+)/\") let matchFn = (_match, p1, p2, _offset, _wholeString) => { switch (Belt.Int.fromString(p1), Belt.Int.fromString(p2)) { | (Some(x), Some(y)) => Belt.Int.toString(x * y) - | _ => "???" + | _ => \"???\" } } -Js.String.unsafeReplaceBy2(re, matchFn, str) == "42" +Js.String.unsafeReplaceBy2(re, matchFn, str) == \"42\" ``` -*) +") +external unsafeReplaceBy2: (Js_re.t, @uncurry (t, t, t, int, t) => t) => t = "replace" -external unsafeReplaceBy3 : - Js_re.t -> ((t -> t -> t -> t -> int -> t -> t)[@bs.uncurry]) -> t = "replace" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" Returns a new `string` with some or all matches of a pattern with three sets of capturing parentheses replaced by the value returned from the given function. The function receives as its parameters the matched string, the captured @@ -552,11 +553,11 @@ matched. See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) on MDN. -*) +") +external unsafeReplaceBy3: (Js_re.t, @uncurry (t, t, t, t, int, t) => t) => t = "replace" -external search : Js_re.t -> int = "search" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `search(regexp, str)` returns the starting position of the first match of `regexp` in the given `str`, or -1 if there is no match. @@ -564,14 +565,14 @@ See [`String.search`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.search(%re("/\d+/"), "testing 1 2 3") == 8 -Js.String.search(%re("/\d+/"), "no numbers") == -1 +Js.String.search(%re(\"/\d+/\"), \"testing 1 2 3\") == 8 +Js.String.search(%re(\"/\d+/\"), \"no numbers\") == -1 ``` -*) +") +external search: Js_re.t => int = "search" -external slice : from:int -> to_:int -> t = "slice" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `slice(from:n1, to_:n2, str)` returns the substring of `str` starting at character `n1` up to but not including `n2`. - If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`. @@ -581,16 +582,16 @@ character `n1` up to but not including `n2`. See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN. ```res example -Js.String.slice(~from=2, ~to_=5, "abcdefg") == "cde" -Js.String.slice(~from=2, ~to_=9, "abcdefg") == "cdefg" -Js.String.slice(~from=-4, ~to_=-2, "abcdefg") == "de" -Js.String.slice(~from=5, ~to_=1, "abcdefg") == "" +Js.String.slice(~from=2, ~to_=5, \"abcdefg\") == \"cde\" +Js.String.slice(~from=2, ~to_=9, \"abcdefg\") == \"cdefg\" +Js.String.slice(~from=-4, ~to_=-2, \"abcdefg\") == \"de\" +Js.String.slice(~from=5, ~to_=1, \"abcdefg\") == \"\" ``` -*) +") +external slice: (~from: int, ~to_: int) => t = "slice" -external sliceToEnd : from:int -> t = "slice" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `sliceToEnd(str, from:n)` returns the substring of `str` starting at character `n` to the end of the string. - If `n` is negative, then it is evaluated as `length(str - n)`. @@ -599,15 +600,15 @@ external sliceToEnd : from:int -> t = "slice" See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN. ```res example -Js.String.sliceToEnd(~from=4, "abcdefg") == "efg" -Js.String.sliceToEnd(~from=-2, "abcdefg") == "fg" -Js.String.sliceToEnd(~from=7, "abcdefg") == "" +Js.String.sliceToEnd(~from=4, \"abcdefg\") == \"efg\" +Js.String.sliceToEnd(~from=-2, \"abcdefg\") == \"fg\" +Js.String.sliceToEnd(~from=7, \"abcdefg\") == \"\" ``` -*) +") +external sliceToEnd: (~from: int) => t = "slice" -external split : t -> t array = "split" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `split(delimiter, str)` splits the given `str` at every occurrence of `delimiter` and returns an array of the resulting substrings. @@ -615,16 +616,16 @@ See [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref on MDN. ```res example -Js.String.split("-", "2018-01-02") == ["2018", "01", "02"] -Js.String.split(",", "a,b,,c") == ["a", "b", "", "c"] -Js.String.split("::", "good::bad as great::awful") == ["good", "bad as great", "awful"] -Js.String.split(";", "has-no-delimiter") == ["has-no-delimiter"] +Js.String.split(\"-\", \"2018-01-02\") == [\"2018\", \"01\", \"02\"] +Js.String.split(\",\", \"a,b,,c\") == [\"a\", \"b\", \"\", \"c\"] +Js.String.split(\"::\", \"good::bad as great::awful\") == [\"good\", \"bad as great\", \"awful\"] +Js.String.split(\";\", \"has-no-delimiter\") == [\"has-no-delimiter\"] ``` -*) +") +external split: t => array = "split" -external splitAtMost : t -> limit:int -> t array = "split" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `splitAtMost(delimiter, ~limit:n, str)` splits the given `str` at every occurrence of `delimiter` and returns an array of the first `n` resulting substrings. If `n` is negative or greater than the number of substrings, the @@ -634,15 +635,15 @@ See [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref on MDN. ```res example -Js.String.splitAtMost("/", ~limit=3, "ant/bee/cat/dog/elk") == ["ant", "bee", "cat"] -Js.String.splitAtMost("/", ~limit=0, "ant/bee/cat/dog/elk") == [] -Js.String.splitAtMost("/", ~limit=9, "ant/bee/cat/dog/elk") == ["ant", "bee", "cat", "dog", "elk"] +Js.String.splitAtMost(\"/\", ~limit=3, \"ant/bee/cat/dog/elk\") == [\"ant\", \"bee\", \"cat\"] +Js.String.splitAtMost(\"/\", ~limit=0, \"ant/bee/cat/dog/elk\") == [] +Js.String.splitAtMost(\"/\", ~limit=9, \"ant/bee/cat/dog/elk\") == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"] ``` -*) +") +external splitAtMost: (t, ~limit: int) => array = "split" -external splitByRe : Js_re.t -> t option array = "split" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `splitByRe(regex, str)` splits the given `str` at every occurrence of `regex` and returns an array of the resulting substrings. @@ -650,18 +651,18 @@ See [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref on MDN. ```res example -Js.String.splitByRe(%re("/\s*[,;]\s*/"), "art; bed , cog ;dad") == [ - Some("art"), - Some("bed"), - Some("cog"), - Some("dad"), +Js.String.splitByRe(%re(\"/\s*[,;]\s*/\"), \"art; bed , cog ;dad\") == [ + Some(\"art\"), + Some(\"bed\"), + Some(\"cog\"), + Some(\"dad\"), ] ``` -*) +") +external splitByRe: Js_re.t => array> = "split" -external splitByReAtMost : Js_re.t -> limit:int -> t option array = "split" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `splitByReAtMost(regex, ~limit:n, str)` splits the given `str` at every occurrence of `regex` and returns an array of the first `n` resulting substrings. If `n` is negative or greater than the number of substrings, the @@ -671,26 +672,26 @@ See [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref on MDN. ```res example -Js.String.splitByReAtMost(%re("/\s*:\s*/"), ~limit=3, "one: two: three: four") == [ - Some("one"), - Some("two"), - Some("three"), +Js.String.splitByReAtMost(%re(\"/\s*:\s*/\"), ~limit=3, \"one: two: three: four\") == [ + Some(\"one\"), + Some(\"two\"), + Some(\"three\"), ] -Js.String.splitByReAtMost(%re("/\s*:\s*/"), ~limit=0, "one: two: three: four") == [] +Js.String.splitByReAtMost(%re(\"/\s*:\s*/\"), ~limit=0, \"one: two: three: four\") == [] -Js.String.splitByReAtMost(%re("/\s*:\s*/"), ~limit=8, "one: two: three: four") == [ - Some("one"), - Some("two"), - Some("three"), - Some("four"), +Js.String.splitByReAtMost(%re(\"/\s*:\s*/\"), ~limit=8, \"one: two: three: four\") == [ + Some(\"one\"), + Some(\"two\"), + Some(\"three\"), + Some(\"four\"), ] ``` -*) +") +external splitByReAtMost: (Js_re.t, ~limit: int) => array> = "split" -external startsWith : t -> bool = "startsWith" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" ES2015: `startsWith(substr, str)` returns `true` if the `str` starts with `substr`, `false` otherwise. @@ -698,15 +699,15 @@ See [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScrip on MDN. ```res example -Js.String.startsWith("Buckle", "BuckleScript") == true -Js.String.startsWith("", "BuckleScript") == true -Js.String.startsWith("Buckle", "JavaScript") == false +Js.String.startsWith(\"Buckle\", \"BuckleScript\") == true +Js.String.startsWith(\"\", \"BuckleScript\") == true +Js.String.startsWith(\"Buckle\", \"JavaScript\") == false ``` -*) +") +external startsWith: t => bool = "startsWith" -external startsWithFrom : t -> int -> bool = "startsWith" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" ES2015: `startsWithFrom(substr, n, str)` returns `true` if the `str` starts with `substr` starting at position `n`, false otherwise. If `n` is negative, the search starts at the beginning of `str`. @@ -715,15 +716,15 @@ See [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScrip on MDN. ```res example -Js.String.startsWithFrom("kle", 3, "BuckleScript") == true -Js.String.startsWithFrom("", 3, "BuckleScript") == true -Js.String.startsWithFrom("Buckle", 2, "JavaScript") == false +Js.String.startsWithFrom(\"kle\", 3, \"BuckleScript\") == true +Js.String.startsWithFrom(\"\", 3, \"BuckleScript\") == true +Js.String.startsWithFrom(\"Buckle\", 2, \"JavaScript\") == false ``` -*) +") +external startsWithFrom: (t, int) => bool = "startsWith" -external substr : from:int -> t = "substr" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `substr(~from:n, str)` returns the substring of `str` from position `n` to the end of the string. - If `n` is less than zero, the starting position is the length of `str - n`. @@ -736,15 +737,15 @@ See [`String.substr`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.substr(~from=3, "abcdefghij") == "defghij" -Js.String.substr(~from=-3, "abcdefghij") == "hij" -Js.String.substr(~from=12, "abcdefghij") == "" +Js.String.substr(~from=3, \"abcdefghij\") == \"defghij\" +Js.String.substr(~from=-3, \"abcdefghij\") == \"hij\" +Js.String.substr(~from=12, \"abcdefghij\") == \"\" ``` -*) +") +external substr: (~from: int) => t = "substr" -external substrAtMost : from:int -> length:int -> t = "substr" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `substrAtMost(~from: pos, ~length: n, str)` returns the substring of `str` of length `n` starting at position `pos`. - If `pos` is less than zero, the starting position is the length of `str - pos`. @@ -758,15 +759,15 @@ See [`String.substr`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.substrAtMost(~from=3, ~length=4, "abcdefghij") == "defg" -Js.String.substrAtMost(~from=-3, ~length=4, "abcdefghij") == "hij" -Js.String.substrAtMost(~from=12, ~length=2, "abcdefghij") == "" +Js.String.substrAtMost(~from=3, ~length=4, \"abcdefghij\") == \"defg\" +Js.String.substrAtMost(~from=-3, ~length=4, \"abcdefghij\") == \"hij\" +Js.String.substrAtMost(~from=12, ~length=2, \"abcdefghij\") == \"\" ``` -*) +") +external substrAtMost: (~from: int, ~length: int) => t = "substr" -external substring : from:int -> to_:int -> t = "substring" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `substring(~from: start, ~to_: finish, str)` returns characters `start` up to but not including finish from `str`. - If `start` is less than zero, it is treated as zero. @@ -776,15 +777,15 @@ but not including finish from `str`. See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN. ```res example -Js.String.substring(~from=3, ~to_=6, "playground") == "ygr" -Js.String.substring(~from=6, ~to_=3, "playground") == "ygr" -Js.String.substring(~from=4, ~to_=12, "playground") == "ground" +Js.String.substring(~from=3, ~to_=6, \"playground\") == \"ygr\" +Js.String.substring(~from=6, ~to_=3, \"playground\") == \"ygr\" +Js.String.substring(~from=4, ~to_=12, \"playground\") == \"ground\" ``` -*) +") +external substring: (~from: int, ~to_: int) => t = "substring" -external substringToEnd : from:int -> t = "substring" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `substringToEnd(~from: start, str)` returns the substring of `str` from position `start` to the end. - If `start` is less than or equal to zero, the entire string is returned. @@ -793,15 +794,15 @@ position `start` to the end. See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN. ```res example -Js.String.substringToEnd(~from=4, "playground") == "ground" -Js.String.substringToEnd(~from=-3, "playground") == "playground" -Js.String.substringToEnd(~from=12, "playground") == "" +Js.String.substringToEnd(~from=4, \"playground\") == \"ground\" +Js.String.substringToEnd(~from=-3, \"playground\") == \"playground\" +Js.String.substringToEnd(~from=12, \"playground\") == \"\" ``` -*) +") +external substringToEnd: (~from: int) => t = "substring" -external toLowerCase : t = "toLowerCase" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `toLowerCase(str)` converts `str` to lower case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can give different results depending upon context, for example with the Greek @@ -812,24 +813,24 @@ See [`String.toLowerCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScri on MDN. ```res example -Js.String.toLowerCase("ABC") == "abc" +Js.String.toLowerCase(\"ABC\") == \"abc\" Js.String.toLowerCase(`ΣΠ`) == `σπ` Js.String.toLowerCase(`ΠΣ`) == `πς` ``` -*) +") +external toLowerCase: t = "toLowerCase" -external toLocaleLowerCase : t = "toLocaleLowerCase" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `toLocaleLowerCase(str)` converts `str` to lower case using the current locale. See [`String.toLocaleLowerCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase) on MDN. -*) +") +external toLocaleLowerCase: t = "toLocaleLowerCase" -external toUpperCase : t = "toUpperCase" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `toUpperCase(str)` converts `str` to upper case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can expand the number of letters in the result; for example the German ß @@ -839,24 +840,24 @@ See [`String.toUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScri on MDN. ```res example -Js.String.toUpperCase("abc") == "ABC" +Js.String.toUpperCase(\"abc\") == \"ABC\" Js.String.toUpperCase(`Straße`) == `STRASSE` Js.String.toUpperCase(`πς`) == `ΠΣ` ``` -*) +") +external toUpperCase: t = "toUpperCase" -external toLocaleUpperCase : t = "toLocaleUpperCase" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `toLocaleUpperCase(str)` converts `str` to upper case using the current locale. See [`String.to:LocaleUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase) on MDN. -*) +") +external toLocaleUpperCase: t = "toLocaleUpperCase" -external trim : t = "trim" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `trim(str)` returns a string that is `str` with whitespace stripped from both ends. Internal whitespace is not removed. @@ -864,16 +865,16 @@ See [`String.trim`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe on MDN. ```res example -Js.String.trim(" abc def ") == "abc def" -Js.String.trim("\n\r\t abc def \n\n\t\r ") == "abc def" +Js.String.trim(\" abc def \") == \"abc def\" +Js.String.trim(\"\n\r\t abc def \n\n\t\r \") == \"abc def\" ``` -*) +") +external trim: t = "trim" -(* HTML wrappers *) +/* HTML wrappers */ -external anchor : t -> t = "anchor" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" `anchor(anchorName, anchorText)` creates a string with an HTML `` element with name attribute of `anchorName` and `anchorText` as its content. Please do not use this method, as it has been removed from the relevant web standards. @@ -882,13 +883,13 @@ See [`String.anchor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.anchor("page1", "Page One") == "Page One" +Js.String.anchor(\"page1\", \"Page One\") == \"Page One\" ``` -*) +") +external anchor: t => t = "anchor" -external link : t -> t = "link" - [@@bs.send.pipe: t] -(** +@bs.send.pipe(: t) +@ocaml.doc(" ES2015: `link(urlText, linkText)` creates a string with an HTML `` element with href attribute of `urlText` and `linkText` as its content. Please do not use this method, as it has been removed from the relevant web standards. @@ -897,18 +898,19 @@ See [`String.link`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe on MDN. ```res example -Js.String.link("page2.html", "Go to page two") == "Go to page two" +Js.String.link(\"page2.html\", \"Go to page two\") == \"Go to page two\" ``` -*) +") +external link: t => t = "link" -external castToArrayLike : t -> t Js_array2.array_like = "%identity" -(** +@ocaml.doc(" Casts its argument to an `array_like` entity that can be processed by functions such as `Js.Array2.fromMap()` ```res example -let s = "abcde" +let s = \"abcde\" let arr = Js.Array2.fromMap(Js.String.castToArrayLike(s), x => x) -arr == ["a", "b", "c", "d", "e"] +arr == [\"a\", \"b\", \"c\", \"d\", \"e\"] ``` -*) +") +external castToArrayLike: t => Js_array2.array_like = "%identity" diff --git a/jscomp/others/release.ninja b/jscomp/others/release.ninja index 83cad595d8..1d3c0db08e 100644 --- a/jscomp/others/release.ninja +++ b/jscomp/others/release.ninja @@ -23,8 +23,8 @@ o others/js_cast.cmj : cc_cmi others/js_cast.res | others/belt_internals.cmi oth o others/js_cast.cmi : cc others/js_cast.resi | others/belt_internals.cmi others/js.cmi $bsc o others/js_console.cmi others/js_console.cmj : cc others/js_console.res | others/belt_internals.cmi others/js.cmi $bsc o others/js_date.cmi others/js_date.cmj : cc others/js_date.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_dict.cmj : cc_cmi others/js_dict.ml | others/belt_internals.cmi others/js.cmi others/js_array2.cmj others/js_dict.cmi $bsc -o others/js_dict.cmi : cc others/js_dict.mli | others/belt_internals.cmi others/js.cmi $bsc +o others/js_dict.cmj : cc_cmi others/js_dict.res | others/belt_internals.cmi others/js.cmi others/js_array2.cmj others/js_dict.cmi $bsc +o others/js_dict.cmi : cc others/js_dict.resi | others/belt_internals.cmi others/js.cmi $bsc o others/js_exn.cmj : cc_cmi others/js_exn.res | others/belt_internals.cmi others/js.cmi others/js_exn.cmi $bsc o others/js_exn.cmi : cc others/js_exn.resi | others/belt_internals.cmi others/js.cmi $bsc o others/js_float.cmi others/js_float.cmj : cc others/js_float.res | others/belt_internals.cmi others/js.cmi $bsc @@ -51,7 +51,7 @@ o others/js_re.cmi others/js_re.cmj : cc others/js_re.res | others/belt_internal o others/js_result.cmj : cc_cmi others/js_result.res | others/belt_internals.cmi others/js.cmi others/js_result.cmi $bsc o others/js_result.cmi : cc others/js_result.resi | others/belt_internals.cmi others/js.cmi $bsc o others/js_set.cmi others/js_set.cmj : cc others/js_set.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_string.cmi others/js_string.cmj : cc others/js_string.ml | others/belt_internals.cmi others/js.cmi others/js_array2.cmj others/js_re.cmj $bsc +o others/js_string.cmi others/js_string.cmj : cc others/js_string.res | others/belt_internals.cmi others/js.cmi others/js_array2.cmj others/js_re.cmj $bsc o others/js_string2.cmi others/js_string2.cmj : cc others/js_string2.res | others/belt_internals.cmi others/js.cmi others/js_array2.cmj others/js_re.cmj $bsc o others/js_typed_array.cmi others/js_typed_array.cmj : cc others/js_typed_array.res | others/belt_internals.cmi others/js.cmi others/js.cmj others/js_typed_array2.cmj $bsc o others/js_typed_array2.cmi others/js_typed_array2.cmj : cc others/js_typed_array2.res | others/belt_internals.cmi others/js.cmi others/js.cmj $bsc diff --git a/lib/es6/js_dict.js b/lib/es6/js_dict.js index fc58964a92..2be98231e8 100644 --- a/lib/es6/js_dict.js +++ b/lib/es6/js_dict.js @@ -39,15 +39,15 @@ function values(dict) { function fromList(entries) { var dict = {}; - var _param = entries; + var _x = entries; while(true) { - var param = _param; - if (!param) { + var x = _x; + if (!x) { return dict; } - var match = param.hd; + var match = x.hd; dict[match[0]] = match[1]; - _param = param.tl; + _x = x.tl; continue ; }; } diff --git a/lib/js/js_dict.js b/lib/js/js_dict.js index f321fe187d..4dfafed9ff 100644 --- a/lib/js/js_dict.js +++ b/lib/js/js_dict.js @@ -39,15 +39,15 @@ function values(dict) { function fromList(entries) { var dict = {}; - var _param = entries; + var _x = entries; while(true) { - var param = _param; - if (!param) { + var x = _x; + if (!x) { return dict; } - var match = param.hd; + var match = x.hd; dict[match[0]] = match[1]; - _param = param.tl; + _x = x.tl; continue ; }; } From 0443260365b45ed0b1d0c51a34e42e2450b117e8 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 15 Aug 2023 10:50:43 +0200 Subject: [PATCH 6/7] Update artifacts.txt --- packages/artifacts.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/artifacts.txt b/packages/artifacts.txt index 19639d99a4..1ea5c1e705 100644 --- a/packages/artifacts.txt +++ b/packages/artifacts.txt @@ -734,8 +734,8 @@ lib/ocaml/js_dict.cmi lib/ocaml/js_dict.cmj lib/ocaml/js_dict.cmt lib/ocaml/js_dict.cmti -lib/ocaml/js_dict.ml -lib/ocaml/js_dict.mli +lib/ocaml/js_dict.res +lib/ocaml/js_dict.resi lib/ocaml/js_exn.cmi lib/ocaml/js_exn.cmj lib/ocaml/js_exn.cmt @@ -827,7 +827,7 @@ lib/ocaml/js_set.res lib/ocaml/js_string.cmi lib/ocaml/js_string.cmj lib/ocaml/js_string.cmt -lib/ocaml/js_string.ml +lib/ocaml/js_string.res lib/ocaml/js_string2.cmi lib/ocaml/js_string2.cmj lib/ocaml/js_string2.cmt From d75c47529ff77370e6d8c059127c1bc676c162de Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 16 Aug 2023 07:40:55 +0200 Subject: [PATCH 7/7] Fix doc comments --- jscomp/others/js_dict.res | 74 +++--- jscomp/others/js_dict.resi | 86 +++---- jscomp/others/js_string.res | 472 ++++++++++++++++++------------------ 3 files changed, 316 insertions(+), 316 deletions(-) diff --git a/jscomp/others/js_dict.res b/jscomp/others/js_dict.res index 01caed7e7a..b08e0759b2 100644 --- a/jscomp/others/js_dict.res +++ b/jscomp/others/js_dict.res @@ -1,48 +1,46 @@ -@@ocaml.text( - /* 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. */ - - " Provides a simple key-value dictionary abstraction over native JavaScript objects " -) - -@ocaml.doc(" The dict type ") +/* 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. */ + +/*** Provides a simple key-value dictionary abstraction over native JavaScript objects */ + +/** The dict type */ type t<'a> -@ocaml.doc(" The key type, an alias of string ") +/** The key type, an alias of string */ type key = string -@ocaml.doc(" +/** `unsafeGet dict key` returns the value associated with `key` in `dict` This function will return an invalid value (`undefined`) if `key` does not exist in `dict`. It will not throw an error. -") +*/ @get_index external unsafeGet: (t<'a>, key) => 'a = "" let \".!()" = unsafeGet -@ocaml.doc(" `get dict key` returns the value associated with `key` in `dict` ") +/** `get dict key` returns the value associated with `key` in `dict` */ let get = (type u, dict: t, k: key): option => if %raw(`k in dict`) { Some(\".!()"(dict, k)) @@ -50,13 +48,17 @@ let get = (type u, dict: t, k: key): option => None } -@ocaml.doc(" `set dict key value` sets the value of `key` in `dict` to `value` ") @set_index +/** `set dict key value` sets the value of `key` in `dict` to `value` */ +@set_index external set: (t<'a>, key, 'a) => unit = "" -@ocaml.doc(" `keys dict` returns an array of all the keys in `dict` ") @val +/** `keys dict` returns an array of all the keys in `dict` */ +@val external keys: t<'a> => array = "Object.keys" -@ocaml.doc(" `empty ()` creates an empty dictionary ") @obj external empty: unit => t<'a> = "" +/** `empty ()` creates an empty dictionary */ +@obj +external empty: unit => t<'a> = "" let unsafeDeleteKey: (. t, string) => unit = %raw(` function (dict,key){ delete dict[key]; diff --git a/jscomp/others/js_dict.resi b/jscomp/others/js_dict.resi index 28f36b7754..23e1f11112 100644 --- a/jscomp/others/js_dict.resi +++ b/jscomp/others/js_dict.resi @@ -1,4 +1,4 @@ -@@ocaml.text(/* Copyright (C) 2015-2016 Bloomberg Finance L.P. +/* 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 @@ -22,132 +22,132 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -" +/*** Provide utilities for JS dictionary object. **Note:** This module's examples will assume this predeclared dictionary: ```res prelude -let ages = Js.Dict.fromList(list{(\"Maria\", 30), (\"Vinh\", 22), (\"Fred\", 49)}) +let ages = Js.Dict.fromList(list{("Maria", 30), ("Vinh", 22), ("Fred", 49)}) ``` -") +*/ -@ocaml.doc(" +/* 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. -") +*/ type t<'a> -@ocaml.doc( - " The type for dictionary keys. This means that dictionaries *must* use `string`s as their keys. " -) +/** + The type for dictionary keys. This means that dictionaries *must* use `string`s as their keys. +*/ type key = string -@ocaml.doc(" +/** `Js.Dict.get(key)` returns `None` if the key is not found in the dictionary, `Some(value)` otherwise. ```res example -Js.Dict.get(ages, \"Vinh\") == Some(22) -Js.Dict.get(ages, \"Paul\") == None +Js.Dict.get(ages, "Vinh") == Some(22) +Js.Dict.get(ages, "Paul") == None ``` -") +*/ let get: (t<'a>, key) => option<'a> @get_index -@ocaml.doc(" +/** `Js.Dict.unsafeGet(key)` returns the value if the key exists, otherwise an `undefined` value is returned. Use this only when you are sure the key exists (i.e. when having used the `keys()` function to check that the key is valid). ```res example -Js.Dict.unsafeGet(ages, \"Fred\") == 49 -Js.Dict.unsafeGet(ages, \"Paul\") // returns undefined +Js.Dict.unsafeGet(ages, "Fred") == 49 +Js.Dict.unsafeGet(ages, "Paul") // returns undefined ``` -") +*/ external unsafeGet: (t<'a>, key) => 'a = "" @set_index -@ocaml.doc(" +/** `Js.Dict.set(dict, key, value)` sets the key/value in the dictionary `dict`. If the key does not exist, and entry will be created for it. *This function modifies the original dictionary.* ```res example -Js.Dict.set(ages, \"Maria\", 31) -Js.log(ages == Js.Dict.fromList(list{(\"Maria\", 31), (\"Vinh\", 22), (\"Fred\", 49)})) +Js.Dict.set(ages, "Maria", 31) +Js.log(ages == Js.Dict.fromList(list{("Maria", 31), ("Vinh", 22), ("Fred", 49)})) -Js.Dict.set(ages, \"David\", 66) -Js.log(ages == Js.Dict.fromList(list{(\"Maria\", 31), (\"Vinh\", 22), (\"Fred\", 49), (\"David\", 66)})) +Js.Dict.set(ages, "David", 66) +Js.log(ages == Js.Dict.fromList(list{("Maria", 31), ("Vinh", 22), ("Fred", 49), ("David", 66)})) ``` -") +*/ external set: (t<'a>, key, 'a) => unit = "" @val -@ocaml.doc(" +/** Returns all the keys in the dictionary `dict`. ```res example -Js.Dict.keys(ages) == [\"Maria\", \"Vinh\", \"Fred\"] +Js.Dict.keys(ages) == ["Maria", "Vinh", "Fred"] ``` -") +*/ external keys: t<'a> => array = "Object.keys" -@obj @ocaml.doc(" Returns an empty dictionary. ") +@obj /** Returns an empty dictionary. */ external empty: unit => t<'a> = "" -@ocaml.doc(" Experimental internal function ") +/** Experimental internal function */ let unsafeDeleteKey: (. t, string) => unit -@ocaml.doc(" +/** Returns an array of key/value pairs in the given dictionary (ES2017). ```res example -Js.Dict.entries(ages) == [(\"Maria\", 30), (\"Vinh\", 22), (\"Fred\", 49)] +Js.Dict.entries(ages) == [("Maria", 30), ("Vinh", 22), ("Fred", 49)] ``` -") +*/ let entries: t<'a> => array<(key, 'a)> -@ocaml.doc(" +/** Returns the values in the given dictionary (ES2017). ```res example Js.Dict.values(ages) == [30, 22, 49] ``` -") +*/ let values: t<'a> => array<'a> -@ocaml.doc(" +/** Creates a new dictionary containing each (key, value) pair in its list argument. ```res example -let capitals = Js.Dict.fromList(list{(\"Japan\", \"Tokyo\"), (\"France\", \"Paris\"), (\"Egypt\", \"Cairo\")}) +let capitals = Js.Dict.fromList(list{("Japan", "Tokyo"), ("France", "Paris"), ("Egypt", "Cairo")}) ``` -") +*/ let fromList: list<(key, 'a)> => t<'a> -@ocaml.doc(" +/** Creates a new dictionary containing each (key, value) pair in its array argument. ```res example -let capitals2 = Js.Dict.fromArray([(\"Germany\", \"Berlin\"), (\"Burkina Faso\", \"Ouagadougou\")]) +let capitals2 = Js.Dict.fromArray([("Germany", "Berlin"), ("Burkina Faso", "Ouagadougou")]) ``` -") +*/ let fromArray: array<(key, 'a)> => t<'a> -@ocaml.doc(" +/** `map(f, dict)` maps `dict` to a new dictionary with the same keys, using the function `f` to map each value. ```res example -let prices = Js.Dict.fromList(list{(\"pen\", 1.00), (\"book\", 5.00), (\"stapler\", 7.00)}) +let prices = Js.Dict.fromList(list{("pen", 1.00), ("book", 5.00), ("stapler", 7.00)}) let discount = (. price) => price *. 0.90 let salePrices = Js.Dict.map(discount, prices) -salePrices == Js.Dict.fromList(list{(\"pen\", 0.90), (\"book\", 4.50), (\"stapler\", 6.30)}) +salePrices == Js.Dict.fromList(list{("pen", 0.90), ("book", 4.50), ("stapler", 6.30)}) ``` -") +*/ let map: ((. 'a) => 'b, t<'a>) => t<'b> diff --git a/jscomp/others/js_string.res b/jscomp/others/js_string.res index 9729739e49..a4cb4ec4ce 100644 --- a/jscomp/others/js_string.res +++ b/jscomp/others/js_string.res @@ -1,72 +1,70 @@ -@@ocaml.text( - /* 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. */ - - " JavaScript String API " -) +/* 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. */ + +/*** JavaScript String API */ @@warning("-103") type t = string @val -@ocaml.doc(" +/** `make(value)` converts the given value to a `string`. ```res example -Js.String2.make(3.5) == \"3.5\" -Js.String2.make([1, 2, 3]) == \"1,2,3\" +Js.String2.make(3.5) == "3.5" +Js.String2.make([1, 2, 3]) == "1,2,3" ``` -") +*/ external make: 'a => t = "String" @val -@ocaml.doc(" +/** `fromCharCode(n)` creates a `string` containing the character corresponding to that number; `n` ranges from 0 to 65535. If out of range, the lower 16 bits of the value are used. Thus, `fromCharCode(0x1F63A)` gives the same result as `fromCharCode(0xF63A)`. See [`String.fromCharCode`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) on MDN. ```res example -Js.String2.fromCharCode(65) == \"A\" +Js.String2.fromCharCode(65) == "A" Js.String2.fromCharCode(0x3c8) == `ψ` Js.String2.fromCharCode(0xd55c) == `한` Js.String2.fromCharCode(-64568) == `ψ` ``` -") +*/ external fromCharCode: int => t = "String.fromCharCode" @val @variadic -@ocaml.doc(" +/** `fromCharCodeMany([n1, n2, n3])` creates a `string` from the characters 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. -") +*/ external fromCharCodeMany: array => t = "String.fromCharCode" @val -@ocaml.doc(" +/** `fromCodePoint(n)` creates a `string` containing the character corresponding to that numeric code point. If the number is not a valid code point, it raises `RangeError`.Thus, `fromCodePoint(0x1F63A)` will produce a correct value, @@ -77,17 +75,17 @@ See [`String.fromCodePoint`](https://developer.mozilla.org/en-US/docs/Web/JavaSc on MDN. ```res example -Js.String2.fromCodePoint(65) == \"A\" +Js.String2.fromCodePoint(65) == "A" Js.String2.fromCodePoint(0x3c8) == `ψ` Js.String2.fromCodePoint(0xd55c) == `한` Js.String2.fromCodePoint(0x1f63a) == `😺` ``` -") +*/ external fromCodePoint: int => t = "String.fromCodePoint" @val @variadic -@ocaml.doc(" +/** `fromCodePointMany([n1, n2, n3])` creates a `string` from the characters corresponding to the given code point numbers, using the same rules as `fromCodePoint`. @@ -98,39 +96,39 @@ on MDN. ```res example Js.String2.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` ``` -") +*/ external fromCodePointMany: array => t = "String.fromCodePoint" /* String.raw: ES2015, meant to be used with template strings, not directly */ @get -@ocaml.doc(" +/** `length(s)` returns the length of the given `string`. See [`String.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length) on MDN. ```res example -Js.String2.length(\"abcd\") == 4 +Js.String2.length("abcd") == 4 ``` -") +*/ external length: t => int = "length" @get_index -@ocaml.doc(" +/** `get(s, n)` returns as a `string` the character at the given index number. If `n` is out of range, this function returns `undefined`, so at some point this function may be modified to return `option(string)`. ```res example -Js.String2.get(\"Reason\", 0) == \"R\" -Js.String2.get(\"Reason\", 4) == \"o\" +Js.String2.get("Reason", 0) == "R" +Js.String2.get("Reason", 4) == "o" Js.String2.get(`Rẽasöń`, 5) == `ń` ``` -") +*/ external get: (t, int) => t = "" @bs.send.pipe(: t) -@ocaml.doc(" +/** `charAt(n, s)` gets the character at index `n` within string `s`. If `n` is negative or greater than the length of `s`, it returns the empty string. If the string contains characters outside the range \u0000-\uffff, it will return the @@ -140,15 +138,15 @@ See [`String.charAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.charAt(0, \"Reason\") == \"R\" -Js.String.charAt(12, \"Reason\") == \"\" +Js.String.charAt(0, "Reason") == "R" +Js.String.charAt(12, "Reason") == "" Js.String.charAt(5, `Rẽasöń`) == `ń` ``` -") +*/ external charAt: int => t = "charAt" @bs.send.pipe(: t) -@ocaml.doc(" +/** `charCodeAt(n, s)` returns the character code at position `n` in string `s`; the result is in the range 0-65535, unlke `codePointAt`, so it will not work correctly for characters with code points greater than or equal to 0x10000. The @@ -162,11 +160,11 @@ on MDN. Js.String.charCodeAt(0, `😺`) == 0xd83d->Belt.Int.toFloat Js.String.codePointAt(0, `😺`) == Some(0x1f63a) ``` -") +*/ external charCodeAt: int => float = "charCodeAt" @bs.send.pipe(: t) -@ocaml.doc(" +/** `codePointAt(n, s)` returns the code point at position `n` within string `s` as a `Some(value)`. The return value handles code points greater than or equal to 0x10000. If there is no code point at the given position, the function returns @@ -177,13 +175,13 @@ on MDN. ```res example Js.String.codePointAt(1, `¿😺?`) == Some(0x1f63a) -Js.String.codePointAt(5, \"abc\") == None +Js.String.codePointAt(5, "abc") == None ``` -") +*/ external codePointAt: int => option = "codePointAt" @bs.send.pipe(: t) -@ocaml.doc(" +/** `concat(append, original)` returns a new `string` with `append` added after `original`. @@ -191,14 +189,14 @@ See [`String.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.concat(\"bell\", \"cow\") == \"cowbell\" +Js.String.concat("bell", "cow") == "cowbell" ``` -") +*/ external concat: t => t = "concat" @bs.send.pipe(: t) @variadic -@ocaml.doc(" +/** `concat(arr, original)` returns a new `string` consisting of each item of an array of strings added to the `original` string. @@ -206,13 +204,13 @@ See [`String.concat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.concatMany([\"2nd\", \"3rd\", \"4th\"], \"1st\") == \"1st2nd3rd4th\" +Js.String.concatMany(["2nd", "3rd", "4th"], "1st") == "1st2nd3rd4th" ``` -") +*/ external concatMany: array => t = "concat" @bs.send.pipe(: t) -@ocaml.doc(" +/** ES2015: `endsWith(substr, str)` returns `true` if the `str` ends with `substr`, `false` otherwise. @@ -220,14 +218,14 @@ See [`String.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ on MDN. ```res example -Js.String.endsWith(\"Script\", \"BuckleScript\") == true -Js.String.endsWith(\"Script\", \"BuckleShoes\") == false +Js.String.endsWith("Script", "BuckleScript") == true +Js.String.endsWith("Script", "BuckleShoes") == false ``` -") +*/ external endsWith: t => bool = "endsWith" @bs.send.pipe(: t) -@ocaml.doc(" +/** `endsWithFrom(ending, len, str)` returns `true` if the first len characters of `str` end with `ending`, `false` otherwise. If `len` is greater than or equal to the length of `str`, then it works like `endsWith`. (Honestly, this should @@ -237,16 +235,16 @@ See [`String.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ on MDN. ```res example -Js.String.endsWithFrom(\"cd\", 4, \"abcd\") == true -Js.String.endsWithFrom(\"cd\", 3, \"abcde\") == false -Js.String.endsWithFrom(\"cde\", 99, \"abcde\") == true -Js.String.endsWithFrom(\"ple\", 7, \"example.dat\") == true +Js.String.endsWithFrom("cd", 4, "abcd") == true +Js.String.endsWithFrom("cd", 3, "abcde") == false +Js.String.endsWithFrom("cde", 99, "abcde") == true +Js.String.endsWithFrom("ple", 7, "example.dat") == true ``` -") +*/ external endsWithFrom: (t, int) => bool = "endsWith" @bs.send.pipe(: t) -@ocaml.doc(" +/** ES2015: `includes(searchValue, str)` returns `true` if `searchValue` is found anywhere within `str`, false otherwise. @@ -254,16 +252,16 @@ See [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ on MDN. ```res example -Js.String.includes(\"gram\", \"programmer\") == true -Js.String.includes(\"er\", \"programmer\") == true -Js.String.includes(\"pro\", \"programmer\") == true -Js.String.includes(\"xyz\", \"programmer.dat\") == false +Js.String.includes("gram", "programmer") == true +Js.String.includes("er", "programmer") == true +Js.String.includes("pro", "programmer") == true +Js.String.includes("xyz", "programmer.dat") == false ``` -") +*/ external includes: t => bool = "includes" @bs.send.pipe(: t) -@ocaml.doc(" +/** ES2015: `includes(searchValue start, str)` returns `true` if `searchValue` is found anywhere within `str` starting at character number `start` (where 0 is the first character), `false` otherwise. @@ -272,15 +270,15 @@ See [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/ on MDN. ```res example -Js.String.includesFrom(\"gram\", 1, \"programmer\") == true -Js.String.includesFrom(\"gram\", 4, \"programmer\") == false +Js.String.includesFrom("gram", 1, "programmer") == true +Js.String.includesFrom("gram", 4, "programmer") == false Js.String.includesFrom(`한`, 1, `대한민국`) == true ``` -") +*/ external includesFrom: (t, int) => bool = "includes" @bs.send.pipe(: t) -@ocaml.doc(" +/** ES2015: `indexOf(searchValue, str)` returns the position at which `searchValue` was first found within `str`, or -1 if `searchValue` is not in `str`. @@ -288,16 +286,16 @@ See [`String.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -Js.String.indexOf(\"ok\", \"bookseller\") == 2 -Js.String.indexOf(\"sell\", \"bookseller\") == 4 -Js.String.indexOf(\"ee\", \"beekeeper\") == 1 -Js.String.indexOf(\"xyz\", \"bookseller\") == -1 +Js.String.indexOf("ok", "bookseller") == 2 +Js.String.indexOf("sell", "bookseller") == 4 +Js.String.indexOf("ee", "beekeeper") == 1 +Js.String.indexOf("xyz", "bookseller") == -1 ``` -") +*/ external indexOf: t => int = "indexOf" @bs.send.pipe(: t) -@ocaml.doc(" +/** `indexOfFrom(searchValue, start, str)` returns the position at which `searchValue` was found within `str` starting at character position `start`, or -1 if `searchValue` is not found in that portion of `str`. The return value is @@ -308,15 +306,15 @@ See [`String.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -Js.String.indexOfFrom(\"ok\", 1, \"bookseller\") == 2 -Js.String.indexOfFrom(\"sell\", 2, \"bookseller\") == 4 -Js.String.indexOfFrom(\"sell\", 5, \"bookseller\") == -1 +Js.String.indexOfFrom("ok", 1, "bookseller") == 2 +Js.String.indexOfFrom("sell", 2, "bookseller") == 4 +Js.String.indexOfFrom("sell", 5, "bookseller") == -1 ``` -") +*/ external indexOfFrom: (t, int) => int = "indexOf" @bs.send.pipe(: t) -@ocaml.doc(" +/** `lastIndexOf(searchValue, str)` returns the position of the last occurrence of `searchValue` within `str`, searching backwards from the end of the string. Returns -1 if `searchValue` is not in `str`. The return value is always @@ -326,15 +324,15 @@ See [`String.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScri on MDN. ```res example -Js.String.lastIndexOf(\"ok\", \"bookseller\") == 2 -Js.String.lastIndexOf(\"ee\", \"beekeeper\") == 4 -Js.String.lastIndexOf(\"xyz\", \"abcdefg\") == -1 +Js.String.lastIndexOf("ok", "bookseller") == 2 +Js.String.lastIndexOf("ee", "beekeeper") == 4 +Js.String.lastIndexOf("xyz", "abcdefg") == -1 ``` -") +*/ external lastIndexOf: t => int = "lastIndexOf" @bs.send.pipe(: t) -@ocaml.doc(" +/** `lastIndexOfFrom(searchValue, start, str)` returns the position of the last occurrence of `searchValue` within `str`, searching backwards from the given start position. Returns -1 if `searchValue` is not in `str`. The return value @@ -344,18 +342,18 @@ See [`String.lastIndexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScri on MDN. ```res example -Js.String.lastIndexOfFrom(\"ok\", 6, \"bookseller\") == 2 -Js.String.lastIndexOfFrom(\"ee\", 8, \"beekeeper\") == 4 -Js.String.lastIndexOfFrom(\"ee\", 3, \"beekeeper\") == 1 -Js.String.lastIndexOfFrom(\"xyz\", 4, \"abcdefg\") == -1 +Js.String.lastIndexOfFrom("ok", 6, "bookseller") == 2 +Js.String.lastIndexOfFrom("ee", 8, "beekeeper") == 4 +Js.String.lastIndexOfFrom("ee", 3, "beekeeper") == 1 +Js.String.lastIndexOfFrom("xyz", 4, "abcdefg") == -1 ``` -") +*/ external lastIndexOfFrom: (t, int) => int = "lastIndexOf" /* extended by ECMA-402 */ @bs.send.pipe(: t) -@ocaml.doc(" +/** `localeCompare(comparison, reference)` returns - a negative value if reference comes before comparison in sort order - zero if reference and comparison have the same sort order @@ -364,17 +362,17 @@ external lastIndexOfFrom: (t, int) => int = "lastIndexOf" See [`String.localeCompare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare) on MDN. ```res example -Js.String.localeCompare(\"ant\", \"zebra\") > 0.0 -Js.String.localeCompare(\"zebra\", \"ant\") < 0.0 -Js.String.localeCompare(\"cat\", \"cat\") == 0.0 -Js.String.localeCompare(\"cat\", \"CAT\") > 0.0 +Js.String.localeCompare("ant", "zebra") > 0.0 +Js.String.localeCompare("zebra", "ant") < 0.0 +Js.String.localeCompare("cat", "cat") == 0.0 +Js.String.localeCompare("cat", "CAT") > 0.0 ``` -") +*/ external localeCompare: t => float = "localeCompare" @bs.send.pipe(: t) @return({null_to_opt: null_to_opt}) -@ocaml.doc(" +/** `match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: @@ -388,17 +386,17 @@ See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref on MDN. ```res example -Js.String.match_(%re(\"/b[aeiou]t/\"), \"The better bats\") == Some([\"bet\"]) -Js.String.match_(%re(\"/b[aeiou]t/g\"), \"The better bats\") == Some([\"bet\", \"bat\"]) -Js.String.match_(%re(\"/(\d+)-(\d+)-(\d+)/\"), \"Today is 2018-04-05.\") == - Some([\"2018-04-05\", \"2018\", \"04\", \"05\"]) -Js.String.match_(%re(\"/b[aeiou]g/\"), \"The large container.\") == None +Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some(["bet"]) +Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some(["bet", "bat"]) +Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") == + Some(["2018-04-05", "2018", "04", "05"]) +Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None ``` -") +*/ external match_: Js_re.t => option>> = "match" @bs.send.pipe(: t) -@ocaml.doc(" +/** `normalize(str)` returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition. Consider the character ã, which can be represented as the single codepoint \u00e3 or the combination of a lower case letter A @@ -410,25 +408,25 @@ on MDN. See also [Unicode technical report #15](https://unicode.org/reports/tr15/) for details. -") +*/ external normalize: t = "normalize" @bs.send.pipe(: t) -@ocaml.doc(" +/** ES2015: `normalize(form, str)` returns the normalized Unicode string using the specified form of normalization, which may be one of: -- \"NFC\" — Normalization Form Canonical Composition. -- \"NFD\" — Normalization Form Canonical Decomposition. -- \"NFKC\" — Normalization Form Compatibility Composition. -- \"NFKD\" — Normalization Form Compatibility Decomposition. +- "NFC" — Normalization Form Canonical Composition. +- "NFD" — Normalization Form Canonical Decomposition. +- "NFKC" — Normalization Form Compatibility Composition. +- "NFKD" — Normalization Form Compatibility Decomposition. 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. -") +*/ external normalizeByForm: t => t = "normalize" @bs.send.pipe(: t) -@ocaml.doc(" +/** `repeat(n, str)` returns a `string` that consists of `n` repetitions of `str`. Raises `RangeError` if `n` is negative. @@ -436,14 +434,14 @@ See [`String.repeat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.repeat(3, \"ha\") == \"hahaha\" -Js.String.repeat(0, \"empty\") == \"\" +Js.String.repeat(3, "ha") == "hahaha" +Js.String.repeat(0, "empty") == "" ``` -") +*/ external repeat: int => t = "repeat" @bs.send.pipe(: t) -@ocaml.doc(" +/** ES2015: `replace(substr, newSubstr, str)` returns a new `string` which is identical to `str` except with the first matching instance of `substr` replaced by `newSubstr`. `substr` is treated as a verbatim string to match, not a @@ -453,14 +451,14 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -Js.String.replace(\"old\", \"new\", \"old string\") == \"new string\" -Js.String.replace(\"the\", \"this\", \"the cat and the dog\") == \"this cat and the dog\" +Js.String.replace("old", "new", "old string") == "new string" +Js.String.replace("the", "this", "the cat and the dog") == "this cat and the dog" ``` -") +*/ external replace: (t, t) => t = "replace" @bs.send.pipe(: t) -@ocaml.doc(" +/** `replaceByRe(regex, replacement, str)` returns a new `string` where occurrences matching regex have been replaced by `replacement`. @@ -468,14 +466,14 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -Js.String.replaceByRe(%re(\"/[aeiou]/g\"), \"x\", \"vowels be gone\") == \"vxwxls bx gxnx\" -Js.String.replaceByRe(%re(\"/(\w+) (\w+)/\"), \"$2, $1\", \"Juan Fulano\") == \"Fulano, Juan\" +Js.String.replaceByRe(%re("/[aeiou]/g"), "x", "vowels be gone") == "vxwxls bx gxnx" +Js.String.replaceByRe(%re("/(\w+) (\w+)/"), "$2, $1", "Juan Fulano") == "Fulano, Juan" ``` -") +*/ external replaceByRe: (Js_re.t, t) => t = "replace" @bs.send.pipe(: t) -@ocaml.doc(" +/** Returns a new `string` with some or all matches of a pattern with no capturing parentheses replaced by the value returned from the given function. The function receives as its parameters the matched string, the offset at which the @@ -485,17 +483,17 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -let str = \"beautiful vowels\" -let re = %re(\"/[aeiou]/g\") +let str = "beautiful vowels" +let re = %re("/[aeiou]/g") let matchFn = (matchPart, _offset, _wholeString) => Js.String.toUpperCase(matchPart) -Js.String.unsafeReplaceBy0(re, matchFn, str) == \"bEAUtIfUl vOwEls\" +Js.String.unsafeReplaceBy0(re, matchFn, str) == "bEAUtIfUl vOwEls" ``` -") +*/ external unsafeReplaceBy0: (Js_re.t, @uncurry (t, int, t) => t) => t = "replace" @bs.send.pipe(: t) -@ocaml.doc(" +/** Returns a new `string` with some or all matches of a pattern with one set of capturing parentheses replaced by the value returned from the given function. The function receives as its parameters the matched string, the captured @@ -506,19 +504,19 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -let str = \"Jony is 40\" -let re = %re(\"/(Jony is )\d+/g\") +let str = "Jony is 40" +let re = %re("/(Jony is )\d+/g") let matchFn = (_match, part1, _offset, _wholeString) => { - part1 ++ \"41\" + part1 ++ "41" } -Js.String.unsafeReplaceBy1(re, matchFn, str) == \"Jony is 41\" +Js.String.unsafeReplaceBy1(re, matchFn, str) == "Jony is 41" ``` -") +*/ external unsafeReplaceBy1: (Js_re.t, @uncurry (t, t, int, t) => t) => t = "replace" @bs.send.pipe(: t) -@ocaml.doc(" +/** Returns a new `string` with some or all matches of a pattern with two sets of capturing parentheses replaced by the value returned from the given function. The function receives as its parameters the matched string, the captured @@ -529,22 +527,22 @@ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R on MDN. ```res example -let str = \"7 times 6\" -let re = %re(\"/(\d+) times (\d+)/\") +let str = "7 times 6" +let re = %re("/(\d+) times (\d+)/") let matchFn = (_match, p1, p2, _offset, _wholeString) => { switch (Belt.Int.fromString(p1), Belt.Int.fromString(p2)) { | (Some(x), Some(y)) => Belt.Int.toString(x * y) - | _ => \"???\" + | _ => "???" } } -Js.String.unsafeReplaceBy2(re, matchFn, str) == \"42\" +Js.String.unsafeReplaceBy2(re, matchFn, str) == "42" ``` -") +*/ external unsafeReplaceBy2: (Js_re.t, @uncurry (t, t, t, int, t) => t) => t = "replace" @bs.send.pipe(: t) -@ocaml.doc(" +/** Returns a new `string` with some or all matches of a pattern with three sets of capturing parentheses replaced by the value returned from the given function. The function receives as its parameters the matched string, the captured @@ -553,11 +551,11 @@ matched. See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) on MDN. -") +*/ external unsafeReplaceBy3: (Js_re.t, @uncurry (t, t, t, t, int, t) => t) => t = "replace" @bs.send.pipe(: t) -@ocaml.doc(" +/** `search(regexp, str)` returns the starting position of the first match of `regexp` in the given `str`, or -1 if there is no match. @@ -565,14 +563,14 @@ See [`String.search`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.search(%re(\"/\d+/\"), \"testing 1 2 3\") == 8 -Js.String.search(%re(\"/\d+/\"), \"no numbers\") == -1 +Js.String.search(%re("/\d+/"), "testing 1 2 3") == 8 +Js.String.search(%re("/\d+/"), "no numbers") == -1 ``` -") +*/ external search: Js_re.t => int = "search" @bs.send.pipe(: t) -@ocaml.doc(" +/** `slice(from:n1, to_:n2, str)` returns the substring of `str` starting at character `n1` up to but not including `n2`. - If either `n1` or `n2` is negative, then it is evaluated as `length(str - n1)` or `length(str - n2)`. @@ -582,16 +580,16 @@ character `n1` up to but not including `n2`. See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN. ```res example -Js.String.slice(~from=2, ~to_=5, \"abcdefg\") == \"cde\" -Js.String.slice(~from=2, ~to_=9, \"abcdefg\") == \"cdefg\" -Js.String.slice(~from=-4, ~to_=-2, \"abcdefg\") == \"de\" -Js.String.slice(~from=5, ~to_=1, \"abcdefg\") == \"\" +Js.String.slice(~from=2, ~to_=5, "abcdefg") == "cde" +Js.String.slice(~from=2, ~to_=9, "abcdefg") == "cdefg" +Js.String.slice(~from=-4, ~to_=-2, "abcdefg") == "de" +Js.String.slice(~from=5, ~to_=1, "abcdefg") == "" ``` -") +*/ external slice: (~from: int, ~to_: int) => t = "slice" @bs.send.pipe(: t) -@ocaml.doc(" +/** `sliceToEnd(str, from:n)` returns the substring of `str` starting at character `n` to the end of the string. - If `n` is negative, then it is evaluated as `length(str - n)`. @@ -600,15 +598,15 @@ external slice: (~from: int, ~to_: int) => t = "slice" See [`String.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) on MDN. ```res example -Js.String.sliceToEnd(~from=4, \"abcdefg\") == \"efg\" -Js.String.sliceToEnd(~from=-2, \"abcdefg\") == \"fg\" -Js.String.sliceToEnd(~from=7, \"abcdefg\") == \"\" +Js.String.sliceToEnd(~from=4, "abcdefg") == "efg" +Js.String.sliceToEnd(~from=-2, "abcdefg") == "fg" +Js.String.sliceToEnd(~from=7, "abcdefg") == "" ``` -") +*/ external sliceToEnd: (~from: int) => t = "slice" @bs.send.pipe(: t) -@ocaml.doc(" +/** `split(delimiter, str)` splits the given `str` at every occurrence of `delimiter` and returns an array of the resulting substrings. @@ -616,16 +614,16 @@ See [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref on MDN. ```res example -Js.String.split(\"-\", \"2018-01-02\") == [\"2018\", \"01\", \"02\"] -Js.String.split(\",\", \"a,b,,c\") == [\"a\", \"b\", \"\", \"c\"] -Js.String.split(\"::\", \"good::bad as great::awful\") == [\"good\", \"bad as great\", \"awful\"] -Js.String.split(\";\", \"has-no-delimiter\") == [\"has-no-delimiter\"] +Js.String.split("-", "2018-01-02") == ["2018", "01", "02"] +Js.String.split(",", "a,b,,c") == ["a", "b", "", "c"] +Js.String.split("::", "good::bad as great::awful") == ["good", "bad as great", "awful"] +Js.String.split(";", "has-no-delimiter") == ["has-no-delimiter"] ``` -") +*/ external split: t => array = "split" @bs.send.pipe(: t) -@ocaml.doc(" +/** `splitAtMost(delimiter, ~limit:n, str)` splits the given `str` at every occurrence of `delimiter` and returns an array of the first `n` resulting substrings. If `n` is negative or greater than the number of substrings, the @@ -635,11 +633,11 @@ See [`String.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref on MDN. ```res example -Js.String.splitAtMost(\"/\", ~limit=3, \"ant/bee/cat/dog/elk\") == [\"ant\", \"bee\", \"cat\"] -Js.String.splitAtMost(\"/\", ~limit=0, \"ant/bee/cat/dog/elk\") == [] -Js.String.splitAtMost(\"/\", ~limit=9, \"ant/bee/cat/dog/elk\") == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"] +Js.String.splitAtMost("/", ~limit=3, "ant/bee/cat/dog/elk") == ["ant", "bee", "cat"] +Js.String.splitAtMost("/", ~limit=0, "ant/bee/cat/dog/elk") == [] +Js.String.splitAtMost("/", ~limit=9, "ant/bee/cat/dog/elk") == ["ant", "bee", "cat", "dog", "elk"] ``` -") +*/ external splitAtMost: (t, ~limit: int) => array = "split" @bs.send.pipe(: t) @@ -691,7 +689,7 @@ Js.String.splitByReAtMost(%re(\"/\s*:\s*/\"), ~limit=8, \"one: two: three: four\ external splitByReAtMost: (Js_re.t, ~limit: int) => array> = "split" @bs.send.pipe(: t) -@ocaml.doc(" +/** ES2015: `startsWith(substr, str)` returns `true` if the `str` starts with `substr`, `false` otherwise. @@ -699,15 +697,15 @@ See [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScrip on MDN. ```res example -Js.String.startsWith(\"Buckle\", \"BuckleScript\") == true -Js.String.startsWith(\"\", \"BuckleScript\") == true -Js.String.startsWith(\"Buckle\", \"JavaScript\") == false +Js.String.startsWith("Buckle", "BuckleScript") == true +Js.String.startsWith("", "BuckleScript") == true +Js.String.startsWith("Buckle", "JavaScript") == false ``` -") +*/ external startsWith: t => bool = "startsWith" @bs.send.pipe(: t) -@ocaml.doc(" +/** ES2015: `startsWithFrom(substr, n, str)` returns `true` if the `str` starts with `substr` starting at position `n`, false otherwise. If `n` is negative, the search starts at the beginning of `str`. @@ -716,15 +714,15 @@ See [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScrip on MDN. ```res example -Js.String.startsWithFrom(\"kle\", 3, \"BuckleScript\") == true -Js.String.startsWithFrom(\"\", 3, \"BuckleScript\") == true -Js.String.startsWithFrom(\"Buckle\", 2, \"JavaScript\") == false +Js.String.startsWithFrom("kle", 3, "BuckleScript") == true +Js.String.startsWithFrom("", 3, "BuckleScript") == true +Js.String.startsWithFrom("Buckle", 2, "JavaScript") == false ``` -") +*/ external startsWithFrom: (t, int) => bool = "startsWith" @bs.send.pipe(: t) -@ocaml.doc(" +/** `substr(~from:n, str)` returns the substring of `str` from position `n` to the end of the string. - If `n` is less than zero, the starting position is the length of `str - n`. @@ -737,15 +735,15 @@ See [`String.substr`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.substr(~from=3, \"abcdefghij\") == \"defghij\" -Js.String.substr(~from=-3, \"abcdefghij\") == \"hij\" -Js.String.substr(~from=12, \"abcdefghij\") == \"\" +Js.String.substr(~from=3, "abcdefghij") == "defghij" +Js.String.substr(~from=-3, "abcdefghij") == "hij" +Js.String.substr(~from=12, "abcdefghij") == "" ``` -") +*/ external substr: (~from: int) => t = "substr" @bs.send.pipe(: t) -@ocaml.doc(" +/** `substrAtMost(~from: pos, ~length: n, str)` returns the substring of `str` of length `n` starting at position `pos`. - If `pos` is less than zero, the starting position is the length of `str - pos`. @@ -759,15 +757,15 @@ See [`String.substr`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.substrAtMost(~from=3, ~length=4, \"abcdefghij\") == \"defg\" -Js.String.substrAtMost(~from=-3, ~length=4, \"abcdefghij\") == \"hij\" -Js.String.substrAtMost(~from=12, ~length=2, \"abcdefghij\") == \"\" +Js.String.substrAtMost(~from=3, ~length=4, "abcdefghij") == "defg" +Js.String.substrAtMost(~from=-3, ~length=4, "abcdefghij") == "hij" +Js.String.substrAtMost(~from=12, ~length=2, "abcdefghij") == "" ``` -") +*/ external substrAtMost: (~from: int, ~length: int) => t = "substr" @bs.send.pipe(: t) -@ocaml.doc(" +/** `substring(~from: start, ~to_: finish, str)` returns characters `start` up to but not including finish from `str`. - If `start` is less than zero, it is treated as zero. @@ -777,15 +775,15 @@ but not including finish from `str`. See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN. ```res example -Js.String.substring(~from=3, ~to_=6, \"playground\") == \"ygr\" -Js.String.substring(~from=6, ~to_=3, \"playground\") == \"ygr\" -Js.String.substring(~from=4, ~to_=12, \"playground\") == \"ground\" +Js.String.substring(~from=3, ~to_=6, "playground") == "ygr" +Js.String.substring(~from=6, ~to_=3, "playground") == "ygr" +Js.String.substring(~from=4, ~to_=12, "playground") == "ground" ``` -") +*/ external substring: (~from: int, ~to_: int) => t = "substring" @bs.send.pipe(: t) -@ocaml.doc(" +/** `substringToEnd(~from: start, str)` returns the substring of `str` from position `start` to the end. - If `start` is less than or equal to zero, the entire string is returned. @@ -794,15 +792,15 @@ position `start` to the end. See [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN. ```res example -Js.String.substringToEnd(~from=4, \"playground\") == \"ground\" -Js.String.substringToEnd(~from=-3, \"playground\") == \"playground\" -Js.String.substringToEnd(~from=12, \"playground\") == \"\" +Js.String.substringToEnd(~from=4, "playground") == "ground" +Js.String.substringToEnd(~from=-3, "playground") == "playground" +Js.String.substringToEnd(~from=12, "playground") == "" ``` -") +*/ external substringToEnd: (~from: int) => t = "substring" @bs.send.pipe(: t) -@ocaml.doc(" +/** `toLowerCase(str)` converts `str` to lower case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can give different results depending upon context, for example with the Greek @@ -813,24 +811,24 @@ See [`String.toLowerCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScri on MDN. ```res example -Js.String.toLowerCase(\"ABC\") == \"abc\" +Js.String.toLowerCase("ABC") == "abc" Js.String.toLowerCase(`ΣΠ`) == `σπ` Js.String.toLowerCase(`ΠΣ`) == `πς` ``` -") +*/ external toLowerCase: t = "toLowerCase" @bs.send.pipe(: t) -@ocaml.doc(" +/** `toLocaleLowerCase(str)` converts `str` to lower case using the current locale. See [`String.toLocaleLowerCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase) on MDN. -") +*/ external toLocaleLowerCase: t = "toLocaleLowerCase" @bs.send.pipe(: t) -@ocaml.doc(" +/** `toUpperCase(str)` converts `str` to upper case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can expand the number of letters in the result; for example the German ß @@ -840,24 +838,24 @@ See [`String.toUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScri on MDN. ```res example -Js.String.toUpperCase(\"abc\") == \"ABC\" +Js.String.toUpperCase("abc") == "ABC" Js.String.toUpperCase(`Straße`) == `STRASSE` Js.String.toUpperCase(`πς`) == `ΠΣ` ``` -") +*/ external toUpperCase: t = "toUpperCase" @bs.send.pipe(: t) -@ocaml.doc(" +/** `toLocaleUpperCase(str)` converts `str` to upper case using the current locale. See [`String.to:LocaleUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase) on MDN. -") +*/ external toLocaleUpperCase: t = "toLocaleUpperCase" @bs.send.pipe(: t) -@ocaml.doc(" +/** `trim(str)` returns a string that is `str` with whitespace stripped from both ends. Internal whitespace is not removed. @@ -865,16 +863,16 @@ See [`String.trim`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe on MDN. ```res example -Js.String.trim(\" abc def \") == \"abc def\" -Js.String.trim(\"\n\r\t abc def \n\n\t\r \") == \"abc def\" +Js.String.trim(" abc def ") == "abc def" +Js.String.trim("\n\r\t abc def \n\n\t\r ") == "abc def" ``` -") +*/ external trim: t = "trim" /* HTML wrappers */ @bs.send.pipe(: t) -@ocaml.doc(" +/** `anchor(anchorName, anchorText)` creates a string with an HTML `` element with name attribute of `anchorName` and `anchorText` as its content. Please do not use this method, as it has been removed from the relevant web standards. @@ -883,13 +881,13 @@ See [`String.anchor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re on MDN. ```res example -Js.String.anchor(\"page1\", \"Page One\") == \"Page One\" +Js.String.anchor("page1", "Page One") == "Page One" ``` -") +*/ external anchor: t => t = "anchor" @bs.send.pipe(: t) -@ocaml.doc(" +/** ES2015: `link(urlText, linkText)` creates a string with an HTML `` element with href attribute of `urlText` and `linkText` as its content. Please do not use this method, as it has been removed from the relevant web standards. @@ -898,19 +896,19 @@ See [`String.link`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe on MDN. ```res example -Js.String.link(\"page2.html\", \"Go to page two\") == \"Go to page two\" +Js.String.link("page2.html", "Go to page two") == "Go to page two" ``` -") +*/ external link: t => t = "link" -@ocaml.doc(" +/** Casts its argument to an `array_like` entity that can be processed by functions such as `Js.Array2.fromMap()` ```res example -let s = \"abcde\" +let s = "abcde" let arr = Js.Array2.fromMap(Js.String.castToArrayLike(s), x => x) -arr == [\"a\", \"b\", \"c\", \"d\", \"e\"] +arr == ["a", "b", "c", "d", "e"] ``` -") +*/ external castToArrayLike: t => Js_array2.array_like = "%identity"