Skip to content

bs.xx -> xx transition, no bs prefix needed #4701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8d539d3
refactoring
bobzhang Sep 16, 2020
25faa72
allow both bs.deriving and deriving
bobzhang Sep 16, 2020
a20f109
allow bs.config and config
bobzhang Sep 16, 2020
69100fd
snapshot
bobzhang Sep 16, 2020
43b4c50
tweak
bobzhang Sep 16, 2020
d4cd553
allow both bs.this and this
bobzhang Sep 16, 2020
5df20b4
snapshot
bobzhang Sep 16, 2020
2daa9b1
allow both bs.meth and meth
bobzhang Sep 16, 2020
373d098
snapshot
bobzhang Sep 16, 2020
3ab5f2c
tweak
bobzhang Sep 16, 2020
eea1d3c
remove BS_NATIVE_PPX
bobzhang Sep 16, 2020
0b87b80
snapshot
bobzhang Sep 16, 2020
f6bcab8
allow bs.as and as
bobzhang Sep 16, 2020
77a45ba
snapshot
bobzhang Sep 16, 2020
13f608a
allow both bs.ignore and ignore
bobzhang Sep 16, 2020
bc53ed6
snapshot
bobzhang Sep 16, 2020
4b6a1ef
bs.string/bs.int + string/int
bobzhang Sep 16, 2020
edcff95
snapshot
bobzhang Sep 16, 2020
c974964
bs.uncurry and bs.unwrap transition
bobzhang Sep 16, 2020
64c7379
snapshot
bobzhang Sep 16, 2020
4c17ece
tweak
bobzhang Sep 16, 2020
798bd23
bs.optional and optional
bobzhang Sep 16, 2020
415d6df
snapshot
bobzhang Sep 16, 2020
dabb255
prepare critical external transition
bobzhang Sep 16, 2020
dbd586f
add bs.get/bs.set transition
bobzhang Sep 16, 2020
b94414e
snapshot
bobzhang Sep 16, 2020
24e91d8
fix ci
bobzhang Sep 16, 2020
1bcbe5b
bs.get_index/bs.set_index transition
bobzhang Sep 17, 2020
67c0c09
snapshot
bobzhang Sep 17, 2020
54063ba
accept both bs.return and return
bobzhang Sep 17, 2020
3218bb2
snapshot
bobzhang Sep 17, 2020
74e11db
accept both bs.new and new
bobzhang Sep 17, 2020
980c385
snapshot
bobzhang Sep 17, 2020
e2d9f39
bs.variadic and bs.send transition
bobzhang Sep 17, 2020
a2c92de
snapshot
bobzhang Sep 17, 2020
9406eb6
bs.obj transition
bobzhang Sep 17, 2020
0fc3908
bs.val and bs.module transition
bobzhang Sep 17, 2020
e4bbfb1
snapshot
bobzhang Sep 17, 2020
2082757
snapshot
bobzhang Sep 17, 2020
6b860c2
adjust %@ issues, fix CI
bobzhang Sep 17, 2020
69af0f0
snapshot
bobzhang Sep 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jscomp/core/js_call_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type call_info =
| Call_ml (* called by plain ocaml expression *)
| Call_builtin_runtime (* built-in externals *)
| Call_na
(* either from [@@bs.val] or not available,
(* either from [@@val] or not available,
such calls does not follow such rules
{[ fun x y -> (f x y) === f ]} when [f] is an atom

Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_call_info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type call_info =
| Call_ml (* called by plain ocaml expression *)
| Call_builtin_runtime (* built-in externals *)
| Call_na
(* either from [@@bs.val] or not available,
(* either from [@@val] or not available,
such calls does not follow such rules
{[ fun x y -> f x y === f ]} when [f] is an atom
*)
Expand Down
6 changes: 3 additions & 3 deletions jscomp/core/lam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ exception Not_simple_form
where [wrap] used to be simple instructions
Note that [external] functions are forced to do eta-conversion
when combined with [|>] operator, we need to make sure beta-reduction
is applied though since `[@bs.splice]` needs such guarantee.
Since `[@bs.splice] is the tail position
is applied though since `[@variadic]` needs such guarantee.
Since `[@variadic] is the tail position
*)
let rec is_eta_conversion_exn
params inner_args outer_args : t list =
Expand Down Expand Up @@ -819,7 +819,7 @@ let sequand l r = if_ l r false_
(** only [handle_bs_non_obj_ffi] will be used outside *)
(**
[no_auto_uncurried_arg_types xs]
check if the FFI have [@@bs.uncurry] attribute.
check if the FFI have @uncurry attribute.
if it does not we wrap it in a nomral way otherwise
*)
let rec no_auto_uncurried_arg_types
Expand Down
10 changes: 5 additions & 5 deletions jscomp/core/lam_compile_external_call.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let append_list x xs =
unbox it in the first place.

Note when optional value is not passed, the unboxed value would be
[undefined], with the combination of `[@bs.int]` it would be still be
[undefined], with the combination of `[@int]` it would be still be
[undefined], this by default is still correct..
{[
(function () {
Expand Down Expand Up @@ -252,7 +252,7 @@ let translate_scoped_module_val
Ext_list.fold_left (Ext_list.append rest [fn]) start E.dot
end
| None ->
(* no [@@bs.module], assume it's global *)
(* no [@@module], assume it's global *)
begin match scopes with
| [] ->
E.js_global fn
Expand Down Expand Up @@ -309,7 +309,7 @@ let translate_ffi
| Js_new { external_module_name = module_name;
name = fn;
scopes
} -> (* handle [@@bs.new]*)
} -> (* handle [@@new]*)
(* This has some side effect, it will
mark its identifier (If it has) as an object,
ATTENTION:
Expand Down Expand Up @@ -356,7 +356,7 @@ let translate_ffi
begin match args with
| self :: args ->
(* PR2162 [self_type] more checks in syntax:
- should not be [bs.as] *)
- should not be [@as] *)
let [@warning"-8"] ( _self_type::arg_types )
= arg_types in
if splice then
Expand All @@ -382,7 +382,7 @@ let translate_ffi

(* TODO #11
1. check args -- error checking
2. support [@@bs.scope "window"]
2. support [@@scope "window"]
we need know whether we should call [add_js_module] or not
*)
translate_scoped_module_val external_module_name name scopes
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_compile_external_call.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ val translate_ffi :

(** TODO: document supported attributes
Attributes starting with `js` are reserved
examples: "bs.splice"
examples: "variadic"
*)
4 changes: 2 additions & 2 deletions jscomp/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -904,15 +904,15 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
]}
is also wrong.

It seems, we need handle [@bs.splice] earlier
It seems, we need handle [@variadic] earlier

or
{[
(fun x y -> f x y) ([|1;2;3|]) -->
let x0, x1, x2 =1,2,3 in
(fun y -> f [|x0;x1;x2|] y)
]}
But this still need us to know [@bs.splice] in advance
But this still need us to know [@variadic] in advance


we should not remove it immediately, since we have to be careful
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_eta_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ let transform_under_supply n ap_info fn args =
cautiously, since
[let u = f] and we are chaning the arity of [f] it will affect
the collection of [u]
A typical use case is to pass an OCaml function to JS side as a callback (i.e, [@bs.uncurry])
A typical use case is to pass an OCaml function to JS side as a callback (i.e, [@uncurry])
*)
let unsafe_adjust_to_arity loc ~(to_:int) ?(from : int option) (fn : Lam.t) : Lam.t =
let ap_info : Lam.ap_info = {ap_loc = loc; ap_inlined = Default_inline; ap_status = App_na } in
Expand Down
6 changes: 3 additions & 3 deletions jscomp/core/record_attributes_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type label = Types.label_description

let find_name (attr : Parsetree.attribute) =
match attr with
| {txt = "bs.as"}, PStr
| {txt = "bs.as" | "as"}, PStr
[{pstr_desc = Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string(s,_))},_ )}] ->
Some s
| _ -> None
Expand All @@ -35,7 +35,7 @@ let find_name (attr : Parsetree.attribute) =
let find_name_with_loc (attr : Parsetree.attribute) :
string Asttypes.loc option =
match attr with
| {txt = "bs.as";loc}, PStr
| {txt = "bs.as" | "as";loc}, PStr
[{pstr_desc = Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string(s,_))},_ )}] ->
Some {txt = s; loc}
| _ -> None
Expand Down Expand Up @@ -79,7 +79,7 @@ let rec check_duplicated_labels_aux
| Some ({txt = s;} as l) ->
if Set_string.mem coll s
(*use coll to make check a bit looser
allow cases like [ x : int [@bs.as "x"]]
allow cases like [ x : int [@as "x"]]
*) then
Some l
else
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ext/ext_array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ let find_and_split arr cmp v : _ split =

