Skip to content

Commit bd4a233

Browse files
committed
Fix issue with gentype and stdlib json.
Fixes #7157
1 parent 7861628 commit bd4a233

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- Fix `Error.fromException`. https://github.com/rescript-lang/rescript/pull/7364
2828
- Fix signature of `throw`. https://github.com/rescript-lang/rescript/pull/7365
2929
- Fix formatter adds superfluous parens in pipe chain. https://github.com/rescript-lang/rescript/pull/7370
30+
- Fix issue wiht gentype and stdlib json. https://github.com/rescript-lang/rescript/pull/7378
3031

3132
#### :house: Internal
3233

Diff for: compiler/gentype/TranslateTypeExprFromTypes.ml

+8-12
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ let rec remove_option ~(label : Asttypes.Noloc.arg_label)
88
| Tconstr (Path.Pident id, [t], _), Optional lbl when Ident.name id = "option"
99
->
1010
Some (lbl, t)
11-
| Tconstr (Pdot (Path.Pident name_space, id, _), [t], _), Optional lbl
12-
when Ident.name name_space = "FB" && id = "option" ->
13-
Some (lbl, t)
1411
| Tlink t, _ -> t |> remove_option ~label
1512
| _ -> None
1613

@@ -75,11 +72,10 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
7572
}
7673
in
7774
match (path |> path_to_list |> List.rev, params_translation) with
78-
| (["FB"; "bool"] | ["bool"]), [] -> {dependencies = []; type_ = boolean_t}
79-
| (["FB"; "int"] | ["int"]), [] -> {dependencies = []; type_ = number_t}
80-
| (["FB"; "float"] | ["float"]), [] -> {dependencies = []; type_ = number_t}
81-
| ( ( ["FB"; "string"]
82-
| ["string"]
75+
| ["bool"], [] -> {dependencies = []; type_ = boolean_t}
76+
| ["int"], [] -> {dependencies = []; type_ = number_t}
77+
| ["float"], [] -> {dependencies = []; type_ = number_t}
78+
| ( ( ["string"]
8379
| ["String"; "t"]
8480
| ["Stdlib"; "String"; "t"]
8581
| ["Js"; ("String" | "String2"); "t"] ),
@@ -118,9 +114,8 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
118114
}
119115
| (["Js"; "Re"; "t"] | ["RegExp"; "t"] | ["Stdlib"; "RegExp"; "t"]), [] ->
120116
{dependencies = []; type_ = regexp_t}
121-
| (["FB"; "unit"] | ["unit"]), [] -> {dependencies = []; type_ = unit_t}
122-
| ( (["FB"; "array"] | ["array"] | ["Js"; ("Array" | "Array2"); "t"]),
123-
[param_translation] ) ->
117+
| ["unit"], [] -> {dependencies = []; type_ = unit_t}
118+
| (["array"] | ["Js"; ("Array" | "Array2"); "t"]), [param_translation] ->
124119
{param_translation with type_ = Array (param_translation.type_, Mutable)}
125120
| ["ImmutableArray"; "t"], [param_translation] ->
126121
{param_translation with type_ = Array (param_translation.type_, Immutable)}
@@ -220,7 +215,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
220215
| ["Jsx"; "element"] ),
221216
[] ) ->
222217
{dependencies = []; type_ = EmitType.type_react_element}
223-
| (["FB"; "option"] | ["option"]), [param_translation] ->
218+
| ["option"], [param_translation] ->
224219
{param_translation with type_ = Option param_translation.type_}
225220
| ( ( ["Js"; "Undefined"; "t"]
226221
| ["Undefined"; "t"]
@@ -253,6 +248,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
253248
| ( (["Js"; "Dict"; "t"] | ["Dict"; "t"] | ["dict"] | ["Stdlib"; "Dict"; "t"]),
254249
[param_translation] ) ->
255250
{param_translation with type_ = Dict param_translation.type_}
251+
| ["Stdlib_JSON"; "t"], [] -> {dependencies = []; type_ = unknown}
256252
| _ -> default_case ()
257253

258254
type process_variant = {

Diff for: tests/gentype_tests/typescript-react-example/src/Core.gen.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ export const weakset1: (x:WeakSet<number[]>) => WeakSet<number[]> = CoreJS.weaks
6868
export const option0: (x:(undefined | string)) => (undefined | string) = CoreJS.option0 as any;
6969

7070
export const option1: (x:(undefined | variant)) => (undefined | variant) = CoreJS.option1 as any;
71+
72+
export const jsonEncodeString: unknown = CoreJS.jsonEncodeString as any;

Diff for: tests/gentype_tests/typescript-react-example/src/Core.res

+3
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ external someFunWithNullUndefinedArg: (
8383
Nullable.t<string> /* Can also be Null.t or option as they are subtypes */,
8484
int,
8585
) => string = "someFunWithNullUndefinedArg"
86+
87+
@genType
88+
let jsonEncodeString = JSON.Encode.string("hello")

Diff for: tests/gentype_tests/typescript-react-example/src/Core.res.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)