Skip to content

Commit 68133f4

Browse files
committed
refactoring to remove reduandant code in processing files
1 parent 4282414 commit 68133f4

File tree

2 files changed

+21
-37
lines changed

2 files changed

+21
-37
lines changed

jscomp/main/js_main.ml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ let output_prefix name =
2020
Filename.remove_extension oname
2121

2222

23-
let process_interface_file ppf name =
24-
Js_implementation.interface ppf name
25-
~parser:Pparse_driver.parse_interface
26-
(output_prefix name)
27-
let process_implementation_file ppf name =
28-
Js_implementation.implementation ppf name
29-
~parser:Pparse_driver.parse_implementation
30-
(output_prefix name)
3123

3224

3325
let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])=
@@ -69,18 +61,19 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref =
6961

7062

7163

72-
73-
74-
75-
76-
let process_file ppf sourcefile =
64+
let process_file sourcefile
65+
?(kind ) ppf =
7766
(* This is a better default then "", it will be changed later
7867
The {!Location.input_name} relies on that we write the binary ast
7968
properly
8069
*)
8170
Location.set_input_name sourcefile;
8271
let opref = output_prefix sourcefile in
83-
match Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile) with
72+
let kind =
73+
match kind with
74+
| None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile)
75+
| Some kind -> kind in
76+
match kind with
8477
| Re -> handle_reason Ml sourcefile ppf opref
8578
| Rei ->
8679
handle_reason Mli sourcefile ppf opref
@@ -139,7 +132,7 @@ let anonymous ~(rev_args : string list) =
139132
begin
140133
match rev_args with
141134
| [filename] ->
142-
process_file ppf filename
135+
process_file filename ppf
143136
| [] -> ()
144137
| _ ->
145138
Bsc_args.bad_arg "can not handle multiple files"
@@ -148,10 +141,10 @@ let anonymous ~(rev_args : string list) =
148141
(** used by -impl -intf *)
149142
let impl filename =
150143
Js_config.js_stdout := false;
151-
process_implementation_file ppf filename;;
144+
process_file filename ~kind:Ml ppf ;;
152145
let intf filename =
153146
Js_config.js_stdout := false ;
154-
process_interface_file ppf filename;;
147+
process_file filename ~kind:Mli ppf;;
155148

156149

157150
let format_file input =

lib/4.06.1/whole_compiler.ml

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -436146,14 +436146,6 @@ let output_prefix name =
436146436146
Filename.remove_extension oname
436147436147

436148436148

436149-
let process_interface_file ppf name =
436150-
Js_implementation.interface ppf name
436151-
~parser:Pparse_driver.parse_interface
436152-
(output_prefix name)
436153-
let process_implementation_file ppf name =
436154-
Js_implementation.implementation ppf name
436155-
~parser:Pparse_driver.parse_implementation
436156-
(output_prefix name)
436157436149

436158436150

436159436151
let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])=
@@ -436195,20 +436187,19 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref =
436195436187

436196436188

436197436189

436198-
436199-
436200-
436201-
436202-
let process_file ppf sourcefile =
436190+
let process_file sourcefile
436191+
?(kind ) ppf =
436203436192
(* This is a better default then "", it will be changed later
436204436193
The {!Location.input_name} relies on that we write the binary ast
436205436194
properly
436206436195
*)
436207-
Location.set_input_name sourcefile;
436208-
let ext = Ext_filename.get_extension_maybe sourcefile in
436209-
let input = Ext_file_extensions.classify_input ext in
436196+
Location.set_input_name sourcefile;
436210436197
let opref = output_prefix sourcefile in
436211-
match input with
436198+
let kind =
436199+
match kind with
436200+
| None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile)
436201+
| Some kind -> kind in
436202+
match kind with
436212436203
| Re -> handle_reason Ml sourcefile ppf opref
436213436204
| Rei ->
436214436205
handle_reason Mli sourcefile ppf opref
@@ -436267,7 +436258,7 @@ let anonymous ~(rev_args : string list) =
436267436258
begin
436268436259
match rev_args with
436269436260
| [filename] ->
436270-
process_file ppf filename
436261+
process_file filename ppf
436271436262
| [] -> ()
436272436263
| _ ->
436273436264
Bsc_args.bad_arg "can not handle multiple files"
@@ -436276,10 +436267,10 @@ let anonymous ~(rev_args : string list) =
436276436267
(** used by -impl -intf *)
436277436268
let impl filename =
436278436269
Js_config.js_stdout := false;
436279-
process_implementation_file ppf filename;;
436270+
process_file filename ~kind:Ml ppf ;;
436280436271
let intf filename =
436281436272
Js_config.js_stdout := false ;
436282-
process_interface_file ppf filename;;
436273+
process_file filename ~kind:Mli ppf;;
436283436274

436284436275

436285436276
let format_file input =

0 commit comments

Comments
 (0)