Skip to content

Commit 0fc3908

Browse files
committed
bs.val and bs.module transition
1 parent 9406eb6 commit 0fc3908

6 files changed

+26
-26
lines changed

jscomp/core/js_call_info.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type call_info =
3737
| Call_ml (* called by plain ocaml expression *)
3838
| Call_builtin_runtime (* built-in externals *)
3939
| Call_na
40-
(* either from [@@bs.val] or not available,
40+
(* either from [@@val] or not available,
4141
such calls does not follow such rules
4242
{[ fun x y -> (f x y) === f ]} when [f] is an atom
4343

jscomp/core/js_call_info.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type call_info =
4040
| Call_ml (* called by plain ocaml expression *)
4141
| Call_builtin_runtime (* built-in externals *)
4242
| Call_na
43-
(* either from [@@bs.val] or not available,
43+
(* either from [@@val] or not available,
4444
such calls does not follow such rules
4545
{[ fun x y -> f x y === f ]} when [f] is an atom
4646
*)

jscomp/core/lam_compile_external_call.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ let translate_scoped_module_val
252252
Ext_list.fold_left (Ext_list.append rest [fn]) start E.dot
253253
end
254254
| None ->
255-
(* no [@@bs.module], assume it's global *)
255+
(* no [@@module], assume it's global *)
256256
begin match scopes with
257257
| [] ->
258258
E.js_global fn

jscomp/reserved_attributs.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ to detect unused attributes in the future
77

88

99

10-
obj
11-
val
12-
module
1310
scope
11+
val -- done
12+
module -- done
13+
obj -- done
1414
variadic -- done
1515
send -- done
1616
return -- done

jscomp/syntax/ast_external_process.ml

+15-15
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,19 @@ let get_opt_arg_type
167167

168168

169169
(**
170-
[@@bs.module "react"]
171-
[@@bs.module "react"]
170+
[@@module "react"]
171+
[@@module "react"]
172172
---
173-
[@@bs.module "@" "react"]
174-
[@@bs.module "@" "react"]
173+
[@@module "@" "react"]
174+
[@@module "@" "react"]
175175
176176
They should have the same module name
177177
178178
TODO: we should emit an warning if we bind
179179
two external files to the same module name
180180
*)
181181
type bundle_source =
182-
[`Nm_payload of string (* from payload [@@bs.val "xx" ]*)
182+
[`Nm_payload of string (* from payload [@@val "xx" ]*)
183183
|`Nm_external of string (* from "" in external *)
184184
| `Nm_val of string lazy_t (* from function name *)
185185
]
@@ -268,7 +268,7 @@ let parse_external_attributes
268268
match payload with
269269
| PStr [] ->
270270
(prim_name_or_pval_prim :> name_source)
271-
(* It is okay to have [@@bs.val] without payload *)
271+
(* It is okay to have [@@val] without payload *)
272272
| _ ->
273273
begin match Ast_payload.is_single_string payload with
274274
| Some (val_name, _) -> `Nm_payload val_name
@@ -289,13 +289,13 @@ let parse_external_attributes
289289
{st with external_module_name = Some { bundle; module_bind_name = Phint_nothing}}
290290
else
291291
let action () = begin match txt with
292-
| "bs.val" ->
292+
| "bs.val" | "val" ->
293293
if no_arguments then
294294
{st with val_name = name_from_payload_or_prim ~loc payload}
295295
else
296296
{st with call_name = name_from_payload_or_prim ~loc payload}
297297

298-
| "bs.module" ->
298+
| "bs.module" | "module" ->
299299
begin match Ast_payload.assert_strings loc payload with
300300
| [bundle] ->
301301
{st with external_module_name =
@@ -617,7 +617,7 @@ let external_desc_of_non_obj
617617
| [], `Nm_na, _ -> Js_module_as_var external_module_name
618618
| _, `Nm_na, _ -> Js_module_as_fn {splice; external_module_name }
619619
| _, #bundle_source, #bundle_source ->
620-
Bs_syntaxerr.err loc (Conflict_ffi_attribute "Attribute found that conflicts with [@@bs.module].")
620+
Bs_syntaxerr.err loc (Conflict_ffi_attribute "Attribute found that conflicts with @@module.")
621621

622622
| _, (`Nm_val _ | `Nm_external _) , `Nm_na
623623
-> Js_module_as_class external_module_name
@@ -627,7 +627,7 @@ let external_desc_of_non_obj
627627
"Incorrect FFI attribute found: (@new should not carry a payload here)"
628628
end
629629
| {module_as_val = Some _; _} ->
630-
Bs_syntaxerr.err loc (Conflict_ffi_attribute "Attribute found that conflicts with [@@bs.module].")
630+
Bs_syntaxerr.err loc (Conflict_ffi_attribute "Attribute found that conflicts with @@module.")
631631
| {call_name = (`Nm_val lazy name | `Nm_external name | `Nm_payload name) ;
632632
splice;
633633
scopes ;
@@ -649,7 +649,7 @@ let external_desc_of_non_obj
649649
Js_call {splice; name; external_module_name; scopes }
650650
| {call_name = #bundle_source ; _ }
651651
->
652-
Bs_syntaxerr.err loc (Conflict_ffi_attribute "Attribute found that conflicts with [@@bs.val]")
652+
Bs_syntaxerr.err loc (Conflict_ffi_attribute "Attribute found that conflicts with @val")
653653
| {val_name = (`Nm_val lazy name | `Nm_external name | `Nm_payload name);
654654
external_module_name;
655655

@@ -670,13 +670,13 @@ let external_desc_of_non_obj
670670
-> (*
671671
if no_arguments -->
672672
{[
673-
external ff : int = "" [@@bs.val]
673+
external ff : int = "" [@@val]
674674
]}
675675
*)
676676
Js_var { name; external_module_name; scopes}
677677
| {val_name = #bundle_source ; _ }
678678
->
679-
Bs_syntaxerr.err loc (Conflict_ffi_attribute "Attribute found that conflicts with [@@bs.val]")
679+
Bs_syntaxerr.err loc (Conflict_ffi_attribute "Attribute found that conflicts with @val")
680680

681681
| {splice ;
682682
scopes ;
@@ -699,7 +699,7 @@ let external_desc_of_non_obj
699699
if arg_type_specs_length = 0 then
700700
(*
701701
{[
702-
external ff : int = "" [@@bs.module "xx"]
702+
external ff : int = "" [@@module "xx"]
703703
]}
704704
*)
705705
Js_var { name; external_module_name; scopes}
@@ -846,7 +846,7 @@ let external_desc_of_non_obj
846846
return_wrapper = _;
847847

848848
}
849-
-> Location.raise_errorf ~loc "Could not infer which FFI category it belongs to, maybe you forgot [%@%@bs.val]? "
849+
-> Location.raise_errorf ~loc "Could not infer which FFI category it belongs to, maybe you forgot %@val? "
850850

851851
(** Note that the passed [type_annotation] is already processed by visitor pattern before*)
852852
let handle_attributes

jscomp/syntax/external_ffi_types.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ type external_spec =
100100
| Js_set { js_set_name = s} -> Printf.sprintf "[@@set %S]" s
101101
| Js_call v -> Printf.sprintf "[@@val %S]" v.name
102102
| Js_send v -> Printf.sprintf "[@@send %S]" v.name
103-
| Js_module_as_fn v -> Printf.sprintf "[@@bs.val %S]" v.external_module_name.bundle
103+
| Js_module_as_fn v -> Printf.sprintf "[@@val %S]" v.external_module_name.bundle
104104
| Js_new v -> Printf.sprintf "[@@new %S]" v.name
105105
| Js_module_as_class v
106-
-> Printf.sprintf "[@@bs.module] %S " v.bundle
106+
-> Printf.sprintf "[@@module] %S " v.bundle
107107
| Js_module_as_var v
108108
->
109-
Printf.sprintf "[@@bs.module] %S " v.bundle
110-
| Js_var v (* FIXME: could be [@@bs.module "xx"] as well *)
109+
Printf.sprintf "[@@module] %S " v.bundle
110+
| Js_var v (* FIXME: could be [@@module "xx"] as well *)
111111
->
112-
Printf.sprintf "[@@bs.val] %S " v.name *)
112+
Printf.sprintf "[@@val] %S " v.name *)
113113

114114
type return_wrapper =
115115
| Return_unset

0 commit comments

Comments
 (0)