(** TODO: available since 4.03, use {!Array.exists} *)

let exists p a =
let exists a p =
let n = Array.length a in
let rec loop i =
if i = n then false
Expand Down
5 changes: 4 additions & 1 deletion jscomp/ext/ext_array.mli
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ val find_and_split :
('a -> 'b -> bool) ->
'b -> 'a split

val exists : ('a -> bool) -> 'a array -> bool
val exists :
'a array ->
('a -> bool) ->
bool

val is_empty : 'a array -> bool

Expand Down
6 changes: 3 additions & 3 deletions jscomp/ounit_tests/ounit_cmd_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let suites =
= ""
[@@bs.send.pipe:int]
[@@bs.splice]|}|] in
OUnit.assert_bool __LOC__ (Ext_string.contain_substring v_output.stderr "bs.splice")
OUnit.assert_bool __LOC__ (Ext_string.contain_substring v_output.stderr "variadic")
end;
__LOC__ >:: begin fun _ ->
let v_output = perform_bsc [|"-bs-eval"; {|external
Expand All @@ -59,7 +59,7 @@ let suites =
= ""
[@@bs.send.pipe:int]
[@@bs.splice] |}|] in
OUnit.assert_bool __LOC__ (Ext_string.contain_substring v_output.stderr "bs.splice")
OUnit.assert_bool __LOC__ (Ext_string.contain_substring v_output.stderr "variadic")
end;

