Skip to content

Commit df31787

Browse files
committed
sanity check and fix for rescript-lang#2027
1 parent 497c5ae commit df31787

37 files changed

+853
-415
lines changed

Diff for: docs/Manual.html

-131
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,6 @@ <h1><a href="https://github.com/bucklescript/bucklescript">BuckleScript</a> User
618618
<ul class="sectlevel2">
619619
<li><a href="#_null_and_undefined">Null and Undefined</a></li>
620620
<li><a href="#_boolean">Boolean</a></li>
621-
<li><a href="#_stable_ish_submodules">Stable-ish submodules</a></li>
622-
<li><a href="#_experimental_incomplete_submodules">Experimental/incomplete submodules</a></li>
623-
<li><a href="#_very_experimental_internal_submodules">Very experimental/internal submodules</a></li>
624-
</ul>
625-
</li>
626-
<li><a href="#_node_module">Node module</a>
627-
<ul class="sectlevel2">
628-
<li><a href="#_submodules">Submodules</a></li>
629621
</ul>
630622
</li>
631623
<li><a href="#_extended_compiler_options">Extended compiler options</a>
@@ -4038,129 +4030,6 @@ <h3 id="_boolean"><a class="anchor" href="#_boolean"></a>Boolean</h3>
40384030
for coercing to and from <code>bool</code>: <code>Js.to_bool</code> and <code>Js.Boolean.to_js_boolean</code>.</p>
40394031
</div>
40404032
</div>
4041-
<div class="sect2">
4042-
<h3 id="_stable_ish_submodules"><a class="anchor" href="#_stable_ish_submodules"></a>Stable-ish submodules</h3>
4043-
<div class="paragraph">
4044-
<p><em>These APIs might change, but is considered mostly complete</em></p>
4045-
</div>
4046-
<div class="ulist">
4047-
<ul>
4048-
<li>
4049-
<p><a href="./api/Js.Null.html">Js.Null</a></p>
4050-
</li>
4051-
<li>
4052-
<p><a href="./api/Js.Undefined.html">Js.Undefined</a></p>
4053-
</li>
4054-
<li>
4055-
<p><a href="./api/Js.Null_undefined.html">Js.Null_undefined</a></p>
4056-
</li>
4057-
<li>
4058-
<p><a href="./api/Js.Array.html">Js.Array</a></p>
4059-
</li>
4060-
<li>
4061-
<p><a href="./api/Js.Date.html">Js.Date</a></p>
4062-
</li>
4063-
<li>
4064-
<p><a href="./api/Js.Math.html">Js.Math</a></p>
4065-
</li>
4066-
<li>
4067-
<p><a href="./api/Js.Re.html">Js.Re</a></p>
4068-
</li>
4069-
<li>
4070-
<p><a href="./api/Js.String.html">Js.String</a></p>
4071-
</li>
4072-
<li>
4073-
<p><a href="./api/Js.Typed_array.html">Js.Typed_array</a></p>
4074-
</li>
4075-
</ul>
4076-
</div>
4077-
</div>
4078-
<div class="sect2">
4079-
<h3 id="_experimental_incomplete_submodules"><a class="anchor" href="#_experimental_incomplete_submodules"></a>Experimental/incomplete submodules</h3>
4080-
<div class="paragraph">
4081-
<p><em>Expect these APIs to change drastically, <strong>use only if you accept breakage.</strong></em></p>
4082-
</div>
4083-
<div class="ulist">
4084-
<ul>
4085-
<li>
4086-
<p><a href="./api/Js.Boolean.html">Js.Boolean</a></p>
4087-
</li>
4088-
<li>
4089-
<p><a href="./api/Js.Dict.html">Js.Dict</a></p>
4090-
</li>
4091-
<li>
4092-
<p><a href="./api/Js.Obj.html">Js.Obj</a></p>
4093-
</li>
4094-
</ul>
4095-
</div>
4096-
</div>
4097-
<div class="sect2">
4098-
<h3 id="_very_experimental_internal_submodules"><a class="anchor" href="#_very_experimental_internal_submodules"></a>Very experimental/internal submodules</h3>
4099-
<div class="paragraph">
4100-
<p><strong><em>Do not use these APIs unless absolutely necessary, they&#8217;re mostly internal</em></strong></p>
4101-
</div>
4102-
<div class="ulist">
4103-
<ul>
4104-
<li>
4105-
<p><a href="./api/Js_float.html">Js_float</a></p>
4106-
</li>
4107-
<li>
4108-
<p><a href="./api/Js_int.html">Js_int</a></p>
4109-
</li>
4110-
<li>
4111-
<p><a href="./api/Js_int64.html">Js_int64</a></p>
4112-
</li>
4113-
<li>
4114-
<p><a href="./api/Js_json.html">Js.Json</a></p>
4115-
</li>
4116-
<li>
4117-
<p><a href="./api/Js_nativeint.html">Js_nativeint</a></p>
4118-
</li>
4119-
<li>
4120-
<p><a href="./api/Js_primitive.html">Js_primitive</a></p>
4121-
</li>
4122-
<li>
4123-
<p><a href="./api/Js_types.html">Js.Types</a></p>
4124-
</li>
4125-
<li>
4126-
<p><a href="./api/Js_unsafe.html">Js_unsafe</a></p>
4127-
</li>
4128-
</ul>
4129-
</div>
4130-
</div>
4131-
</div>
4132-
</div>
4133-
<div class="sect1">
4134-
<h2 id="_node_module"><a class="anchor" href="#_node_module"></a>Node module</h2>
4135-
<div class="sectionbody">
4136-
<div class="paragraph">
4137-
<p><a href="./api/Node.html">Node</a></p>
4138-
</div>
4139-
<div class="sect2">
4140-
<h3 id="_submodules"><a class="anchor" href="#_submodules"></a>Submodules</h3>
4141-
<div class="ulist">
4142-
<ul>
4143-
<li>
4144-
<p><a href="./api/Node_buffer.html">Node.Buffer</a></p>
4145-
</li>
4146-
<li>
4147-
<p><a href="./api/Node_child_process.html">Node.Child_process</a></p>
4148-
</li>
4149-
<li>
4150-
<p><a href="./api/Node_fs.html">Node.Fs</a></p>
4151-
</li>
4152-
<li>
4153-
<p><a href="./api/Node_module.html">Node.Module</a></p>
4154-
</li>
4155-
<li>
4156-
<p><a href="./api/Node_path.html">Node.Path</a></p>
4157-
</li>
4158-
<li>
4159-
<p><a href="./api/Node_process.html">Node.Process</a></p>
4160-
</li>
4161-
</ul>
4162-
</div>
4163-
</div>
41644033
</div>
41654034
</div>
41664035
<div class="sect1">

