Skip to content

Commit 1bc9e03

Browse files
authored
Remove remaining "bs." attributes (#6643)
* @bs.string -> @string * @bs.this -> @this * @bs.uncurry -> uncurry * @bs.unwrap -> @unwrap * @bs.val -> @Val * @bs.debugger -> @debugger * @bs.external -> @external * @bs.raw -> @raw * @bs.re -> @re * @bs.time -> @time * @bs.config -> @config * Cleanup * Changelog * Deactivate unused argument check for @int
1 parent 470d034 commit 1bc9e03

File tree

110 files changed

+260
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+260
-333
lines changed

CHANGELOG.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
1313
# 12.0.0-alpha.1 (Unreleased)
1414

15-
#### :house: Internal
16-
17-
- Build with OCaml 5.1.1. https://github.com/rescript-lang/rescript-compiler/pull/6641
18-
1915
#### :boom: Breaking Change
2016

2117
- `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
18+
- Remove handling of attributes with `bs.` prefix (`@bs.as` -> `@as` etc.). https://github.com/rescript-lang/rescript-compiler/pull/6643
19+
- Remove obsolete `@bs.open` feature. https://github.com/rescript-lang/rescript-compiler/pull/6629
20+
21+
#### :house: Internal
22+
23+
- Build with OCaml 5.1.1. https://github.com/rescript-lang/rescript-compiler/pull/6641
2224

2325
# 11.1.0-rc.2
2426

jscomp/bsc/rescript_compiler_main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
457457

458458

459459

460-
(** parse flags in bs.config *)
460+
(** parse flags in config *)
461461
let file_level_flags_handler (e : Parsetree.expression option) =
462462
match e with
463463
| None -> ()

jscomp/build_tests/cmd/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type bla
2121
2222
external foo : bla = "foo.react" [@@module]
2323
24-
external bar : unit -> bla = "bar" [@@bs.val] [@@module "foo.react"]
24+
external bar : unit -> bla = "bar" [@@val] [@@module "foo.react"]
2525
2626
let c = foo
2727

jscomp/build_tests/react_ppx/src/recursive_component_test.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@@warning("-39")
22
// https://github.com/rescript-lang/rescript-compiler/issues/4511
33
/*
4-
[@bs.config {
4+
[@config {
55
flags : [|"-dsource"|]
66
}];
77
*/

jscomp/core/design.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Curry.__N o
9898
]}
9999
Another use case:
100100
{[
101-
external f : ('a -> 'b [@bs.uncurry]) -> unit
101+
external f : ('a -> 'b [@uncurry]) -> unit
102102
103103
f g (* The compiler will do such converison internally*)
104104
]}
@@ -173,12 +173,12 @@ We can simply do inlining, it may have side efffect in `b0`, `b1`, our optimizer
173173

174174
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)
175175

176-
Note this also interacts with `[@bs.uncurry]`
176+
Note this also interacts with `[@uncurry]`
177177

178178
for example
179179

180180
```ocaml
181-
external filter : 'a array -> ('a -> bool [@bs.uncurry]) -> 'a array = "filter"
181+
external filter : 'a array -> ('a -> bool [@uncurry]) -> 'a array = "filter"
182182
[@@send]
183183
184184
let f xs =
@@ -211,7 +211,7 @@ if (typeof x === "undefined"){
211211

212212
```ocaml
213213
external of_char : char -> string = "String.fromCharCode"
214-
[@@bs.val]
214+
[@@val]
215215
```
216216

217217
We introduced `#` so that we can do some optimizations.

jscomp/core/lam_compile.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ and compile_prim (prim_info : Lam.prim_info)
15141514
compile_sequand l r lambda_cxt
15151515
| { primitive = Psequor; args = [ l; r ] } -> compile_sequor l r lambda_cxt
15161516
| { primitive = Pdebugger; _ } ->
1517-
(* [%bs.debugger] guarantees that the expression does not matter
1517+
(* [%debugger] guarantees that the expression does not matter
15181518
TODO: make it even safer *)
15191519
Js_output.output_of_block_and_expression lambda_cxt.continuation
15201520
S.debugger_block E.unit

jscomp/frontend/ast_attributes.ml

+6-10
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@ let process_attributes_rev (attrs : t) : attr_kind * t =
8686
match (txt, st) with
8787
| "bs", (Nothing | Uncurry _) ->
8888
(Uncurry attr, acc) (* TODO: warn unused/duplicated attribute *)
89-
| ("bs.this" | "this"), (Nothing | Meth_callback _) ->
90-
(Meth_callback attr, acc)
89+
| "this", (Nothing | Meth_callback _) -> (Meth_callback attr, acc)
9190
| "meth", (Nothing | Method _) -> (Method attr, acc)
92-
| ("bs" | "bs.this" | "this"), _ ->
93-
Bs_syntaxerr.err loc Conflict_bs_bs_this_bs_meth
91+
| ("bs" | "this"), _ -> Bs_syntaxerr.err loc Conflict_bs_bs_this_bs_meth
9492
| _, _ -> (st, attr :: acc))
9593

9694
let process_bs (attrs : t) =
@@ -150,8 +148,7 @@ let rs_externals (attrs : t) pval_prim =
150148
prims_to_be_encoded pval_prim
151149
| _, _ ->
152150
Ext_list.exists_fst attrs (fun ({txt} : string Asttypes.loc) ->
153-
Ext_string.starts_with txt "bs."
154-
|| Ext_array.exists external_attrs (fun (x : string) -> txt = x))
151+
Ext_array.exists external_attrs (fun (x : string) -> txt = x))
155152
|| prims_to_be_encoded pval_prim
156153

