diff --git a/jscomp/bin/bsdep.ml b/jscomp/bin/bsdep.ml index 2611f829e7..896fc065ed 100644 --- a/jscomp/bin/bsdep.ml +++ b/jscomp/bin/bsdep.ml @@ -31793,15 +31793,14 @@ let rec unsafe_mapper : Ast_mapper.mapper = payload) -> let strip s = - let len = String.length s in - if s.[len - 1] = '_' then - String.sub s 0 (len - 1) - else s in + match s with + | "_module" -> "module" + | x -> x in begin match Ast_payload.as_ident payload with | Some {txt = Lident - ("__filename" + ( "__filename" | "__dirname" - | "module_" + | "_module" | "require" as name); loc} -> let exp = @@ -31810,7 +31809,7 @@ let rec unsafe_mapper : Ast_mapper.mapper = (strip name) ) in let typ = Ast_comb.to_undefined_type loc @@ - if name = "module_" then + if name = "_module" then Typ.constr ~loc { txt = Ldot (Lident "Node", "node_module") ; loc} [] diff --git a/jscomp/bin/bsppx.ml b/jscomp/bin/bsppx.ml index 52238ab28f..19432e96dc 100644 --- a/jscomp/bin/bsppx.ml +++ b/jscomp/bin/bsppx.ml @@ -14977,15 +14977,14 @@ let rec unsafe_mapper : Ast_mapper.mapper = payload) -> let strip s = - let len = String.length s in - if s.[len - 1] = '_' then - String.sub s 0 (len - 1) - else s in + match s with + | "_module" -> "module" + | x -> x in begin match Ast_payload.as_ident payload with | Some {txt = Lident - ("__filename" + ( "__filename" | "__dirname" - | "module_" + | "_module" | "require" as name); loc} -> let exp = @@ -14994,7 +14993,7 @@ let rec unsafe_mapper : Ast_mapper.mapper = (strip name) ) in let typ = Ast_comb.to_undefined_type loc @@ - if name = "module_" then + if name = "_module" then Typ.constr ~loc { txt = Ldot (Lident "Node", "node_module") ; loc} [] diff --git a/jscomp/bin/whole_compiler.ml b/jscomp/bin/whole_compiler.ml index 440713838b..a2205f73ec 100644 --- a/jscomp/bin/whole_compiler.ml +++ b/jscomp/bin/whole_compiler.ml @@ -66008,7 +66008,7 @@ let const ct : t = Lconst ct *) let apply fn args loc status : t = match fn with - (*| Lfunction {kind ; params ; + | Lfunction {kind ; params ; body = Lprim {primitive = (Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt | Pis_null | Pis_null_undefined | Pjs_boolean_to_bool | Pjs_typeof ) as wrap; args = [Lprim ({primitive; args = inner_args} as primitive_call)] @@ -66020,7 +66020,7 @@ let apply fn args loc status : t = Lprim {primitive = wrap ; args = [Lprim { primitive_call with args ; loc = loc }] ; loc } | exception _ -> Lapply { fn; args; loc; status } - end *) + end | Lfunction {kind ; params; body = Lsequence (Lprim ({primitive; args = inner_args}as primitive_call), (Lconst _ as const )) } -> @@ -66203,16 +66203,16 @@ let prim ~primitive:(prim : primitive) ~args:(ll : t list) loc : t = Lift.int (int_of_float (float_of_string a)) (* | Pnegfloat -> Lift.float (-. a) *) (* | Pabsfloat -> Lift.float (abs_float a) *) - | Pstringlength, ( (Const_string (a)) ) + | Pstringlength, Const_string a -> Lift.int (String.length a) (* | Pnegbint Pnativeint, ( (Const_nativeint i)) *) (* -> *) (* Lift.nativeint (Nativeint.neg i) *) - | Pnegbint Pint32, ( (Const_int32 a)) + | Pnegbint Pint32, Const_int32 a -> Lift.int32 (Int32.neg a) - | Pnegbint Pint64, ( (Const_int64 a)) + | Pnegbint Pint64, Const_int64 a -> Lift.int64 (Int64.neg a) | Pnot , Const_pointer (a,_) @@ -66413,6 +66413,7 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : t = | Pint_as_pointer | Pidentity -> begin match args with [x] -> x | _ -> assert false end + | Pccall _ -> assert false | Prevapply -> assert false | Pdirapply -> assert false | Ploc loc -> assert false (* already compiled away here*) @@ -66448,38 +66449,6 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : t = -> prim ~primitive:(Pduprecord(repr,i)) ~args loc | Plazyforce -> prim ~primitive:Plazyforce ~args loc - | Pccall a -> - let prim_name = a.prim_name in - begin match Ast_ffi_types.from_string a.prim_native_name with - | Ffi_normal -> - if Pervasives.not @@ Ext_string.starts_with prim_name "js_" then - prim ~primitive:(Pccall a ) ~args loc else - if prim_name = Literals.js_debugger then - prim ~primitive:Pdebugger ~args loc else - if prim_name = Literals.js_fn_run || prim_name = Literals.js_method_run then - prim ~primitive:(Pjs_fn_run (int_of_string a.prim_native_name)) ~args loc else - if prim_name = Literals.js_fn_mk then - prim ~primitive:(Pjs_fn_make (int_of_string a.prim_native_name)) ~args loc else - if prim_name = Literals.js_fn_method then - prim ~primitive:(Pjs_fn_method (int_of_string a.prim_native_name)) ~args loc else - if prim_name = Literals.js_fn_runmethod then - prim ~primitive:(Pjs_fn_runmethod (int_of_string a.prim_native_name)) ~args loc - else - prim ~primitive:(Pccall a) ~args loc - | Ffi_obj_create labels -> - prim ~primitive:(Pjs_object_create labels) ~args loc - | Ffi_bs(arg_types, result_type, ffi) -> - - if no_auto_uncurried_arg_types arg_types then - result_wrap loc result_type @@ prim ~primitive:(Pjs_call(prim_name, arg_types, ffi)) - ~args loc - else - let n_arg_types, n_args = - transform_uncurried_arg_type loc arg_types args in - result_wrap loc result_type @@ - prim ~primitive:(Pjs_call (prim_name, n_arg_types, ffi)) - ~args:n_args loc - end | Praise _ -> if Js_config.get_no_any_assert () then @@ -66860,23 +66829,23 @@ let convert exports lam : _ * _ = | Lprim(Prevapply, [x ; f ], outer_loc) | Lprim(Pdirapply, [f ; x], outer_loc) -> begin match f with - (* [x|>f] - TODO: [airty = 0] when arity =0, it can not be escaped user can only - write [f x ] instead of [x |> f ] - *) + (* [x|>f] + TODO: [airty = 0] when arity =0, it can not be escaped user can only + write [f x ] instead of [x |> f ] + *) | Lfunction(kind, [param],Lprim(external_fn,[Lvar inner_arg],inner_loc)) - when Ident.same param inner_arg - -> - aux (Lprim(external_fn, [x], outer_loc)) + when Ident.same param inner_arg + -> + aux (Lprim(external_fn, [x], outer_loc)) | Lapply(Lfunction(kind, params,Lprim(external_fn,inner_args,inner_loc)), args, outer_loc ) (* x |> f a *) - - when Ext_list.for_all2_no_exn (fun x y -> match y with Lambda.Lvar y when Ident.same x y -> true | _ -> false ) params inner_args - && - Ext_list.length_larger_than_n 1 inner_args args - -> - - aux (Lprim(external_fn, args @ [x], outer_loc)) + + when Ext_list.for_all2_no_exn (fun x y -> match y with Lambda.Lvar y when Ident.same x y -> true | _ -> false ) params inner_args + && + Ext_list.length_larger_than_n 1 inner_args args + -> + + aux (Lprim(external_fn, args @ [x], outer_loc)) | _ -> let x = aux x in let f = aux f in @@ -66927,7 +66896,7 @@ let convert exports lam : _ * _ = prim ~primitive:Pnull_to_opt ~args:[aux arg] loc | _ -> assert false end - | Lprim (Pccall {prim_name = "js_is_nil"}, args, loc) -> + | Lprim (Pccall {prim_name = "js_is_nil" }, args, loc) -> begin match args with | [arg] -> prim ~primitive:Pis_null ~args:[aux arg] loc | _ -> assert false @@ -66958,23 +66927,55 @@ let convert exports lam : _ * _ = | [e] -> prim ~primitive:Pjs_typeof ~args:[aux e] loc | _ -> assert false end + | Lprim(Pccall a, args, loc) -> + let args = List.map aux args in + let prim_name = a.prim_name in + begin match Ast_ffi_types.from_string a.prim_native_name with + | Ffi_normal -> + if Pervasives.not @@ Ext_string.starts_with prim_name "js_" then + prim ~primitive:(Pccall a ) ~args loc else + if prim_name = Literals.js_debugger then + prim ~primitive:Pdebugger ~args loc else + if prim_name = Literals.js_fn_run || prim_name = Literals.js_method_run then + prim ~primitive:(Pjs_fn_run (int_of_string a.prim_native_name)) ~args loc else + if prim_name = Literals.js_fn_mk then + prim ~primitive:(Pjs_fn_make (int_of_string a.prim_native_name)) ~args loc else + if prim_name = Literals.js_fn_method then + prim ~primitive:(Pjs_fn_method (int_of_string a.prim_native_name)) ~args loc else + if prim_name = Literals.js_fn_runmethod then + prim ~primitive:(Pjs_fn_runmethod (int_of_string a.prim_native_name)) ~args loc + else + prim ~primitive:(Pccall a) ~args loc + | Ffi_obj_create labels -> + prim ~primitive:(Pjs_object_create labels) ~args loc + | Ffi_bs(arg_types, result_type, ffi) -> + + if no_auto_uncurried_arg_types arg_types then + result_wrap loc result_type @@ prim ~primitive:(Pjs_call(prim_name, arg_types, ffi)) + ~args loc + else + let n_arg_types, n_args = + transform_uncurried_arg_type loc arg_types args in + result_wrap loc result_type @@ + prim ~primitive:(Pjs_call (prim_name, n_arg_types, ffi)) + ~args:n_args loc + end + (* TODO: pick a invalid external name to avod conflict *) + | Lprim (Pgetglobal id, args, loc) -> + let args = List.map aux args in + if Ident.is_predef_exn id then + Lprim {primitive = Pglobal_exception id; args ; loc} + else + begin + may_depend may_depends (Lam_module_ident.of_ml id); + assert (args = []); + Lglobal_module id + end | Lprim (primitive,args, loc) -> - let args = (List.map aux args) in - begin match primitive with - | Pgetglobal id -> - if Ident.is_predef_exn id then - Lprim {primitive = Pglobal_exception id; args ; loc} - else - begin - may_depend may_depends (Lam_module_ident.of_ml id); - assert (args = []); - Lglobal_module id - end - | _ -> - lam_prim ~primitive ~args loc - end + let args = List.map aux args in + lam_prim ~primitive ~args loc | Lswitch (e,s) -> Lswitch (aux e, aux_switch s) | Lstringswitch (e, cases, default,_) -> @@ -67017,8 +67018,8 @@ let convert exports lam : _ * _ = Lsend(kind, aux a, b, List.map aux ls, loc ) end | Levent (e, event) -> - (* disabled by upstream*) - assert false + (* disabled by upstream*) + assert false | Lifused (id, e) -> Lifused(id, aux e) (* TODO: remove it ASAP *) and aux_switch (s : Lambda.lambda_switch) : switch = @@ -91986,8 +91987,19 @@ let translate loc | _ -> assert false end | Lam.Pnull_undefined_to_opt -> - E.runtime_call Js_config.js_primitive - "js_from_nullable_def" args + (*begin match args with + | [e] -> + begin match e.expression_desc with + | Var _ -> + E.econd (E.or_ (E.is_undef e) (E.is_nil e)) + Js_of_lam_option.none + (Js_of_lam_option.some e) + | _ ->*) + E.runtime_call Js_config.js_primitive + "js_from_nullable_def" args + (*end*) + (* | _ -> assert false *) + (* end *) | Pis_null -> begin match args with | [e] -> E.is_nil e @@ -103402,15 +103414,14 @@ let rec unsafe_mapper : Ast_mapper.mapper = payload) -> let strip s = - let len = String.length s in - if s.[len - 1] = '_' then - String.sub s 0 (len - 1) - else s in + match s with + | "_module" -> "module" + | x -> x in begin match Ast_payload.as_ident payload with | Some {txt = Lident - ("__filename" + ( "__filename" | "__dirname" - | "module_" + | "_module" | "require" as name); loc} -> let exp = @@ -103419,7 +103430,7 @@ let rec unsafe_mapper : Ast_mapper.mapper = (strip name) ) in let typ = Ast_comb.to_undefined_type loc @@ - if name = "module_" then + if name = "_module" then Typ.constr ~loc { txt = Ldot (Lident "Node", "node_module") ; loc} [] diff --git a/jscomp/build.sh b/jscomp/build.sh index 418cb1c74a..86355a43dd 100755 --- a/jscomp/build.sh +++ b/jscomp/build.sh @@ -44,4 +44,11 @@ echo "Snapshot && update deps" >> ./build.compile make -C test depend 2>>../build.compile make -j7 depend snapshotml 2>> ./build.compile + +echo "Updating dependencies in runtime" +cd runtime; make depend; cd .. + +echo "Updating dependencies in others" +cd others; make depend; cd .. + echo "Done" >> ./build.compile diff --git a/jscomp/core/lam.ml b/jscomp/core/lam.ml index 8a0ad0dd2e..680a79a384 100644 --- a/jscomp/core/lam.ml +++ b/jscomp/core/lam.ml @@ -1034,16 +1034,16 @@ let prim ~primitive:(prim : primitive) ~args:(ll : t list) loc : t = Lift.int (int_of_float (float_of_string a)) (* | Pnegfloat -> Lift.float (-. a) *) (* | Pabsfloat -> Lift.float (abs_float a) *) - | Pstringlength, ( (Const_string (a)) ) + | Pstringlength, Const_string a -> Lift.int (String.length a) (* | Pnegbint Pnativeint, ( (Const_nativeint i)) *) (* -> *) (* Lift.nativeint (Nativeint.neg i) *) - | Pnegbint Pint32, ( (Const_int32 a)) + | Pnegbint Pint32, Const_int32 a -> Lift.int32 (Int32.neg a) - | Pnegbint Pint64, ( (Const_int64 a)) + | Pnegbint Pint64, Const_int64 a -> Lift.int64 (Int64.neg a) | Pnot , Const_pointer (a,_) @@ -1244,6 +1244,7 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : t = | Pint_as_pointer | Pidentity -> begin match args with [x] -> x | _ -> assert false end + | Pccall _ -> assert false | Prevapply -> assert false | Pdirapply -> assert false | Ploc loc -> assert false (* already compiled away here*) @@ -1279,38 +1280,6 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : t = -> prim ~primitive:(Pduprecord(repr,i)) ~args loc | Plazyforce -> prim ~primitive:Plazyforce ~args loc - | Pccall a -> - let prim_name = a.prim_name in - begin match Ast_ffi_types.from_string a.prim_native_name with - | Ffi_normal -> - if Pervasives.not @@ Ext_string.starts_with prim_name "js_" then - prim ~primitive:(Pccall a ) ~args loc else - if prim_name = Literals.js_debugger then - prim ~primitive:Pdebugger ~args loc else - if prim_name = Literals.js_fn_run || prim_name = Literals.js_method_run then - prim ~primitive:(Pjs_fn_run (int_of_string a.prim_native_name)) ~args loc else - if prim_name = Literals.js_fn_mk then - prim ~primitive:(Pjs_fn_make (int_of_string a.prim_native_name)) ~args loc else - if prim_name = Literals.js_fn_method then - prim ~primitive:(Pjs_fn_method (int_of_string a.prim_native_name)) ~args loc else - if prim_name = Literals.js_fn_runmethod then - prim ~primitive:(Pjs_fn_runmethod (int_of_string a.prim_native_name)) ~args loc - else - prim ~primitive:(Pccall a) ~args loc - | Ffi_obj_create labels -> - prim ~primitive:(Pjs_object_create labels) ~args loc - | Ffi_bs(arg_types, result_type, ffi) -> - - if no_auto_uncurried_arg_types arg_types then - result_wrap loc result_type @@ prim ~primitive:(Pjs_call(prim_name, arg_types, ffi)) - ~args loc - else - let n_arg_types, n_args = - transform_uncurried_arg_type loc arg_types args in - result_wrap loc result_type @@ - prim ~primitive:(Pjs_call (prim_name, n_arg_types, ffi)) - ~args:n_args loc - end | Praise _ -> if Js_config.get_no_any_assert () then @@ -1691,23 +1660,23 @@ let convert exports lam : _ * _ = | Lprim(Prevapply, [x ; f ], outer_loc) | Lprim(Pdirapply, [f ; x], outer_loc) -> begin match f with - (* [x|>f] - TODO: [airty = 0] when arity =0, it can not be escaped user can only - write [f x ] instead of [x |> f ] - *) + (* [x|>f] + TODO: [airty = 0] when arity =0, it can not be escaped user can only + write [f x ] instead of [x |> f ] + *) | Lfunction(kind, [param],Lprim(external_fn,[Lvar inner_arg],inner_loc)) - when Ident.same param inner_arg - -> - aux (Lprim(external_fn, [x], outer_loc)) + when Ident.same param inner_arg + -> + aux (Lprim(external_fn, [x], outer_loc)) | Lapply(Lfunction(kind, params,Lprim(external_fn,inner_args,inner_loc)), args, outer_loc ) (* x |> f a *) - - when Ext_list.for_all2_no_exn (fun x y -> match y with Lambda.Lvar y when Ident.same x y -> true | _ -> false ) params inner_args - && - Ext_list.length_larger_than_n 1 inner_args args - -> - - aux (Lprim(external_fn, args @ [x], outer_loc)) + + when Ext_list.for_all2_no_exn (fun x y -> match y with Lambda.Lvar y when Ident.same x y -> true | _ -> false ) params inner_args + && + Ext_list.length_larger_than_n 1 inner_args args + -> + + aux (Lprim(external_fn, args @ [x], outer_loc)) | _ -> let x = aux x in let f = aux f in @@ -1758,7 +1727,7 @@ let convert exports lam : _ * _ = prim ~primitive:Pnull_to_opt ~args:[aux arg] loc | _ -> assert false end - | Lprim (Pccall {prim_name = "js_is_nil"}, args, loc) -> + | Lprim (Pccall {prim_name = "js_is_nil" }, args, loc) -> begin match args with | [arg] -> prim ~primitive:Pis_null ~args:[aux arg] loc | _ -> assert false @@ -1789,23 +1758,55 @@ let convert exports lam : _ * _ = | [e] -> prim ~primitive:Pjs_typeof ~args:[aux e] loc | _ -> assert false end + | Lprim(Pccall a, args, loc) -> + let args = List.map aux args in + let prim_name = a.prim_name in + begin match Ast_ffi_types.from_string a.prim_native_name with + | Ffi_normal -> + if Pervasives.not @@ Ext_string.starts_with prim_name "js_" then + prim ~primitive:(Pccall a ) ~args loc else + if prim_name = Literals.js_debugger then + prim ~primitive:Pdebugger ~args loc else + if prim_name = Literals.js_fn_run || prim_name = Literals.js_method_run then + prim ~primitive:(Pjs_fn_run (int_of_string a.prim_native_name)) ~args loc else + if prim_name = Literals.js_fn_mk then + prim ~primitive:(Pjs_fn_make (int_of_string a.prim_native_name)) ~args loc else + if prim_name = Literals.js_fn_method then + prim ~primitive:(Pjs_fn_method (int_of_string a.prim_native_name)) ~args loc else + if prim_name = Literals.js_fn_runmethod then + prim ~primitive:(Pjs_fn_runmethod (int_of_string a.prim_native_name)) ~args loc + else + prim ~primitive:(Pccall a) ~args loc + | Ffi_obj_create labels -> + prim ~primitive:(Pjs_object_create labels) ~args loc + | Ffi_bs(arg_types, result_type, ffi) -> + + if no_auto_uncurried_arg_types arg_types then + result_wrap loc result_type @@ prim ~primitive:(Pjs_call(prim_name, arg_types, ffi)) + ~args loc + else + let n_arg_types, n_args = + transform_uncurried_arg_type loc arg_types args in + result_wrap loc result_type @@ + prim ~primitive:(Pjs_call (prim_name, n_arg_types, ffi)) + ~args:n_args loc + end + (* TODO: pick a invalid external name to avod conflict *) + | Lprim (Pgetglobal id, args, loc) -> + let args = List.map aux args in + if Ident.is_predef_exn id then + Lprim {primitive = Pglobal_exception id; args ; loc} + else + begin + may_depend may_depends (Lam_module_ident.of_ml id); + assert (args = []); + Lglobal_module id + end | Lprim (primitive,args, loc) -> - let args = (List.map aux args) in - begin match primitive with - | Pgetglobal id -> - if Ident.is_predef_exn id then - Lprim {primitive = Pglobal_exception id; args ; loc} - else - begin - may_depend may_depends (Lam_module_ident.of_ml id); - assert (args = []); - Lglobal_module id - end - | _ -> - lam_prim ~primitive ~args loc - end + let args = List.map aux args in + lam_prim ~primitive ~args loc | Lswitch (e,s) -> Lswitch (aux e, aux_switch s) | Lstringswitch (e, cases, default,_) -> @@ -1848,8 +1849,8 @@ let convert exports lam : _ * _ = Lsend(kind, aux a, b, List.map aux ls, loc ) end | Levent (e, event) -> - (* disabled by upstream*) - assert false + (* disabled by upstream*) + assert false | Lifused (id, e) -> Lifused(id, aux e) (* TODO: remove it ASAP *) and aux_switch (s : Lambda.lambda_switch) : switch = diff --git a/jscomp/core/lam_compile_primitive.ml b/jscomp/core/lam_compile_primitive.ml index a78313a6ff..7e79ae956f 100644 --- a/jscomp/core/lam_compile_primitive.ml +++ b/jscomp/core/lam_compile_primitive.ml @@ -87,8 +87,19 @@ let translate loc | _ -> assert false end | Lam.Pnull_undefined_to_opt -> - E.runtime_call Js_config.js_primitive - "js_from_nullable_def" args + (*begin match args with + | [e] -> + begin match e.expression_desc with + | Var _ -> + E.econd (E.or_ (E.is_undef e) (E.is_nil e)) + Js_of_lam_option.none + (Js_of_lam_option.some e) + | _ ->*) + E.runtime_call Js_config.js_primitive + "js_from_nullable_def" args + (*end*) + (* | _ -> assert false *) + (* end *) | Pis_null -> begin match args with | [e] -> E.is_nil e diff --git a/jscomp/others/node_fs.ml b/jscomp/others/node_fs.ml index 848783a18e..e0e0eba13b 100644 --- a/jscomp/others/node_fs.ml +++ b/jscomp/others/node_fs.ml @@ -124,5 +124,10 @@ external readFileSync : string = "readFileSync" [@@bs.val] [@@bs.module "fs"] +external readFileAsUtf8Sync : + string -> (_[@bs.as "utf8"]) -> + string = "readFileSync" +[@@bs.val] [@@bs.module "fs"] + external existsSync : string -> bool = "" [@@bs.val] [@@bs.module "fs"] diff --git a/jscomp/runtime/.depend b/jscomp/runtime/.depend index 81be433f1e..95355f3124 100644 --- a/jscomp/runtime/.depend +++ b/jscomp/runtime/.depend @@ -2,18 +2,18 @@ caml_array.cmj : caml_array.cmi caml_string.cmj : bs_string.cmj caml_string.cmi caml_bytes.cmj : caml_bytes.cmi caml_obj.cmj : js.cmj caml_array.cmj bs_obj.cmj caml_obj.cmi -caml_int64.cmj : typed_array.cmj js_float.cmj js.cmj caml_utils.cmj \ - caml_int32.cmj bs_string.cmj caml_int64.cmi +caml_int64.cmj : typed_array.cmj js_float.cmj caml_utils.cmj caml_int32.cmj \ + bs_string.cmj caml_int64.cmi caml_exceptions.cmj : caml_builtin_exceptions.cmj caml_exceptions.cmi caml_utils.cmj : caml_utils.cmi caml_sys.cmj : js_float.cmj caml_sys.cmi caml_io.cmj : js_undefined.cmj js.cmj bs_string.cmj -caml_float.cmj : typed_array.cmj js_float.cmj js.cmj caml_float.cmi +caml_float.cmj : typed_array.cmj js_float.cmj caml_float.cmi caml_lexer.cmj : caml_lexer.cmi caml_parser.cmj : caml_parser.cmi caml_primitive.cmj : caml_primitive.cmi caml_format.cmj : js_nativeint.cmj js_int64.cmj js_int.cmj js_float.cmj \ - js.cmj caml_utils.cmj bs_string.cmj caml_format.cmi + caml_utils.cmj bs_string.cmj caml_format.cmi caml_md5.cmj : bs_string.cmj caml_md5.cmi caml_queue.cmj : caml_queue.cmi caml_hash.cmj : js_undefined.cmj js.cmj caml_queue.cmj bs_string.cmj \ @@ -22,14 +22,15 @@ caml_weak.cmj : js_undefined.cmj caml_array.cmj caml_weak.cmi caml_backtrace.cmj : caml_backtrace.cmi caml_int32.cmj : caml_int32.cmi caml_gc.cmj : caml_gc.cmi -typed_array.cmj : +typed_array.cmj : js.cmj js_primitive.cmj : js_undefined.cmj js.cmj js_primitive.cmi caml_basic.cmj : js_undefined.cmj js.cmj caml_basic.cmi caml_oo.cmj : caml_array.cmj bs_obj.cmj caml_oo.cmi -curry.cmj : caml_oo.cmj caml_array.cmj +curry.cmj : caml_array.cmj +caml_oo_curry.cmj : curry.cmj caml_oo.cmj caml_module.cmj : bs_string.cmj : -js_float.cmj : js.cmj +js_float.cmj : bs_obj.cmj : js.cmj js_nativeint.cmj : js_int.cmj : diff --git a/jscomp/runtime/Makefile b/jscomp/runtime/Makefile index c7d431c175..98e805f407 100644 --- a/jscomp/runtime/Makefile +++ b/jscomp/runtime/Makefile @@ -17,6 +17,7 @@ caml_oo.cmj : caml_array.cmj js_unsafe.cmj:js_unsafe.cmi js.cmj js.cmi js_unsafe.cmi js.cmj: js.cmi caml_format.cmj caml_io.cmj caml_oo_curry.cmj: curry.cmj +caml_format.cmj: caml_int64.cmj caml_int32.cmj caml_utils.cmj caml_string.cmj caml_weak.cmj caml_module.cmj: caml_obj.cmj js_primitive.cmj caml_builtin_exceptions.cmj: caml_builtin_exceptions.cmi js_unsafe.cmi block.cmj: block.cmi diff --git a/jscomp/syntax/ppx_entry.ml b/jscomp/syntax/ppx_entry.ml index fa17460837..9db810cfbf 100644 --- a/jscomp/syntax/ppx_entry.ml +++ b/jscomp/syntax/ppx_entry.ml @@ -274,15 +274,14 @@ let rec unsafe_mapper : Ast_mapper.mapper = payload) -> let strip s = - let len = String.length s in - if s.[len - 1] = '_' then - String.sub s 0 (len - 1) - else s in + match s with + | "_module" -> "module" + | x -> x in begin match Ast_payload.as_ident payload with | Some {txt = Lident - ("__filename" + ( "__filename" | "__dirname" - | "module_" + | "_module" | "require" as name); loc} -> let exp = @@ -291,7 +290,7 @@ let rec unsafe_mapper : Ast_mapper.mapper = (strip name) ) in let typ = Ast_comb.to_undefined_type loc @@ - if name = "module_" then + if name = "_module" then Typ.constr ~loc { txt = Ldot (Lident "Node", "node_module") ; loc} [] diff --git a/jscomp/test/.depend b/jscomp/test/.depend index 7c083b4d2c..2420213ed4 100644 --- a/jscomp/test/.depend +++ b/jscomp/test/.depend @@ -522,6 +522,7 @@ typed_array_test.cmj : ../runtime/typed_array.cmj mt.cmj ../runtime/js.cmj \ ../stdlib/int32.cmj ../stdlib/array.cmj typeof_test.cmj : mt.cmj ../runtime/js.cmj uncurry_glob_test.cmj : ../runtime/caml_utils.cmj +undef_regression2_test.cmj : ../runtime/js.cmj undef_regression_test.cmj : ../runtime/js.cmj ../runtime/bs_obj.cmj unicode_type_error.cmj : unitest_string.cmj : diff --git a/jscomp/test/fs_test.ml b/jscomp/test/fs_test.ml index d2679a0c3c..1ada1ee6df 100644 --- a/jscomp/test/fs_test.ml +++ b/jscomp/test/fs_test.ml @@ -39,7 +39,7 @@ let () = let _content = readFileSync current_file `utf8 in let _file_list = Fs.readdirSync current_dir_name in let pathobj = Path.parse current_dir_name in - match Js.Undefined.to_opt [%bs.node module_] with + match Js.Undefined.to_opt [%bs.node _module] with | Some module_ -> Js.log (module_##id, module_##paths) ; eq __LOC__ (pathobj##name, "test" ) diff --git a/jscomp/test/test_require.ml b/jscomp/test/test_require.ml index 47bcf8b0b1..3f9137904e 100644 --- a/jscomp/test/test_require.ml +++ b/jscomp/test/test_require.ml @@ -5,7 +5,7 @@ let () = | None -> () | Some u -> Js.log @@ u#@resolve "./test_require.js"; - if u##main == [%bs.node module_] && u##main != Js.Undefined.empty then + if u##main == [%bs.node _module] && u##main != Js.Undefined.empty then Js.log "is main" else Js.log "not main" diff --git a/jscomp/test/undef_regression2_test.ml b/jscomp/test/undef_regression2_test.ml new file mode 100644 index 0000000000..a1fe5a6833 --- /dev/null +++ b/jscomp/test/undef_regression2_test.ml @@ -0,0 +1,9 @@ + + + + + +let a = + match Js.Undefined.to_opt [%raw {|___undefined_value|}] with + | None -> 1 + | Some _ -> 2 \ No newline at end of file diff --git a/site/docsource/Release.1.5.1.adoc b/site/docsource/Release.1.5.1.adoc new file mode 100644 index 0000000000..a0b1225c9d --- /dev/null +++ b/site/docsource/Release.1.5.1.adoc @@ -0,0 +1,6 @@ + + + +# Minor breaking changes + +changes NodeJS special variables from `module_` to `_module` to make it more consistent \ No newline at end of file