Skip to content

Commit bac81a6

Browse files
committed
refactor: extract fun from process_cmt_file
1 parent 6de936a commit bac81a6

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

jscomp/gentype/GenTypeMain.ml

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,47 @@ let readCmt cmtFile =
9090
Log_.item "Try to clean and rebuild.\n\n";
9191
assert false
9292

93+
let readInputCmt isInterface cmtFile =
94+
let inputCMT = readCmt cmtFile in
95+
let ignoreInterface = ref false in
96+
let checkAnnotation ~loc:_ attributes =
97+
if
98+
attributes
99+
|> Annotation.getAttributePayload Annotation.tagIsGenTypeIgnoreInterface
100+
<> None
101+
then ignoreInterface := true;
102+
attributes
103+
|> Annotation.getAttributePayload Annotation.tagIsOneOfTheGenTypeAnnotations
104+
<> None
105+
in
106+
let hasGenTypeAnnotations =
107+
inputCMT |> cmtCheckAnnotations ~checkAnnotation
108+
in
109+
if isInterface then
110+
let cmtFileImpl =
111+
(cmtFile |> (Filename.chop_extension [@doesNotRaise])) ^ ".cmt"
112+
in
113+
let inputCMTImpl = readCmt cmtFileImpl in
114+
let hasGenTypeAnnotationsImpl =
115+
inputCMTImpl
116+
|> cmtCheckAnnotations ~checkAnnotation:(fun ~loc attributes ->
117+
if attributes |> checkAnnotation ~loc then (
118+
if not !ignoreInterface 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 !ignoreInterface with
127+
| true -> inputCMTImpl
128+
| false -> inputCMT),
129+
match !ignoreInterface with
130+
| true -> hasGenTypeAnnotationsImpl
131+
| false -> hasGenTypeAnnotations )
132+
else (inputCMT, hasGenTypeAnnotations)
133+
93134
let processCmtFile cmt =
94135
let config = Paths.readConfig ~namespace:(cmt |> Paths.findNameSpace) in
95136
if !Debug.basic then Log_.item "Cmt %s\n" cmt;
@@ -104,49 +145,7 @@ let processCmtFile cmt =
104145
~excludeFile:(fun fname ->
105146
fname = "React.res" || fname = "ReasonReact.res")
106147
in
107-
let inputCMT, hasGenTypeAnnotations =
108-
let inputCMT = readCmt cmtFile in
109-
let ignoreInterface = ref false in
110-
let checkAnnotation ~loc:_ attributes =
111-
if
112-
attributes
113-
|> Annotation.getAttributePayload
114-
Annotation.tagIsGenTypeIgnoreInterface
115-
<> None
116-
then ignoreInterface := true;
117-
attributes
118-
|> Annotation.getAttributePayload
119-
Annotation.tagIsOneOfTheGenTypeAnnotations
120-
<> None
121-
in
122-
let hasGenTypeAnnotations =
123-
inputCMT |> cmtCheckAnnotations ~checkAnnotation
124-
in
125-
if isInterface then
126-
let cmtFileImpl =
127-
(cmtFile |> (Filename.chop_extension [@doesNotRaise])) ^ ".cmt"
128-
in
129-
let inputCMTImpl = readCmt cmtFileImpl in
130-
let hasGenTypeAnnotationsImpl =
131-
inputCMTImpl
132-
|> cmtCheckAnnotations ~checkAnnotation:(fun ~loc attributes ->
133-
if attributes |> checkAnnotation ~loc then (
134-
if not !ignoreInterface 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 !ignoreInterface with
143-
| true -> inputCMTImpl
144-
| false -> inputCMT),
145-
match !ignoreInterface with
146-
| true -> hasGenTypeAnnotationsImpl
147-
| false -> hasGenTypeAnnotations )
148-
else (inputCMT, hasGenTypeAnnotations)
149-
in
148+
let inputCMT, hasGenTypeAnnotations = readInputCmt isInterface cmtFile in
150149
if hasGenTypeAnnotations then
151150
let sourceFile =
152151
match inputCMT.cmt_annots |> FindSourceFile.cmt with

0 commit comments

Comments
 (0)