Skip to content

Commit 45c6f5a

Browse files
committed
revert unrelated changes
1 parent 6926f33 commit 45c6f5a

File tree

14 files changed

+62
-179
lines changed

14 files changed

+62
-179
lines changed

compiler/gentype/Annotation.ml

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ type attribute_payload =
77
| IntPayload of string
88
| StringPayload of string
99
| TuplePayload of attribute_payload list
10-
| RecordPayload of (string * attribute_payload) list
1110
| UnrecognizedPayload
1211

1312
type t = GenType | GenTypeOpaque | NoGenType
@@ -29,14 +28,12 @@ let tag_is_tag s = s = "tag"
2928
let tag_is_unboxed s = s = "unboxed" || s = "ocaml.unboxed"
3029
let tag_is_gentype_import s = s = "genType.import" || s = "gentype.import"
3130
let tag_is_gentype_opaque s = s = "genType.opaque" || s = "gentype.opaque"
32-
let tag_is_gentype_satisfies s = s = "genType.satisfies" || s = "gentype.satisfies"
31+
let tag_is_gentype_satisfies s =
32+
s = "genType.satisfies" || s = "gentype.satisfies"
3333

3434
let tag_is_one_of_the_gentype_annotations s =
35-
tag_is_gentype s
36-
|| tag_is_gentype_as s
37-
|| tag_is_gentype_import s
38-
|| tag_is_gentype_opaque s
39-
|| tag_is_gentype_satisfies s
35+
tag_is_gentype s || tag_is_gentype_as s || tag_is_gentype_import s
36+
|| tag_is_gentype_opaque s || tag_is_gentype_satisfies s
4037

4138
let tag_is_gentype_ignore_interface s =
4239
s = "genType.ignoreInterface" || s = "gentype.ignoreInterface"
@@ -68,26 +65,6 @@ let rec get_attribute_payload check_text (attributes : Typedtree.attributes) =
6865
[]
6966
in
7067
Some (TuplePayload payloads)
71-
| {pexp_desc = Pexp_record (fields, _)} ->
72-
let items =
73-
fields
74-
|> List.fold_left
75-
(fun acc
76-
({Parsetree.lid; x; _} :
77-
Parsetree.expression Parsetree.record_element) ->
78-
let key_opt =
79-
match lid.Location.txt with
80-
| Longident.Lident s -> Some s
81-
| Longident.Ldot (_, s) -> Some s
82-
| _ -> None
83-
in
84-
match (key_opt, from_expr x) with
85-
| Some key, Some v -> (key, v) :: acc
86-
| _ -> acc)
87-
[]
88-
|> List.rev
89-
in
90-
Some (RecordPayload items)
9168
| {pexp_desc = Pexp_ident {txt}} -> Some (IdentPayload txt)
9269
| _ -> None
9370
in
@@ -163,15 +140,14 @@ let get_attribute_import_renaming attributes =
163140
let gentype_as_renaming = attributes |> get_gentype_as_renaming in
164141
match (attribute_import, gentype_as_renaming) with
165142
| Some (_, StringPayload import_string), _ ->
166-
(Some import_string, gentype_as_renaming, None, None)
143+
(Some import_string, gentype_as_renaming)
167144
| ( Some
168145
( _,
169146
TuplePayload
170147
[StringPayload import_string; StringPayload rename_string] ),
171148
_ ) ->
172-
(* Tuple form encodes (importPath, remoteExportName). Keep remote name separate. *)
173-
(Some import_string, gentype_as_renaming, None, Some rename_string)
174-
| _ -> (None, gentype_as_renaming, None, None)
149+
(Some import_string, Some rename_string)
150+
| _ -> (None, gentype_as_renaming)
175151

176152
let get_attribute_satisfies attributes =
177153
match attributes |> get_attribute_payload tag_is_gentype_satisfies with

compiler/gentype/EmitJs.ml

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ let propagate_annotation_to_sub_types ~code_items
601601
in
602602
(new_type_map, !annotated_set)
603603