Diff for: jscomp/all.depend

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ ext/ext_path.cmx : ext/literals.cmx ext/ext_string.cmx \
9393
ext/ext_pervasives.cmx ext/ext_path.cmi
9494
ext/ext_filename.cmx : ext/literals.cmx ext/ext_string.cmx \
9595
ext/ext_pervasives.cmx ext/ext_path.cmx ext/ext_filename.cmi
96-
ext/ext_modulename.cmx : ext/ext_path.cmx ext/ext_modulename.cmi
96+
ext/ext_modulename.cmx : ext/ext_string.cmx ext/ext_path.cmx \
97+
ext/ext_modulename.cmi
9798
ext/ext_namespace.cmx : ext/literals.cmx ext/ext_namespace.cmi
9899
ext/literals.cmi :
99100
ext/ext_util.cmi :

Diff for: jscomp/bin/all_ounit_tests.ml

+70-19
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,10 @@ val single_colon : string
18001800
val parent_dir_lit : string
18011801
val current_dir_lit : string
18021802

1803+
val capitalize_ascii : string -> string
1804+
1805+
(** return [Some xx] means the original *)
1806+
(* val capitalize_ascii_opt : string -> string option *)
18031807
end = struct
18041808
#1 "ext_string.ml"
18051809
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -2137,11 +2141,11 @@ let is_valid_module_file (s : string) =
21372141

21382142

