Skip to content

Commit 4ef7501

Browse files
committed
tweak: add an example showing the new conversion from/ToJS
1 parent ecd89cb commit 4ef7501

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

jscomp/test/build.ninja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ build test/poly_variant_test.cmj : cc_cmi test/poly_variant_test.ml | test/mt.cm
494494
build test/poly_variant_test.cmi : cc test/poly_variant_test.mli | $stdlib
495495
build test/polymorphism_test.cmj : cc_cmi test/polymorphism_test.ml | test/polymorphism_test.cmi $stdlib
496496
build test/polymorphism_test.cmi : cc test/polymorphism_test.mli | $stdlib
497+
build test/polyvar_convert.cmi test/polyvar_convert.cmj : cc test/polyvar_convert.ml | $stdlib
497498
build test/polyvar_test.cmi test/polyvar_test.cmj : cc test/polyvar_test.ml | $stdlib
498499
build test/ppx_apply_test.cmi test/ppx_apply_test.cmj : cc test/ppx_apply_test.ml | test/mt.cmj $stdlib
499500
build test/ppx_this_obj_field.cmi test/ppx_this_obj_field.cmj : cc test/ppx_this_obj_field.ml | test/mt.cmj $stdlib

jscomp/test/debug_tmp.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
(* "-dlambda"; *)
66
(* "-dtypedtree"; *)
77
(* "-bs-diagnose" *)
8-
8+
(* "-bs-diagnose"; *)
9+
(* "-dsource"; *)
910
|]
1011
}]
1112

jscomp/test/polyvar_convert.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
4+
var revData = {"x":"a","b":"b"};
5+
6+
var data = {"a":"x","b":"b"};
7+
8+
function tToJs(x) {
9+
return data[x];
10+
}
11+
12+
function vFromJsOpt(s) {
13+
return revData[s];
14+
}
15+
16+
function vFromJs(s) {
17+
return revData[s];
18+
}
19+
20+
exports.revData = revData;
21+
exports.data = data;
22+
exports.tToJs = tToJs;
23+
exports.vFromJsOpt = vFromJsOpt;
24+
exports.vFromJs = vFromJs;
25+
/* No side effect */

jscomp/test/polyvar_convert.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
type t =
2+
[ `a [@as "x"]
3+
| `b ]
4+
5+
6+
let revData = [%raw {| {"x":"a","b":"b"} |}]
7+
let data = [%raw {| {"a":"x","b":"b"} |}]
8+
external get : 'a -> 'b -> 'c = "" [@@bs.get_index]
9+
10+
let tToJs (x : t ) : string =
11+
get data x
12+
13+
let vFromJsOpt (s : string) : t option =
14+
get revData s
15+
16+
let vFromJs (s : string) : t =
17+
get revData s

0 commit comments

Comments
 (0)