604-
let emit_translation_as_string ~(config : Config.t) ~file_name
604+
let emit_translation_as_string ~config ~file_name
605605
~input_cmt_translate_type_declarations ~output_file_relative ~resolver
606606
(translation : Translation.t) =
607607
let initial_env =
@@ -649,33 +649,8 @@ let emit_translation_as_string ~(config : Config.t) ~file_name
649649
and env = initial_env in
650650
let env, emitters =
651651
(* imports from type declarations go first to build up type tables *)
652-
let all_import_types =
653-
import_types_from_type_declarations @ translation.import_types
654-
|> List.sort_uniq Translation.import_type_compare
655-
in
656-
(* Prefer direct imports of an alias name over aliased imports from other modules.
657-
Use a single pass map: keep first direct (no alias) for a given name,
658-
otherwise keep the first seen. *)
659-
let chosen_by_name =
660-
List.fold_left
661-
(fun acc (it : CodeItem.import_type) ->
662-
let key =
663-
match it.as_type_name with
664-
| Some alias -> alias
665-
| None -> it.type_name
666-
in
667-
match StringMap.find key acc with
668-
| (prev : CodeItem.import_type) -> (
669-
match (prev.as_type_name, it.as_type_name) with
670-
| None, Some _ -> acc (* keep direct over aliased *)
671-
| _ -> acc)
672-
| exception Not_found -> StringMap.add key it acc)
673-
StringMap.empty all_import_types
674-
in
675-
let filtered_import_types =
676-
chosen_by_name |> StringMap.to_seq |> Seq.map snd |> List.of_seq
677-
in
678-
filtered_import_types
652+
import_types_from_type_declarations @ translation.import_types
653+
|> List.sort_uniq Translation.import_type_compare
679654
|> emit_import_types ~config ~emitters ~env
680655
~input_cmt_translate_type_declarations ~output_file_relative ~resolver
681656
~type_name_is_interface

compiler/gentype/EmitType.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ let emit_import_react ~emitters =
426426

427427
let emit_satisfies_helper ~emitters =
428428
let alias =
429-
"export type $RescriptTypeSatisfiesTypeScriptType<RescriptType, TypeScriptType extends RescriptType> = TypeScriptType;"
429+
"export type $RescriptTypeSatisfiesTypeScriptType<RescriptType, \
430+
TypeScriptType extends RescriptType> = TypeScriptType;"
430431
in
431432
Emitters.export_early ~emitters alias
432433

compiler/gentype/GentypeTypeFold.ml

Lines changed: 0 additions & 19 deletions
This file was deleted.

