From ca71539a13820914b1f2d1dd970eda5f1a323fea Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 11 Feb 2024 19:15:30 +0100 Subject: [PATCH 01/14] @bs.string -> @string --- jscomp/frontend/ast_attributes.ml | 2 +- jscomp/frontend/bs_ast_invariant.ml | 13 +++++++------ jscomp/gentype/Annotation.ml | 2 +- jscomp/ounit_tests/ounit_cmd_tests.ml | 8 ++++---- jscomp/ounit_tests/ounit_ffi_error_debug_test.ml | 6 +++--- jscomp/test/gpr_1072.res | 6 +++--- jscomp/test/gpr_1072_reg.res | 16 ++++++++-------- jscomp/test/gpr_return_type_unused_attribute.res | 2 +- jscomp/test/poly_variant_test.res | 2 +- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/jscomp/frontend/ast_attributes.ml b/jscomp/frontend/ast_attributes.ml index e998f0e416..09c68f9631 100644 --- a/jscomp/frontend/ast_attributes.ml +++ b/jscomp/frontend/ast_attributes.ml @@ -221,7 +221,7 @@ let iter_process_bs_string_int_unwrap_uncurry (attrs : t) = in Ext_list.iter attrs (fun (({txt; loc = _}, (payload : _)) as attr) -> match txt with - | "bs.string" | "string" -> assign `String attr + | "string" -> assign `String attr | "int" -> assign `Int attr | "ignore" -> assign `Ignore attr | "bs.unwrap" | "unwrap" -> assign `Unwrap attr diff --git a/jscomp/frontend/bs_ast_invariant.ml b/jscomp/frontend/bs_ast_invariant.ml index 36d420098f..bffdc68150 100644 --- a/jscomp/frontend/bs_ast_invariant.ml +++ b/jscomp/frontend/bs_ast_invariant.ml @@ -27,12 +27,13 @@ it may fail third party ppxes *) let is_bs_attribute txt = - let len = String.length txt in - len >= 2 - (*TODO: check the stringing padding rule, this preciate may not be needed *) - && String.unsafe_get txt 0 = 'b' - && String.unsafe_get txt 1 = 's' - && (len = 2 || String.unsafe_get txt 2 = '.') + (let len = String.length txt in + len >= 2 + (*TODO: check the stringing padding rule, this preciate may not be needed *) + && String.unsafe_get txt 0 = 'b' + && String.unsafe_get txt 1 = 's' + && (len = 2 || String.unsafe_get txt 2 = '.')) + || txt = "string" (* TODO: Issue 6636 *) let used_attributes : string Asttypes.loc Hash_set_poly.t = Hash_set_poly.create 16 diff --git a/jscomp/gentype/Annotation.ml b/jscomp/gentype/Annotation.ml index 1ed02dd846..e6836690cb 100644 --- a/jscomp/gentype/Annotation.ml +++ b/jscomp/gentype/Annotation.ml @@ -21,7 +21,7 @@ let tagIsGenType s = s = "genType" || s = "gentype" let tagIsGenTypeAs s = s = "genType.as" || s = "gentype.as" let tagIsAs s = s = "as" let tagIsInt s = s = "int" -let tagIsString s = s = "bs.string" || s = "string" +let tagIsString s = s = "string" let tagIsTag s = s = "tag" diff --git a/jscomp/ounit_tests/ounit_cmd_tests.ml b/jscomp/ounit_tests/ounit_cmd_tests.ml index b7ce460246..42cb990ab2 100644 --- a/jscomp/ounit_tests/ounit_cmd_tests.ml +++ b/jscomp/ounit_tests/ounit_cmd_tests.ml @@ -64,7 +64,7 @@ let suites = __LOC__ >:: begin fun _ -> let should_be_warning = - bsc_check_eval {| external mk : int -> ([`a|`b [@bs.string]]) = "mk" [@@bs.val] |} in + bsc_check_eval {| external mk : int -> ([`a|`b [@string]]) = "mk" [@@bs.val] |} in OUnit.assert_bool __LOC__ (Ext_string.contain_substring should_be_warning.stderr "Unused") @@ -120,7 +120,7 @@ external ff : __LOC__ >:: begin fun _ -> let should_err = bsc_check_eval {| - external mk : int -> ([`a|`b] [@bs.string]) = "" [@@bs.val] + external mk : int -> ([`a|`b] [@string]) = "" [@@bs.val] |} in OUnit.assert_bool __LOC__ (not @@ Ext_string.is_empty should_err.stderr) end; @@ -131,7 +131,7 @@ external ff : |} in OUnit.assert_bool __LOC__ ( Ext_string.is_empty should_err.stderr) (* give a warning or ? - ( [`a | `b ] [@bs.string] ) + ( [`a | `b ] [@string] ) (* auto-convert to ocaml poly-variant *) *) end; @@ -261,7 +261,7 @@ let rec y = A y;; external mk : int -> ( [`a|`b] - [@bs.string] + [@string] ) = "mk" [@@bs.val] |} in (* Ounit_cmd_util.debug_output should_err ; *) diff --git a/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml b/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml index 340720e091..74e958b94e 100644 --- a/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml +++ b/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml @@ -22,7 +22,7 @@ let suites = __LOC__ >:: begin fun _ -> let output = bsc_eval {| external err : - hi_should_error:([`a of int | `b of string ] [@bs.string]) -> + hi_should_error:([`a of int | `b of string ] [@string]) -> unit -> _ = "" [@@obj] |} in OUnit.assert_bool __LOC__ @@ -31,7 +31,7 @@ external err : __LOC__ >:: begin fun _ -> let output = bsc_eval {| external err : - ?hi_should_error:([`a of int | `b of string ] [@bs.string]) -> + ?hi_should_error:([`a of int | `b of string ] [@string]) -> unit -> _ = "" [@@obj] |} in OUnit.assert_bool __LOC__ @@ -40,7 +40,7 @@ let output = bsc_eval {| __LOC__ >:: begin fun _ -> let output = bsc_eval {| external err : - ?hi_should_error:([`a of int | `b of string ] [@bs.string]) -> + ?hi_should_error:([`a of int | `b of string ] [@string]) -> unit -> unit = "err" [@@bs.val] |} in OUnit.assert_bool __LOC__ diff --git a/jscomp/test/gpr_1072.res b/jscomp/test/gpr_1072.res index d8a5058af7..4c603b21e1 100644 --- a/jscomp/test/gpr_1072.res +++ b/jscomp/test/gpr_1072.res @@ -1,6 +1,6 @@ /* external ice_cream: - ?flavor:([`vanilla | `chocolate ] [@bs.string]) -> + ?flavor:([`vanilla | `chocolate ] [@string]) -> num:int -> unit -> _ = "" @@ -11,7 +11,7 @@ let my_scoop = ice_cream ~flavor:`vanilla ~num:3 () */ /* external ice_cream_2: - flavor:([`vanilla | `chocolate ] [@bs.string]) -> + flavor:([`vanilla | `chocolate ] [@string]) -> num:int -> unit -> _ = "" @@ -175,7 +175,7 @@ let () = { again4(~x=incr(side_effect), ~y=(), __LINE__, ()) } -/* external again5 : ?x__ignore:([`a of unit -> int | `b of string -> int ] [@bs.string]) */ +/* external again5 : ?x__ignore:([`a of unit -> int | `b of string -> int ] [@string]) */ /* -> int -> unit = "" [@@bs.val] */ /* let v = again5 3 */ diff --git a/jscomp/test/gpr_1072_reg.res b/jscomp/test/gpr_1072_reg.res index 13256d9ca2..f111986111 100644 --- a/jscomp/test/gpr_1072_reg.res +++ b/jscomp/test/gpr_1072_reg.res @@ -38,28 +38,28 @@ let v1 = make( external make2 : ?localeMatcher: - ([`lookup | `best_fit [@as \"best fit\"]] [@bs.string]) -> + ([`lookup | `best_fit [@as \"best fit\"]] [@string]) -> ?timeZone:string -> ?hour12:bool -> ?formatMatcher: - ([`basic | `best_fit [@as \"best fit\"]] [@bs.string]) -> + ([`basic | `best_fit [@as \"best fit\"]] [@string]) -> - ?weekday:([`narrow | `short | `long] [@bs.string]) -> - ?era:([`narrow | `short | `long] [@bs.string]) -> - ?year:([`numeric | `two_digit [@as \"2-digit\"]] [@bs.string]) -> + ?weekday:([`narrow | `short | `long] [@string]) -> + ?era:([`narrow | `short | `long] [@string]) -> + ?year:([`numeric | `two_digit [@as \"2-digit\"]] [@string]) -> ?month: ([`narrow | `short | `long | `numeric | - `two_digit [@as \"2-digit\"]] [@bs.string]) -> + `two_digit [@as \"2-digit\"]] [@string]) -> - ?day:(([`numeric | `two_digit [@as \"2-digit\"]] [@bs.string]) as 'num) -> + ?day:(([`numeric | `two_digit [@as \"2-digit\"]] [@string]) as 'num) -> ?hour:('num) -> ?minute:('num) -> ?second:('num) -> - ?timeZoneName:([`short | `long] [@bs.string]) -> + ?timeZoneName:([`short | `long] [@string]) -> unit -> t = \"\" [@@obj] diff --git a/jscomp/test/gpr_return_type_unused_attribute.res b/jscomp/test/gpr_return_type_unused_attribute.res index 35beb73a3f..c6a266be41 100644 --- a/jscomp/test/gpr_return_type_unused_attribute.res +++ b/jscomp/test/gpr_return_type_unused_attribute.res @@ -2,7 +2,7 @@ @val external mk: int => [#a | #b] = "mk" -/* [@bs.string] */ +/* [@string] */ let v = mk(2) diff --git a/jscomp/test/poly_variant_test.res b/jscomp/test/poly_variant_test.res index c03dc4c7cf..1a49b579f3 100644 --- a/jscomp/test/poly_variant_test.res +++ b/jscomp/test/poly_variant_test.res @@ -93,7 +93,7 @@ let register = readline => { /* external on : */ /* ([ `line of (string -> unit [@bs]) */ /* | `close of (unit -> unit [@bs])] */ -/* [@bs.string]) -> */ +/* [@string]) -> */ /* readline -> readline = */ /* "on" [@@send] */ @send From 64324222e258c56847605c5683ed48573f4cc6e6 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 12 Feb 2024 19:29:40 +0100 Subject: [PATCH 02/14] @bs.this -> @this --- jscomp/frontend/ast_attributes.ml | 6 ++---- jscomp/frontend/ast_typ_uncurry.mli | 2 +- jscomp/frontend/ast_uncurry_gen.mli | 2 +- jscomp/ml/oprint.ml | 2 +- jscomp/ounit_tests/ounit_cmd_tests.ml | 4 ++-- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/jscomp/frontend/ast_attributes.ml b/jscomp/frontend/ast_attributes.ml index 09c68f9631..9d3d1750c8 100644 --- a/jscomp/frontend/ast_attributes.ml +++ b/jscomp/frontend/ast_attributes.ml @@ -86,11 +86,9 @@ let process_attributes_rev (attrs : t) : attr_kind * t = match (txt, st) with | "bs", (Nothing | Uncurry _) -> (Uncurry attr, acc) (* TODO: warn unused/duplicated attribute *) - | ("bs.this" | "this"), (Nothing | Meth_callback _) -> - (Meth_callback attr, acc) + | "this", (Nothing | Meth_callback _) -> (Meth_callback attr, acc) | "meth", (Nothing | Method _) -> (Method attr, acc) - | ("bs" | "bs.this" | "this"), _ -> - Bs_syntaxerr.err loc Conflict_bs_bs_this_bs_meth + | ("bs" | "this"), _ -> Bs_syntaxerr.err loc Conflict_bs_bs_this_bs_meth | _, _ -> (st, attr :: acc)) let process_bs (attrs : t) = diff --git a/jscomp/frontend/ast_typ_uncurry.mli b/jscomp/frontend/ast_typ_uncurry.mli index afb1bc521e..ebd95e1bbd 100644 --- a/jscomp/frontend/ast_typ_uncurry.mli +++ b/jscomp/frontend/ast_typ_uncurry.mli @@ -56,5 +56,5 @@ val to_uncurry_type : uncurry_type_gen val to_method_callback_type : uncurry_type_gen (** syntax: - {[ 'obj -> int -> int [@bs.this] ]} + {[ 'obj -> int -> int [@this] ]} *) diff --git a/jscomp/frontend/ast_uncurry_gen.mli b/jscomp/frontend/ast_uncurry_gen.mli index 047c2b16a0..00a757583c 100644 --- a/jscomp/frontend/ast_uncurry_gen.mli +++ b/jscomp/frontend/ast_uncurry_gen.mli @@ -47,5 +47,5 @@ val to_method_callback : Parsetree.expression -> Parsetree.expression_desc (** syntax: - {[fun [@bs.this] obj pat pat1 -> body]} + {[fun [@this] obj pat pat1 -> body]} *) diff --git a/jscomp/ml/oprint.ml b/jscomp/ml/oprint.ml index 293795a240..a4ee54dd18 100644 --- a/jscomp/ml/oprint.ml +++ b/jscomp/ml/oprint.ml @@ -292,7 +292,7 @@ and print_simple_out_type ppf = | Otyp_constr (Oide_dot (Oide_dot (Oide_ident "Js_OO", "Callback" ), _), [tyl]) -> - fprintf ppf "@[<0>(%a@ [@bs.this])@]" print_out_type_1 tyl + fprintf ppf "@[<0>(%a@ [@this])@]" print_out_type_1 tyl | Otyp_constr (id, tyl) -> pp_open_box ppf 0; print_typargs ppf tyl; diff --git a/jscomp/ounit_tests/ounit_cmd_tests.ml b/jscomp/ounit_tests/ounit_cmd_tests.ml index 42cb990ab2..ef0dd7e9fc 100644 --- a/jscomp/ounit_tests/ounit_cmd_tests.ml +++ b/jscomp/ounit_tests/ounit_cmd_tests.ml @@ -155,7 +155,7 @@ external ff : (* #1510 *) __LOC__ >:: begin fun _ -> let should_err = bsc_check_eval {| - let should_fail = fun [@bs.this] (Some x) y u -> y + u + let should_fail = fun [@this] (Some x) y u -> y + u |} in OUnit.assert_bool __LOC__ (Ext_string.contain_substring should_err.stderr "simple") @@ -163,7 +163,7 @@ external ff : __LOC__ >:: begin fun _ -> let should_err = bsc_check_eval {| - let should_fail = fun [@bs.this] (Some x as v) y u -> y + u + let should_fail = fun [@this] (Some x as v) y u -> y + u |} in (* Ounit_cmd_util.debug_output should_err; *) OUnit.assert_bool __LOC__ From 071557ff39b1e3096e6009d5b61f1917eee965a1 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 13:05:30 +0100 Subject: [PATCH 03/14] @bs.uncurry -> uncurry --- jscomp/core/design.md | 6 +++--- jscomp/frontend/ast_attributes.ml | 3 +-- jscomp/frontend/ast_external_process.ml | 3 +-- jscomp/frontend/bs_ast_invariant.ml | 17 ++++++++++------- jscomp/frontend/external_arg_spec.mli | 3 +-- jscomp/ounit_tests/ounit_cmd_tests.ml | 6 +++--- jscomp/test/bs_auto_uncurry.res | 6 +++--- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/jscomp/core/design.md b/jscomp/core/design.md index 2455180bb9..f15e1230e1 100644 --- a/jscomp/core/design.md +++ b/jscomp/core/design.md @@ -98,7 +98,7 @@ Curry.__N o ]} Another use case: {[ - external f : ('a -> 'b [@bs.uncurry]) -> unit + external f : ('a -> 'b [@uncurry]) -> unit f g (* The compiler will do such converison internally*) ]} @@ -173,12 +173,12 @@ We can simply do inlining, it may have side efffect in `b0`, `b1`, our optimizer Maybe in the future, we should lift the restriction about `variadic` (delegate to `slow` mode when we can not resolve it statically, my personal expereince is that people will complain about why it fails to compile more than why it is slow in some corner cases) -Note this also interacts with `[@bs.uncurry]` +Note this also interacts with `[@uncurry]` for example ```ocaml -external filter : 'a array -> ('a -> bool [@bs.uncurry]) -> 'a array = "filter" +external filter : 'a array -> ('a -> bool [@uncurry]) -> 'a array = "filter" [@@send] let f xs = diff --git a/jscomp/frontend/ast_attributes.ml b/jscomp/frontend/ast_attributes.ml index 9d3d1750c8..d2012f1979 100644 --- a/jscomp/frontend/ast_attributes.ml +++ b/jscomp/frontend/ast_attributes.ml @@ -223,8 +223,7 @@ let iter_process_bs_string_int_unwrap_uncurry (attrs : t) = | "int" -> assign `Int attr | "ignore" -> assign `Ignore attr | "bs.unwrap" | "unwrap" -> assign `Unwrap attr - | "bs.uncurry" | "uncurry" -> - assign (`Uncurry (Ast_payload.is_single_int payload)) attr + | "uncurry" -> assign (`Uncurry (Ast_payload.is_single_int payload)) attr | _ -> ()); !st diff --git a/jscomp/frontend/ast_external_process.ml b/jscomp/frontend/ast_external_process.ml index 9b6833a37d..b380bf8a3c 100644 --- a/jscomp/frontend/ast_external_process.ml +++ b/jscomp/frontend/ast_external_process.ml @@ -418,8 +418,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string) with Not_handled_external_attribute -> (attr :: attrs, st)) let has_bs_uncurry (attrs : Ast_attributes.t) = - Ext_list.exists_fst attrs (fun {txt; loc = _} -> - txt = "bs.uncurry" || txt = "uncurry") + Ext_list.exists_fst attrs (fun {txt; loc = _} -> txt = "uncurry") let check_return_wrapper loc (wrapper : External_ffi_types.return_wrapper) result_type = diff --git a/jscomp/frontend/bs_ast_invariant.ml b/jscomp/frontend/bs_ast_invariant.ml index bffdc68150..47c8b006ad 100644 --- a/jscomp/frontend/bs_ast_invariant.ml +++ b/jscomp/frontend/bs_ast_invariant.ml @@ -27,13 +27,16 @@ it may fail third party ppxes *) let is_bs_attribute txt = - (let len = String.length txt in - len >= 2 - (*TODO: check the stringing padding rule, this preciate may not be needed *) - && String.unsafe_get txt 0 = 'b' - && String.unsafe_get txt 1 = 's' - && (len = 2 || String.unsafe_get txt 2 = '.')) - || txt = "string" (* TODO: Issue 6636 *) + match txt with + (* TODO: Issue 6636 *) + | "string" | "uncurry" -> true + | _ -> + let len = String.length txt in + len >= 2 + (*TODO: check the stringing padding rule, this preciate may not be needed *) + && String.unsafe_get txt 0 = 'b' + && String.unsafe_get txt 1 = 's' + && (len = 2 || String.unsafe_get txt 2 = '.') let used_attributes : string Asttypes.loc Hash_set_poly.t = Hash_set_poly.create 16 diff --git a/jscomp/frontend/external_arg_spec.mli b/jscomp/frontend/external_arg_spec.mli index 8f679d961a..62a56da38a 100644 --- a/jscomp/frontend/external_arg_spec.mli +++ b/jscomp/frontend/external_arg_spec.mli @@ -31,8 +31,7 @@ type attr = | Poly_var of {descr: (string * string) list option} | Int of (string * int) list (* ([`a | `b ] [@int])*) | Arg_cst of cst - | Fn_uncurry_arity of - int (* annotated with [@bs.uncurry ] or [@bs.uncurry 2]*) + | Fn_uncurry_arity of int (* annotated with [@uncurry ] or [@uncurry 2]*) (* maybe we can improve it as a combination of {!Asttypes.constant} and tuple *) | Extern_unit | Nothing diff --git a/jscomp/ounit_tests/ounit_cmd_tests.ml b/jscomp/ounit_tests/ounit_cmd_tests.ml index ef0dd7e9fc..c2012a88c7 100644 --- a/jscomp/ounit_tests/ounit_cmd_tests.ml +++ b/jscomp/ounit_tests/ounit_cmd_tests.ml @@ -88,20 +88,20 @@ external ff : *) let should_err = bsc_check_eval {| external v3 : - int -> int -> (int -> int -> int [@bs.uncurry]) + int -> int -> (int -> int -> int [@uncurry]) = "v3"[@@bs.val] |} in (* Ounit_cmd_util.debug_output should_err;*) OUnit.assert_bool __LOC__ (Ext_string.contain_substring - should_err.stderr "bs.uncurry") + should_err.stderr "uncurry") end ; __LOC__ >:: begin fun _ -> let should_err = bsc_check_eval {| external v4 : - (int -> int -> int [@bs.uncurry]) = "" + (int -> int -> int [@uncurry]) = "" [@@bs.val] |} in diff --git a/jscomp/test/bs_auto_uncurry.res b/jscomp/test/bs_auto_uncurry.res index f6e09ec83c..f132c25242 100644 --- a/jscomp/test/bs_auto_uncurry.res +++ b/jscomp/test/bs_auto_uncurry.res @@ -6,7 +6,7 @@ module Block = {} type id = int => int @val external map2: (array, @uncurry (int => int)) => array = "Array.prototype.map.cal" -/* [@bs.uncurry n] should not be documented, +/* [@uncurry n] should not be documented, since such inconsistency could not be checked */ @@ -92,7 +92,7 @@ let v = fishy_unit_2 () [@bs] /* external ff : int -> - (unit -> unit [@bs.uncurry]) -> + (unit -> unit [@uncurry]) -> int = "" [@@bs.val] @@ -117,7 +117,7 @@ Maybe we can create a sugar /* external config : - hi: (int -> int [@bs.uncurry]) -> + hi: (int -> int [@uncurry]) -> lo: int -> unit -> _ = "" [@@obj] From 07c1c0ac06f53092feb8bff008ef7d4135ec54d4 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 13:27:31 +0100 Subject: [PATCH 04/14] @bs.unwrap -> @unwrap --- jscomp/frontend/ast_attributes.ml | 2 +- jscomp/ounit_tests/ounit_ffi_error_debug_test.ml | 8 ++++---- jscomp/test/bs_unwrap_test.res | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/jscomp/frontend/ast_attributes.ml b/jscomp/frontend/ast_attributes.ml index d2012f1979..cf19e85a2f 100644 --- a/jscomp/frontend/ast_attributes.ml +++ b/jscomp/frontend/ast_attributes.ml @@ -222,7 +222,7 @@ let iter_process_bs_string_int_unwrap_uncurry (attrs : t) = | "string" -> assign `String attr | "int" -> assign `Int attr | "ignore" -> assign `Ignore attr - | "bs.unwrap" | "unwrap" -> assign `Unwrap attr + | "unwrap" -> assign `Unwrap attr | "uncurry" -> assign (`Uncurry (Ast_payload.is_single_int payload)) attr | _ -> ()); !st diff --git a/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml b/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml index 74e958b94e..3a01f6eddd 100644 --- a/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml +++ b/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml @@ -49,12 +49,12 @@ let output = bsc_eval {| __LOC__ >:: begin fun _ -> (* - Each [@bs.unwrap] variant constructor requires an argument + Each [@unwrap] variant constructor requires an argument *) let output = bsc_eval {| external err : - ?hi_should_error:([`a of int | `b] [@bs.unwrap]) -> unit -> unit = "err" [@@bs.val] + ?hi_should_error:([`a of int | `b] [@unwrap]) -> unit -> unit = "err" [@@bs.val] |} in OUnit.assert_bool __LOC__ @@ -63,12 +63,12 @@ let output = bsc_eval {| __LOC__ >:: begin fun _ -> (* - [@bs.unwrap] args are not supported in [@@obj] functions + [@unwrap] args are not supported in [@@obj] functions *) let output = bsc_eval {| external err : - ?hi_should_error:([`a of int] [@bs.unwrap]) -> unit -> _ = "" [@@obj] + ?hi_should_error:([`a of int] [@unwrap]) -> unit -> _ = "" [@@obj] |} in OUnit.assert_bool __LOC__ diff --git a/jscomp/test/bs_unwrap_test.res b/jscomp/test/bs_unwrap_test.res index 5fe7e5670d..6360f8dd26 100644 --- a/jscomp/test/bs_unwrap_test.res +++ b/jscomp/test/bs_unwrap_test.res @@ -76,7 +76,7 @@ external log4: @unwrap | #Options({"foo": int}) ] => unit = "console.log" -/* Make sure [@bs.unwrap] plays nicely with [%obj] */ +/* Make sure [@unwrap] plays nicely with [%obj] */ let _ = log4(#String("foo")) let _ = log4(#Options({"foo": 1})) From b70599a71e9a1af85d1ee453c426d73e169869be Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 13:31:03 +0100 Subject: [PATCH 05/14] @bs.val -> @val --- jscomp/build_tests/cmd/input.js | 2 +- jscomp/core/design.md | 2 +- jscomp/frontend/ast_external_process.ml | 2 +- jscomp/others/js.ml | 9 +- jscomp/others/js_dict.res | 4 +- jscomp/others/js_json.res | 2 +- jscomp/others/js_math.ml | 114 +++++++++--------- jscomp/others/js_string2.res | 2 +- jscomp/others/js_typed_array.res | 4 +- jscomp/others/js_typed_array2.res | 4 +- jscomp/ounit_tests/ounit_cmd_tests.ml | 16 +-- .../ounit_tests/ounit_ffi_error_debug_test.ml | 4 +- jscomp/runtime/caml_int64.res | 2 +- jscomp/runtime/js.ml | 9 +- jscomp/syntax/benchmarks/data/Napkinscript.ml | 4 +- .../syntax/benchmarks/data/Napkinscript.res | 4 +- .../reprocessing/Reprocessing_Draw.res | 6 +- .../reprocessing/Reprocessing_Draw.resi | 6 +- .../parsing/grammar/expressions/block.res | 4 +- .../expressions/expected/block.res.txt | 4 +- .../typexpr/expected/uncurried.res.txt | 2 +- .../parsing/grammar/typexpr/uncurried.res | 2 +- jscomp/test/bs_auto_uncurry.res | 2 +- jscomp/test/bs_qualified.res | 2 +- jscomp/test/bs_rest_test.res | 1 - jscomp/test/event_ffi.res | 2 +- jscomp/test/gpr_1072.res | 2 +- jscomp/test/gpr_658.res | 2 +- jscomp/test/number_lexer.mll | 2 +- jscomp/test/prepend_data_ffi.res | 2 +- jscomp/test/test.res | 2 +- jscomp/test/test_int_map_find.res | 2 +- 32 files changed, 112 insertions(+), 115 deletions(-) diff --git a/jscomp/build_tests/cmd/input.js b/jscomp/build_tests/cmd/input.js index e90ae47441..cbec80a60c 100644 --- a/jscomp/build_tests/cmd/input.js +++ b/jscomp/build_tests/cmd/input.js @@ -21,7 +21,7 @@ type bla external foo : bla = "foo.react" [@@module] -external bar : unit -> bla = "bar" [@@bs.val] [@@module "foo.react"] +external bar : unit -> bla = "bar" [@@val] [@@module "foo.react"] let c = foo diff --git a/jscomp/core/design.md b/jscomp/core/design.md index f15e1230e1..50ab484a13 100644 --- a/jscomp/core/design.md +++ b/jscomp/core/design.md @@ -211,7 +211,7 @@ if (typeof x === "undefined"){ ```ocaml external of_char : char -> string = "String.fromCharCode" -[@@bs.val] +[@@val] ``` We introduced `#` so that we can do some optimizations. diff --git a/jscomp/frontend/ast_external_process.ml b/jscomp/frontend/ast_external_process.ml index b380bf8a3c..880572a442 100644 --- a/jscomp/frontend/ast_external_process.ml +++ b/jscomp/frontend/ast_external_process.ml @@ -258,7 +258,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string) else let action () = match txt with - | "bs.val" | "val" -> + | "val" -> if no_arguments then {st with val_name = Some (name_from_payload_or_prim ~loc payload)} else diff --git a/jscomp/others/js.ml b/jscomp/others/js.ml index c99eb1e77a..64a3661f38 100644 --- a/jscomp/others/js.ml +++ b/jscomp/others/js.ml @@ -141,14 +141,13 @@ external log : 'a -> unit = "log" [@@val] [@@scope "console"] (** Equivalent to console.log any value. *) -external log2 : 'a -> 'b -> unit = "log" [@@bs.val] [@@scope "console"] -external log3 : 'a -> 'b -> 'c -> unit = "log" [@@bs.val] [@@scope "console"] +external log2 : 'a -> 'b -> unit = "log" [@@val] [@@scope "console"] +external log3 : 'a -> 'b -> 'c -> unit = "log" [@@val] [@@scope "console"] -external log4 : 'a -> 'b -> 'c -> 'd -> unit = "log" -[@@bs.val] [@@scope "console"] +external log4 : 'a -> 'b -> 'c -> 'd -> unit = "log" [@@val] [@@scope "console"] external logMany : 'a array -> unit = "log" -[@@bs.val] [@@scope "console"] [@@variadic] +[@@val] [@@scope "console"] [@@variadic] (** A convenience function to console.log more than 4 arguments *) external eqNull : 'a -> 'a null -> bool = "%bs_equal_null" diff --git a/jscomp/others/js_dict.res b/jscomp/others/js_dict.res index 5daef592fd..cd07c15ee1 100644 --- a/jscomp/others/js_dict.res +++ b/jscomp/others/js_dict.res @@ -66,7 +66,7 @@ let unsafeDeleteKey: (. t, string) => unit = %raw(` function (dict,key){ `) @new external unsafeCreate: int => array<'a> = "Array" -/* external entries : 'a t -> (key * 'a) array = "Object.entries" [@@bs.val] (* ES2017 *) */ +/* external entries : 'a t -> (key * 'a) array = "Object.entries" [@@val] (* ES2017 *) */ let entries = dict => { let keys = keys(dict) let l = Js_array2.length(keys) @@ -78,7 +78,7 @@ let entries = dict => { values } -/* external values : 'a t -> 'a array = "Object.values" [@@bs.val] (* ES2017 *) */ +/* external values : 'a t -> 'a array = "Object.values" [@@val] (* ES2017 *) */ let values = dict => { let keys = keys(dict) let l = Js_array2.length(keys) diff --git a/jscomp/others/js_json.res b/jscomp/others/js_json.res index 03bb5783ac..47ea235e60 100644 --- a/jscomp/others/js_json.res +++ b/jscomp/others/js_json.res @@ -131,7 +131,7 @@ let decodeNull = (json): option> => } /* external parse : string -> t = "parse" - [@@bs.val][@@scope "JSON"] */ + [@@val][@@scope "JSON"] */ @val @scope("JSON") external parseExn: string => t = "parse" diff --git a/jscomp/others/js_math.ml b/jscomp/others/js_math.ml index 5801c61493..977af91f9e 100644 --- a/jscomp/others/js_math.ml +++ b/jscomp/others/js_math.ml @@ -30,7 +30,7 @@ names begin with upper case.) *) external _E : float = "E" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Euler's number; ≈ 2.718281828459045. See [`Math.E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/E) @@ -38,7 +38,7 @@ on MDN. *) external _LN2 : float = "LN2" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Natural logarithm of 2; ≈ 0.6931471805599453. See [`Math.LN2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LN2) @@ -46,7 +46,7 @@ on MDN. *) external _LN10 : float = "LN10" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Natural logarithm of 10; ≈ 2.302585092994046. See [`Math.LN10`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LN10) @@ -54,7 +54,7 @@ on MDN. *) external _LOG2E : float = "LOG2E" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Base 2 logarithm of E; ≈ 1.4426950408889634. See [`Math.LOG2E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LOG2E) @@ -62,7 +62,7 @@ on MDN. *) external _LOG10E : float = "LOG10E" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Base 10 logarithm of E; ≈ 0.4342944819032518. See [`Math.LOG10E`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/LOG10E) @@ -70,7 +70,7 @@ on MDN. *) external _PI : float = "PI" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793. See [`Math.PI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI) @@ -78,7 +78,7 @@ on MDN. *) external _SQRT1_2 : float = "SQRT1_2" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Square root of 1/2; ≈ 0.7071067811865476. See [`Math.SQRT1_2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/SQRT1_2) @@ -86,7 +86,7 @@ on MDN. *) external _SQRT2 : float = "SQRT2" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Square root of 2; ≈ 1.4142135623730951. See [`Math.SQRT2`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/SQRT2) @@ -94,7 +94,7 @@ on MDN. *) external abs_int : int -> int = "abs" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Absolute value for integer argument. See [`Math.abs`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs) @@ -102,7 +102,7 @@ on MDN. *) external abs_float : float -> float = "abs" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Absolute value for float argument. See [`Math.abs`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs) @@ -110,7 +110,7 @@ on MDN. *) external acos : float -> float = "acos" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Arccosine (in radians) of argument; returns `NaN` if the argument is outside the range [-1.0, 1.0]. See @@ -119,7 +119,7 @@ on MDN. *) external acosh : float -> float = "acosh" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Hyperbolic arccosine (in radians) of argument; returns `NaN` if the argument is less than 1.0. See @@ -128,7 +128,7 @@ on MDN. *) external asin : float -> float = "asin" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Arcsine (in radians) of argument; returns `NaN` if the argument is outside the range [-1.0, 1.0]. See @@ -137,7 +137,7 @@ on MDN. *) external asinh : float -> float = "asinh" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Hyperbolic arcsine (in radians) of argument. See [`Math.asinh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh) @@ -145,7 +145,7 @@ on MDN. *) external atan : float -> float = "atan" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Arctangent (in radians) of argument. See [`Math.atan`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan) @@ -153,7 +153,7 @@ on MDN. *) external atanh : float -> float = "atanh" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Hyperbolic arctangent (in radians) of argument; returns `NaN` if the argument is is outside the range [-1.0, 1.0]. Returns `-Infinity` and `Infinity` for @@ -163,7 +163,7 @@ on MDN. *) external atan2 : y:float -> x:float -> unit -> float = "atan2" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the angle (in radians) of the quotient `y /. x`. It is also the angle between the *x*-axis and point (*x*, *y*). See @@ -182,7 +182,7 @@ Js.Math.atan2(~x=-0.0, ~y=-5.0, ()) == -.Js.Math._PI /. 2.0 *) external cbrt : float -> float = "cbrt" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Cube root. See [`Math.cbrt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt) @@ -190,7 +190,7 @@ on MDN *) external unsafe_ceil_int : float -> int = "ceil" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the smallest integer greater than or equal to the argument. This function may return values not representable by `int`, whose range is @@ -237,7 +237,7 @@ let ceil_int (f : float) : int = let ceil = ceil_int [@@deprecated "Please use `ceil_int` instead"] external ceil_float : float -> float = "ceil" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the smallest integral value greater than or equal to the argument. The result is a `float` and is not restricted to the `int` data type range. @@ -256,7 +256,7 @@ Js.Math.ceil_float(2_150_000_000.3) == 2_150_000_001.0 *) external clz32 : int -> int = "clz32" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Number of leading zero bits of the argument's 32 bit int representation. See [`Math.clz32`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32) @@ -272,7 +272,7 @@ Js.Math.clz32(255) == 24 *) external cos : float -> float = "cos" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Cosine of argument, which must be specified in radians. See [`Math.cos`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos) @@ -280,7 +280,7 @@ on MDN. *) external cosh : float -> float = "cosh" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Hyperbolic cosine of argument, which must be specified in radians. See [`Math.cosh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh) @@ -288,7 +288,7 @@ on MDN. *) external exp : float -> float = "exp" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Natural exponentional; returns *e* (the base of natural logarithms) to the power of the given argument. See @@ -297,7 +297,7 @@ on MDN. *) external expm1 : float -> float = "expm1" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns *e* (the base of natural logarithms) to the power of the given argument minus 1. See @@ -306,7 +306,7 @@ on MDN. *) external unsafe_floor_int : float -> int = "floor" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the largest integer less than or equal to the argument. This function may return values not representable by `int`, whose range is -2147483648 to @@ -353,7 +353,7 @@ let floor_int f = let floor = floor_int [@@deprecated "Please use `floor_int` instead"] external floor_float : float -> float = "floor" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the largest integral value less than or equal to the argument. The result is a `float` and is not restricted to the `int` data type range. See @@ -371,7 +371,7 @@ Js.Math.floor_float(2_150_000_000.3) == 2_150_000_000.0 *) external fround : float -> float = "fround" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Round to nearest single precision float. See [`Math.fround`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround) @@ -386,7 +386,7 @@ Js.Math.fround(5.05) == 5.050000190734863 *) external hypot : float -> float -> float = "hypot" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the square root of the sum of squares of its two arguments (the Pythagorean formula). See @@ -395,7 +395,7 @@ on MDN. *) external hypotMany : float array -> float = "hypot" -[@@bs.val] [@@variadic] [@@scope "Math"] +[@@val] [@@variadic] [@@scope "Math"] (** Returns the square root of the sum of squares of the numbers in the array argument (generalized Pythagorean equation). Using an array allows you to @@ -411,7 +411,7 @@ Js.Math.hypotMany([3.0, 4.0, 12.0]) == 13.0 *) external imul : int -> int -> int = "imul" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** 32-bit integer multiplication. Use this only when you need to optimize performance of multiplication of numbers stored as 32-bit integers. See @@ -420,7 +420,7 @@ on MDN. *) external log : float -> float = "log" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the natural logarithm of its argument; this is the number *x* such that *e**x* equals the argument. Returns `NaN` for negative @@ -437,7 +437,7 @@ Js.Math.log(100.0) == 4.605170185988092 *) external log1p : float -> float = "log1p" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the natural logarithm of one plus the argument. Returns `NaN` for arguments less than -1. See @@ -453,7 +453,7 @@ Js.Math.log1p(99.0) == 4.605170185988092 *) external log10 : float -> float = "log10" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the base 10 logarithm of its argument. Returns `NaN` for negative arguments. See @@ -470,7 +470,7 @@ Js.Math.log10(Js.Math.sqrt(10.0)) == 0.5 *) external log2 : float -> float = "log2" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the base 2 logarithm of its argument. Returns `NaN` for negative arguments. See @@ -487,7 +487,7 @@ Js.Math.log2(Js.Math._SQRT2) == 0.5000000000000001 // due to precision *) external max_int : int -> int -> int = "max" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the maximum of its two integer arguments. See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) @@ -495,7 +495,7 @@ on MDN. *) external maxMany_int : int array -> int = "max" -[@@bs.val] [@@variadic] [@@scope "Math"] +[@@val] [@@variadic] [@@scope "Math"] (** Returns the maximum of the integers in the given array. See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) @@ -503,7 +503,7 @@ on MDN. *) external max_float : float -> float -> float = "max" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the maximum of its two floating point arguments. See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) @@ -511,7 +511,7 @@ on MDN. *) external maxMany_float : float array -> float = "max" -[@@bs.val] [@@variadic] [@@scope "Math"] +[@@val] [@@variadic] [@@scope "Math"] (** Returns the maximum of the floating point values in the given array. See [`Math.max`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) @@ -519,7 +519,7 @@ on MDN. *) external min_int : int -> int -> int = "min" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the minimum of its two integer arguments. See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) @@ -527,7 +527,7 @@ on MDN. *) external minMany_int : int array -> int = "min" -[@@bs.val] [@@variadic] [@@scope "Math"] +[@@val] [@@variadic] [@@scope "Math"] (** Returns the minimum of the integers in the given array. See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) @@ -535,7 +535,7 @@ on MDN. *) external min_float : float -> float -> float = "min" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the minimum of its two floating point arguments. See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) @@ -543,7 +543,7 @@ on MDN. *) external minMany_float : float array -> float = "min" -[@@bs.val] [@@variadic] [@@scope "Math"] +[@@val] [@@variadic] [@@scope "Math"] (** Returns the minimum of the floating point values in the given array. See [`Math.min`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) @@ -551,7 +551,7 @@ on MDN. *) external pow_int : base:int -> exp:int -> int = "pow" -[@@bs.val] +[@@val] [@@scope "Math"] [@@deprecated "use `pow_float` instead, the return type may be not int"] (** @@ -568,7 +568,7 @@ Js.Math.pow_int(~base=3, ~exp=4) == 81 *) external pow_float : base:float -> exp:float -> float = "pow" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Raises the given base to the given exponent. (Arguments and result are floats.) Returns `NaN` if the result would be imaginary. See @@ -587,7 +587,7 @@ Js.Float.isNaN(Js.Math.pow_float(~base=-2.0, ~exp=0.5)) == true *) external random : unit -> float = "random" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns a random number in the half-closed interval [0,1). See [`Math.random`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) @@ -603,7 +603,7 @@ on MDN. let random_int min max = floor (random () *. Js_int.toFloat (max - min)) + min external unsafe_round : float -> int = "round" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Rounds its argument to nearest integer. For numbers with a fractional portion of exactly 0.5, the argument is rounded to the next integer in the direction @@ -624,7 +624,7 @@ Js.Math.unsafe_round(2_150_000_000_000.3) // out of range for int *) external round : float -> float = "round" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Rounds to nearest integral value (expressed as a float). See [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round) @@ -632,7 +632,7 @@ on MDN. *) external sign_int : int -> int = "sign" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the sign of its integer argument: -1 if negative, 0 if zero, 1 if positive. See @@ -641,7 +641,7 @@ on MDN. *) external sign_float : float -> float = "sign" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Returns the sign of its float argument: -1.0 if negative, 0.0 if zero, 1.0 if positive. See @@ -650,7 +650,7 @@ on MDN. *) external sin : float -> float = "sin" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Sine of argument, which must be specified in radians. See [`Math.sin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin) @@ -658,7 +658,7 @@ on MDN. *) external sinh : float -> float = "sinh" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Hyperbolic sine of argument, which must be specified in radians. See [`Math.sinh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh) @@ -666,7 +666,7 @@ on MDN. *) external sqrt : float -> float = "sqrt" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Square root. If the argument is negative, this function returns `NaN`. See [`Math.sqrt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt) @@ -674,7 +674,7 @@ on MDN. *) external tan : float -> float = "tan" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Tangent of argument, which must be specified in radians. Returns `NaN` if the argument is positive infinity or negative infinity. See @@ -683,7 +683,7 @@ on MDN. *) external tanh : float -> float = "tanh" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Hyperbolic tangent of argument, which must be specified in radians. See [`Math.tanh`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh) @@ -691,7 +691,7 @@ on MDN. *) external unsafe_trunc : float -> int = "trunc" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Truncates its argument; i.e., removes fractional digits. This function may return values not representable by `int`, whose range is -2147483648 to @@ -703,7 +703,7 @@ on MDN. *) external trunc : float -> float = "trunc" -[@@bs.val] [@@scope "Math"] +[@@val] [@@scope "Math"] (** Truncates its argument; i.e., removes fractional digits. See [`Math.trunc`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc) diff --git a/jscomp/others/js_string2.res b/jscomp/others/js_string2.res index 998b60c6bc..7dd51fd285 100644 --- a/jscomp/others/js_string2.res +++ b/jscomp/others/js_string2.res @@ -983,7 +983,7 @@ Js.String2.link("Go to page two", "page2.html") == "Go to p external link: (t, t) => t = "link" /* FIXME: we should not encourage people to use [%identity], better - to provide something using [@@bs.val] so that we can track such + to provide something using [@@val] so that we can track such casting */ /** diff --git a/jscomp/others/js_typed_array.res b/jscomp/others/js_typed_array.res index 21b010b1a0..bd0728fb68 100644 --- a/jscomp/others/js_typed_array.res +++ b/jscomp/others/js_typed_array.res @@ -50,8 +50,8 @@ module ArrayBuffer = { /* ArrayBuffer.isView: seems pointless with a type system */ /* experimental - external transfer : array_buffer -> t = "ArrayBuffer.transfer" [@@bs.val] - external transferWithLength : array_buffer -> int -> t = "ArrayBuffer.transfer" [@@bs.val] + external transfer : array_buffer -> t = "ArrayBuffer.transfer" [@@val] + external transferWithLength : array_buffer -> int -> t = "ArrayBuffer.transfer" [@@val] */ @get external byteLength: t => int = "byteLength" diff --git a/jscomp/others/js_typed_array2.res b/jscomp/others/js_typed_array2.res index c31f20b829..71eee7316c 100644 --- a/jscomp/others/js_typed_array2.res +++ b/jscomp/others/js_typed_array2.res @@ -45,8 +45,8 @@ module ArrayBuffer = { /* ArrayBuffer.isView: seems pointless with a type system */ /* experimental - external transfer : array_buffer -> t = "ArrayBuffer.transfer" [@@bs.val] - external transferWithLength : array_buffer -> int -> t = "ArrayBuffer.transfer" [@@bs.val] + external transfer : array_buffer -> t = "ArrayBuffer.transfer" [@@val] + external transferWithLength : array_buffer -> int -> t = "ArrayBuffer.transfer" [@@val] */ @get external byteLength: t => int = "byteLength" diff --git a/jscomp/ounit_tests/ounit_cmd_tests.ml b/jscomp/ounit_tests/ounit_cmd_tests.ml index c2012a88c7..22b5471cdf 100644 --- a/jscomp/ounit_tests/ounit_cmd_tests.ml +++ b/jscomp/ounit_tests/ounit_cmd_tests.ml @@ -64,7 +64,7 @@ let suites = __LOC__ >:: begin fun _ -> let should_be_warning = - bsc_check_eval {| external mk : int -> ([`a|`b [@string]]) = "mk" [@@bs.val] |} in + bsc_check_eval {| external mk : int -> ([`a|`b [@string]]) = "mk" [@@val] |} in OUnit.assert_bool __LOC__ (Ext_string.contain_substring should_be_warning.stderr "Unused") @@ -89,7 +89,7 @@ external ff : let should_err = bsc_check_eval {| external v3 : int -> int -> (int -> int -> int [@uncurry]) - = "v3"[@@bs.val] + = "v3"[@@val] |} in (* Ounit_cmd_util.debug_output should_err;*) @@ -102,7 +102,7 @@ external ff : let should_err = bsc_check_eval {| external v4 : (int -> int -> int [@uncurry]) = "" - [@@bs.val] + [@@val] |} in (* Ounit_cmd_util.debug_output should_err ; *) @@ -120,14 +120,14 @@ external ff : __LOC__ >:: begin fun _ -> let should_err = bsc_check_eval {| - external mk : int -> ([`a|`b] [@string]) = "" [@@bs.val] + external mk : int -> ([`a|`b] [@string]) = "" [@@val] |} in OUnit.assert_bool __LOC__ (not @@ Ext_string.is_empty should_err.stderr) end; __LOC__ >:: begin fun _ -> let should_err = bsc_check_eval {| - external mk : int -> ([`a|`b] ) = "mk" [@@bs.val] + external mk : int -> ([`a|`b] ) = "mk" [@@val] |} in OUnit.assert_bool __LOC__ ( Ext_string.is_empty should_err.stderr) (* give a warning or ? @@ -139,7 +139,7 @@ external ff : __LOC__ >:: begin fun _ -> let should_err = bsc_check_eval {| type t - external mk : int -> (_ [@as {json| { x : 3 } |json}]) -> t = "mk" [@@bs.val] + external mk : int -> (_ [@as {json| { x : 3 } |json}]) -> t = "mk" [@@val] |} in OUnit.assert_bool __LOC__ (Ext_string.is_empty should_err.stderr) end @@ -147,7 +147,7 @@ external ff : __LOC__ >:: begin fun _ -> let should_err = bsc_check_eval {| type t - external mk : int -> (_ [@as {json| { "x" : 3 } |json}]) -> t = "mk" [@@bs.val] + external mk : int -> (_ [@as {json| { "x" : 3 } |json}]) -> t = "mk" [@@val] |} in OUnit.assert_bool __LOC__ (Ext_string.is_empty should_err.stderr) end @@ -262,7 +262,7 @@ let rec y = A y;; ( [`a|`b] [@string] - ) = "mk" [@@bs.val] + ) = "mk" [@@val] |} in (* Ounit_cmd_util.debug_output should_err ; *) OUnit.assert_bool __LOC__ diff --git a/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml b/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml index 3a01f6eddd..a8b5db5d21 100644 --- a/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml +++ b/jscomp/ounit_tests/ounit_ffi_error_debug_test.ml @@ -41,7 +41,7 @@ let output = bsc_eval {| let output = bsc_eval {| external err : ?hi_should_error:([`a of int | `b of string ] [@string]) -> - unit -> unit = "err" [@@bs.val] + unit -> unit = "err" [@@val] |} in OUnit.assert_bool __LOC__ (Ext_string.contain_substring output.stderr "hi_should_error") @@ -54,7 +54,7 @@ let output = bsc_eval {| let output = bsc_eval {| external err : - ?hi_should_error:([`a of int | `b] [@unwrap]) -> unit -> unit = "err" [@@bs.val] + ?hi_should_error:([`a of int | `b] [@unwrap]) -> unit -> unit = "err" [@@val] |} in OUnit.assert_bool __LOC__ diff --git a/jscomp/runtime/caml_int64.res b/jscomp/runtime/caml_int64.res index 7958282981..d079cdc4af 100644 --- a/jscomp/runtime/caml_int64.res +++ b/jscomp/runtime/caml_int64.res @@ -320,7 +320,7 @@ let rec of_float = (x: float): t => @val @scope("Math") external log: float => float = "log" @val @scope("Math") external ceil: float => float = "ceil" @val @scope("Math") external floor: float => float = "floor" -/* external maxFloat : float -> float -> float = "Math.max" [@@bs.val] */ +/* external maxFloat : float -> float -> float = "Math.max" [@@val] */ /* either top 11 bits are all 0 or all 1 when it is all 1, we need exclude -2^53 diff --git a/jscomp/runtime/js.ml b/jscomp/runtime/js.ml index 6e280c60de..d62961a2da 100644 --- a/jscomp/runtime/js.ml +++ b/jscomp/runtime/js.ml @@ -104,13 +104,12 @@ external log : 'a -> unit = "log" [@@val] [@@scope "console"] (** A convenience function to log everything *) -external log2 : 'a -> 'b -> unit = "log" [@@bs.val] [@@scope "console"] -external log3 : 'a -> 'b -> 'c -> unit = "log" [@@bs.val] [@@scope "console"] -external log4 : 'a -> 'b -> 'c -> 'd -> unit = "log" -[@@bs.val] [@@scope "console"] +external log2 : 'a -> 'b -> unit = "log" [@@val] [@@scope "console"] +external log3 : 'a -> 'b -> 'c -> unit = "log" [@@val] [@@scope "console"] +external log4 : 'a -> 'b -> 'c -> 'd -> unit = "log" [@@val] [@@scope "console"] external logMany : 'a array -> unit = "log" -[@@bs.val] [@@scope "console"] [@@variadic] +[@@val] [@@scope "console"] [@@variadic] (** A convenience function to log more than 4 arguments *) external eqNull : 'a -> 'a null -> bool = "%bs_equal_null" diff --git a/jscomp/syntax/benchmarks/data/Napkinscript.ml b/jscomp/syntax/benchmarks/data/Napkinscript.ml index 2ade45da31..37512e4fcd 100644 --- a/jscomp/syntax/benchmarks/data/Napkinscript.ml +++ b/jscomp/syntax/benchmarks/data/Napkinscript.ml @@ -6714,7 +6714,7 @@ module Printer = struct and printJsFfiImport (valueDescription: Parsetree.value_description) cmtTbl = let attrs = List.filter (fun attr -> match attr with - | ({Location.txt = "bs.val" | "genType.import" | "scope" }, _) -> false + | ({Location.txt = "val" | "genType.import" | "scope" }, _) -> false | _ -> true ) valueDescription.pval_attributes in let (ident, alias) = match valueDescription.pval_prim with @@ -11514,7 +11514,7 @@ module JsFfi = struct } let toParsetree importDescr = - let bsVal = (Location.mknoloc "bs.val", Parsetree.PStr []) in + let bsVal = (Location.mknoloc "val", Parsetree.PStr []) in let attrs = match importDescr.jid_scope with | Global -> [bsVal] (* @genType.import("./MyMath"), diff --git a/jscomp/syntax/benchmarks/data/Napkinscript.res b/jscomp/syntax/benchmarks/data/Napkinscript.res index 01ccbaea93..710590ed3a 100644 --- a/jscomp/syntax/benchmarks/data/Napkinscript.res +++ b/jscomp/syntax/benchmarks/data/Napkinscript.res @@ -6906,7 +6906,7 @@ module Printer = { and printJsFfiImport = (valueDescription: Parsetree.value_description, cmtTbl) => { let attrs = List.filter(attr => switch attr { - | ({Location.txt: "bs.val" | "genType.import" | "scope"}, _) => false + | ({Location.txt: "val" | "genType.import" | "scope"}, _) => false | _ => true } , valueDescription.pval_attributes) @@ -11881,7 +11881,7 @@ module JsFfi = { } let toParsetree = importDescr => { - let bsVal = (Location.mknoloc("bs.val"), Parsetree.PStr(list{})) + let bsVal = (Location.mknoloc("val"), Parsetree.PStr(list{})) let attrs = switch importDescr.jid_scope { | Global => list{bsVal} /* @genType.import("./MyMath"), diff --git a/jscomp/syntax/tests/idempotency/reprocessing/Reprocessing_Draw.res b/jscomp/syntax/tests/idempotency/reprocessing/Reprocessing_Draw.res index 22c9daad5c..416775d9e9 100644 --- a/jscomp/syntax/tests/idempotency/reprocessing/Reprocessing_Draw.res +++ b/jscomp/syntax/tests/idempotency/reprocessing/Reprocessing_Draw.res @@ -6,9 +6,9 @@ open Reprocessing_Common * This is where all the fancy things happen. * * ```reason;shared(sandbox) - * [@bs.val] external sandboxCanvasId: string = \"\"; - * [@bs.val] external sandboxCanvas: 'canvas = \"\"; - * [@bs.val] external containerDiv: 'node = \"\"; + * [@val] external sandboxCanvasId: string = \"\"; + * [@val] external sandboxCanvas: 'canvas = \"\"; + * [@val] external containerDiv: 'node = \"\"; * [@send] external addEventListener: ('node, string, 'eventT => unit) => unit = \"addEventListener\"; * let id = sandboxCanvasId; * addEventListener(containerDiv, \"mouseleave\", (_) => Reprocessing.playPause(id, false) |> ignore); diff --git a/jscomp/syntax/tests/idempotency/reprocessing/Reprocessing_Draw.resi b/jscomp/syntax/tests/idempotency/reprocessing/Reprocessing_Draw.resi index 53a66a8b2d..a30ab392d0 100644 --- a/jscomp/syntax/tests/idempotency/reprocessing/Reprocessing_Draw.resi +++ b/jscomp/syntax/tests/idempotency/reprocessing/Reprocessing_Draw.resi @@ -3,9 +3,9 @@ * This is where all the fancy things happen. * * ```reason;shared(sandbox) - * [@bs.val] external sandboxCanvasId: string = \"\"; - * [@bs.val] external sandboxCanvas: 'canvas = \"\"; - * [@bs.val] external containerDiv: 'node = \"\"; + * [@val] external sandboxCanvasId: string = \"\"; + * [@val] external sandboxCanvas: 'canvas = \"\"; + * [@val] external containerDiv: 'node = \"\"; * [@send] external addEventListener: ('node, string, 'eventT => unit) => unit = \"addEventListener\"; * let id = sandboxCanvasId; * addEventListener(containerDiv, \"mouseleave\", (_) => Reprocessing.playPause(id, false) |> ignore); diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/block.res b/jscomp/syntax/tests/parsing/grammar/expressions/block.res index f652ecabd5..bce0a822dd 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/block.res +++ b/jscomp/syntax/tests/parsing/grammar/expressions/block.res @@ -127,8 +127,8 @@ let f = () => { let reifyStyle = (type a, x: 'a): (style, a) => { module Internal = { type rec constructor - @bs.val external canvasGradient: constructor = "CanvasGradient" /* internal */ - @bs.val external canvasPattern: constructor = "CanvasPattern" /* internal */ + @val external canvasGradient: constructor = "CanvasGradient" /* internal */ + @val external canvasPattern: constructor = "CanvasPattern" /* internal */ let instanceOf = ( %bs.raw(`function(x,y) {return +(x instanceof y)}`): ('a, constructor) => bool ) /* internal */ diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/block.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/block.res.txt index 0cce867c20..7309a686a3 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/block.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/block.res.txt @@ -46,8 +46,8 @@ let reifyStyle (type a) (x : 'a) = (((let module Internal = struct type constructor - external canvasGradient : constructor = "CanvasGradient"[@@bs.val ] - external canvasPattern : constructor = "CanvasPattern"[@@bs.val ] + external canvasGradient : constructor = "CanvasGradient"[@@val ] + external canvasPattern : constructor = "CanvasPattern"[@@val ] let instanceOf = ([%bs.raw (({js|function(x,y) {return +(x instanceof y)}|js}) diff --git a/jscomp/syntax/tests/parsing/grammar/typexpr/expected/uncurried.res.txt b/jscomp/syntax/tests/parsing/grammar/typexpr/expected/uncurried.res.txt index 5097ce68d8..126cacdee2 100644 --- a/jscomp/syntax/tests/parsing/grammar/typexpr/expected/uncurried.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/typexpr/expected/uncurried.res.txt @@ -22,7 +22,7 @@ type nonrec t = [ `Has_arity2 ]) function$ external setTimeout : (unit -> unit, [ `Has_arity1 ]) function$ -> int -> timerId = "setTimeout" -[@@bs.val ] +[@@val ] external setTimeout : ((unit -> unit) -> int -> timerId, [ `Has_arity2 ]) function$ = "setTimeout" \ No newline at end of file diff --git a/jscomp/syntax/tests/parsing/grammar/typexpr/uncurried.res b/jscomp/syntax/tests/parsing/grammar/typexpr/uncurried.res index 7ea7f55fd8..91fc3a548b 100644 --- a/jscomp/syntax/tests/parsing/grammar/typexpr/uncurried.res +++ b/jscomp/syntax/tests/parsing/grammar/typexpr/uncurried.res @@ -8,7 +8,7 @@ type t = (. @attr float, @attr2 int, . @attr3 bool, @attr4 string) => unit type t = @attr (. float) => @attr2 int => @attr3 (. bool) => @attr4 string => unit type t = (. (@attr float), (@attr2 int), . (@attr3 bool), (@attr4 string)) => unit -@bs.val +@val external setTimeout : ((. ()) => unit, int) => timerId = "setTimeout" // totally different meaning external setTimeout : (. unit => unit, int) => timerId = "setTimeout" diff --git a/jscomp/test/bs_auto_uncurry.res b/jscomp/test/bs_auto_uncurry.res index f132c25242..7f1e243d9e 100644 --- a/jscomp/test/bs_auto_uncurry.res +++ b/jscomp/test/bs_auto_uncurry.res @@ -95,7 +95,7 @@ external ff : (unit -> unit [@uncurry]) -> int = "" -[@@bs.val] +[@@val] */ /* diff --git a/jscomp/test/bs_qualified.res b/jscomp/test/bs_qualified.res index 54ae1188d2..96096477aa 100644 --- a/jscomp/test/bs_qualified.res +++ b/jscomp/test/bs_qualified.res @@ -29,7 +29,7 @@ external makeBuffer2: int => buffer = "Buffer" external makeBuffer3: int => buffer = "makeBuffer3" @scope("Math") @val external max: (float, float) => float = "max" -/* TODO: `bs.val` is not necessary, by default is good? +/* TODO: `@val` is not necessary, by default is good? */ type t diff --git a/jscomp/test/bs_rest_test.res b/jscomp/test/bs_rest_test.res index b3be3b2fc2..74d25fcd1c 100644 --- a/jscomp/test/bs_rest_test.res +++ b/jscomp/test/bs_rest_test.res @@ -16,5 +16,4 @@ include ( ) let u = xxx(. 3) -/** Do we need both [bs.val] and [bs.call]* instead of just one [bs.val] */ let xx = xxx(. "3") diff --git a/jscomp/test/event_ffi.res b/jscomp/test/event_ffi.res index ecd2c7b739..30f6738f9a 100644 --- a/jscomp/test/event_ffi.res +++ b/jscomp/test/event_ffi.res @@ -8,7 +8,7 @@ external on : process -> ] -> unit Js.fn -> unit = "on" [@@send] -external p : process = "process" [@@bs.val] +external p : process = "process" [@@val] external on_hi : process -> diff --git a/jscomp/test/gpr_1072.res b/jscomp/test/gpr_1072.res index 4c603b21e1..92492c67ae 100644 --- a/jscomp/test/gpr_1072.res +++ b/jscomp/test/gpr_1072.res @@ -176,6 +176,6 @@ let () = { } /* external again5 : ?x__ignore:([`a of unit -> int | `b of string -> int ] [@string]) */ -/* -> int -> unit = "" [@@bs.val] */ +/* -> int -> unit = "" [@@val] */ /* let v = again5 3 */ diff --git a/jscomp/test/gpr_658.res b/jscomp/test/gpr_658.res index 141f538953..9a67d6105b 100644 --- a/jscomp/test/gpr_658.res +++ b/jscomp/test/gpr_658.res @@ -1,4 +1,4 @@ -/* external obj : < hi : int > = "{hi:1}" [@@bs.val] */ +/* external obj : < hi : int > = "{hi:1}" [@@val] */ @obj external mk: (~hi: int, unit) => {"hi": int} = "" diff --git a/jscomp/test/number_lexer.mll b/jscomp/test/number_lexer.mll index b423508e9b..56e7c458f3 100644 --- a/jscomp/test/number_lexer.mll +++ b/jscomp/test/number_lexer.mll @@ -1,5 +1,5 @@ { -external log : string -> unit = "caml_alloc_dummy" [@@bs.val "console.log"] +external log : string -> unit = "caml_alloc_dummy" [@@val "console.log"] let l = #if BS then log diff --git a/jscomp/test/prepend_data_ffi.res b/jscomp/test/prepend_data_ffi.res index b074bc1acf..13a506b801 100644 --- a/jscomp/test/prepend_data_ffi.res +++ b/jscomp/test/prepend_data_ffi.res @@ -66,7 +66,7 @@ external on_exit_slice5: ( ) => unit = "xx" /** - TODO: @send conflicts with bs.val: better error message + TODO: @send conflicts with @val: better error message */ let f = (x: t) => { x->on_exit_slice1(__LINE__, [1, 2, 3]) diff --git a/jscomp/test/test.res b/jscomp/test/test.res index 0a1c7a2c1f..befbb1b7ca 100644 --- a/jscomp/test/test.res +++ b/jscomp/test/test.res @@ -8,7 +8,7 @@ let a = external file : string option = "__filename" -[@@bs.val] [@@return{undefined_to_opt}] +[@@val] [@@return{undefined_to_opt}] let a = diff --git a/jscomp/test/test_int_map_find.res b/jscomp/test/test_int_map_find.res index d205fa2cf0..df1ba9ab83 100644 --- a/jscomp/test/test_int_map_find.res +++ b/jscomp/test/test_int_map_find.res @@ -13,7 +13,7 @@ include ( list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, ) - /* external log : 'a -> unit = "" [@@bs.val "console.log"] */ + /* external log : 'a -> unit = "" [@@val "console.log"] */ let assert_test = () => if IntMap.find(10, m) == 'a' { From 4fa1cb8c3b27e7fe9f5113c010f60afaedd31d9e Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 13:32:26 +0100 Subject: [PATCH 06/14] @bs.debugger -> @debugger --- jscomp/core/lam_compile.ml | 2 +- jscomp/frontend/ast_exp_extension.ml | 2 +- jscomp/runtime/caml_format.ml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jscomp/core/lam_compile.ml b/jscomp/core/lam_compile.ml index 7361a1e22d..ed5a704cef 100644 --- a/jscomp/core/lam_compile.ml +++ b/jscomp/core/lam_compile.ml @@ -1514,7 +1514,7 @@ and compile_prim (prim_info : Lam.prim_info) compile_sequand l r lambda_cxt | { primitive = Psequor; args = [ l; r ] } -> compile_sequor l r lambda_cxt | { primitive = Pdebugger; _ } -> - (* [%bs.debugger] guarantees that the expression does not matter + (* [%debugger] guarantees that the expression does not matter TODO: make it even safer *) Js_output.output_of_block_and_expression lambda_cxt.continuation S.debugger_block E.unit diff --git a/jscomp/frontend/ast_exp_extension.ml b/jscomp/frontend/ast_exp_extension.ml index ccd6fe4bba..9be2f99e4d 100644 --- a/jscomp/frontend/ast_exp_extension.ml +++ b/jscomp/frontend/ast_exp_extension.ml @@ -69,7 +69,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper) (Exp.ident ~loc {loc; txt = Lident "timed"}))) | _ -> Location.raise_errorf ~loc "expect a boolean expression in the payload") - | "bs.debugger" | "debugger" -> + | "debugger" -> {e with pexp_desc = Ast_exp_handle_external.handle_debugger loc payload} | "obj" -> ( match payload with diff --git a/jscomp/runtime/caml_format.ml b/jscomp/runtime/caml_format.ml index 6a4a5a8463..c36929a2c3 100644 --- a/jscomp/runtime/caml_format.ml +++ b/jscomp/runtime/caml_format.ml @@ -103,7 +103,7 @@ let int_of_string (s : string) : int = let () = if d < 0 || d >= base then failwith "int_of_string" in - (* let () = [%bs.debugger] in *) + (* let () = [%debugger] in *) let rec aux acc k = if k = len then acc else From bf63b057ecb49985ed32a038532bf6362b7cb728 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 13:40:35 +0100 Subject: [PATCH 07/14] @bs.external -> @external --- jscomp/frontend/ast_exp_extension.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jscomp/frontend/ast_exp_extension.ml b/jscomp/frontend/ast_exp_extension.ml index 9be2f99e4d..f832a1514f 100644 --- a/jscomp/frontend/ast_exp_extension.ml +++ b/jscomp/frontend/ast_exp_extension.ml @@ -33,7 +33,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper) Exp.constraint_ ~loc (Ast_exp_handle_external.handle_raw ~kind:Raw_re loc payload) (Ast_comb.to_js_re_type loc) - | "bs.external" | "external" -> ( + | "external" -> ( match Ast_payload.as_ident payload with | Some {txt = Lident x} -> Ast_exp_handle_external.handle_external loc x From 3531354aa50f99db0a95619ed660e4d067f0bad3 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 13:43:22 +0100 Subject: [PATCH 08/14] @bs.raw -> @raw --- jscomp/frontend/ast_exp_extension.ml | 3 +-- jscomp/frontend/bs_builtin_ppx.ml | 4 ++-- jscomp/syntax/benchmarks/data/HeroGraphic.ml | 2 +- jscomp/syntax/benchmarks/data/HeroGraphic.res | 2 +- jscomp/syntax/benchmarks/data/RedBlackTree.ml | 2 +- jscomp/syntax/benchmarks/data/RedBlackTree.res | 2 +- .../benchmarks/data/RedBlackTreeNoComments.res | 2 +- .../Webapi__Dom/Webapi__Dom__Document__test.res | 2 +- .../wildcards-world-ui/SsrEntryPoint.res | 2 +- .../tests/parsing/grammar/expressions/block.res | 2 +- .../grammar/expressions/expected/block.res.txt | 2 +- .../grammar/expressions/expected/extension.res.txt | 2 +- .../parsing/grammar/expressions/extension.res | 2 +- .../grammar/pattern/expected/extension.res.txt | 14 +++++++------- .../tests/parsing/grammar/pattern/extension.res | 14 +++++++------- jscomp/test/mt.res | 2 +- jscomp/test/unsafe_ppx_test.res | 2 +- 17 files changed, 30 insertions(+), 31 deletions(-) diff --git a/jscomp/frontend/ast_exp_extension.ml b/jscomp/frontend/ast_exp_extension.ml index f832a1514f..cd52ba9674 100644 --- a/jscomp/frontend/ast_exp_extension.ml +++ b/jscomp/frontend/ast_exp_extension.ml @@ -27,8 +27,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper) (({txt; loc}, payload) : Parsetree.extension) = match txt with | "ffi" -> Ast_exp_handle_external.handle_ffi ~loc ~payload - | "bs.raw" | "raw" -> - Ast_exp_handle_external.handle_raw ~kind:Raw_exp loc payload + | "raw" -> Ast_exp_handle_external.handle_raw ~kind:Raw_exp loc payload | "bs.re" | "re" -> Exp.constraint_ ~loc (Ast_exp_handle_external.handle_raw ~kind:Raw_re loc payload) diff --git a/jscomp/frontend/bs_builtin_ppx.ml b/jscomp/frontend/bs_builtin_ppx.ml index 69644b9d1b..16391ce757 100644 --- a/jscomp/frontend/bs_builtin_ppx.ml +++ b/jscomp/frontend/bs_builtin_ppx.ml @@ -28,7 +28,7 @@ (** 1. extension point {[ - [%bs.raw{| blabla |}] + [%raw{| blabla |}] ]} will be desugared into {[ @@ -514,7 +514,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t) | [] -> [] | item :: rest -> ( match item.pstr_desc with - | Pstr_extension (({txt = "bs.raw" | "raw"; loc}, payload), _attrs) -> + | Pstr_extension (({txt = "raw"; loc}, payload), _attrs) -> Ast_exp_handle_external.handle_raw_structure loc payload :: structure_mapper ~await_context self rest (* | Pstr_extension (({txt = "i"}, _),_) diff --git a/jscomp/syntax/benchmarks/data/HeroGraphic.ml b/jscomp/syntax/benchmarks/data/HeroGraphic.ml index 08feb30e3d..e33360dbd5 100644 --- a/jscomp/syntax/benchmarks/data/HeroGraphic.ml +++ b/jscomp/syntax/benchmarks/data/HeroGraphic.ml @@ -1,4 +1,4 @@ -;;[%bs.raw {|require('./HeroGraphic.css')|}] +;;[%raw {|require('./HeroGraphic.css')|}] let make ?(width= "760") ?(height= "380") = ((svg ~width:((width)) ~height:((height)) ~viewBox:(("0 0 758 381")) ~fill:(("none") diff --git a/jscomp/syntax/benchmarks/data/HeroGraphic.res b/jscomp/syntax/benchmarks/data/HeroGraphic.res index 53decfa8a0..22927a7fd1 100644 --- a/jscomp/syntax/benchmarks/data/HeroGraphic.res +++ b/jscomp/syntax/benchmarks/data/HeroGraphic.res @@ -1,4 +1,4 @@ -%bs.raw(`require('./HeroGraphic.css')`) +%raw(`require('./HeroGraphic.css')`) @react.component let make = (~width="760", ~height="380") => diff --git a/jscomp/syntax/benchmarks/data/RedBlackTree.ml b/jscomp/syntax/benchmarks/data/RedBlackTree.ml index 6e2551caa7..b2a0b42e7c 100644 --- a/jscomp/syntax/benchmarks/data/RedBlackTree.ml +++ b/jscomp/syntax/benchmarks/data/RedBlackTree.ml @@ -193,7 +193,7 @@ let removeNode rbt node = let (successor, isLeaf) = match successor with | None -> - let leaf = createNode ~value:([%bs.raw "0"]) ~color:Black ~height:0. in + let leaf = createNode ~value:([%raw "0"]) ~color:Black ~height:0. in let isLeaf = ((fun x -> x == leaf)[@bs ]) in (leaf, isLeaf) | Some successor -> (successor, (((fun _ -> false))[@bs ])) in let nodeParent = nodeToRemove.parent in diff --git a/jscomp/syntax/benchmarks/data/RedBlackTree.res b/jscomp/syntax/benchmarks/data/RedBlackTree.res index fbf68c266e..409c4feb32 100644 --- a/jscomp/syntax/benchmarks/data/RedBlackTree.res +++ b/jscomp/syntax/benchmarks/data/RedBlackTree.res @@ -334,7 +334,7 @@ let removeNode = (rbt, node) => { } let (successor, isLeaf) = switch successor { | None => - let leaf = createNode(~value=%bs.raw("0"), ~color=Black, ~height=0.) + let leaf = createNode(~value=%raw("0"), ~color=Black, ~height=0.) let isLeaf = (. x) => x === leaf; (leaf, isLeaf) | Some(successor) => diff --git a/jscomp/syntax/benchmarks/data/RedBlackTreeNoComments.res b/jscomp/syntax/benchmarks/data/RedBlackTreeNoComments.res index 67a2a5463c..6f68764300 100644 --- a/jscomp/syntax/benchmarks/data/RedBlackTreeNoComments.res +++ b/jscomp/syntax/benchmarks/data/RedBlackTreeNoComments.res @@ -252,7 +252,7 @@ let removeNode = (rbt, node) => { } let (successor, isLeaf) = switch successor { | None => - let leaf = createNode(~value=%bs.raw("0"), ~color=Black, ~height=0.) + let leaf = createNode(~value=%raw("0"), ~color=Black, ~height=0.) let isLeaf = (. x) => x === leaf (leaf, isLeaf) | Some(successor) => (successor, (. _) => false) diff --git a/jscomp/syntax/tests/idempotency/bs-webapi/tests/Webapi/Webapi__Dom/Webapi__Dom__Document__test.res b/jscomp/syntax/tests/idempotency/bs-webapi/tests/Webapi/Webapi__Dom/Webapi__Dom__Document__test.res index bee60a1847..4a734f9ef0 100644 --- a/jscomp/syntax/tests/idempotency/bs-webapi/tests/Webapi/Webapi__Dom/Webapi__Dom__Document__test.res +++ b/jscomp/syntax/tests/idempotency/bs-webapi/tests/Webapi/Webapi__Dom/Webapi__Dom__Document__test.res @@ -75,7 +75,7 @@ let _ = importNode(el, document) let _ = importNodeDeep(el, document) /* TODO: These get dead code eliminated let _ = registerElement(document, "my-component"); -let _ = registerElementWithOptions(document, "my-component", [%bs.raw "{}"]); +let _ = registerElementWithOptions(document, "my-component", [%raw "{}"]); */ let _ = getElementById("root", document) let _ = querySelector(".lstlisting", document) diff --git a/jscomp/syntax/tests/idempotency/wildcards-world-ui/SsrEntryPoint.res b/jscomp/syntax/tests/idempotency/wildcards-world-ui/SsrEntryPoint.res index f85b346e06..8bffc6131f 100644 --- a/jscomp/syntax/tests/idempotency/wildcards-world-ui/SsrEntryPoint.res +++ b/jscomp/syntax/tests/idempotency/wildcards-world-ui/SsrEntryPoint.res @@ -1,4 +1,4 @@ -// [%bs.raw {|require("./custom.css")|}]; +// [%raw {|require("./custom.css")|}]; open Globals module Router = { diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/block.res b/jscomp/syntax/tests/parsing/grammar/expressions/block.res index bce0a822dd..a7af95bc5c 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/block.res +++ b/jscomp/syntax/tests/parsing/grammar/expressions/block.res @@ -130,7 +130,7 @@ let reifyStyle = (type a, x: 'a): (style, a) => { @val external canvasGradient: constructor = "CanvasGradient" /* internal */ @val external canvasPattern: constructor = "CanvasPattern" /* internal */ let instanceOf = ( - %bs.raw(`function(x,y) {return +(x instanceof y)}`): ('a, constructor) => bool + %raw(`function(x,y) {return +(x instanceof y)}`): ('a, constructor) => bool ) /* internal */ } diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/block.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/block.res.txt index 7309a686a3..6777f28579 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/block.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/block.res.txt @@ -49,7 +49,7 @@ let reifyStyle (type a) (x : 'a) = external canvasGradient : constructor = "CanvasGradient"[@@val ] external canvasPattern : constructor = "CanvasPattern"[@@val ] let instanceOf = - ([%bs.raw + ([%raw (({js|function(x,y) {return +(x instanceof y)}|js}) [@res.template ])] : 'a -> constructor -> bool) end in diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/extension.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/extension.res.txt index b97d310d57..21b88f9fcb 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/extension.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/extension.res.txt @@ -2,4 +2,4 @@ ;;[%expr.extension ] ;;[%expr.extension.with.args {js|argument|js}] ;;[%expr.extension.with.args fun x -> f x] -let x = ([%bs.raw {js|1|js}]) + ([%bs.raw {js|2|js}]) \ No newline at end of file +let x = ([%raw {js|1|js}]) + ([%raw {js|2|js}]) \ No newline at end of file diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/extension.res b/jscomp/syntax/tests/parsing/grammar/expressions/extension.res index 8f363f442d..c7a62d6c6a 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/extension.res +++ b/jscomp/syntax/tests/parsing/grammar/expressions/extension.res @@ -6,4 +6,4 @@ %expr.extension.with.args(x => f(x)) -let x = %bs.raw("1") + %bs.raw("2") +let x = %raw("1") + %raw("2") diff --git a/jscomp/syntax/tests/parsing/grammar/pattern/expected/extension.res.txt b/jscomp/syntax/tests/parsing/grammar/pattern/expected/extension.res.txt index 1f14e53578..ca0ed6d49f 100644 --- a/jscomp/syntax/tests/parsing/grammar/pattern/expected/extension.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/pattern/expected/extension.res.txt @@ -1,8 +1,8 @@ let [%patternExtension ] = () let [%pattern.extension ] = () -let [%bs.raw {js|x|js}] = () -let ([%bs.raw {js|x|js}] : unit) = () -let [%bs.raw {js|x|js}] as y = () +let [%raw {js|x|js}] = () +let ([%raw {js|x|js}] : unit) = () +let [%raw {js|x|js}] as y = () let [%patExt1 ]|[%patExt2 ] = () ;;match x with | [%patternExtension ] -> () @@ -13,10 +13,10 @@ let [%patExt1 ]|[%patExt2 ] = () | [%patExt1 ]|[%patExt2 ] -> () let f [%patternExtension ] = () let f [%pattern.extension ] = () -let f [%bs.raw {js|x|js}] = () -let f [%bs.raw {js|x|js}] [%bs.raw {js|y|js}] = () -let f ([%bs.raw {js|x|js}] as _y) = () -let f ([%bs.raw {js|x|js}] : unit) = () +let f [%raw {js|x|js}] = () +let f [%raw {js|x|js}] [%raw {js|y|js}] = () +let f ([%raw {js|x|js}] as _y) = () +let f ([%raw {js|x|js}] : unit) = () let f ([%patExt1 ]|[%patExt2 ]) = () ;;for [%ext ] = x to y do () done ;;for [%ext1 ]|[%ext2 ] = x to y do () done diff --git a/jscomp/syntax/tests/parsing/grammar/pattern/extension.res b/jscomp/syntax/tests/parsing/grammar/pattern/extension.res index a24db1a8ce..c04a2a3faa 100644 --- a/jscomp/syntax/tests/parsing/grammar/pattern/extension.res +++ b/jscomp/syntax/tests/parsing/grammar/pattern/extension.res @@ -2,9 +2,9 @@ let %patternExtension = () let %pattern.extension = () -let %bs.raw("x") = () -let (%bs.raw("x") : unit) = () -let %bs.raw("x") as y = () +let %raw("x") = () +let (%raw("x") : unit) = () +let %raw("x") as y = () let %patExt1 | %patExt2 = () @@ -19,10 +19,10 @@ switch x { let f = (%patternExtension) => () let f = (%pattern.extension) => () -let f = (%bs.raw("x")) => () -let f = (%bs.raw("x"), %bs.raw("y")) => () -let f = (%bs.raw("x") as _y) => () -let f = (%bs.raw("x") : unit) => () +let f = (%raw("x")) => () +let f = (%raw("x"), %raw("y")) => () +let f = (%raw("x") as _y) => () +let f = (%raw("x") : unit) => () let f = (%patExt1 | %patExt2) => () for %ext in x to y { () } diff --git a/jscomp/test/mt.res b/jscomp/test/mt.res index 5810bfac2a..aaf6e225bc 100644 --- a/jscomp/test/mt.res +++ b/jscomp/test/mt.res @@ -277,7 +277,7 @@ let old_from_promise_suites_donotuse = (name, suites: list<(string, Js.Promise.t Note that [require] is a file local value, we need type [require] -let is_top : unit -> bool = [%bs.raw{| +let is_top : unit -> bool = [%raw{| function (_){ console.log('hi'); if (typeof require === "undefined"){ diff --git a/jscomp/test/unsafe_ppx_test.res b/jscomp/test/unsafe_ppx_test.res index 7bc594e045..2b4b48eaf6 100644 --- a/jscomp/test/unsafe_ppx_test.res +++ b/jscomp/test/unsafe_ppx_test.res @@ -3,7 +3,7 @@ let x: string = %raw(`"\\x01\\x02\\x03"`) let max: (. float, float) => float = %raw("Math.max") let u = v => max(. 1., v) -/* let max2 : float -> float -> float = [%bs.raw {Math.max} ] */ +/* let max2 : float -> float -> float = [%raw {Math.max} ] */ %%raw(` function $$test(x,y){ From b12eaca93215df8d34a353b272435cfd43ef1259 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 13:44:04 +0100 Subject: [PATCH 09/14] @bs.re -> @re --- jscomp/frontend/ast_exp_extension.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jscomp/frontend/ast_exp_extension.ml b/jscomp/frontend/ast_exp_extension.ml index cd52ba9674..4317f8a52a 100644 --- a/jscomp/frontend/ast_exp_extension.ml +++ b/jscomp/frontend/ast_exp_extension.ml @@ -28,7 +28,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper) match txt with | "ffi" -> Ast_exp_handle_external.handle_ffi ~loc ~payload | "raw" -> Ast_exp_handle_external.handle_raw ~kind:Raw_exp loc payload - | "bs.re" | "re" -> + | "re" -> Exp.constraint_ ~loc (Ast_exp_handle_external.handle_raw ~kind:Raw_re loc payload) (Ast_comb.to_js_re_type loc) From ca660413afc55cbcb672ede76ba92610f4dfcdda Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 13:44:39 +0100 Subject: [PATCH 10/14] @bs.time -> @time --- jscomp/frontend/ast_exp_extension.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jscomp/frontend/ast_exp_extension.ml b/jscomp/frontend/ast_exp_extension.ml index 4317f8a52a..8cd6bf75fc 100644 --- a/jscomp/frontend/ast_exp_extension.ml +++ b/jscomp/frontend/ast_exp_extension.ml @@ -42,7 +42,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper) *) | None | Some _ -> Location.raise_errorf ~loc "external expects a single identifier") - | "bs.time" | "time" -> ( + | "time" -> ( match payload with | PStr [{pstr_desc = Pstr_eval (e, _)}] -> let locString = From 3b5f75c01db778b32691f2a1a2b312742a904f41 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 13:46:00 +0100 Subject: [PATCH 11/14] @bs.config -> @config --- jscomp/bsc/rescript_compiler_main.ml | 2 +- .../react_ppx/src/recursive_component_test.res | 2 +- jscomp/frontend/ast_config.ml | 14 ++++---------- jscomp/frontend/bs_builtin_ppx.ml | 2 +- jscomp/ml/ast_payload.mli | 6 +++--- jscomp/others/belt_List.res | 2 +- jscomp/others/belt_internalAVLset.res | 2 +- jscomp/others/belt_internalAVLtree.res | 2 +- jscomp/others/belt_internalMapInt.res | 2 +- jscomp/others/belt_internalMapString.res | 2 +- jscomp/others/internal_map.cppo.res | 2 +- jscomp/others/js.ml | 2 +- jscomp/others/js_OO.res | 2 +- jscomp/runtime/caml_hash.res | 2 +- jscomp/runtime/js.ml | 2 +- jscomp/stdlib-406/callback.res | 2 +- jscomp/stdlib-406/camlinternalLazy.res | 2 +- jscomp/stdlib-406/sys.res | 2 +- jscomp/syntax/tests/idempotency/mareo/Main.res | 2 +- .../CoursesCurriculum__SubmissionBuilder.res | 2 +- .../courses/SubmissionChecklistItemShow.res | 2 +- ...CurriculumEditor__TargetChecklistItemEditor.res | 2 +- .../idempotency/reductive/reductiveContext.res | 2 +- .../tests/idempotency/reductive/subscription.res | 2 +- jscomp/test/alias_default_value_test.res | 2 +- jscomp/test/bs_MapInt_test.res | 2 +- jscomp/test/config1_test.res | 2 +- jscomp/test/debug_mode_value.res | 2 +- jscomp/test/gpr_1698_test.res | 2 +- jscomp/test/gpr_2682_test.res | 2 +- jscomp/test/gpr_4280_test.res | 2 +- jscomp/test/gpr_459_test.res | 2 +- jscomp/test/include_side_effect.res | 2 +- jscomp/test/include_side_effect_free.res | 2 +- jscomp/test/inline_string_test.res | 2 +- jscomp/test/jsxv4_newtype.res | 2 +- jscomp/test/key_word_property.res | 2 +- jscomp/test/mario_game.res | 2 +- jscomp/test/mutable_uncurry_test.res | 2 +- jscomp/test/obj_magic_test.res | 2 +- jscomp/test/ocaml_re_test.res | 2 +- jscomp/test/poly_empty_array.res | 2 +- jscomp/test/polyvar_test.res | 2 +- jscomp/test/rec_module_opt.res | 2 +- jscomp/test/record_debug_test.res | 2 +- jscomp/test/recursive_react_component.res | 2 +- jscomp/test/string_get_set_test.res | 2 +- jscomp/test/tramp_fib.res | 2 +- jscomp/test/unit_undefined_test.res | 2 +- 49 files changed, 54 insertions(+), 60 deletions(-) diff --git a/jscomp/bsc/rescript_compiler_main.ml b/jscomp/bsc/rescript_compiler_main.ml index b59f22f661..9173948f47 100644 --- a/jscomp/bsc/rescript_compiler_main.ml +++ b/jscomp/bsc/rescript_compiler_main.ml @@ -457,7 +457,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array = -(** parse flags in bs.config *) +(** parse flags in config *) let file_level_flags_handler (e : Parsetree.expression option) = match e with | None -> () diff --git a/jscomp/build_tests/react_ppx/src/recursive_component_test.res b/jscomp/build_tests/react_ppx/src/recursive_component_test.res index cdd39ebc09..70682b0c69 100644 --- a/jscomp/build_tests/react_ppx/src/recursive_component_test.res +++ b/jscomp/build_tests/react_ppx/src/recursive_component_test.res @@ -1,7 +1,7 @@ @@warning("-39") // https://github.com/rescript-lang/rescript-compiler/issues/4511 /* -[@bs.config { +[@config { flags : [|"-dsource"|] }]; */ diff --git a/jscomp/frontend/ast_config.ml b/jscomp/frontend/ast_config.ml index 9f7eb7e311..c45c04c367 100644 --- a/jscomp/frontend/ast_config.ml +++ b/jscomp/frontend/ast_config.ml @@ -57,11 +57,8 @@ let process_directives str = let rec iter_on_bs_config_str (x : Parsetree.structure) = match x with | [] -> () - | { - pstr_desc = - Pstr_attribute (({txt = "bs.config" | "config"; loc}, payload) as attr); - } - :: _ -> + | {pstr_desc = Pstr_attribute (({txt = "config"; loc}, payload) as attr)} :: _ + -> Bs_ast_invariant.mark_used_bs_attribute attr; Ext_list.iter (Ast_payload.ident_or_record_as_config loc payload) @@ -76,11 +73,8 @@ let process_str str = let rec iter_on_bs_config_sig (x : Parsetree.signature) = match x with | [] -> () - | { - psig_desc = - Psig_attribute (({txt = "bs.config" | "config"; loc}, payload) as attr); - } - :: _ -> + | {psig_desc = Psig_attribute (({txt = "config"; loc}, payload) as attr)} :: _ + -> Bs_ast_invariant.mark_used_bs_attribute attr; Ext_list.iter (Ast_payload.ident_or_record_as_config loc payload) diff --git a/jscomp/frontend/bs_builtin_ppx.ml b/jscomp/frontend/bs_builtin_ppx.ml index 16391ce757..ea0be00e1f 100644 --- a/jscomp/frontend/bs_builtin_ppx.ml +++ b/jscomp/frontend/bs_builtin_ppx.ml @@ -467,7 +467,7 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) : Pstr_value (Nonrecursive, [{pvb_pat; pvb_expr; pvb_attributes; pvb_loc}]); }) - | Pstr_attribute ({txt = "bs.config" | "config"}, _) -> str + | Pstr_attribute ({txt = "config"}, _) -> str | _ -> default_mapper.structure_item self str let local_module_name = diff --git a/jscomp/ml/ast_payload.mli b/jscomp/ml/ast_payload.mli index addd8f9116..ef9964b8e2 100644 --- a/jscomp/ml/ast_payload.mli +++ b/jscomp/ml/ast_payload.mli @@ -63,11 +63,11 @@ val assert_strings : Location.t -> t -> string list (** as a record or empty it will accept - {[ [@@@bs.config ]]} + {[ [@@@config ]]} or - {[ [@@@bs.config no_export ] ]} + {[ [@@@config no_export ] ]} or - {[ [@@@bs.config { property .. } ]]} + {[ [@@@config { property .. } ]]} Note that we only {[ { flat_property} diff --git a/jscomp/others/belt_List.res b/jscomp/others/belt_List.res index e3f73fd71b..e96d69986c 100644 --- a/jscomp/others/belt_List.res +++ b/jscomp/others/belt_List.res @@ -59,7 +59,7 @@ ``` */ -@@bs.config({flags: ["-bs-noassertfalse"]}) +@@config({flags: ["-bs-noassertfalse"]}) type t<'a> = list<'a> diff --git a/jscomp/others/belt_internalAVLset.res b/jscomp/others/belt_internalAVLset.res index 1fedc4ff4c..e8cec936f0 100644 --- a/jscomp/others/belt_internalAVLset.res +++ b/jscomp/others/belt_internalAVLset.res @@ -21,7 +21,7 @@ * 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. */ -@@bs.config({flags: ["-bs-noassertfalse"]}) +@@config({flags: ["-bs-noassertfalse"]}) type rec node<'value> = { @as("v") mutable value: 'value, @as("h") mutable height: int, diff --git a/jscomp/others/belt_internalAVLtree.res b/jscomp/others/belt_internalAVLtree.res index ff557badf9..1ff41c7256 100644 --- a/jscomp/others/belt_internalAVLtree.res +++ b/jscomp/others/belt_internalAVLtree.res @@ -13,7 +13,7 @@ /* Almost rewritten by authors of ReScript */ -@@bs.config({flags: ["-bs-noassertfalse"]}) +@@config({flags: ["-bs-noassertfalse"]}) type rec node<'k, 'v> = { @as("k") mutable key: 'k, @as("v") mutable value: 'v, diff --git a/jscomp/others/belt_internalMapInt.res b/jscomp/others/belt_internalMapInt.res index 86d18f7bea..36d292842b 100644 --- a/jscomp/others/belt_internalMapInt.res +++ b/jscomp/others/belt_internalMapInt.res @@ -1,4 +1,4 @@ -@@bs.config({flags: ["-bs-noassertfalse"]}) +@@config({flags: ["-bs-noassertfalse"]}) type key = int diff --git a/jscomp/others/belt_internalMapString.res b/jscomp/others/belt_internalMapString.res index e088f69781..cf8ab58f99 100644 --- a/jscomp/others/belt_internalMapString.res +++ b/jscomp/others/belt_internalMapString.res @@ -1,4 +1,4 @@ -@@bs.config({flags: ["-bs-noassertfalse"]}) +@@config({flags: ["-bs-noassertfalse"]}) type key = string diff --git a/jscomp/others/internal_map.cppo.res b/jscomp/others/internal_map.cppo.res index 0afe893c6a..bea7b72481 100644 --- a/jscomp/others/internal_map.cppo.res +++ b/jscomp/others/internal_map.cppo.res @@ -1,4 +1,4 @@ -@@bs.config({flags: ["-bs-noassertfalse"]}) +@@config({flags: ["-bs-noassertfalse"]}) #ifdef TYPE_STRING type key = string diff --git a/jscomp/others/js.ml b/jscomp/others/js.ml index 64a3661f38..621871c4c3 100644 --- a/jscomp/others/js.ml +++ b/jscomp/others/js.ml @@ -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. *) -[@@@bs.config {flags = [|"-unboxed-types"; "-w"; "-49"|]}] +[@@@config {flags = [|"-unboxed-types"; "-w"; "-49"|]}] (* DESIGN: - It does not have any code, all its code will be inlined so that there will never be diff --git a/jscomp/others/js_OO.res b/jscomp/others/js_OO.res index e568c95066..033ab69b60 100644 --- a/jscomp/others/js_OO.res +++ b/jscomp/others/js_OO.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. */ -@@bs.config({flags: ["-unboxed-types"]}) +@@config({flags: ["-unboxed-types"]}) external unsafe_to_method: 'a => 'a = "#fn_method" diff --git a/jscomp/runtime/caml_hash.res b/jscomp/runtime/caml_hash.res index 60542c5d69..b33bedb049 100644 --- a/jscomp/runtime/caml_hash.res +++ b/jscomp/runtime/caml_hash.res @@ -21,7 +21,7 @@ * 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. */ -@@bs.config({flags: ["-bs-noassertfalse"]}) +@@config({flags: ["-bs-noassertfalse"]}) type rec cell<'a> = { content: 'a, mutable next: option>, diff --git a/jscomp/runtime/js.ml b/jscomp/runtime/js.ml index d62961a2da..e816b2dd59 100644 --- a/jscomp/runtime/js.ml +++ b/jscomp/runtime/js.ml @@ -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. *) -[@@@bs.config {flags = [|"-unboxed-types"; "-w"; "-49"|]}] +[@@@config {flags = [|"-unboxed-types"; "-w"; "-49"|]}] (* DESIGN: - It does not have any code, all its code will be inlined so that there will never be diff --git a/jscomp/stdlib-406/callback.res b/jscomp/stdlib-406/callback.res index 66378892f0..89d44b6368 100644 --- a/jscomp/stdlib-406/callback.res +++ b/jscomp/stdlib-406/callback.res @@ -12,7 +12,7 @@ /* special exception on linking described in the file LICENSE. */ /* */ /* ************************************************************************ */ -@@bs.config({flags: ["-bs-no-cross-module-opt"]}) +@@config({flags: ["-bs-no-cross-module-opt"]}) /* Registering OCaml values with the C runtime for later callbacks */ let register = (_, _) => () diff --git a/jscomp/stdlib-406/camlinternalLazy.res b/jscomp/stdlib-406/camlinternalLazy.res index 4db5dddacc..f93ce9058a 100644 --- a/jscomp/stdlib-406/camlinternalLazy.res +++ b/jscomp/stdlib-406/camlinternalLazy.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. */ -@@bs.config({flags: ["-bs-no-cross-module-opt"]}) +@@config({flags: ["-bs-no-cross-module-opt"]}) /* Internals of forcing lazy values. */ type t<'a> = { diff --git a/jscomp/stdlib-406/sys.res b/jscomp/stdlib-406/sys.res index bffe3aaf29..947c892f61 100644 --- a/jscomp/stdlib-406/sys.res +++ b/jscomp/stdlib-406/sys.res @@ -1,4 +1,4 @@ -@@bs.config({flags: ["-bs-no-cross-module-opt"]}) +@@config({flags: ["-bs-no-cross-module-opt"]}) /* ************************************************************************ */ /* */ /* OCaml */ diff --git a/jscomp/syntax/tests/idempotency/mareo/Main.res b/jscomp/syntax/tests/idempotency/mareo/Main.res index 2d742a7454..16f0ffb1b1 100644 --- a/jscomp/syntax/tests/idempotency/mareo/Main.res +++ b/jscomp/syntax/tests/idempotency/mareo/Main.res @@ -1,4 +1,4 @@ -@@bs.config({no_export: no_export}) +@@config({no_export: no_export}) open Belt diff --git a/jscomp/syntax/tests/idempotency/pupilfirst/courses/CoursesCurriculum__SubmissionBuilder.res b/jscomp/syntax/tests/idempotency/pupilfirst/courses/CoursesCurriculum__SubmissionBuilder.res index 3c1b082388..93ca1719d4 100644 --- a/jscomp/syntax/tests/idempotency/pupilfirst/courses/CoursesCurriculum__SubmissionBuilder.res +++ b/jscomp/syntax/tests/idempotency/pupilfirst/courses/CoursesCurriculum__SubmissionBuilder.res @@ -1,4 +1,4 @@ -@@bs.config({jsx: 3}) +@@config({jsx: 3}) open CoursesCurriculum__Types diff --git a/jscomp/syntax/tests/idempotency/pupilfirst/courses/SubmissionChecklistItemShow.res b/jscomp/syntax/tests/idempotency/pupilfirst/courses/SubmissionChecklistItemShow.res index 8f9024aea0..60fd0249ce 100644 --- a/jscomp/syntax/tests/idempotency/pupilfirst/courses/SubmissionChecklistItemShow.res +++ b/jscomp/syntax/tests/idempotency/pupilfirst/courses/SubmissionChecklistItemShow.res @@ -1,4 +1,4 @@ -@@bs.config({jsx: 3}) +@@config({jsx: 3}) module ChecklistItem = SubmissionChecklistItem diff --git a/jscomp/syntax/tests/idempotency/pupilfirst/schools/CurriculumEditor__TargetChecklistItemEditor.res b/jscomp/syntax/tests/idempotency/pupilfirst/schools/CurriculumEditor__TargetChecklistItemEditor.res index faf609a9c8..a2ef33216b 100644 --- a/jscomp/syntax/tests/idempotency/pupilfirst/schools/CurriculumEditor__TargetChecklistItemEditor.res +++ b/jscomp/syntax/tests/idempotency/pupilfirst/schools/CurriculumEditor__TargetChecklistItemEditor.res @@ -1,4 +1,4 @@ -@@bs.config({jsx: 3}) +@@config({jsx: 3}) open CurriculumEditor__Types diff --git a/jscomp/syntax/tests/idempotency/reductive/reductiveContext.res b/jscomp/syntax/tests/idempotency/reductive/reductiveContext.res index 0d994d2ba4..4faa0e5add 100644 --- a/jscomp/syntax/tests/idempotency/reductive/reductiveContext.res +++ b/jscomp/syntax/tests/idempotency/reductive/reductiveContext.res @@ -1,4 +1,4 @@ -@@bs.config({jsx: 3}) +@@config({jsx: 3}) module type Config = { type state type action diff --git a/jscomp/syntax/tests/idempotency/reductive/subscription.res b/jscomp/syntax/tests/idempotency/reductive/subscription.res index d87978b3fd..2b6e4d70b4 100644 --- a/jscomp/syntax/tests/idempotency/reductive/subscription.res +++ b/jscomp/syntax/tests/idempotency/reductive/subscription.res @@ -1,4 +1,4 @@ -@@bs.config({jsx: 3}) +@@config({jsx: 3}) @deriving({jsConverter: newType}) type source<'a> = { diff --git a/jscomp/test/alias_default_value_test.res b/jscomp/test/alias_default_value_test.res index 68d6a8b5f8..5bdeda0728 100644 --- a/jscomp/test/alias_default_value_test.res +++ b/jscomp/test/alias_default_value_test.res @@ -1,4 +1,4 @@ -@@bs.config({ +@@config({ flags: ["-bs-jsx", "4"], }) diff --git a/jscomp/test/bs_MapInt_test.res b/jscomp/test/bs_MapInt_test.res index a09919cdcb..a66fa9f58f 100644 --- a/jscomp/test/bs_MapInt_test.res +++ b/jscomp/test/bs_MapInt_test.res @@ -1,4 +1,4 @@ -@@bs.config({flags: ["-bs-no-cross-module-opt"]}) +@@config({flags: ["-bs-no-cross-module-opt"]}) let should = b => if !b { Js.Exn.raiseError("IMPOSSIBLE") diff --git a/jscomp/test/config1_test.res b/jscomp/test/config1_test.res index 15c7ddcf26..319fe1c9bb 100644 --- a/jscomp/test/config1_test.res +++ b/jscomp/test/config1_test.res @@ -1,3 +1,3 @@ -@@bs.config(no_export) +@@config(no_export) let a = 3 diff --git a/jscomp/test/debug_mode_value.res b/jscomp/test/debug_mode_value.res index b2b010d909..3b63c9df68 100644 --- a/jscomp/test/debug_mode_value.res +++ b/jscomp/test/debug_mode_value.res @@ -1,4 +1,4 @@ -@@bs.config({ +@@config({ flags: [ /* "-drawlambda"; */ /* "-dlambda"; */ diff --git a/jscomp/test/gpr_1698_test.res b/jscomp/test/gpr_1698_test.res index 0cfd35ad6b..b49992f479 100644 --- a/jscomp/test/gpr_1698_test.res +++ b/jscomp/test/gpr_1698_test.res @@ -1,4 +1,4 @@ -@@bs.config({no_export: true}) +@@config({no_export: true}) type value = | Natural(int) | Symbol(string) diff --git a/jscomp/test/gpr_2682_test.res b/jscomp/test/gpr_2682_test.res index 638604b79c..7a21ef4665 100644 --- a/jscomp/test/gpr_2682_test.res +++ b/jscomp/test/gpr_2682_test.res @@ -1,5 +1,5 @@ @@warning("-22") -/* [@@@bs.config no_export] */ +/* [@@@config no_export] */ /* let for_each n = ([%raw{| for (var key in n){ diff --git a/jscomp/test/gpr_4280_test.res b/jscomp/test/gpr_4280_test.res index a8c039a3d6..ac0fc6e15e 100644 --- a/jscomp/test/gpr_4280_test.res +++ b/jscomp/test/gpr_4280_test.res @@ -1,4 +1,4 @@ -@@bs.config({flags: [/* "-bs-diagnose" */]}) +@@config({flags: [/* "-bs-diagnose" */]}) let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) diff --git a/jscomp/test/gpr_459_test.res b/jscomp/test/gpr_459_test.res index dcbce38181..e4e51bda81 100644 --- a/jscomp/test/gpr_459_test.res +++ b/jscomp/test/gpr_459_test.res @@ -1,4 +1,4 @@ -@@bs.config({no_export: no_export}) +@@config({no_export: no_export}) let suites: ref = ref(list{}) let test_id = ref(0) diff --git a/jscomp/test/include_side_effect.res b/jscomp/test/include_side_effect.res index 14f7d6dc6a..2652357abc 100644 --- a/jscomp/test/include_side_effect.res +++ b/jscomp/test/include_side_effect.res @@ -1,2 +1,2 @@ -@@bs.config({no_export: no_export}) +@@config({no_export: no_export}) include Side_effect diff --git a/jscomp/test/include_side_effect_free.res b/jscomp/test/include_side_effect_free.res index 92bf8eea56..1b16ed1576 100644 --- a/jscomp/test/include_side_effect_free.res +++ b/jscomp/test/include_side_effect_free.res @@ -1,4 +1,4 @@ -@@bs.config(no_export) +@@config(no_export) /* since it is side effect free , this should generate a dummy file */ include Side_effect_free diff --git a/jscomp/test/inline_string_test.res b/jscomp/test/inline_string_test.res index 6bcc79f4ce..4264e2be32 100644 --- a/jscomp/test/inline_string_test.res +++ b/jscomp/test/inline_string_test.res @@ -1,4 +1,4 @@ -@@bs.config({no_export: no_export}) +@@config({no_export: no_export}) type t = | A_list | A_hashtable diff --git a/jscomp/test/jsxv4_newtype.res b/jscomp/test/jsxv4_newtype.res index 8989c18998..62919a8284 100644 --- a/jscomp/test/jsxv4_newtype.res +++ b/jscomp/test/jsxv4_newtype.res @@ -1,4 +1,4 @@ -@@bs.config({ +@@config({ flags: ["-bs-jsx", "4"], }) diff --git a/jscomp/test/key_word_property.res b/jscomp/test/key_word_property.res index cece2e9d25..d5282aa5c6 100644 --- a/jscomp/test/key_word_property.res +++ b/jscomp/test/key_word_property.res @@ -1,4 +1,4 @@ -/* [@@@bs.config {flags = [| +/* [@@@config {flags = [| "-bs-package-output"; "es6:jscomp/test" |]}] */ diff --git a/jscomp/test/mario_game.res b/jscomp/test/mario_game.res index dfd833f693..4dc4f04851 100644 --- a/jscomp/test/mario_game.res +++ b/jscomp/test/mario_game.res @@ -1,4 +1,4 @@ -@@bs.config({flags: ["-w", "a", "-bs-no-bin-annot"]}) +@@config({flags: ["-w", "a", "-bs-no-bin-annot"]}) module Actors: { type dir_1d = Left | Right diff --git a/jscomp/test/mutable_uncurry_test.res b/jscomp/test/mutable_uncurry_test.res index 8acbd3401d..3754f69662 100644 --- a/jscomp/test/mutable_uncurry_test.res +++ b/jscomp/test/mutable_uncurry_test.res @@ -1,4 +1,4 @@ -@@bs.config({ +@@config({ flags: [ /* "-bs-diagnose" */ ], diff --git a/jscomp/test/obj_magic_test.res b/jscomp/test/obj_magic_test.res index eaed75b587..4c67bc866c 100644 --- a/jscomp/test/obj_magic_test.res +++ b/jscomp/test/obj_magic_test.res @@ -1,4 +1,4 @@ -@@bs.config({ +@@config({ flags: [ /* "-drawlambda" */ ], diff --git a/jscomp/test/ocaml_re_test.res b/jscomp/test/ocaml_re_test.res index d4b40171c6..c75c80134b 100644 --- a/jscomp/test/ocaml_re_test.res +++ b/jscomp/test/ocaml_re_test.res @@ -1,4 +1,4 @@ -@@bs.config({flags: ["-w", "a", "-bs-no-bin-annot"], no_export}) +@@config({flags: ["-w", "a", "-bs-no-bin-annot"], no_export}) let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => { diff --git a/jscomp/test/poly_empty_array.res b/jscomp/test/poly_empty_array.res index 63ee85b156..06375bd609 100644 --- a/jscomp/test/poly_empty_array.res +++ b/jscomp/test/poly_empty_array.res @@ -1,2 +1,2 @@ -@@bs.config({flags: ["-bs-unsafe-empty-array"]}) +@@config({flags: ["-bs-unsafe-empty-array"]}) let a = [] diff --git a/jscomp/test/polyvar_test.res b/jscomp/test/polyvar_test.res index 7758f58f30..ed27d1cc3e 100644 --- a/jscomp/test/polyvar_test.res +++ b/jscomp/test/polyvar_test.res @@ -1,4 +1,4 @@ -@@bs.config(no_export) +@@config(no_export) let f = x => switch x { diff --git a/jscomp/test/rec_module_opt.res b/jscomp/test/rec_module_opt.res index 816cf1deed..a3e36cdda7 100644 --- a/jscomp/test/rec_module_opt.res +++ b/jscomp/test/rec_module_opt.res @@ -1,4 +1,4 @@ -@@bs.config({ +@@config({ flags: [ /* "-drawlambda"; */ /* "-dlambda"; */ diff --git a/jscomp/test/record_debug_test.res b/jscomp/test/record_debug_test.res index 208c09826c..8fed66a72c 100644 --- a/jscomp/test/record_debug_test.res +++ b/jscomp/test/record_debug_test.res @@ -1,4 +1,4 @@ -/* [@@@bs.config {flags = [|"-dsource"|]}] */ +/* [@@@config {flags = [|"-dsource"|]}] */ let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) diff --git a/jscomp/test/recursive_react_component.res b/jscomp/test/recursive_react_component.res index c6437ceb53..8e2756aa79 100644 --- a/jscomp/test/recursive_react_component.res +++ b/jscomp/test/recursive_react_component.res @@ -1,4 +1,4 @@ -@@bs.config({ +@@config({ flags: [ "-bs-jsx", "3", // "-dsource", diff --git a/jscomp/test/string_get_set_test.res b/jscomp/test/string_get_set_test.res index 6399809a57..3e9b4b076a 100644 --- a/jscomp/test/string_get_set_test.res +++ b/jscomp/test/string_get_set_test.res @@ -1,4 +1,4 @@ -@@bs.config({no_export: no_export}) +@@config({no_export: no_export}) let \".%()" = (s: string, i) => String.get(s, i) Mt.from_pair_suites(__FILE__, list{(__LOC__, _ => Eq(\".%()"("h", 0), 'h'))}) diff --git a/jscomp/test/tramp_fib.res b/jscomp/test/tramp_fib.res index da165a9e42..92dd521e26 100644 --- a/jscomp/test/tramp_fib.res +++ b/jscomp/test/tramp_fib.res @@ -1,4 +1,4 @@ -@@bs.config({flags: ["-w", "a", "-bs-noassertfalse"]}) +@@config({flags: ["-w", "a", "-bs-noassertfalse"]}) let suites: ref = ref(list{}) let test_id = ref(0) diff --git a/jscomp/test/unit_undefined_test.res b/jscomp/test/unit_undefined_test.res index 492cc01e38..72138880f1 100644 --- a/jscomp/test/unit_undefined_test.res +++ b/jscomp/test/unit_undefined_test.res @@ -1,4 +1,4 @@ -@@bs.config({ +@@config({ flags: [ /* "-bs-diagnose" */ /* ; "-drawlambda" */ From f02409a2cc08b865e0b919056491279625773778 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 14:08:10 +0100 Subject: [PATCH 12/14] Cleanup --- jscomp/frontend/ast_attributes.ml | 3 +- jscomp/frontend/bs_ast_invariant.ml | 13 +++---- jscomp/syntax/src/res_ast_conversion.ml | 12 ------- jscomp/syntax/src/res_printer.ml | 47 ++----------------------- jscomp/syntax/src/res_printer.mli | 3 -- 5 files changed, 7 insertions(+), 71 deletions(-) diff --git a/jscomp/frontend/ast_attributes.ml b/jscomp/frontend/ast_attributes.ml index cf19e85a2f..6cffbed669 100644 --- a/jscomp/frontend/ast_attributes.ml +++ b/jscomp/frontend/ast_attributes.ml @@ -148,8 +148,7 @@ let rs_externals (attrs : t) pval_prim = prims_to_be_encoded pval_prim | _, _ -> Ext_list.exists_fst attrs (fun ({txt} : string Asttypes.loc) -> - Ext_string.starts_with txt "bs." - || Ext_array.exists external_attrs (fun (x : string) -> txt = x)) + Ext_array.exists external_attrs (fun (x : string) -> txt = x)) || prims_to_be_encoded pval_prim let is_inline : attr -> bool = fun ({txt}, _) -> txt = "inline" diff --git a/jscomp/frontend/bs_ast_invariant.ml b/jscomp/frontend/bs_ast_invariant.ml index 47c8b006ad..de87edcdc9 100644 --- a/jscomp/frontend/bs_ast_invariant.ml +++ b/jscomp/frontend/bs_ast_invariant.ml @@ -28,15 +28,10 @@ *) let is_bs_attribute txt = match txt with - (* TODO: Issue 6636 *) - | "string" | "uncurry" -> true - | _ -> - let len = String.length txt in - len >= 2 - (*TODO: check the stringing padding rule, this preciate may not be needed *) - && String.unsafe_get txt 0 = 'b' - && String.unsafe_get txt 1 = 's' - && (len = 2 || String.unsafe_get txt 2 = '.') + | "bs" | "config" | "ignore" | "int" | "optional" | "string" | "uncurry" + | "unwrap" -> + true + | _ -> false let used_attributes : string Asttypes.loc Hash_set_poly.t = Hash_set_poly.create 16 diff --git a/jscomp/syntax/src/res_ast_conversion.ml b/jscomp/syntax/src/res_ast_conversion.ml index b8c419b80f..b274bcaf51 100644 --- a/jscomp/syntax/src/res_ast_conversion.ml +++ b/jscomp/syntax/src/res_ast_conversion.ml @@ -274,18 +274,6 @@ let normalize = let open Ast_mapper in { default_mapper with - extension = - (fun mapper ext -> - match ext with - | id, payload -> - ( {id with txt = Res_printer.convertBsExtension id.txt}, - default_mapper.payload mapper payload )); - attribute = - (fun mapper attr -> - match attr with - | id, payload -> - ( {id with txt = Res_printer.convertBsExternalAttribute id.txt}, - default_mapper.payload mapper payload )); attributes = (fun mapper attrs -> attrs diff --git a/jscomp/syntax/src/res_printer.ml b/jscomp/syntax/src/res_printer.ml index 65b8e91bec..9c0181ee62 100644 --- a/jscomp/syntax/src/res_printer.ml +++ b/jscomp/syntax/src/res_printer.ml @@ -16,49 +16,6 @@ type callbackStyle = *) | ArgumentsFitOnOneLine -(* Since compiler version 8.3, the bs. prefix is no longer needed *) -(* Synced from - https://github.com/rescript-lang/rescript-compiler/blob/29174de1a5fde3b16cf05d10f5ac109cfac5c4ca/jscomp/frontend/ast_external_process.ml#L291-L367 *) -let convertBsExternalAttribute = function - | "bs.as" -> "as" - | "bs.deriving" -> "deriving" - | "bs.get" -> "get" - | "bs.get_index" -> "get_index" - | "bs.ignore" -> "ignore" - | "bs.inline" -> "inline" - | "bs.int" -> "int" - | "bs.meth" -> "meth" - | "bs.module" -> "module" - | "bs.new" -> "new" - | "bs.obj" -> "obj" - | "bs.optional" -> "optional" - | "bs.return" -> "return" - | "bs.send" -> "send" - | "bs.scope" -> "scope" - | "bs.set" -> "set" - | "bs.set_index" -> "set_index" - | "bs.splice" | "bs.variadic" -> "variadic" - | "bs.string" -> "string" - | "bs.this" -> "this" - | "bs.uncurry" -> "uncurry" - | "bs.unwrap" -> "unwrap" - | "bs.val" -> "val" - (* bs.send.pipe shouldn't be transformed *) - | txt -> txt - -(* These haven't been needed for a long time now *) -(* Synced from - https://github.com/rescript-lang/rescript-compiler/blob/29174de1a5fde3b16cf05d10f5ac109cfac5c4ca/jscomp/frontend/ast_exp_extension.ml *) -let convertBsExtension = function - | "bs.debugger" -> "debugger" - | "bs.external" -> "raw" - (* We should never see this one since we use the sugared object form, but still *) - | "bs.obj" -> "obj" - | "bs.raw" -> "raw" - | "bs.re" -> "re" - (* TODO: what about bs.time and bs.node? *) - | txt -> txt - let addParens doc = Doc.group (Doc.concat @@ -2154,7 +2111,7 @@ and printPackageConstraint ~state i cmtTbl (longidentLoc, typ) = ] and printExtension ~state ~atModuleLvl (stringLoc, payload) cmtTbl = - let txt = convertBsExtension stringLoc.Location.txt in + let txt = stringLoc.Location.txt in let extName = let doc = Doc.concat @@ -5466,7 +5423,7 @@ and printAttribute ?(standalone = false) ~state (Doc.concat [ Doc.text (if standalone then "@@" else "@"); - Doc.text (convertBsExternalAttribute id.txt); + Doc.text id.txt; printPayload ~state payload cmtTbl; ]), Doc.line ) diff --git a/jscomp/syntax/src/res_printer.mli b/jscomp/syntax/src/res_printer.mli index 3647dc3790..5253ce6a27 100644 --- a/jscomp/syntax/src/res_printer.mli +++ b/jscomp/syntax/src/res_printer.mli @@ -1,6 +1,3 @@ -val convertBsExternalAttribute : string -> string -val convertBsExtension : string -> string - val printTypeParams : (Parsetree.core_type * Asttypes.variance) list -> Res_comments_table.t -> From 1aebc9d119b8e7ffb70235c978c47039cec6327a Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 18 Feb 2024 17:07:00 +0100 Subject: [PATCH 13/14] Changelog --- CHANGELOG.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14d9eaa053..e61eb1acda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,13 +12,15 @@ # 12.0.0-alpha.1 (Unreleased) -#### :house: Internal - -- Build with OCaml 5.1.1. https://github.com/rescript-lang/rescript-compiler/pull/6641 - #### :boom: Breaking Change - `lazy` syntax is no longer supported. If you're using it, use `Lazy` module or `React.lazy_` instead. https://github.com/rescript-lang/rescript-compiler/pull/6342 +- Remove handling of attributes with `bs.` prefix (`@bs.as` -> `@as` etc.). https://github.com/rescript-lang/rescript-compiler/pull/6643 +- Remove obsolete `@bs.open` feature. https://github.com/rescript-lang/rescript-compiler/pull/6629 + +#### :house: Internal + +- Build with OCaml 5.1.1. https://github.com/rescript-lang/rescript-compiler/pull/6641 # 11.1.0-rc.2 From d662127acaad012d0e519525ee0d52a445ac25f4 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 20 Feb 2024 12:33:13 +0100 Subject: [PATCH 14/14] Deactivate unused argument check for @int --- jscomp/frontend/bs_ast_invariant.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jscomp/frontend/bs_ast_invariant.ml b/jscomp/frontend/bs_ast_invariant.ml index de87edcdc9..5be055870d 100644 --- a/jscomp/frontend/bs_ast_invariant.ml +++ b/jscomp/frontend/bs_ast_invariant.ml @@ -28,8 +28,8 @@ *) let is_bs_attribute txt = match txt with - | "bs" | "config" | "ignore" | "int" | "optional" | "string" | "uncurry" - | "unwrap" -> + (* TODO #6636: | "as "| "int" *) + | "bs" | "config" | "ignore" | "optional" | "string" | "uncurry" | "unwrap" -> true | _ -> false