Skip to content

address #3146 #3151

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 4 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 22 additions & 24 deletions jscomp/syntax/ast_derive_js_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let js_field (o : Parsetree.expression) m =
(Exp.ident m)




let handle_config (config : Parsetree.expression option) =
match config with
Expand Down Expand Up @@ -152,7 +152,7 @@ let assertExp e =
let derivingName = "jsConverter"

(* let notApplicable loc =
Location.prerr_warning
Location.prerr_warning
loc
(Warnings.Bs_derive_warning ( derivingName ^ " not applicable to this type")) *)

Expand Down Expand Up @@ -194,8 +194,7 @@ let init () =
let coerceResultToNewType e =
if createType then
e +> newType
else e
in
else e in
match tdcl.ptype_kind with
| Ptype_record label_declarations ->
let exp =
Expand Down Expand Up @@ -254,7 +253,7 @@ let init () =
| Some name ->
name
| None ->
Ast_compatible.const_exp_string(Ast_compatible.label_of_name label)
Ast_compatible.const_exp_string(Ast_compatible.label_of_name label)
)
| _ -> assert false (* checked by [is_enum_polyvar] *)
) in
Expand All @@ -270,7 +269,7 @@ let init () =
Exp.tuple
[
Ast_compatible.const_exp_int i;
str
str
]
) ));
(
Expand Down Expand Up @@ -390,11 +389,11 @@ let init () =
+>
core_type
else
(Exp.ifthenelse
( (exp_param <=~ range_upper) &&~ (range_low <=~ exp_param))
(Exp.construct {loc; txt = Lident "Some"}
( Some (exp_param -~ Ast_compatible.const_exp_int offset)))
(Some (Exp.construct {loc; txt = Lident "None"} None)))
Exp.ifthenelse
( (exp_param <=~ range_upper) &&~ (range_low <=~ exp_param))
(Exp.construct {loc; txt = Ast_literal.predef_some}
( Some (exp_param -~ Ast_compatible.const_exp_int offset)))
(Some (Exp.construct {loc; txt = Ast_literal.predef_none} None))
+>
Ast_core_type.lift_option_type core_type
)
Expand All @@ -404,13 +403,13 @@ let init () =
else
begin
U.notApplicable
tdcl.Parsetree.ptype_loc
derivingName;
tdcl.Parsetree.ptype_loc
derivingName;
[]
end
| Ptype_open ->
U.notApplicable tdcl.Parsetree.ptype_loc
derivingName;
derivingName;
[] in
Ext_list.flat_map tdcls handle_tdcl
);
Expand Down Expand Up @@ -467,19 +466,18 @@ let init () =

| None ->
U.notApplicable tdcl.Parsetree.ptype_loc
derivingName;
derivingName;
[])

| Ptype_variant ctors
->

if Ast_polyvar.is_enum_constructors ctors then
let ty1 =
if createType then newType
else Ast_literal.type_int() in
let ty2 =
if createType then core_type
else Ast_core_type.lift_option_type core_type (*-FIXME**) in
else Ast_core_type.lift_option_type core_type in
newTypeStr +?
[
toJsType ty1;
Expand All @@ -489,19 +487,19 @@ let init () =
]

else
begin
U.notApplicable tdcl.Parsetree.ptype_loc
derivingName;
[]
end
begin
U.notApplicable tdcl.Parsetree.ptype_loc
derivingName;
[]
end
| Ptype_open ->
U.notApplicable tdcl.Parsetree.ptype_loc
derivingName;
derivingName;
[] in
Ext_list.flat_map tdcls handle_tdcl

);
expression_gen = None
}
)
;
;
2 changes: 1 addition & 1 deletion jscomp/test/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ test_incr_ref.cmj :
test_index.cmj : ../runtime/js.cmj
test_int_map_find.cmj :
test_internalOO.cmj :
test_is_js.cmj : test_is_js.cmi
test_is_js.cmj : mt.cmj test_is_js.cmi
test_js_ffi.cmj :
test_let.cmj :
test_list.cmj :
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/gpr_3142_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let v,u = tToJs, tFromJs


(* not applicable to thiis type, and unused warning*)
#if false then
#if 0 then
type t0 =
[ `a of int [@bs.as "hi"] ]
[@@bs.deriving jsConverter]
Expand Down
22 changes: 21 additions & 1 deletion jscomp/test/test_is_js.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
'use strict';

var Mt = require("./mt.js");

var suites = /* record */[/* contents : [] */0];

var test_id = /* record */[/* contents */0];

function b(loc, x) {
return Mt.bool_suites(test_id, suites, loc, x);
}

b("File \"test_is_js.ml\", line 15, characters 2-9", true);

b("File \"test_is_js.ml\", line 23, characters 2-9", true);

b("File \"test_is_js.ml\", line 37, characters 2-9", true);

Mt.from_pair_suites("test_is_js.ml", suites[0]);

/* Not a pure module */
35 changes: 35 additions & 0 deletions jscomp/test/test_is_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,38 @@ let v =
#else
false
#end

let suites : Mt.pair_suites ref = ref []
let test_id = ref 0
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
let b loc x = Mt.bool_suites ~test_id ~suites loc x;;


#if 1 then
b __LOC__ true;;
#end

#if 0 then
b __LOC__ false ;;
#end

#if 1 > 0 then
b __LOC__ true;;
#end


#if 1 < 0 then
b __LOC__ false;;
#end

#if 0 > 1 then
b __LOC__ false;;
#end


#if 0 < 1 then
b __LOC__ true;;
#end


let () = Mt.from_pair_suites __FILE__ !suites
Loading