Skip to content

Commit 964460d

Browse files
committed
refactor: extract funs to remove duplication
1 parent e32dfb5 commit 964460d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

jscomp/gentype/Paths.ml

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

36-
let getOutputFileRelative ~config source_path =
37-
if Filename.is_relative source_path then
38-
(source_path |> handleNamespace) ^ ModuleExtension.tsInputFileSuffix ~config
36+
let appendSuffix ~config sourcePath =
37+
(sourcePath |> handleNamespace) ^ ModuleExtension.tsInputFileSuffix ~config
38+
39+
let getOutputFileRelative ~config sourcePath =
40+
if Filename.is_relative sourcePath then appendSuffix ~config sourcePath
3941
else
4042
let relative_path =
41-
remove_project_root_from_absolute_path ~config source_path
43+
remove_project_root_from_absolute_path ~config sourcePath
4244
in
43-
(relative_path |> handleNamespace)
44-
^ ModuleExtension.tsInputFileSuffix ~config
45+
appendSuffix ~config relative_path
46+
47+
let computeAbsoluteOutputFilePath ~(config : Config.t) path =
48+
Filename.concat config.projectRoot (getOutputFileRelative ~config path)
4549

4650
let getOutputFile ~(config : Config.t) sourcePath =
4751
if Filename.is_relative sourcePath then
4852
(* assuming a relative path from the project root *)
49-
Filename.concat config.projectRoot
50-
(getOutputFileRelative ~config sourcePath)
53+
computeAbsoluteOutputFilePath ~config sourcePath
5154
else
52-
(* we want to place the output beside the source file *)
55+
(* for absolute paths we want to place the output beside the source file *)
5356
let relative_path =
5457
remove_project_root_from_absolute_path ~config sourcePath
5558
in
56-
Filename.concat config.projectRoot
57-
(getOutputFileRelative ~config relative_path)
59+
computeAbsoluteOutputFilePath ~config relative_path
5860

5961
let getModuleName cmt =
6062
cmt |> handleNamespace |> Filename.basename |> ModuleName.fromStringUnsafe

0 commit comments

Comments
 (0)