21392143
(* https://docs.npmjs.com/files/package.json
2140-
Some rules:
2141-
The name must be less than or equal to 214 characters. This includes the scope for scoped packages.
2142-
The name can't start with a dot or an underscore.
2143-
New packages must not have uppercase letters in the name.
2144-
The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can't contain any non-URL-safe characters.
2144+
Some rules:
2145+
The name must be less than or equal to 214 characters. This includes the scope for scoped packages.
2146+
The name can't start with a dot or an underscore.
2147+
New packages must not have uppercase letters in the name.
2148+
The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can't contain any non-URL-safe characters.
21452149
*)
21462150
let is_valid_npm_package_name (s : string) =
21472151
let len = String.length s in
@@ -2161,10 +2165,10 @@ type check_result =
21612165
| Good
21622166
| Invalid_module_name
21632167
| Suffix_mismatch
2164-
(**
2165-
TODO: move to another module
2166-
Make {!Ext_filename} not stateful
2167-
*)
2168+
(**
2169+
TODO: move to another module
2170+
Make {!Ext_filename} not stateful
2171+
*)
21682172
let is_valid_source_name name : check_result =
21692173
match check_any_suffix_case_then_chop name [
21702174
".ml";
@@ -2186,9 +2190,9 @@ let rec unsafe_no_char x ch i last_idx =
21862190
let rec unsafe_no_char_idx x ch i last_idx =
21872191
if i > last_idx then -1
21882192
else
2189-
if String.unsafe_get x i <> ch then
2190-
unsafe_no_char_idx x ch (i + 1) last_idx
2191-
else i
2193+
if String.unsafe_get x i <> ch then
2194+
unsafe_no_char_idx x ch (i + 1) last_idx
2195+
else i
21922196

21932197
let no_char x ch i len : bool =
21942198
let str_len = String.length x in
@@ -2223,7 +2227,6 @@ let empty = ""
22232227

22242228
external compare : string -> string -> int = "caml_string_length_based_compare" "noalloc";;
22252229

2226-
22272230
let single_space = " "
22282231
let single_colon = ":"
22292232

@@ -2273,7 +2276,7 @@ let concat4 a b c d =
22732276
let c_len = String.length c in
22742277
let d_len = String.length d in
22752278
let len = a_len + b_len + c_len + d_len in
2276-
2279+
22772280
let target = Bytes.create len in
22782281
String.unsafe_blit a 0 target 0 a_len ;
22792282
String.unsafe_blit b 0 target a_len b_len;
@@ -2289,7 +2292,7 @@ let concat5 a b c d e =
22892292
let d_len = String.length d in
22902293
let e_len = String.length e in
22912294
let len = a_len + b_len + c_len + d_len + e_len in
2292-
2295+
22932296
let target = Bytes.create len in
22942297
String.unsafe_blit a 0 target 0 a_len ;
22952298
String.unsafe_blit b 0 target a_len b_len;
@@ -2301,7 +2304,7 @@ let concat5 a b c d e =
23012304

23022305

23032306
let inter2 a b =
2304-
concat3 a single_space b
2307+
concat3 a single_space b
23052308

23062309

23072310
let inter3 a b c =
@@ -2313,11 +2316,46 @@ let inter3 a b c =
23132316

23142317
let inter4 a b c d =
23152318
concat_array single_space [| a; b ; c; d|]
2316-
2317-
2319+
2320+
23182321
let parent_dir_lit = ".."
23192322
let current_dir_lit = "."
23202323

2324+
2325+
(* reference {!Bytes.unppercase} *)
2326+
let capitalize_ascii (s : string) : string =
2327+
if String.length s = 0 then s
2328+
else
2329+
begin
2330+
let c = String.unsafe_get s 0 in
2331+
if (c >= 'a' && c <= 'z')
2332+
|| (c >= '\224' && c <= '\246')
2333+
|| (c >= '\248' && c <= '\254') then
2334+
let uc = Char.unsafe_chr (Char.code c - 32) in
2335+
let bytes = Bytes.of_string s in
2336+
Bytes.unsafe_set bytes 0 uc;
2337+
Bytes.unsafe_to_string bytes
2338+
else s
2339+
end
2340+
2341+
let capitalize_ascii_opt (s : string) : string option =
2342+
if String.length s = 0 then None
2343+
else
2344+
begin
2345+
let c = String.unsafe_get s 0 in
2346+
if (c >= 'a' && c <= 'z')
2347+
|| (c >= '\224' && c <= '\246')
2348+
|| (c >= '\248' && c <= '\254') then
2349+
let uc = Char.unsafe_chr (Char.code c - 32) in
2350+
let bytes = Bytes.of_string s in
2351+
Bytes.unsafe_set bytes 0 uc;
2352+
Some (Bytes.unsafe_to_string bytes)
2353+
else None
2354+
end
2355+
2356+
2357+
2358+
23212359
end
23222360
module Ounit_array_tests
23232361
= struct
@@ -6501,7 +6539,7 @@ let js_module_table : Ident.t String_hashtbl.t = String_hashtbl.create 31
65016539
*)
65026540
let create_js_module (name : string) : Ident.t =
65036541
let name =
6504-
String.concat "" @@ List.map (String.capitalize ) @@
6542+
String.concat "" @@ List.map (Ext_string.capitalize_ascii ) @@
65056543
Ext_string.split name '-' in
65066544
(* TODO: if we do such transformation, we should avoid collision for example:
65076545
react-dom
@@ -13990,6 +14028,19 @@ let suites =
1399014028
=~ "aA.js";
1399114029
Ext_namespace.js_name_of_modulename ~little:false "AA-b"
1399214030
=~ "AA.js";
14031+
end;
14032+
14033+
__LOC__ >:: begin fun _ ->
14034+
let (=~) = OUnit.assert_equal ~printer:(fun x -> x) in
14035+
let f = Ext_string.capitalize_ascii in
14036+
f "x" =~ "X";
14037+
f "X" =~ "X";
14038+
f "" =~ "";
14039+
f "abc" =~ "Abc";
14040+
f "_bc" =~ "_bc";
14041+
let v = "bc" in
14042+
f v =~ "Bc";
14043+
v =~ "bc"
1399314044
end
1399414045
]
1399514046

0 commit comments

Comments
 (0)