157154
let is_inline : attr -> bool = fun ({txt}, _) -> txt = "inline"
@@ -221,12 +218,11 @@ let iter_process_bs_string_int_unwrap_uncurry (attrs : t) =
221218
in
222219
Ext_list.iter attrs (fun (({txt; loc = _}, (payload : _)) as attr) ->
223220
match txt with
224-
| "bs.string" | "string" -> assign `String attr
221+
| "string" -> assign `String attr
225222
| "int" -> assign `Int attr
226223
| "ignore" -> assign `Ignore attr
227-
| "bs.unwrap" | "unwrap" -> assign `Unwrap attr
228-
| "bs.uncurry" | "uncurry" ->
229-
assign (`Uncurry (Ast_payload.is_single_int payload)) attr
224+
| "unwrap" -> assign `Unwrap attr
225+
| "uncurry" -> assign (`Uncurry (Ast_payload.is_single_int payload)) attr
230226
| _ -> ());
231227
!st
232228

jscomp/frontend/ast_config.ml

+4-10
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ let process_directives str =
5757
let rec iter_on_bs_config_str (x : Parsetree.structure) =
5858
match x with
5959
| [] -> ()
60-
| {
61-
pstr_desc =
62-
Pstr_attribute (({txt = "bs.config" | "config"; loc}, payload) as attr);
63-
}
64-
:: _ ->
60+
| {pstr_desc = Pstr_attribute (({txt = "config"; loc}, payload) as attr)} :: _
61+
->
6562
Bs_ast_invariant.mark_used_bs_attribute attr;
6663
Ext_list.iter
6764
(Ast_payload.ident_or_record_as_config loc payload)
@@ -76,11 +73,8 @@ let process_str str =
7673
let rec iter_on_bs_config_sig (x : Parsetree.signature) =
7774
match x with
7875
| [] -> ()
79-
| {
80-
psig_desc =
81-
Psig_attribute (({txt = "bs.config" | "config"; loc}, payload) as attr);
82-
}
83-
:: _ ->
76+
| {psig_desc = Psig_attribute (({txt = "config"; loc}, payload) as attr)} :: _
77+
->
8478
Bs_ast_invariant.mark_used_bs_attribute attr;
8579
Ext_list.iter
8680
(Ast_payload.ident_or_record_as_config loc payload)

jscomp/frontend/ast_exp_extension.ml

+5-6
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ let handle_extension e (self : Bs_ast_mapper.mapper)
2727
(({txt; loc}, payload) : Parsetree.extension) =
2828
match txt with
2929
| "ffi" -> Ast_exp_handle_external.handle_ffi ~loc ~payload
30-
| "bs.raw" | "raw" ->
31-
Ast_exp_handle_external.handle_raw ~kind:Raw_exp loc payload
32-
| "bs.re" | "re" ->
30+
| "raw" -> Ast_exp_handle_external.handle_raw ~kind:Raw_exp loc payload
31+
| "re" ->
3332
Exp.constraint_ ~loc
3433
(Ast_exp_handle_external.handle_raw ~kind:Raw_re loc payload)
3534
(Ast_comb.to_js_re_type loc)
36-
| "bs.external" | "external" -> (
35+
| "external" -> (
3736
match Ast_payload.as_ident payload with
3837
| Some {txt = Lident x} ->
3938
Ast_exp_handle_external.handle_external loc x
@@ -43,7 +42,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper)
4342
*)
4443
| None | Some _ ->
4544
Location.raise_errorf ~loc "external expects a single identifier")
46-
| "bs.time" | "time" -> (
45+
| "time" -> (
4746
match payload with
4847
| PStr [{pstr_desc = Pstr_eval (e, _)}] ->
4948
let locString =
@@ -69,7 +68,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper)
6968
(Exp.ident ~loc {loc; txt = Lident "timed"})))
7069
| _ ->
7170
Location.raise_errorf ~loc "expect a boolean expression in the payload")
72-
| "bs.debugger" | "debugger" ->
71+
| "debugger" ->
7372
{e with pexp_desc = Ast_exp_handle_external.handle_debugger loc payload}
7473
| "obj" -> (
7574
match payload with

jscomp/frontend/ast_external_process.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
258258
else
259259
let action () =
260260
match txt with
261-
| "bs.val" | "val" ->
261+
| "val" ->
262262
if no_arguments then
263263
{st with val_name = Some (name_from_payload_or_prim ~loc payload)}
264264
else
@@ -418,8 +418,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
418418
with Not_handled_external_attribute -> (attr :: attrs, st))
419419

