Skip to content

Commit 6fe622e

Browse files
committed
clean up pp_print_string
1 parent 0035dc6 commit 6fe622e

File tree

6 files changed

+44
-44
lines changed

6 files changed

+44
-44
lines changed

jscomp/all.depend

+2-2
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ core/lam_pass_collect.cmx : core/lam_util.cmx core/lam_stats_util.cmx \
484484
core/js_program_loader.cmx : core/lam_module_ident.cmx \
485485
core/lam_compile_env.cmx core/js_stmt_make.cmx core/js_exp_make.cmx \
486486
common/js_config.cmx core/j.cmx ext/ident_set.cmx ext/ext_sys.cmx \
487-
ext/ext_string.cmx ext/ext_pervasives.cmx ext/ext_filename.cmx \
488-
core/config_util.cmx depends/bs_exception.cmx core/js_program_loader.cmi
487+
ext/ext_string.cmx ext/ext_filename.cmx core/config_util.cmx \
488+
depends/bs_exception.cmx core/js_program_loader.cmi
489489
core/js_dump.cmx : ext/literals.cmx core/lam_module_ident.cmx \
490490
core/js_stmt_make.cmx core/js_program_loader.cmx core/js_op_util.cmx \
491491
core/js_op.cmx core/js_number.cmx core/js_fun_env.cmx \

jscomp/bin/whole_compiler.ml

