Skip to content

Commit f62fd61

Browse files
committed
refactor: extract funs to remove duplication
1 parent 8d22164 commit f62fd61

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

compiler/gentype/Paths.ml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,31 @@ let remove_project_root_from_absolute_path ~(config : Config.t) source_path =
3434
let n = String.length source_path - i in
3535
(String.sub source_path i n [@doesNotRaise])
3636

37-
let get_output_file_relative ~config source_path =
38-
if Filename.is_relative source_path then
39-
(source_path |> handle_namespace)
40-
^ ModuleExtension.ts_input_file_suffix ~config
37+
let append_suffix ~config source_path =
38+
(source_path |> handle_namespace)
39+
^ ModuleExtension.ts_input_file_suffix ~config
40+
41+
let get_output_file_relative ~(config : Config.t) source_path =
42+
if Filename.is_relative source_path then append_suffix ~config source_path
4143
else
4244
let relative_path =
4345
remove_project_root_from_absolute_path ~config source_path
4446
in
45-
(relative_path |> handle_namespace)
46-
^ ModuleExtension.ts_input_file_suffix ~config
47+
append_suffix ~config relative_path
48+
49+
let compute_absolute_output_file_path ~(config : Config.t) path =
50+
Filename.concat config.project_root (get_output_file_relative ~config path)
4751

4852
let get_output_file ~(config : Config.t) sourcePath =
4953
if Filename.is_relative sourcePath then
5054
(* assuming a relative path from the project root *)
51-
Filename.concat config.project_root
52-
(get_output_file_relative ~config sourcePath)
55+
compute_absolute_output_file_path ~config sourcePath
5356
else
54-
(* we want to place the output beside the source file *)
57+
(* for absolute paths we want to place the output beside the source file *)
5558
let relative_path =
5659
remove_project_root_from_absolute_path ~config sourcePath
5760
in
58-
Filename.concat config.project_root
59-
(get_output_file_relative ~config relative_path)
61+
compute_absolute_output_file_path ~config relative_path
6062

6163
let get_module_name cmt =
6264
cmt |> handle_namespace |> Filename.basename |> ModuleName.from_string_unsafe

0 commit comments

Comments
 (0)