Skip to content

Commit 295116a

Browse files
committed
fix gentype output
1 parent b574afe commit 295116a

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

compiler/gentype/TranslateTypeExprFromTypes.ml

+28-13
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,40 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
8181
| ( ( ["FB"; "string"]
8282
| ["string"]
8383
| ["String"; "t"]
84+
| ["Stdlib_String"; "t"]
8485
| ["Js"; ("String" | "String2"); "t"] ),
8586
[] ) ->
8687
{dependencies = []; type_ = string_t}
87-
| (["Js"; "Types"; "bigint_val"] | ["BigInt"; "t"]), [] ->
88+
| ( (["Js"; "Types"; "bigint_val"] | ["BigInt"; "t"] | ["Stdlib_BigInt"; "t"]),
89+
[] ) ->
8890
{dependencies = []; type_ = bigint_t}
89-
| (["Js"; "Date"; "t"] | ["Date"; "t"]), [] ->
91+
| (["Js"; "Date"; "t"] | ["Date"; "t"] | ["Stdlib_Date"; "t"]), [] ->
9092
{dependencies = []; type_ = date_t}
91-
| ["Map"; "t"], [param_translation1; param_translation2] ->
93+
| ( (["Map"; "t"] | ["Stdlib_Map"; "t"]),
94+
[param_translation1; param_translation2] ) ->
9295
{
9396
dependencies =
9497
param_translation1.dependencies @ param_translation2.dependencies;
9598
type_ = map_t (param_translation1.type_, param_translation2.type_);
9699
}
97-
| ["WeakMap"; "t"], [param_translation1; param_translation2] ->
100+
| ( (["WeakMap"; "t"] | ["Stdlib_WeakMap"; "t"]),
101+
[param_translation1; param_translation2] ) ->
98102
{
99103
dependencies =
100104
param_translation1.dependencies @ param_translation2.dependencies;
101105
type_ = weakmap_t (param_translation1.type_, param_translation2.type_);
102106
}
103-
| ["Set"; "t"], [param_translation] ->
107+
| (["Set"; "t"] | ["Stdlib_Set"; "t"]), [param_translation] ->
104108
{
105109
dependencies = param_translation.dependencies;
106110
type_ = set_t param_translation.type_;
107111
}
108-
| ["WeakSet"; "t"], [param_translation] ->
112+
| (["WeakSet"; "t"] | ["Stdlib_WeakSet"; "t"]), [param_translation] ->
109113
{
110114
dependencies = param_translation.dependencies;
111115
type_ = weakset_t param_translation.type_;
112116
}
113-
| (["Js"; "Re"; "t"] | ["RegExp"; "t"]), [] ->
117+
| (["Js"; "Re"; "t"] | ["RegExp"; "t"] | ["Stdlib_RegExp"; "t"]), [] ->
114118
{dependencies = []; type_ = regexp_t}
115119
| (["FB"; "unit"] | ["unit"]), [] -> {dependencies = []; type_ = unit_t}
116120
| ( (["FB"; "array"] | ["array"] | ["Js"; ("Array" | "Array2"); "t"]),
@@ -134,7 +138,10 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
134138
};
135139
] );
136140
}
137-
| ( (["Pervasives"; "result"] | ["Belt"; "Result"; "t"] | ["result"]),
141+
| ( ( ["Pervasives"; "result"]
142+
| ["Belt"; "Result"; "t"]
143+
| ["result"]
144+
| ["Stdlib_Result"; "t"] ),
138145
[param_translation1; param_translation2] ) ->
139146
let case name type_ = {case = {label_js = StringLabel name}; t = type_} in
140147
let variant =
@@ -216,20 +223,28 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
216223
| ( (["Js"; "Undefined"; "t"] | ["Undefined"; "t"] | ["Js"; "undefined"]),
217224
[param_translation] ) ->
218225
{param_translation with type_ = Option param_translation.type_}
219-
| (["Js"; "Null"; "t"] | ["Null"; "t"] | ["Js"; "null"]), [param_translation]
220-
->
226+
| ( ( ["Js"; "Null"; "t"]
227+
| ["Null"; "t"]
228+
| ["Js"; "null"]
229+
| ["Stdlib_Null"; "t"] ),
230+
[param_translation] ) ->
221231
{param_translation with type_ = Null param_translation.type_}
222232
| ( ( ["Js"; "Nullable"; "t"]
223233
| ["Nullable"; "t"]
224234
| ["Js"; "nullable"]
225235
| ["Js"; "Null_undefined"; "t"]
226-
| ["Js"; "null_undefined"] ),
236+
| ["Js"; "null_undefined"]
237+
| ["Stdlib_Nullable"; "t"] ),
227238
[param_translation] ) ->
228239
{param_translation with type_ = Nullable param_translation.type_}
229-
| ( (["Js"; "Promise"; "t"] | ["Promise"; "t"] | ["promise"]),
240+
| ( ( ["Js"; "Promise"; "t"]
241+
| ["Promise"; "t"]
242+
| ["promise"]
243+
| ["Stdlib_Promise"; "t"] ),
230244
[param_translation] ) ->
231245
{param_translation with type_ = Promise param_translation.type_}
232-
| (["Js"; "Dict"; "t"] | ["Dict"; "t"] | ["dict"]), [param_translation] ->
246+
| ( (["Js"; "Dict"; "t"] | ["Dict"; "t"] | ["dict"] | ["Stdlib_Dict"; "t"]),
247+
[param_translation] ) ->
233248
{param_translation with type_ = Dict param_translation.type_}
234249
| _ -> default_case ()
235250

tests/gentype_tests/typescript-react-example/package-lock.json

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

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

+11-25
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,19 @@ import {someFunWithNullThenOptionalArgs as someFunWithNullThenOptionalArgsNotChe
88
import {someFunWithNullUndefinedArg as someFunWithNullUndefinedArgNotChecked} from './CoreTS';
99

1010
// In case of type error, check the type of 'someFunWithNullThenOptionalArgs' in 'Core.res' and './CoreTS'.
11-
export const someFunWithNullThenOptionalArgsTypeChecked: (_1:Stdlib_Null_t<string>, _2:(undefined | string)) => string = someFunWithNullThenOptionalArgsNotChecked as any;
11+
export const someFunWithNullThenOptionalArgsTypeChecked: (_1:(null | string), _2:(undefined | string)) => string = someFunWithNullThenOptionalArgsNotChecked as any;
1212

1313
// Export 'someFunWithNullThenOptionalArgs' early to allow circular import from the '.bs.js' file.
14-
export const someFunWithNullThenOptionalArgs: unknown = someFunWithNullThenOptionalArgsTypeChecked as (_1:Stdlib_Null_t<string>, _2:(undefined | string)) => string as any;
14+
export const someFunWithNullThenOptionalArgs: unknown = someFunWithNullThenOptionalArgsTypeChecked as (_1:(null | string), _2:(undefined | string)) => string as any;
1515

1616
// In case of type error, check the type of 'someFunWithNullUndefinedArg' in 'Core.res' and './CoreTS'.
17-
export const someFunWithNullUndefinedArgTypeChecked: (_1:Stdlib_Nullable_t<string>, _2:number) => string = someFunWithNullUndefinedArgNotChecked as any;
17+
export const someFunWithNullUndefinedArgTypeChecked: (_1:(null | undefined | string), _2:number) => string = someFunWithNullUndefinedArgNotChecked as any;
1818

1919
// Export 'someFunWithNullUndefinedArg' early to allow circular import from the '.bs.js' file.
20-
export const someFunWithNullUndefinedArg: unknown = someFunWithNullUndefinedArgTypeChecked as (_1:Stdlib_Nullable_t<string>, _2:number) => string as any;
20+
export const someFunWithNullUndefinedArg: unknown = someFunWithNullUndefinedArgTypeChecked as (_1:(null | undefined | string), _2:number) => string as any;
2121

2222
const CoreJS = require('./Core.res.js');
2323

24-
import type {Date_t as Stdlib_Date_t} from './Stdlib.gen';
25-
26-
import type {Null_t as Stdlib_Null_t} from './Stdlib.gen';
27-
28-
import type {Nullable_t as Stdlib_Nullable_t} from './Stdlib.gen';
29-
30-
import type {Promise_t as Stdlib_Promise_t} from './Stdlib.gen';
31-
32-
import type {RegExp_t as Stdlib_RegExp_t} from './Stdlib.gen';
33-
34-
import type {WeakMap_t as Stdlib_WeakMap_t} from './Stdlib.gen';
35-
36-
import type {WeakSet_t as Stdlib_WeakSet_t} from './Stdlib.gen';
37-
3824
export type variant = "A" | { TAG: "B"; _0: string };
3925

4026
export type t1 = { readonly x?: string };
@@ -43,11 +29,11 @@ export type t2 = { readonly x: (undefined | string) };
4329

4430
export const null0: (x:(null | number)) => (null | number) = CoreJS.null0 as any;
4531

46-
export const null1: (x:Stdlib_Null_t<number>) => Stdlib_Null_t<number> = CoreJS.null1 as any;
32+
export const null1: (x:(null | number)) => (null | number) = CoreJS.null1 as any;
4733

4834
export const nullable0: (x:(null | undefined | number)) => (null | undefined | number) = CoreJS.nullable0 as any;
4935

50-
export const nullable1: (x:Stdlib_Nullable_t<number>) => Stdlib_Nullable_t<number> = CoreJS.nullable1 as any;
36+
export const nullable1: (x:(null | undefined | number)) => (null | undefined | number) = CoreJS.nullable1 as any;
5137

5238
export const undefined0: (x:(undefined | number)) => (undefined | number) = CoreJS.undefined0 as any;
5339

@@ -59,25 +45,25 @@ export const dict1: (x:{[id: string]: string}) => {[id: string]: string} = CoreJ
5945

6046
export const promise0: (x:Promise<string>) => Promise<string> = CoreJS.promise0 as any;
6147

62-
export const promise1: (x:Stdlib_Promise_t<string>) => Stdlib_Promise_t<string> = CoreJS.promise1 as any;
48+
export const promise1: (x:Promise<string>) => Promise<string> = CoreJS.promise1 as any;
6349

6450
export const date0: (x:Date) => Date = CoreJS.date0 as any;
6551

66-
export const date1: (x:Stdlib_Date_t) => Stdlib_Date_t = CoreJS.date1 as any;
52+
export const date1: (x:Date) => Date = CoreJS.date1 as any;
6753

6854
export const bigint0: (x:bigint) => bigint = CoreJS.bigint0 as any;
6955

7056
export const regexp0: (x:RegExp) => RegExp = CoreJS.regexp0 as any;
7157

72-
export const regexp1: (x:Stdlib_RegExp_t) => Stdlib_RegExp_t = CoreJS.regexp1 as any;
58+
export const regexp1: (x:RegExp) => RegExp = CoreJS.regexp1 as any;
7359

7460
export const map1: (x:Map<string,number>) => Map<string,number> = CoreJS.map1 as any;
7561

76-
export const weakmap1: (x:Stdlib_WeakMap_t<number[],number>) => Stdlib_WeakMap_t<number[],number> = CoreJS.weakmap1 as any;
62+
export const weakmap1: (x:WeakMap<number[],number>) => WeakMap<number[],number> = CoreJS.weakmap1 as any;
7763

7864
export const set1: (x:Set<string>) => Set<string> = CoreJS.set1 as any;
7965

80-
export const weakset1: (x:Stdlib_WeakSet_t<number[]>) => Stdlib_WeakSet_t<number[]> = CoreJS.weakset1 as any;
66+
export const weakset1: (x:WeakSet<number[]>) => WeakSet<number[]> = CoreJS.weakset1 as any;
8167

8268
export const option0: (x:(undefined | string)) => (undefined | string) = CoreJS.option0 as any;
8369

0 commit comments

Comments
 (0)