Skip to content

Commit f5f7aed

Browse files
committed
String char access is standarized as codePointAt
1 parent a1b4977 commit f5f7aed

16 files changed

+95
-94
lines changed

jscomp/core/js_dump_lit.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ let colon_space = ": "
4242
let throw = "throw"
4343
let default = "default"
4444
let length = "length"
45-
let char_code_at = "charCodeAt"
46-
let codePointAt = "charCodeAt" (* FIXME*)
45+
let codePointAt = "codePointAt"
4746
let new_ = "new"
4847
let array = "Array"
4948
let question = "?"

jscomp/test/chn_test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,24 @@ eq("File \"chn_test.ml\", line 63, characters 5-12", convert("\uD83D\uDE80\uD83D
186186

187187
eq("No inline string length", "\uD83D\uDE80\0".length, 3);
188188

189-
eq("No inline string access", Caml_string.get("\uD83D\uDE80\0", 0) & 255, 61);
189+
eq("File \"chn_test.ml\", line 72, characters 6-13", Caml_string.get("\uD83D\uDE80\0", 0), 128640);
190190

191-
eq("File \"chn_test.ml\", line 79, characters 5-12", convert("\uD83D\uDE80"), {
191+
eq("File \"chn_test.ml\", line 76, characters 6-13", Caml_string.get("🚀", 0), 128640);
192+
193+
eq("File \"chn_test.ml\", line 81, characters 5-12", convert("\uD83D\uDE80"), {
192194
hd: 128640,
193195
tl: /* [] */0
194196
});
195197

196-
eq("File \"chn_test.ml\", line 81, characters 5-12", convert("\uD83D\uDE80\uD83D\uDE80"), {
198+
eq("File \"chn_test.ml\", line 83, characters 5-12", convert("\uD83D\uDE80\uD83D\uDE80"), {
197199
hd: 128640,
198200
tl: {
199201
hd: 128640,
200202
tl: /* [] */0
201203
}
202204
});
203205

204-
eq("File \"chn_test.ml\", line 82, characters 5-12", convert(" \b\t\n\v\f\ra"), {
206+
eq("File \"chn_test.ml\", line 84, characters 5-12", convert(" \b\t\n\v\f\ra"), {
205207
hd: 32,
206208
tl: {
207209
hd: 8,
@@ -227,7 +229,7 @@ eq("File \"chn_test.ml\", line 82, characters 5-12", convert(" \b\t\n\v\f\ra"),
227229
}
228230
});
229231

230-
eq("File \"chn_test.ml\", line 89, characters 6-13", convert(" \b\t\n\v\f\r\"'\\\0a"), {
232+
eq("File \"chn_test.ml\", line 91, characters 6-13", convert(" \b\t\n\v\f\r\"'\\\0a"), {
231233
hd: 32,
232234
tl: {
233235
hd: 8,

jscomp/test/chn_test.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let convert (s : string) : int list =
1616
Js_array2.fromMap
1717
(Js_string.castToArrayLike s)
1818
(fun x ->
19-
match Js_string.codePointAt 0 x with
19+
match Js_string2.codePointAt x 0 with
2020
| None -> assert false
2121
| Some x -> x ) |> Array.to_list
2222
@@ -69,10 +69,12 @@ let () =
6969
*)
7070
(* eq __LOC__
7171
(Js.String.codePointAt 0 {js|\uD83D\uDE80\0|js} ) 128640; *)
72-
eq "No inline string access"
73-
(Char.code {js|\uD83D\uDE80\0|js}.[0] land 255)
72+
eq __LOC__
73+
({js|\uD83D\uDE80\0|js}.[0] :> int)
7474
(*TODO: Char.code need normalization? *)
75-
61;
75+
128640;
76+
eq __LOC__ ({j|🚀|j}.[0] :> int) 128640;
77+
7678
(* "\uD83D\uDE80".charCodeAt(0) & 255
7779
61 *)
7880
(** Note that [char] maximum is 255 *)

jscomp/test/ext_filename_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function chop_extension_if_any(fname) {
9090
}
9191
}
9292

93-
var os_path_separator_char = Filename.dir_sep.charCodeAt(0);
93+
var os_path_separator_char = Filename.dir_sep.codePointAt(0);
9494

9595
function relative_path(file_or_dir_1, file_or_dir_2) {
9696
var relevant_dir1 = file_or_dir_1.NAME === "File" ? Curry._1(Filename.dirname, file_or_dir_1.VAL) : file_or_dir_1.VAL;
@@ -159,7 +159,7 @@ function node_relative_path(node_modules_shorten, file1, dep_file) {
159159
Error: new Error()
160160
};
161161
}
162-
var curr_char = file2.charCodeAt(i);
162+
var curr_char = file2.codePointAt(i);
163163
if (!(curr_char === os_path_separator_char || curr_char === /* '.' */46)) {
164164
return i;
165165
}

jscomp/test/ext_string_test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function trim(s) {
5757
while((function () {
5858
var tmp = false;
5959
if (i < j) {
60-
var u = s.charCodeAt(i);
60+
var u = s.codePointAt(i);
6161
tmp = u === /* '\t' */9 || u === /* '\n' */10 || u === /* ' ' */32;
6262
}
6363
return tmp;
@@ -68,7 +68,7 @@ function trim(s) {
6868
while((function () {
6969
var tmp = false;
7070
if (k >= i) {
71-
var u = s.charCodeAt(k);
71+
var u = s.codePointAt(k);
7272
tmp = u === /* '\t' */9 || u === /* '\n' */10 || u === /* ' ' */32;
7373
}
7474
return tmp;
@@ -105,7 +105,7 @@ function starts_with(s, beg) {
105105
return false;
106106
}
107107
var i = 0;
108-
while(i < beg_len && s.charCodeAt(i) === beg.charCodeAt(i)) {
108+
while(i < beg_len && s.codePointAt(i) === beg.codePointAt(i)) {
109109
i = i + 1 | 0;
110110
};
111111
return i === beg_len;
@@ -125,7 +125,7 @@ function ends_with_index(s, end_) {
125125
if (k < 0) {
126126
return j + 1 | 0;
127127
}
128-
if (s.charCodeAt(j) !== end_.charCodeAt(k)) {
128+
if (s.codePointAt(j) !== end_.codePointAt(k)) {
129129
return -1;
130130
}
131131
_k = k - 1 | 0;
@@ -175,7 +175,7 @@ function escaped(s) {
175175
if (i >= s.length) {
176176
return false;
177177
}
178-
var match = s.charCodeAt(i);
178+
var match = s.codePointAt(i);
179179
if (match < 32) {
180180
return true;
181181
}
@@ -206,7 +206,7 @@ function unsafe_for_all_range(s, _start, finish, p) {
206206
if (start > finish) {
207207
return true;
208208
}
209-
if (!Curry._1(p, s.charCodeAt(start))) {
209+
if (!Curry._1(p, s.codePointAt(start))) {
210210
return false;
211211
}
212212
_start = start + 1 | 0;
@@ -251,7 +251,7 @@ function unsafe_is_sub(sub, i, s, j, len) {
251251
if (k === len) {
252252
return true;
253253
}
254-
if (sub.charCodeAt(i + k | 0) !== s.charCodeAt(j + k | 0)) {
254+
if (sub.codePointAt(i + k | 0) !== s.codePointAt(j + k | 0)) {
255255
return false;
256256
}
257257
_k = k + 1 | 0;
@@ -378,7 +378,7 @@ function starts_with_and_number(s, offset, beg) {
378378
return -1;
379379
}
380380
var i = offset;
381-
while(i < finish_delim && s.charCodeAt(i) === beg.charCodeAt(i - offset | 0)) {
381+
while(i < finish_delim && s.codePointAt(i) === beg.codePointAt(i - offset | 0)) {
382382
i = i + 1 | 0;
383383
};
384384
if (i === finish_delim) {
@@ -398,7 +398,7 @@ function rindex_rec(s, _i, c) {
398398
if (i < 0) {
399399
return i;
400400
}
401-
if (s.charCodeAt(i) === c) {
401+
if (s.codePointAt(i) === c) {
402402
return i;
403403
}
404404
_i = i - 1 | 0;
@@ -412,7 +412,7 @@ function rindex_rec_opt(s, _i, c) {
412412
if (i < 0) {
413413
return ;
414414
}
415-
if (s.charCodeAt(i) === c) {
415+
if (s.codePointAt(i) === c) {
416416
return i;
417417
}
418418
_i = i - 1 | 0;
@@ -433,7 +433,7 @@ function is_valid_module_file(s) {
433433
if (len <= 0) {
434434
return false;
435435
}
436-
var match = s.charCodeAt(0);
436+
var match = s.codePointAt(0);
437437
if (match >= 91) {
438438
if (match > 122 || match < 97) {
439439
return false;
@@ -465,7 +465,7 @@ function is_valid_npm_package_name(s) {
465465
if (len <= 0) {
466466
return false;
467467
}
468-
var match = s.charCodeAt(0);
468+
var match = s.codePointAt(0);
469469
if (match >= 97) {
470470
if (match >= 123) {
471471
return false;
@@ -520,7 +520,7 @@ function unsafe_no_char(x, ch, _i, last_idx) {
520520
if (i > last_idx) {
521521
return true;
522522
}
523-
if (x.charCodeAt(i) === ch) {
523+
if (x.codePointAt(i) === ch) {
524524
return false;
525525
}
526526
_i = i + 1 | 0;
@@ -534,7 +534,7 @@ function unsafe_no_char_idx(x, ch, _i, last_idx) {
534534
if (i > last_idx) {
535535
return -1;
536536
}
537-
if (x.charCodeAt(i) === ch) {
537+
if (x.codePointAt(i) === ch) {
538538
return i;
539539
}
540540
_i = i + 1 | 0;

jscomp/test/sexpm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js");
1515
function _must_escape(s) {
1616
try {
1717
for(var i = 0 ,i_finish = s.length; i < i_finish; ++i){
18-
var c = s.charCodeAt(i);
18+
var c = s.codePointAt(i);
1919
var exit = 0;
2020
if (c >= 42) {
2121
if (c !== 59) {

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84207,8 +84207,7 @@ let colon_space = ": "
8420784207
let throw = "throw"
8420884208
let default = "default"
8420984209
let length = "length"
84210-
let char_code_at = "charCodeAt"
84211-
let codePointAt = "charCodeAt" (* FIXME*)
84210+
let codePointAt = "codePointAt" (* FIXME*)
8421284211
let new_ = "new"
8421384212
let array = "Array"
8421484213
let question = "?"

lib/4.06.1/whole_compiler.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374173,8 +374173,7 @@ let colon_space = ": "
374173374173
let throw = "throw"
374174374174
let default = "default"
374175374175
let length = "length"
374176-
let char_code_at = "charCodeAt"
374177-
let codePointAt = "charCodeAt" (* FIXME*)
374176+
let codePointAt = "codePointAt" (* FIXME*)
374178374177
let new_ = "new"
374179374178
let array = "Array"
374180374179
let question = "?"

lib/es6/bytes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function of_string(s) {
106106
var len = s.length;
107107
var res = new Array(len);
108108
for(var i = 0; i < len; ++i){
109-
res[i] = s.charCodeAt(i);
109+
res[i] = s.codePointAt(i);
110110
}
111111
return res;
112112
}
@@ -214,12 +214,12 @@ function blit_string(s1, ofs1, s2, ofs2, len) {
214214
var off1 = s1.length - ofs1 | 0;
215215
if (len <= off1) {
216216
for(var i = 0; i < len; ++i){
217-
s2[ofs2 + i | 0] = s1.charCodeAt(ofs1 + i | 0);
217+
s2[ofs2 + i | 0] = s1.codePointAt(ofs1 + i | 0);
218218
}
219219
return ;
220220
}
221221
for(var i$1 = 0; i$1 < off1; ++i$1){
222-
s2[ofs2 + i$1 | 0] = s1.charCodeAt(ofs1 + i$1 | 0);
222+
s2[ofs2 + i$1 | 0] = s1.codePointAt(ofs1 + i$1 | 0);
223223
}
224224
for(var i$2 = off1; i$2 < len; ++i$2){
225225
s2[ofs2 + i$2 | 0] = /* '\000' */0;

0 commit comments

Comments
 (0)