compiler/gentype/TranslateTypeDeclarations.ml

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
5959
| false -> None
6060
(* one means don't know *)
6161
in
62-
let import_string_opt, name_as, _import_exact_opt, remote_export_name_opt =
62+
let import_string_opt, name_as =
6363
type_attributes |> Annotation.get_attribute_import_renaming
6464
in
6565
let satisfies_opt = type_attributes |> Annotation.get_attribute_satisfies in
@@ -99,9 +99,8 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
9999
(translation : TranslateTypeExprFromTypes.translation) =
100100
let export_from_type_declaration =
101101
type_name
102-
|> create_export_type_from_type_declaration ~annotation:annotation_for_export
103-
~loc ~name_as
104-
~opaque
102+
|> create_export_type_from_type_declaration
103+
~annotation:annotation_for_export ~loc ~name_as ~opaque
105104
~type_:(apply_satisfies_wrapper translation.type_)
106105
~type_env ~doc_string ~type_vars
107106
in
@@ -173,35 +172,31 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
173172
let name_with_module_path =
174173
typeName_ |> TypeEnv.add_module_path ~type_env |> ResolvedName.to_string
175174
in
176-
(* Use the remote export name (if provided) to build the import and alias.
177-
Preserve casing from the TS source exactly. *)
178-
let remote_type_name =
179-
match remote_export_name_opt with
180-
| Some s -> s
181-
| None -> name_with_module_path
175+
let type_name, as_type_name =
176+
match name_as with
177+
| Some as_string -> (as_string, "$$" ^ name_with_module_path)
178+
| None -> (name_with_module_path, "$$" ^ name_with_module_path)
182179
in
183-
let type_name = remote_type_name in
184-
let as_type_name = remote_type_name ^ "$TypeScript" in
185-
let import_path = import_string |> ImportPath.from_string_unsafe in
186-
let base_import =
187-
{CodeItem.type_name; as_type_name = Some as_type_name; import_path}
180+
let import_types =
181+
[
182+
{
183+
CodeItem.type_name;
184+
as_type_name = Some as_type_name;
185+
import_path = import_string |> ImportPath.from_string_unsafe;
186+
};
187+
]
188188
in
189-
(* Only import the aliased TypeScript type; no wrappers or extra aliases. *)
190-
let import_types = [base_import] in
191189
let export_from_type_declaration =
192190
(* Make the imported type usable from other modules by exporting it too. *)
193-
let export_type_body =
194-
as_type_name
195-
|> ident ~type_args:(type_vars |> List.map (fun s -> TypeVar s))
196-
in
197191
typeName_
198192
|> create_export_type_from_type_declaration ~doc_string
199193
~annotation:GenType ~loc ~name_as:None ~opaque:(Some false)
200-
~type_:export_type_body ~type_env ~type_vars
194+
~type_:
195+
(as_type_name
196+
|> ident ~type_args:(type_vars |> List.map (fun s -> TypeVar s)))
197+
~type_env ~type_vars
201198
in
202-
[
203-
{CodeItem.import_types; export_from_type_declaration};
204-
]
199+
[{CodeItem.import_types; export_from_type_declaration}]
205200
| (GeneralDeclarationFromTypes None | GeneralDeclaration None), None ->
206201
{
207202
CodeItem.import_types = [];
@@ -248,8 +243,7 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
248243
| _ -> translation.type_
249244
in
250245
{translation with type_ = apply_satisfies_wrapper type_}
251-
|> handle_general_declaration
252-
|> return_type_declaration
246+
|> handle_general_declaration |> return_type_declaration
253247
| RecordDeclarationFromTypes label_declarations, None ->
254248
let {TranslateTypeExprFromTypes.dependencies; type_} =
255249
label_declarations |> translate_label_declarations
@@ -264,8 +258,8 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
264258
export_from_type_declaration =
265259
type_name
266260
|> create_export_type_from_type_declaration ~doc_string
267-
~annotation:annotation_for_export ~loc
268-
~name_as ~opaque ~type_:(apply_satisfies_wrapper type_)
261+
~annotation:annotation_for_export ~loc ~name_as ~opaque
262+
~type_:(apply_satisfies_wrapper type_)
269263
~type_env ~type_vars;
270264
}
271265
|> return_type_declaration

compiler/gentype/TranslateTypeExprFromTypes.ml

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -118,48 +118,6 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
118118
}
119119
| (["Js"; "Re"; "t"] | ["RegExp"; "t"] | ["Stdlib"; "RegExp"; "t"]), [] ->
120120
{dependencies = []; type_ = regexp_t}
121-
| ["Stdlib"; "ArrayBuffer"; "t"], [] ->
122-
{dependencies = []; type_ = ident "ArrayBuffer"}
123-
| ["Stdlib"; "DataView"; "t"], [] ->
124-
{dependencies = []; type_ = ident "DataView"}
125-
| ["Stdlib"; "Int8Array"; "t"], [] ->
126-
{dependencies = []; type_ = ident "Int8Array"}
127-
| ["Stdlib"; "Uint8Array"; "t"], [] ->
128-
{dependencies = []; type_ = ident "Uint8Array"}
129-
| ["Stdlib"; "Uint8ClampedArray"; "t"], [] ->
130-
{dependencies = []; type_ = ident "Uint8ClampedArray"}
131-
| ["Stdlib"; "Int16Array"; "t"], [] ->
132-
{dependencies = []; type_ = ident "Int16Array"}
133-
| ["Stdlib"; "Uint16Array"; "t"], [] ->
134-
{dependencies = []; type_ = ident "Uint16Array"}
135-
| ["Stdlib"; "Int32Array"; "t"], [] ->
136-
{dependencies = []; type_ = ident "Int32Array"}
137-
| ["Stdlib"; "Uint32Array"; "t"], [] ->
138-
{dependencies = []; type_ = ident "Uint32Array"}
139-
| ["Stdlib"; "Float32Array"; "t"], [] ->
140-
{dependencies = []; type_ = ident "Float32Array"}
141-
| ["Stdlib"; "Float64Array"; "t"], [] ->
142-
{dependencies = []; type_ = ident "Float64Array"}
143-
| ["Stdlib"; "BigInt64Array"; "t"], [] ->
144-
{dependencies = []; type_ = ident "BigInt64Array"}
145-
| ["Stdlib"; "BigUint64Array"; "t"], [] ->
146-
{dependencies = []; type_ = ident "BigUint64Array"}
147-
| ["Stdlib"; "Symbol"; "t"], [] -> {dependencies = []; type_ = ident "symbol"}
148-
| ["Stdlib"; "Intl"; intl_module; "t"], [] ->
149-
{dependencies = []; type_ = ident ("Intl." ^ intl_module)}
150-
| (["Stdlib"; "Error"; "t"] | ["Stdlib"; "JsError"; "t"]), [] ->
151-
{dependencies = []; type_ = ident "Error"}
152-
| ["Stdlib"; "Iterator"; "t"], [param_translation] ->
153-
{
154-
dependencies = param_translation.dependencies;
155-
type_ = ident ~type_args:[param_translation.type_] "Iterator";
156-
}
157-
| ["Stdlib"; "AsyncIterator"; "t"], [param_translation] ->
158-
{
159-
dependencies = param_translation.dependencies;
160-
type_ = ident ~type_args:[param_translation.type_] "AsyncIterator";
161-
}
162-
| ["Stdlib"; "Ordering"; "t"], [] -> {dependencies = []; type_ = number_t}
163121
| ["unit"], [] -> {dependencies = []; type_ = unit_t}
164122
| (["array"] | ["Js"; ("Array" | "Array2"); "t"]), [param_translation] ->
165123
{param_translation with type_ = Array (param_translation.type_, Mutable)}

