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

Commit da10fed

Browse files
glennslcristianoc
authored andcommitted
jsx/fix: mangle generated type variables from newtypes
1 parent 56b69f6 commit da10fed

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/reactjs_jsx_ppx_v3.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,11 @@ let makeExternalDecl fnName loc namedArgListWithKeyAndRef namedTypeList =
234234
[@@raises Invalid_argument]
235235

236236
let newtypeToVar newtype type_ =
237+
let var_desc = Ptyp_var ("type-" ^ newtype) in
237238
let typ (mapper : Ast_mapper.mapper) typ =
238239
match typ.ptyp_desc with
239240
| Ptyp_constr ({txt = Lident name}, _) when name = newtype ->
240-
{typ with ptyp_desc = Ptyp_var newtype}
241+
{typ with ptyp_desc = var_desc}
241242
| _ -> Ast_mapper.default_mapper.typ mapper typ
242243
in
243244
let mapper = {Ast_mapper.default_mapper with typ} in
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
@obj
22
external makeProps: (
3-
~a: 'a,
4-
~b: array<option<[#Foo('a)]>>,
3+
~a: '\"type-a",
4+
~b: array<option<[#Foo('\"type-a")]>>,
5+
~c: 'a,
56
~key: string=?,
67
unit,
7-
) => {"a": 'a, "b": array<option<[#Foo('a)]>>} = ""
8-
let make = (type a, ~a: a, ~b: array<option<[#Foo(a)]>>, _) =>
8+
) => {"a": '\"type-a", "b": array<option<[#Foo('\"type-a")]>>, "c": 'a} = ""
9+
let make = (type a, ~a: a, ~b: array<option<[#Foo(a)]>>, ~c: 'a, _) =>
910
ReactDOMRe.createDOMElementVariadic("div", [])
1011
let make = {
11-
let \"Newtype" = (\"Props": {"a": 'a, "b": array<option<[#Foo('a)]>>}) =>
12-
make(~b=\"Props"["b"], ~a=\"Props"["a"])
12+
let \"Newtype" = (\"Props": {"a": '\"type-a", "b": array<option<[#Foo('\"type-a")]>>, "c": 'a}) =>
13+
make(~c=\"Props"["c"], ~b=\"Props"["b"], ~a=\"Props"["a"])
1314
\"Newtype"
1415
}

tests/ppx/react/newtype.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@react.component
2-
let make = (type a, ~a: a, ~b: array<option<[#Foo(a)]>>, _) => <div />
2+
let make = (type a, ~a: a, ~b: array<option<[#Foo(a)]>>, ~c: 'a, _) => <div />

0 commit comments

Comments
 (0)