@@ -90,74 +90,73 @@ let read_cmt cmt_file =
90
90
Log_. item " Try to clean and rebuild.\n\n " ;
91
91
assert false
92
92
93
+ let read_input_cmt is_interface cmt_file =
94
+ let input_cmt = read_cmt cmt_file in
95
+ let ignore_interface = ref false in
96
+ let check_annotation ~loc :_ attributes =
97
+ if
98
+ attributes
99
+ |> Annotation. get_attribute_payload Annotation. tag_is_gentype_ignore_interface
100
+ <> None
101
+ then ignore_interface := true ;
102
+ attributes
103
+ |> Annotation. get_attribute_payload Annotation. tag_is_one_of_the_gentype_annotations
104
+ <> None
105
+ in
106
+ let has_gentype_annotations =
107
+ input_cmt |> cmt_check_annotations ~check_annotation
108
+ in
109
+ if is_interface then
110
+ let cmt_file_impl =
111
+ (cmt_file |> (Filename. chop_extension [@ doesNotRaise])) ^ " .cmt"
112
+ in
113
+ let input_cmt_impl = read_cmt cmt_file_impl in
114
+ let has_gentype_annotations_impl =
115
+ input_cmt_impl
116
+ |> cmt_check_annotations ~check_annotation: (fun ~loc attributes ->
117
+ if attributes |> check_annotation ~loc then (
118
+ if not ! ignore_interface then (
119
+ Log_.Color. setup () ;
120
+ Log_. info ~loc ~name: " Warning genType" (fun ppf () ->
121
+ Format. fprintf ppf
122
+ " Annotation is ignored as there's a .rei file" ));
123
+ true )
124
+ else false )
125
+ in
126
+ ( (match ! ignore_interface with
127
+ | true -> input_cmt_impl
128
+ | false -> input_cmt),
129
+ match ! ignore_interface with
130
+ | true -> has_gentype_annotations_impl
131
+ | false -> has_gentype_annotations )
132
+ else (input_cmt, has_gentype_annotations)
133
+
93
134
let process_cmt_file cmt =
94
135
let config = Paths. read_config ~namespace: (cmt |> Paths. find_name_space) in
95
136
if ! Debug. basic then Log_. item " Cmt %s\n " cmt;
96
137
let cmt_file = cmt |> Paths. get_cmt_file in
97
138
if cmt_file <> " " then
98
- let output_file = cmt |> Paths. get_output_file ~config in
99
- let output_file_relative = cmt |> Paths. get_output_file_relative ~config in
100
139
let file_name = cmt |> Paths. get_module_name in
101
140
let is_interface = Filename. check_suffix cmt_file " .cmti" in
141
+ let input_cmt, has_gentype_annotations = read_input_cmt is_interface cmt_file in
142
+ let source_file =
143
+ match input_cmt.cmt_annots |> FindSourceFile. cmt with
144
+ | Some source_file -> source_file
145
+ | None -> (
146
+ (file_name |> ModuleName. to_string)
147
+ ^
148
+ match is_interface with
149
+ | true -> " .resi"
150
+ | false -> " .res" )
151
+ in
152
+ let output_file = source_file |> Paths. get_output_file ~config in
153
+ let output_file_relative = source_file |> Paths. get_output_file_relative ~config in
102
154
let resolver =
103
155
ModuleResolver. create_lazy_resolver ~config
104
156
~extensions: [" .res" ; " .shim.ts" ] ~exclude_file: (fun fname ->
105
157
fname = " React.res" || fname = " ReasonReact.res" )
106
158
in
107
- let input_cmt, has_gentype_annotations =
108
- let input_cmt = read_cmt cmt_file in
109
- let ignore_interface = ref false in
110
- let check_annotation ~loc :_ attributes =
111
- if
112
- attributes
113
- |> Annotation. get_attribute_payload
114
- Annotation. tag_is_gentype_ignore_interface
115
- <> None
116
- then ignore_interface := true ;
117
- attributes
118
- |> Annotation. get_attribute_payload
119
- Annotation. tag_is_one_of_the_gentype_annotations
120
- <> None
121
- in
122
- let has_gentype_annotations =
123
- input_cmt |> cmt_check_annotations ~check_annotation
124
- in
125
- if is_interface then
126
- let cmt_file_impl =
127
- (cmt_file |> (Filename. chop_extension [@ doesNotRaise])) ^ " .cmt"
128
- in
129
- let input_cmt_impl = read_cmt cmt_file_impl in
130
- let has_gentype_annotations_impl =
131
- input_cmt_impl
132
- |> cmt_check_annotations ~check_annotation: (fun ~loc attributes ->
133
- if attributes |> check_annotation ~loc then (
134
- if not ! ignore_interface then (
135
- Log_.Color. setup () ;
136
- Log_. info ~loc ~name: " Warning genType" (fun ppf () ->
137
- Format. fprintf ppf
138
- " Annotation is ignored as there's a .rei file" ));
139
- true )
140
- else false )
141
- in
142
- ( (match ! ignore_interface with
143
- | true -> input_cmt_impl
144
- | false -> input_cmt),
145
- match ! ignore_interface with
146
- | true -> has_gentype_annotations_impl
147
- | false -> has_gentype_annotations )
148
- else (input_cmt, has_gentype_annotations)
149
- in
150
159
if has_gentype_annotations then
151
- let source_file =
152
- match input_cmt.cmt_annots |> FindSourceFile. cmt with
153
- | Some source_file -> source_file
154
- | None -> (
155
- (file_name |> ModuleName. to_string)
156
- ^
157
- match is_interface with
158
- | true -> " .resi"
159
- | false -> " .res" )
160
- in
161
160
input_cmt
162
161
|> translate_c_m_t ~config ~output_file_relative ~resolver
163
162
|> emit_translation ~config ~file_name ~output_file ~output_file_relative
0 commit comments