420420
let has_bs_uncurry (attrs : Ast_attributes.t) =
421-
Ext_list.exists_fst attrs (fun {txt; loc = _} ->
422-
txt = "bs.uncurry" || txt = "uncurry")
421+
Ext_list.exists_fst attrs (fun {txt; loc = _} -> txt = "uncurry")
423422

424423
let check_return_wrapper loc (wrapper : External_ffi_types.return_wrapper)
425424
result_type =

jscomp/frontend/ast_typ_uncurry.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ val to_uncurry_type : uncurry_type_gen
5656

5757
val to_method_callback_type : uncurry_type_gen
5858
(** syntax:
59-
{[ 'obj -> int -> int [@bs.this] ]}
59+
{[ 'obj -> int -> int [@this] ]}
6060
*)

jscomp/frontend/ast_uncurry_gen.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ val to_method_callback :
4747
Parsetree.expression ->
4848
Parsetree.expression_desc
4949
(** syntax:
50-
{[fun [@bs.this] obj pat pat1 -> body]}
50+
{[fun [@this] obj pat pat1 -> body]}
5151
*)

jscomp/frontend/bs_ast_invariant.ml

+5-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727
it may fail third party ppxes
2828
*)
2929
let is_bs_attribute txt =
30-
let len = String.length txt in
31-
len >= 2
32-
(*TODO: check the stringing padding rule, this preciate may not be needed *)
33-
&& String.unsafe_get txt 0 = 'b'
34-
&& String.unsafe_get txt 1 = 's'
35-
&& (len = 2 || String.unsafe_get txt 2 = '.')
30+
match txt with
31+
(* TODO #6636: | "as "| "int" *)
32+
| "bs" | "config" | "ignore" | "optional" | "string" | "uncurry" | "unwrap" ->
33+
true
34+
| _ -> false
3635

3736
let used_attributes : string Asttypes.loc Hash_set_poly.t =
3837
Hash_set_poly.create 16

jscomp/frontend/bs_builtin_ppx.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
(**
2929
1. extension point
3030
{[
31-
[%bs.raw{| blabla |}]
31+
[%raw{| blabla |}]
3232
]}
3333
will be desugared into
3434
{[
@@ -467,7 +467,7 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
467467
Pstr_value
468468
(Nonrecursive, [{pvb_pat; pvb_expr; pvb_attributes; pvb_loc}]);
469469
})
470-
| Pstr_attribute ({txt = "bs.config" | "config"}, _) -> str
470+
| Pstr_attribute ({txt = "config"}, _) -> str
471471
| _ -> default_mapper.structure_item self str
472472

473473
let local_module_name =
@@ -514,7 +514,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
514514
| [] -> []
515515
| item :: rest -> (
516516
match item.pstr_desc with
517-
| Pstr_extension (({txt = "bs.raw" | "raw"; loc}, payload), _attrs) ->
517+
| Pstr_extension (({txt = "raw"; loc}, payload), _attrs) ->
518518
Ast_exp_handle_external.handle_raw_structure loc payload
519519
:: structure_mapper ~await_context self rest
520520
(* | Pstr_extension (({txt = "i"}, _),_)

jscomp/frontend/external_arg_spec.mli

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ type attr =
3131
| Poly_var of {descr: (string * string) list option}
3232
| Int of (string * int) list (* ([`a | `b ] [@int])*)
3333
| Arg_cst of cst
34-
| Fn_uncurry_arity of
35-
int (* annotated with [@bs.uncurry ] or [@bs.uncurry 2]*)
34+
| Fn_uncurry_arity of int (* annotated with [@uncurry ] or [@uncurry 2]*)
3635
(* maybe we can improve it as a combination of {!Asttypes.constant} and tuple *)
3736
| Extern_unit
3837
| Nothing

jscomp/gentype/Annotation.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let tagIsGenType s = s = "genType" || s = "gentype"
2121
let tagIsGenTypeAs s = s = "genType.as" || s = "gentype.as"
2222
let tagIsAs s = s = "as"
2323
let tagIsInt s = s = "int"
24-
let tagIsString s = s = "bs.string" || s = "string"
24+
let tagIsString s = s = "string"
2525

2626
let tagIsTag s = s = "tag"
2727

jscomp/ml/ast_payload.mli

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ val assert_strings : Location.t -> t -> string list
6363
(** as a record or empty
6464
it will accept
6565
66-
{[ [@@@bs.config ]]}
66+
{[ [@@@config ]]}
6767
or
68-
{[ [@@@bs.config no_export ] ]}
68+
{[ [@@@config no_export ] ]}
6969
or
70-
{[ [@@@bs.config { property .. } ]]}
70+
{[ [@@@config { property .. } ]]}
7171
Note that we only
7272
{[
7373
{ flat_property}

jscomp/ml/oprint.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ and print_simple_out_type ppf =
292292
| Otyp_constr (Oide_dot (Oide_dot (Oide_ident "Js_OO", "Callback" ), _),
293293
[tyl])
294294
->
295-
fprintf ppf "@[<0>(%a@ [@bs.this])@]" print_out_type_1 tyl
295+
fprintf ppf "@[<0>(%a@ [@this])@]" print_out_type_1 tyl
296296
| Otyp_constr (id, tyl) ->
297297
pp_open_box ppf 0;
298298
print_typargs ppf tyl;

jscomp/others/belt_List.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
```
6060
*/
6161

62-
@@bs.config({flags: ["-bs-noassertfalse"]})
62+
@@config({flags: ["-bs-noassertfalse"]})
6363

6464
type t<'a> = list<'a>
6565

jscomp/others/belt_internalAVLset.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24-
@@bs.config({flags: ["-bs-noassertfalse"]})
24+
@@config({flags: ["-bs-noassertfalse"]})
2525
type rec node<'value> = {
2626
@as("v") mutable value: 'value,
2727
@as("h") mutable height: int,

jscomp/others/belt_internalAVLtree.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/* Almost rewritten by authors of ReScript */
1515

16-
@@bs.config({flags: ["-bs-noassertfalse"]})
16+
@@config({flags: ["-bs-noassertfalse"]})
1717
type rec node<'k, 'v> = {
1818
@as("k") mutable key: 'k,
1919
@as("v") mutable value: 'v,

jscomp/others/belt_internalMapInt.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@@bs.config({flags: ["-bs-noassertfalse"]})
1+
@@config({flags: ["-bs-noassertfalse"]})
22

33
type key = int
44

jscomp/others/belt_internalMapString.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@@bs.config({flags: ["-bs-noassertfalse"]})
1+
@@config({flags: ["-bs-noassertfalse"]})
22

33
type key = string
44

jscomp/others/internal_map.cppo.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@@bs.config({flags: ["-bs-noassertfalse"]})
1+
@@config({flags: ["-bs-noassertfalse"]})
22

33
#ifdef TYPE_STRING
44
type key = string

jscomp/others/js.ml

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
[@@@bs.config {flags = [|"-unboxed-types"; "-w"; "-49"|]}]
25+
[@@@config {flags = [|"-unboxed-types"; "-w"; "-49"|]}]
2626
(* DESIGN:
2727
- It does not have any code, all its code will be inlined so that
2828
there will never be
@@ -141,14 +141,13 @@ external log : 'a -> unit = "log"
141141
[@@val] [@@scope "console"]
142142
(** Equivalent to console.log any value. *)
143143

144-
external log2 : 'a -> 'b -> unit = "log" [@@bs.val] [@@scope "console"]
145-
external log3 : 'a -> 'b -> 'c -> unit = "log" [@@bs.val] [@@scope "console"]
144+
external log2 : 'a -> 'b -> unit = "log" [@@val] [@@scope "console"]
145+
external log3 : 'a -> 'b -> 'c -> unit = "log" [@@val] [@@scope "console"]
146146

147-
external log4 : 'a -> 'b -> 'c -> 'd -> unit = "log"
148-
[@@bs.val] [@@scope "console"]
147+
external log4 : 'a -> 'b -> 'c -> 'd -> unit = "log" [@@val] [@@scope "console"]
149148

150149
external logMany : 'a array -> unit = "log"
151-
[@@bs.val] [@@scope "console"] [@@variadic]
150+
[@@val] [@@scope "console"] [@@variadic]
152151
(** A convenience function to console.log more than 4 arguments *)
153152

154153
external eqNull : 'a -> 'a null -> bool = "%bs_equal_null"

jscomp/others/js_OO.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

25-
@@bs.config({flags: ["-unboxed-types"]})
25+
@@config({flags: ["-unboxed-types"]})
2626

2727
external unsafe_to_method: 'a => 'a = "#fn_method"
2828

0 commit comments

Comments
 (0)