__LOC__ >:: begin fun _ ->
Expand Down Expand Up @@ -115,7 +115,7 @@ external ff :
(* 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 _ ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ounit_tests/ounit_ffi_error_debug_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let output = bsc_eval {|
|}
in
OUnit.assert_bool __LOC__
(Ext_string.contain_substring output.stderr "bs.unwrap")
(Ext_string.contain_substring output.stderr "unwrap")
end;

__LOC__ >:: begin fun _ ->
Expand Down
4 changes: 2 additions & 2 deletions jscomp/outcome_printer/tweaked_reason_oprint.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ and print_simple_out_type ppf =
let res =
if name = "arity0" then Otyp_arrow ("", Otyp_constr (Oide_ident "unit", []),ty)
else ty in
fprintf ppf "@[<0>(%a)@ [@bs.meth]@]" (print_out_type_1 ~uncurried:false) res
fprintf ppf "@[<0>(%a)@ [%@meth]@]" (print_out_type_1 ~uncurried:false) res

| Otyp_constr (
Oide_dot (Oide_dot (
Oide_ident "Js_OO", "Callback" ), _),
[res]
) ->
fprintf ppf "@[<0>(%a)@ [@bs.this]@]" (print_out_type_1 ~uncurried:false) res
fprintf ppf "@[<0>(%a)@ [%@this]@]" (print_out_type_1 ~uncurried:false) res

(* also BuckleScript-specific. Turns Js.t({. foo: bar}) into {. "foo": bar} *)
| Otyp_constr (
Expand Down
58 changes: 31 additions & 27 deletions jscomp/reserved_attributs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,47 @@ This is a list of reserved attributes, we may use such information
to detect unused attributes in the future


get
set
this
meth



scope
val -- done
module -- done
obj -- done
variadic -- done
send -- done
return -- done
new -- done
get_index -- done
set_index -- done
get -- done
set -- done
optional -- done
uncurry -- done
note [@uncurry 3] is okay but rarely used
maybe we should remove it
unwrap -- done
string -- done
int -- done
ignore -- done
as -- done
meth -- done
this -- done
send.pipe -- deprecated, no short-cut
splice -- deprecated, use variadic
config -- done
open -- not decided
inline --
inline -- done
this would conflict exist one or not?
invalid payload in bs.inline
seems that we need loose the check
deriving
string
int
ignore
unwrap
uncurry
as
optional
get_index
return
config
obj
deriving -- done
raw -- not needed
re -- not needed
external -- not needed
time -- not needed
node -- not needed
debugger -- not needed
val
module
scope
splice -- deprecated, use variadic
variadic
send
send.pipe -- deprecated, no short-cut
new
set_index

debugger.chrome -- deprecated

keywords is okay `[@open]` is a valid syntax
Expand Down
Loading