compiler/gentype/Translation.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ let translate_primitive ~config ~output_file_relative ~resolver ~type_env
138138
value_description.val_desc
139139
|> TranslateCoreType.translate_core_type ~config ~type_env
140140
in
141-
let ( attribute_import,
142-
attribute_renaming,
143-
_import_exact_opt,
144-
_remote_export_name_opt ) =
141+
let attribute_import, attribute_renaming =
145142
value_description.val_attributes |> Annotation.get_attribute_import_renaming
146143
in
147144
match (type_expr_translation.type_, attribute_import) with
@@ -208,7 +205,6 @@ let add_type_declarations_from_module_equations ~type_env (translation : t) =
208205
.annotation;
209206
};
210207
import_types = [];
211-
212208
}))
213209
|> List.concat
214210
in

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint-disable */
44
/* tslint:disable */
55

6-
import {make as makeNotChecked} from './hookExample';
6+
import {default as makeNotChecked} from './hookExample';
77

88
import {default as defaultNotChecked} from './hookExample';
99

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,37 @@ export const $$default: unknown = defaultTypeChecked as number as any;
7777

7878
const ImportJsValueJS = require('./ImportJsValue.res.js');
7979

80-
import type {AbsoluteValue as AbsoluteValue$TypeScript} from './MyMath';
80+
import type {AbsoluteValue as $$AbsoluteValue_t} from './MyMath';
8181

82-
import type {num as num$TypeScript} from './MyMath';
82+
import type {num as $$myNum} from './MyMath';
8383

84-
import type {numberOrString as numberOrString$TypeScript} from './MyMath';
84+
import type {num as $$num} from './MyMath';
8585

86-
import type {polyType as polyType$TypeScript} from './MyMath';
86+
import type {numberOrString as $$numberOrString} from './MyMath';
8787

88-
import type {stringFunction as stringFunction$TypeScript} from './MyMath';
88+
import type {polyType as $$polyType} from './MyMath';
89+
90+
import type {stringFunction as $$stringFunction} from './MyMath';
8991

9092
export type point = { readonly x: number; readonly y: (undefined | number) };
9193

92-
export type numberOrString = numberOrString$TypeScript;
94+
export type numberOrString = $$numberOrString;
9395

94-
export type AbsoluteValue_t = AbsoluteValue$TypeScript;
96+
export type AbsoluteValue_t = $$AbsoluteValue_t;
9597

96-
export type stringFunction = stringFunction$TypeScript;
98+
export type stringFunction = $$stringFunction;
9799

98100
export type color = "tomato" | "gray";
99101

100102
export type variant =
101103
{ TAG: "I"; _0: number }
102104
| { TAG: "S"; _0: string };
103105

104-
export type num = num$TypeScript;
106+
export type num = $$num;
105107

106-
export type myNum = num$TypeScript;
108+
export type myNum = $$myNum;
107109

108-
export type polyType<a> = polyType$TypeScript<a>;
110+
export type polyType<a> = $$polyType<a>;
109111

110112
export const roundedNumber: number = ImportJsValueJS.roundedNumber as any;
111113

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export const defaultTypeChecked: React.ComponentType<{ readonly onFocus?: (_1:in
1111
// Export '$$default' early to allow circular import from the '.bs.js' file.
1212
export const $$default: unknown = defaultTypeChecked as React.ComponentType<{ readonly onFocus?: (_1:inputFocusEvent) => void }> as any;
1313

14-
import type {inputFocusEvent as inputFocusEvent$TypeScript} from './shims/JsxEvent.shim';
14+
import type {inputFocusEvent as $$inputFocusEvent} from './shims/JsxEvent.shim';
1515

16-
export type inputFocusEvent = inputFocusEvent$TypeScript;
16+
export type inputFocusEvent = $$inputFocusEvent;
1717

1818
export type props<onFocus> = { readonly onFocus?: onFocus };
1919

0 commit comments

Comments
 (0)