Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 7ff315d

Browse files
committed
Add conversion test for Js.t
1 parent 046bf63 commit 7ff315d

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

src/res_ast_conversion.ml

+4-13
Original file line numberDiff line numberDiff line change
@@ -385,19 +385,10 @@ let normalize =
385385
end;
386386
typ = (fun mapper typ ->
387387
match typ.ptyp_desc with
388-
| Ptyp_constr(
389-
{txt = Longident.Ldot(Longident.Lident "Js", "t")},
390-
[{ptyp_desc = Ptyp_object (fields, openFlag)} as objectType]
391-
) ->
392-
(* Js.t({"a": b}) -> {"a": b}. Since compiler >9.0.1 objects don't
393-
need Js.t wrapping anymore *)
394-
let newFields = fields |> List.map (fun (field: Parsetree.object_field) ->
395-
match field with
396-
| Otag (label, attributes, typ) -> Parsetree.Otag (label, attributes, mapper.typ mapper typ)
397-
| Oinherit typ -> Oinherit (mapper.typ mapper typ)
398-
)
399-
in
400-
{objectType with ptyp_desc = Ptyp_object (newFields, openFlag)}
388+
| Ptyp_constr({txt = Longident.Ldot(Longident.Lident "Js", "t")}, [arg]) ->
389+
(* Js.t({"a": b}) -> {"a": b}
390+
Since compiler >9.0.1 objects don't need Js.t wrapping anymore *)
391+
mapper.typ mapper arg
401392
| _ -> default_mapper.typ mapper typ
402393
);
403394
expr = (fun mapper expr ->

tests/conversion/reason/__snapshots__/render.spec.js.snap

+21
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,27 @@ let element = props[\\"element\\"]
12571257
12581258
let y = {\\"age\\": 30}
12591259
let y = {\\"age\\": 30, \\"name\\": \\"steve\\"}
1260+
1261+
type propField<'a> = {.}
1262+
type propField<'a> = {..} as 'a
1263+
type propField<'a> = {..} as 'a
1264+
type propField<'a> = Js.nullable<{..} as 'a>
1265+
1266+
type propField<'a> = {\\"a\\": b}
1267+
type propField<'a> = {..\\"a\\": b}
1268+
type propField<'a> = {\\"a\\": {\\"b\\": c}}
1269+
"
1270+
`;
1271+
1272+
exports[`jsObject.rei 1`] = `
1273+
"type propField<'a> = {.}
1274+
type propField<'a> = {..} as 'a
1275+
type propField<'a> = {..} as 'a
1276+
type propField<'a> = Js.nullable<{..} as 'a>
1277+
1278+
type propField<'a> = {\\"a\\": b}
1279+
type propField<'a> = {..\\"a\\": b}
1280+
type propField<'a> = {\\"a\\": {\\"b\\": c}}
12601281
"
12611282
`;
12621283

tests/conversion/reason/jsObject.re

+9
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ let element = props##element
44

55
let y = {"age": 30}
66
let y = {"age": 30, "name": "steve"}
7+
8+
type propField('a) = Js.t({.})
9+
type propField('a) = Js.t({..} as 'a)
10+
type propField('a) = Js.t({..}) as 'a
11+
type propField('a) = Js.nullable(Js.t({..} as 'a))
12+
13+
type propField('a) = {. "a": b}
14+
type propField('a) = {.. "a": b}
15+
type propField('a) = Js.t(Js.t({. "a": Js.t({. "b": c})}))

tests/conversion/reason/jsObject.rei

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type propField('a) = Js.t({.})
2+
type propField('a) = Js.t({..} as 'a)
3+
type propField('a) = Js.t({..}) as 'a
4+
type propField('a) = Js.nullable(Js.t({..} as 'a))
5+
6+
type propField('a) = {. "a": b}
7+
type propField('a) = {.. "a": b}
8+
type propField('a) = Js.t(Js.t({. "a": Js.t({. "b": c})}))

0 commit comments

Comments
 (0)