+21-21
Original file line numberDiff line numberDiff line change
@@ -22621,6 +22621,8 @@ type error =
2262122621
| Bs_package_not_found of string
2262222622
| Bs_main_not_exist of string
2262322623
| Bs_invalid_path of string
22624+
| Missing_ml_dependency of string
22625+
| Dependency_script_module_dependent_not of string
2262422626
(*
2262522627
TODO: In the futrue, we should refine dependency [bsb]
2262622628
should not rely on such exception, it should have its own exception handling
@@ -22668,12 +22670,21 @@ type error =
2266822670
| Bs_package_not_found of string
2266922671
| Bs_main_not_exist of string
2267022672
| Bs_invalid_path of string
22673+
| Missing_ml_dependency of string
22674+
| Dependency_script_module_dependent_not of string
2267122675
(** TODO: we need add location handling *)
2267222676
exception Error of error
2267322677

2267422678
let error err = raise (Error err)
2267522679

2267622680
let report_error ppf = function
22681+
| Dependency_script_module_dependent_not s
22682+
->
22683+
Format.fprintf ppf
22684+
"%s is compiled in script mode while its dependent is not"
22685+
s
22686+
| Missing_ml_dependency s ->
22687+
Format.fprintf ppf "Missing dependency %s in search path" s
2267722688
| Cmj_not_found s ->
2267822689
Format.fprintf ppf "%s not found, cmj format is generated by BuckleScript" s
2267922690
| Js_not_found s ->
@@ -83071,21 +83082,16 @@ let string_of_module_id ~output_prefix
8307183082
Js_config.get_current_package_name_and_path module_system
8307283083
in
8307383084
begin match module_system, dependency_pkg_info, current_pkg_info with
83074-
| _, NotFound , _ ->
83075-
Ext_pervasives.failwithf ~loc:__LOC__
83076-
" @[dependent module is not found while %s not in search path - compiling %s @] "
83077-
js_file !Location.input_name
83085+
| _, NotFound , _
83086+
->
83087+
Bs_exception.error (Missing_ml_dependency js_file)
8307883088
| Goog, (Empty | Package_script _), _
8307983089
->
83080-
Ext_pervasives.failwithf ~loc:__LOC__
83081-
" @[%s was not compiled with goog support in search path - while compiling %s @] "
83082-
js_file !Location.input_name
83090+
Bs_exception.error (Dependency_script_module_dependent_not js_file)
8308383091
| (AmdJS | NodeJS | Es6 | Es6_global | AmdJS_global),
8308483092
( Empty | Package_script _) ,
8308583093
Found _ ->
83086-
Ext_pervasives.failwithf ~loc:__LOC__
83087-
"@[dependency %s was compiled in script mode - while compiling %s in package mode @]"
83088-
js_file !Location.input_name
83094+
Bs_exception.error (Dependency_script_module_dependent_not js_file)
8308983095
| Goog , Found (package_name, x), _ ->
8309083096
package_name ^ "." ^ String.uncapitalize id.name
8309183097
| (AmdJS | NodeJS| Es6 | Es6_global|AmdJS_global),
@@ -83427,7 +83433,7 @@ let array_conv =
8342783433

8342883434

8342983435
(* https://mathiasbynens.be/notes/javascript-escapes *)
83430-
let pp_string f ?(quote='"') (* ?(utf=false)*) s =
83436+
let pp_string f (* ?(utf=false)*) s =
8343183437
let pp_raw_string f (* ?(utf=false)*) s =
8343283438
let l = String.length s in
8343383439
for i = 0 to l - 1 do
@@ -83461,20 +83467,14 @@ let pp_string f ?(quote='"') (* ?(utf=false)*) s =
8346183467
P.string f "\\x";
8346283468
P.string f (Array.unsafe_get array_conv (c lsr 4));
8346383469
P.string f (Array.unsafe_get array_conv (c land 0xf))
83464-
(* | '\'' -> P.string f "\\'" *)
83465-
(* | '\"' -> P.string f "\\\"" *)
83470+
| '\"' -> P.string f "\\\"" (* quote*)
8346683471
| _ ->
83467-
begin
83468-
(if c = quote then
83469-
P.string f "\\");
8347083472
P.string f (Array.unsafe_get array_str1 (Char.code c))
83471-
end
8347283473
done
8347383474
in
83474-
let quote_s = String.make 1 quote in
83475-
P.string f quote_s;
83475+
P.string f "\"";
8347683476
pp_raw_string f (*~utf*) s ;
83477-
P.string f quote_s
83477+
P.string f "\""
8347883478
;;
8347983479

8348083480
(** used in printing keys
@@ -84982,7 +84982,7 @@ let imports cxt f (modules : (Ident.t * string) list ) =
8498284982
P.nspace f (margin - String.length s + 1) ;
8498384983
P.string f L.from;
8498484984
P.space f;
84985-
pp_string f (file ^ ".js") ;
84985+
pp_string f file ;
8498684986
semi f ;
8498784987
P.newline f ;
8498884988
) reversed_list;

jscomp/core/js_dump.ml

+5-11
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ let array_conv =
194194

195195

196196
(* https://mathiasbynens.be/notes/javascript-escapes *)
197-
let pp_string f ?(quote='"') (* ?(utf=false)*) s =
197+
let pp_string f (* ?(utf=false)*) s =
198198
let pp_raw_string f (* ?(utf=false)*) s =
199199
let l = String.length s in
200200
for i = 0 to l - 1 do
@@ -228,20 +228,14 @@ let pp_string f ?(quote='"') (* ?(utf=false)*) s =
228228
P.string f "\\x";
229229
P.string f (Array.unsafe_get array_conv (c lsr 4));
230230
P.string f (Array.unsafe_get array_conv (c land 0xf))
231-
(* | '\'' -> P.string f "\\'" *)
232-
(* | '\"' -> P.string f "\\\"" *)
231+
| '\"' -> P.string f "\\\"" (* quote*)
233232
| _ ->
234-
begin
235-
(if c = quote then
236-
P.string f "\\");
237233
P.string f (Array.unsafe_get array_str1 (Char.code c))
238-
end
239234
done
240235
in
241-
let quote_s = String.make 1 quote in
242-
P.string f quote_s;
236+
P.string f "\"";
243237
pp_raw_string f (*~utf*) s ;
244-
P.string f quote_s
238+
P.string f "\""
245239
;;
246240

247241
(** used in printing keys
@@ -1749,7 +1743,7 @@ let imports cxt f (modules : (Ident.t * string) list ) =
17491743
P.nspace f (margin - String.length s + 1) ;
17501744
P.string f L.from;
17511745
P.space f;
1752-
pp_string f (file ^ ".js") ;
1746+
pp_string f file ;
17531747
semi f ;
17541748
P.newline f ;
17551749
) reversed_list;

jscomp/core/js_program_loader.ml

+5-10
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,16 @@ let string_of_module_id ~output_prefix
9797
Js_config.get_current_package_name_and_path module_system
9898
in
9999
begin match module_system, dependency_pkg_info, current_pkg_info with
100-
| _, NotFound , _ ->
101-
Ext_pervasives.failwithf ~loc:__LOC__
102-
" @[dependent module is not found while %s not in search path - compiling %s @] "
103-
js_file !Location.input_name
100+
| _, NotFound , _
101+
->
102+
Bs_exception.error (Missing_ml_dependency js_file)
104103
| Goog, (Empty | Package_script _), _
105104
->
106-
Ext_pervasives.failwithf ~loc:__LOC__
107-
" @[%s was not compiled with goog support in search path - while compiling %s @] "
108-
js_file !Location.input_name
105+
Bs_exception.error (Dependency_script_module_dependent_not js_file)
109106
| (AmdJS | NodeJS | Es6 | Es6_global | AmdJS_global),
110107
( Empty | Package_script _) ,
111108
Found _ ->
112-
Ext_pervasives.failwithf ~loc:__LOC__
113-
"@[dependency %s was compiled in script mode - while compiling %s in package mode @]"
114-
js_file !Location.input_name
109+
Bs_exception.error (Dependency_script_module_dependent_not js_file)
115110
| Goog , Found (package_name, x), _ ->
116111
package_name ^ "." ^ String.uncapitalize id.name
117112
| (AmdJS | NodeJS| Es6 | Es6_global|AmdJS_global),

jscomp/depends/bs_exception.ml

+9
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@ type error =
3232
| Bs_package_not_found of string
3333
| Bs_main_not_exist of string
3434
| Bs_invalid_path of string
35+
| Missing_ml_dependency of string
36+
| Dependency_script_module_dependent_not of string
3537
(** TODO: we need add location handling *)
3638
exception Error of error
3739

3840
let error err = raise (Error err)
3941

4042
let report_error ppf = function
43+
| Dependency_script_module_dependent_not s
44+
->
45+
Format.fprintf ppf
46+
"%s is compiled in script mode while its dependent is not"
47+
s
48+
| Missing_ml_dependency s ->
49+
Format.fprintf ppf "Missing dependency %s in search path" s
4150
| Cmj_not_found s ->
4251
Format.fprintf ppf "%s not found, cmj format is generated by BuckleScript" s
4352
| Js_not_found s ->

jscomp/depends/bs_exception.mli

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type error =
3131
| Bs_package_not_found of string
3232
| Bs_main_not_exist of string
3333
| Bs_invalid_path of string
34+
| Missing_ml_dependency of string
35+
| Dependency_script_module_dependent_not of string
3436
(*
3537
TODO: In the futrue, we should refine dependency [bsb]
3638
should not rely on such exception, it should have its own exception handling

0 commit comments

Comments
 (0)