diff --git a/jscomp/common/js_config.ml b/jscomp/common/js_config.ml index 05118ebc14..43b87c1c81 100644 --- a/jscomp/common/js_config.ml +++ b/jscomp/common/js_config.ml @@ -86,7 +86,7 @@ let no_stdlib = ref false let no_export = ref false -let record_as_js_object = ref false (* otherwise has an attribute *) + let as_ppx = ref false diff --git a/jscomp/common/js_config.mli b/jscomp/common/js_config.mli index 6134718468..69da84f706 100644 --- a/jscomp/common/js_config.mli +++ b/jscomp/common/js_config.mli @@ -96,7 +96,7 @@ val all_module_aliases : bool ref val no_stdlib: bool ref val no_export: bool ref -val record_as_js_object : bool ref + val as_ppx : bool ref val mono_empty_array : bool ref diff --git a/jscomp/others/node_path.ml b/jscomp/others/node_path.ml index e54234d15c..d8e3ad5606 100644 --- a/jscomp/others/node_path.ml +++ b/jscomp/others/node_path.ml @@ -35,14 +35,14 @@ external dirname : string -> string = "dirname" [@@bs.module "path"] external dirname_ext : string -> string -> string = "dirname" [@@bs.module "path"] type pathObject = - [%bs.obj: < - dir : string ; - root : string ; - base : string ; - name : string ; - ext : string - > - ] + < + dir : string ; + root : string ; + base : string ; + name : string ; + ext : string + > Js.t + external format : pathObject -> string = "format" [@@bs.module "path"] external isAbsolute : string -> bool = "isAbsolute" [@@bs.module "path"] diff --git a/jscomp/syntax/ast_core_type_class_type.ml b/jscomp/syntax/ast_core_type_class_type.ml index c11a61c6da..1858aef726 100644 --- a/jscomp/syntax/ast_core_type_class_type.ml +++ b/jscomp/syntax/ast_core_type_class_type.ml @@ -128,16 +128,11 @@ let default_typ_mapper = Bs_ast_mapper.default_mapper.typ we can only use it locally *) -let typ_mapper - record_as_js_object +let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) = match ty with - | {ptyp_desc = Ptyp_extension({txt = ("bs.obj"|"obj")}, PTyp ty)} - -> - Ext_ref.non_exn_protect record_as_js_object true - (fun _ -> self.typ self ty ) | {ptyp_attributes ; ptyp_desc = Ptyp_arrow (label, args, body); (* let it go without regard label names, @@ -205,14 +200,10 @@ let typ_mapper Ast_compatible.object_field label attrs (self.typ self core_type) in process_getter_setter ~not_getter_setter ~get ~set loc label ptyp_attrs core_type acc - )in - let inner_type = - { ty - with ptyp_desc = Ptyp_object(new_methods, closed_flag); - } in - if !record_as_js_object then - Ast_comb.to_js_type loc inner_type - else inner_type + )in + { ty + with ptyp_desc = Ptyp_object(new_methods, closed_flag); + } | _ -> default_typ_mapper self ty let handle_class_type_fields self fields = diff --git a/jscomp/syntax/ast_core_type_class_type.mli b/jscomp/syntax/ast_core_type_class_type.mli index 091551072a..7d04841e48 100644 --- a/jscomp/syntax/ast_core_type_class_type.mli +++ b/jscomp/syntax/ast_core_type_class_type.mli @@ -30,7 +30,6 @@ val handle_class_type_fields : Parsetree.class_type_field list val typ_mapper : - bool ref -> Bs_ast_mapper.mapper -> Parsetree.core_type -> Parsetree.core_type \ No newline at end of file diff --git a/jscomp/syntax/ast_exp_extension.ml b/jscomp/syntax/ast_exp_extension.ml index 72a7c7794c..68d6a2f0f9 100644 --- a/jscomp/syntax/ast_exp_extension.ml +++ b/jscomp/syntax/ast_exp_extension.ml @@ -27,7 +27,7 @@ open Ast_helper -let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper) +let handle_extension e (self : Bs_ast_mapper.mapper) (({txt ; loc} , payload) : Parsetree.extension) = begin match txt with | "bs.raw" | "raw" -> @@ -134,11 +134,15 @@ let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper) {e with pexp_desc = Ast_exp_handle_external.handle_debugger loc payload} | "bs.obj" | "obj" -> begin match payload with - | PStr [{pstr_desc = Pstr_eval (e,_)}] + |PStr [{pstr_desc = Pstr_eval ({pexp_desc = Pexp_record(label_exprs, None)} as e,_)}] -> - Ext_ref.non_exn_protect record_as_js_object true - (fun () -> self.expr self e ) - | _ -> Location.raise_errorf ~loc "Expect an expression here" + {e + with + pexp_desc = + Ast_util.record_as_js_object e.pexp_loc self label_exprs + } + + | _ -> Location.raise_errorf ~loc "Expect a record expression here" end | _ -> e (* For an unknown extension, we don't really need to process further*) diff --git a/jscomp/syntax/ast_exp_extension.mli b/jscomp/syntax/ast_exp_extension.mli index d19177b162..46656b3fea 100644 --- a/jscomp/syntax/ast_exp_extension.mli +++ b/jscomp/syntax/ast_exp_extension.mli @@ -24,7 +24,6 @@ val handle_extension : - bool ref -> Parsetree.expression -> Bs_ast_mapper.mapper -> Parsetree.extension -> diff --git a/jscomp/syntax/bs_builtin_ppx.ml b/jscomp/syntax/bs_builtin_ppx.ml index ad4b866f1b..e5cd1779f3 100644 --- a/jscomp/syntax/bs_builtin_ppx.ml +++ b/jscomp/syntax/bs_builtin_ppx.ml @@ -75,7 +75,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) = match e.pexp_desc with (** Its output should not be rewritten anymore *) | Pexp_extension extension -> - Ast_exp_extension.handle_extension Js_config.record_as_js_object e self extension + Ast_exp_extension.handle_extension e self extension | Pexp_constant ( Pconst_string (s, (Some delim))) @@ -134,26 +134,6 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) = end | Pexp_apply (fn, args ) -> Ast_exp_apply.app_exp_mapper e self fn args - | Pexp_record (label_exprs, opt_exp) -> - (* could be supported using `Object.assign`? - type - {[ - external update : 'a Js.t -> 'b Js.t -> 'a Js.t = "" - constraint 'b :> 'a - ]} - *) - if !Js_config.record_as_js_object then - (match opt_exp with - | None -> - { e with - pexp_desc = - Ast_util.record_as_js_object e.pexp_loc self label_exprs; - } - | Some e -> - Location.raise_errorf - ~loc:e.pexp_loc "`with` construct is not supported in js obj ") - else - default_expr_mapper self e | Pexp_object {pcstr_self; pcstr_fields} -> (match Ast_attributes.process_bs e.pexp_attributes with | true, pexp_attributes @@ -204,7 +184,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) = let typ_mapper (self : mapper) (typ : Parsetree.core_type) = - Ast_core_type_class_type.typ_mapper Js_config.record_as_js_object self typ + Ast_core_type_class_type.typ_mapper self typ let class_type_mapper (self : mapper) ({pcty_attributes; pcty_loc} as ctd : Parsetree.class_type) = match Ast_attributes.process_bs pcty_attributes with diff --git a/jscomp/test/arity.js b/jscomp/test/arity.js index 9036dce06b..e0955de20e 100644 --- a/jscomp/test/arity.js +++ b/jscomp/test/arity.js @@ -27,9 +27,16 @@ function h(u) { return m(1, 2); } +var nested = { + x: { + y: 3 + } +}; + exports.u = u; exports.u2 = u2; exports.f = f; exports.add = add; exports.h = h; +exports.nested = nested; /* No side effect */ diff --git a/jscomp/test/arity.re b/jscomp/test/arity.re index a8cae5147f..2a878edfcb 100644 --- a/jscomp/test/arity.re +++ b/jscomp/test/arity.re @@ -59,4 +59,7 @@ let u = obj => { let h = u => { let m = u##hi ; m(.1,2); -} \ No newline at end of file +} + + // +let nested = ({ "x" : {"y" : 3 }} : {. "x" : {. "y" : int }}) \ No newline at end of file diff --git a/jscomp/test/bs_unwrap_test.ml b/jscomp/test/bs_unwrap_test.ml index d54dc0199a..55c72dfb25 100644 --- a/jscomp/test/bs_unwrap_test.ml +++ b/jscomp/test/bs_unwrap_test.ml @@ -70,7 +70,7 @@ let _ = dyn_log3 ~req:(`Int 8) ~opt:(`Bool true) () external log4 : ([ `String of string - | `Options of [%bs.obj: < foo : int > ] + | `Options of < foo : int > Js.t ] [@bs.unwrap]) -> unit = "console.log" [@@bs.val] diff --git a/jscomp/test/chain_code_test.ml b/jscomp/test/chain_code_test.ml index e8198a2a51..885a6ba77a 100644 --- a/jscomp/test/chain_code_test.ml +++ b/jscomp/test/chain_code_test.ml @@ -25,6 +25,6 @@ let f4 h x y = (* ##(draw (x,y)) *) (* ##(draw(x,y)) *) let () = - eq __LOC__ 32 [%bs.obj f2 { x = {y = {z = 32}}} ] + eq __LOC__ 32 ( f2 [%obj{ x = [%obj{y = [%obj{z = 32}]}]}] ) let () = Mt.from_pair_suites __MODULE__ !suites diff --git a/jscomp/test/config2_test.ml b/jscomp/test/config2_test.ml index 1f2d9837c8..ac5d94638c 100644 --- a/jscomp/test/config2_test.ml +++ b/jscomp/test/config2_test.ml @@ -11,15 +11,15 @@ class type v2 = object end [@bs] type vv = - [%obj: < + < hey : int -> int -> int [@bs] - > ] + > Js.t type vv2 = - [%obj: < + < hey : int -> int -> int [@bs] - > ] + > Js.t let hh (x : v) : v2 = x diff --git a/jscomp/test/config2_test.mli b/jscomp/test/config2_test.mli index aaa2d62aac..ed0a887cba 100644 --- a/jscomp/test/config2_test.mli +++ b/jscomp/test/config2_test.mli @@ -9,14 +9,14 @@ class type v2 = object end [@bs] type vv = - [%bs.obj: < + < hey : int -> int -> int [@bs] - > ] + > Js.t type vv2 = - [%bs.obj: < + < hey : int -> int -> int [@bs] - > ] + > Js.t val test_v : v Js.t -> int diff --git a/jscomp/test/demo.ml b/jscomp/test/demo.ml index d019d9876f..b864888ed9 100644 --- a/jscomp/test/demo.ml +++ b/jscomp/test/demo.ml @@ -74,7 +74,7 @@ let ui_layout stackPanel##addChild grid; stackPanel##addChild inputCode; stackPanel##addChild button; - let mk_titleRow text = [%bs.obj {label = {text } } ] in + let mk_titleRow text = [%obj {label = [%obj{text }] } ] in let u = [%bs.obj {width = 200} ] in grid##minHeight #= 300; grid##titleRows #= diff --git a/jscomp/test/demo_binding.ml b/jscomp/test/demo_binding.ml index 1ced3f6231..1b0612d093 100644 --- a/jscomp/test/demo_binding.ml +++ b/jscomp/test/demo_binding.ml @@ -80,11 +80,11 @@ class type grid = object inherit widget inherit measure - method columns : [%bs.obj: ] array [@@bs.set] + method columns : Js.t array [@@bs.set] method titleRows : - [%bs.obj: