Skip to content

Commit d09b5c3

Browse files
cknittJonoPrest
authored andcommitted
Remove remaining "bs." attributes (rescript-lang#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 6b21f0b commit d09b5c3

File tree

110 files changed

+260
-329
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
-329
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
#### :boom: Breaking Change
4545

4646
- `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
47+
- Remove handling of attributes with `bs.` prefix (`@bs.as` -> `@as` etc.). https://github.com/rescript-lang/rescript-compiler/pull/6643
48+
- Remove obsolete `@bs.open` feature. https://github.com/rescript-lang/rescript-compiler/pull/6629
49+
50+
#### :house: Internal
51+
52+
- Build with OCaml 5.1.1. https://github.com/rescript-lang/rescript-compiler/pull/6641
4753

4854
# 11.1.0-rc.2
4955

jscomp/bsc/rescript_compiler_main.ml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ and compile_prim (prim_info : Lam.prim_info)
15191519
compile_sequand l r lambda_cxt
15201520
| { primitive = Psequor; args = [ l; r ] } -> compile_sequor l r lambda_cxt
15211521
| { primitive = Pdebugger; _ } ->
1522-
(* [%bs.debugger] guarantees that the expression does not matter
1522+
(* [%debugger] guarantees that the expression does not matter
15231523
TODO: make it even safer *)
15241524
Js_output.output_of_block_and_expression lambda_cxt.continuation
15251525
S.debugger_block E.unit

jscomp/frontend/ast_attributes.ml

Lines changed: 6 additions & 10 deletions
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

Lines changed: 4 additions & 10 deletions
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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 2 additions & 3 deletions
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 =

0 commit comments

Comments
 (0)