Skip to content

Commit 34da477

Browse files
committed
tweak, reduce the deps on Stdlib.Arg
1 parent 3339266 commit 34da477

File tree

1 file changed

+47
-45
lines changed

1 file changed

+47
-45
lines changed

jscomp/main/js_main.ml

+47-45
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ type valid_input =
7070
| Mlmap
7171
| Cmi
7272

73+
let bad_arg s = raise_notrace (Arg.Bad(s))
74+
7375
(** This is per-file based,
7476
when [ocamlc] [-c -o another_dir/xx.cmi]
7577
it will return (another_dir/xx)
@@ -111,7 +113,7 @@ let process_file ppf sourcefile =
111113
Resi
112114
| _ when ext = Literals.suffix_resast -> Resast
113115
| _ when ext = Literals.suffix_resiast -> Resiast
114-
| _ -> raise(Arg.Bad("don't know what to do with " ^ sourcefile)) in
116+
| _ -> bad_arg ("don't know what to do with " ^ sourcefile) in
115117
let opref = Compenv.output_prefix sourcefile in
116118
match input with
117119
| Re -> handle_reason Ml sourcefile ppf opref
@@ -205,13 +207,13 @@ let define_variable s =
205207
match Ext_string.split ~keep_empty:true s '=' with
206208
| [key; v] ->
207209
if not (Lexer.define_key_value key v) then
208-
raise (Arg.Bad ("illegal definition: " ^ s))
209-
| _ -> raise (Arg.Bad ("illegal definition: " ^ s))
210+
bad_arg ("illegal definition: " ^ s)
211+
| _ -> bad_arg ("illegal definition: " ^ s)
210212

211213

212214
let buckle_script_flags : (string * Arg.spec * string) list =
213215
("-bs-super-errors",
214-
Arg.Unit
216+
Unit
215217
(* needs to be set here instead of, say, setting a
216218
Js_config.better_errors flag; otherwise, when `anonymous` runs, we
217219
don't have time to set the custom printer before it starts outputting
@@ -222,117 +224,117 @@ let buckle_script_flags : (string * Arg.spec * string) list =
222224
)
223225
::
224226
("-unboxed-types",
225-
Arg.Set Clflags.unboxed_types,
227+
Set Clflags.unboxed_types,
226228
" unannotated unboxable types will be unboxed"
227229
)
228230
::
229231
("-bs-re-out",
230-
Arg.Unit (fun _ -> Lazy.force Reason_outcome_printer_main.setup),
232+
Unit (fun _ -> Lazy.force Reason_outcome_printer_main.setup),
231233
" Print compiler output in Reason syntax"
232234
)
233235
::
234236
("-bs-jsx",
235-
Arg.Int (fun i ->
236-
(if i <> 3 then raise (Arg.Bad (" Not supported jsx version : " ^ string_of_int i)));
237+
Int (fun i ->
238+
(if i <> 3 then bad_arg (" Not supported jsx version : " ^ string_of_int i));
237239
Js_config.jsx_version := i),
238240
" Set jsx version"
239241
)
240242
::
241243
("-bs-refmt",
242-
Arg.String (fun s -> Js_config.refmt := Some s),
244+
String (fun s -> Js_config.refmt := Some s),
243245
" Set customized refmt path"
244246
)
245247

246248
::
247249
(
248250
"-bs-gentype",
249-
Arg.String (fun s -> Clflags.bs_gentype := Some s),
251+
String (fun s -> Clflags.bs_gentype := Some s),
250252
" Pass gentype command"
251253
)
252254
::
253255
("-bs-suffix",
254-
Arg.Set Js_config.bs_suffix,
256+
Set Js_config.bs_suffix,
255257
" Set suffix to .bs.js"
256258
)
257259
::
258-
("-bs-no-implicit-include", Arg.Set Clflags.no_implicit_current_dir
260+
("-bs-no-implicit-include", Set Clflags.no_implicit_current_dir
259261
, " Don't include current dir implicitly")
260262
::
261-
("-bs-read-cmi", Arg.Unit (fun _ -> Clflags.assume_no_mli := Clflags.Mli_exists),
263+
("-bs-read-cmi", Unit (fun _ -> Clflags.assume_no_mli := Clflags.Mli_exists),
262264
" (internal) Assume mli always exist ")
263265
::
264-
("-bs-D", Arg.String define_variable,
266+
("-bs-D", String define_variable,
265267
" Define conditional variable e.g, -D DEBUG=true"
266268
)
267269
::
268-
("-bs-unsafe-empty-array", Arg.Clear Js_config.mono_empty_array,
270+
("-bs-unsafe-empty-array", Clear Js_config.mono_empty_array,
269271
" Allow [||] to be polymorphic"
270272
)
271273
::
272-
("-nostdlib", Arg.Set Js_config.no_stdlib,
274+
("-nostdlib", Set Js_config.no_stdlib,
273275
" Don't use stdlib")
274276
::
275-
("-bs-internal-check", Arg.Unit (Bs_cmi_load.check ),
277+
("-bs-internal-check", Unit (Bs_cmi_load.check ),
276278
" Built in check corrupted data"
277279
)
278280
::
279281
("-bs-list-conditionals",
280-
Arg.Unit (fun () -> Lexer.list_variables Format.err_formatter),
282+
Unit (fun () -> Lexer.list_variables Format.err_formatter),
281283
" List existing conditional variables")
282284
::
283285
(
284-
"-bs-binary-ast", Arg.Set Js_config.binary_ast,
286+
"-bs-binary-ast", Set Js_config.binary_ast,
285287
" Generate binary .mli_ast and ml_ast"
286288
)
287289
::
288290
(
289-
"-bs-simple-binary-ast", Arg.Set Js_config.simple_binary_ast,
291+
"-bs-simple-binary-ast", Set Js_config.simple_binary_ast,
290292
" Generate binary .mliast_simple and mlast_simple"
291293
)
292294
::
293295
("-bs-syntax-only",
294-
Arg.Set Js_config.syntax_only,
296+
Set Js_config.syntax_only,
295297
" only check syntax"
296298
)
297299
::
298-
("-bs-no-bin-annot", Arg.Clear Clflags.binary_annotations,
300+
("-bs-no-bin-annot", Clear Clflags.binary_annotations,
299301
" disable binary annotations (by default on)")
300302
::
301303
("-bs-eval",
302-
Arg.String (fun s -> eval s ~suffix:Literals.suffix_ml),
304+
String (fun s -> eval s ~suffix:Literals.suffix_ml),
303305
" (experimental) Set the string to be evaluated in OCaml syntax"
304306
)
305307
::
306308
("-e",
307-
Arg.String (fun s -> eval s ~suffix:Literals.suffix_re),
309+
String (fun s -> eval s ~suffix:Literals.suffix_re),
308310
" (experimental) Set the string to be evaluated in ReasonML syntax"
309311
)
310312
::
311313
(
312314
"-bs-cmi-only",
313-
Arg.Set Js_config.cmi_only,
315+
Set Js_config.cmi_only,
314316
" Stop after generating cmi file"
315317
)
316318
::
317319
(
318320
"-bs-cmi",
319-
Arg.Set Js_config.force_cmi,
321+
Set Js_config.force_cmi,
320322
" Not using cached cmi, always generate cmi"
321323
)
322324
::
323325
("-bs-cmj",
324-
Arg.Set Js_config.force_cmj,
326+
Set Js_config.force_cmj,
325327
" Not using cached cmj, always generate cmj"
326328
)
327329
::
328330
(
329331
"-as-ppx",
330-
Arg.Set Js_config.as_ppx,
332+
Set Js_config.as_ppx,
331333
" As ppx for editor integration"
332334
)
333335
::
334336
("-bs-g",
335-
Arg.Unit
337+
Unit
336338
(fun _ -> Js_config.debug := true;
337339
Lexer.replace_directive_bool "DEBUG" true
338340
),
@@ -341,70 +343,70 @@ let buckle_script_flags : (string * Arg.spec * string) list =
341343
::
342344
(
343345
"-bs-sort-imports",
344-
Arg.Set Js_config.sort_imports,
346+
Set Js_config.sort_imports,
345347
" Sort the imports by lexical order so the output will be more stable (default false)"
346348
)
347349
::
348350
( "-bs-no-sort-imports",
349-
Arg.Clear Js_config.sort_imports,
351+
Clear Js_config.sort_imports,
350352
" No sort (see -bs-sort-imports)"
351353
)
352354
::
353355
("-bs-package-name",
354-
Arg.String Js_packages_state.set_package_name,
356+
String Js_packages_state.set_package_name,
355357
" set package name, useful when you want to produce npm packages")
356358
::
357359
( "-bs-ns",
358-
Arg.String Js_packages_state.set_package_map,
360+
String Js_packages_state.set_package_map,
359361
" set package map, not only set package name but also use it as a namespace"
360362
)
361363
::
362364
("-bs-no-version-header",
363-
Arg.Set Js_config.no_version_header,
365+
Set Js_config.no_version_header,
364366
" Don't print version header"
365367
)
366368
::
367369
("-bs-package-output",
368-
Arg.String
370+
String
369371
Js_packages_state.update_npm_package_path,
370372
" set npm-output-path: [opt_module]:path, for example: 'lib/cjs', 'amdjs:lib/amdjs', 'es6:lib/es6' ")
371373
::
372374
("-bs-no-builtin-ppx",
373-
Arg.Set Js_config.no_builtin_ppx,
375+
Set Js_config.no_builtin_ppx,
374376
"disable built-in ppx (internal use)")
375377
::
376378
("-bs-cross-module-opt",
377-
Arg.Set Js_config.cross_module_inline,
379+
Set Js_config.cross_module_inline,
378380
"enable cross module inlining(experimental), default(false)")
379381
::
380382
("-bs-no-cross-module-opt",
381-
Arg.Clear Js_config.cross_module_inline,
383+
Clear Js_config.cross_module_inline,
382384
"disable cross module inlining(experimental)")
383385
::
384386
("-bs-diagnose",
385-
Arg.Set Js_config.diagnose,
387+
Set Js_config.diagnose,
386388
" More verbose output")
387389
::
388390
("-bs-no-check-div-by-zero",
389-
Arg.Clear Js_config.check_div_by_zero,
391+
Clear Js_config.check_div_by_zero,
390392
" unsafe mode, don't check div by zero and mod by zero")
391393
::
392394
("-bs-noassertfalse",
393-
Arg.Set Clflags.no_assert_false,
395+
Set Clflags.no_assert_false,
394396
" no code for assert false"
395397
)
396398
::
397399
("-bs-loc",
398-
Arg.Set Clflags.dump_location,
400+
Set Clflags.dump_location,
399401
" dont display location with -dtypedtree, -dparsetree"
400402
)
401403
::
402-
("-impl", Arg.String
404+
("-impl", String
403405
(fun file -> Js_config.js_stdout := false; impl file ),
404406
"<file> Compile <file> as a .ml file"
405407
)
406408
::
407-
("-intf", Arg.String
409+
("-intf", String
408410
(fun file -> Js_config.js_stdout := false ; intf file),
409411
"<file> Compile <file> as a .mli file")
410412
(* :: Ocaml_options.mk__ anonymous *)
@@ -448,7 +450,7 @@ let _ : unit =
448450
~target:output
449451
Ppx_entry.rewrite_implementation
450452
Ppx_entry.rewrite_signature
451-
| _ -> raise_notrace (Arg.Bad "Wrong format when use -as-ppx")
453+
| _ -> bad_arg "Wrong format when use -as-ppx"
452454
end
453455
with x ->
454456
begin

0 commit comments

Comments
 (0)