Skip to content

Commit ccf82e0

Browse files
committed
[refact] fix some space issues (#284)
1 parent 1a2a528 commit ccf82e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+203
-189
lines changed

jscomp/js_dump.ml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,26 @@ module L = struct
9090
let console = "console"
9191
let define = "define"
9292
let break = "break"
93+
let continue = "continue"
94+
let switch = "switch"
9395
let strict_directive = "'use strict';"
9496
let true_ = "true"
9597
let false_ = "false"
9698
let app = Literals.app (* curry arbitrary args *)
9799
let app_array = Literals.app_array
100+
let debugger = "debugger"
98101
let tag = "tag"
99102
let bind = "bind"
100103
let math = "Math"
101104
let apply = "apply"
102105
let null = "null"
103106
let string_cap = "String"
104107
let fromCharcode = "fromCharCode"
108+
let eq = "="
109+
let le = "<="
110+
let ge = ">="
111+
let plus_plus = "++" (* FIXME: use (i = i + 1 | 0) instead *)
112+
let minus_minus = "--"
105113
end
106114
let return_indent = (String.length L.return / Ext_pp.indent_length)
107115

@@ -1284,25 +1292,29 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
12841292
cxt, None
12851293
| None , _ ->
12861294
P.string f L.var;
1287-
P.string f " ";
1295+
P.space f ;
12881296
let id = Ext_ident.create (Ident.name id ^ "_finish") in
12891297
let cxt = ident cxt f id in
1290-
P.string f " = "; (* FIXME: space *)
1298+
P.space f ;
1299+
P.string f L.eq ;
1300+
P.space f ;
12911301
expression 15 cxt f finish, Some id
12921302
) in
1303+
12931304
semi f ;
12941305
P.space f;
12951306
let cxt = ident cxt f id in
1307+
P.space f;
12961308
let right_prec =
12971309

12981310
match direction with
12991311
| Upto ->
13001312
let (_,_,right) = op_prec Le in
1301-
P.string f "<=";
1313+
P.string f L.le;
13021314
right
13031315
| Downto ->
13041316
let (_,_,right) = op_prec Ge in
1305-
P.string f ">=" ;
1317+
P.string f L.ge ;
13061318
right
13071319
in
13081320
P.space f ;
@@ -1315,8 +1327,8 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
13151327
P.space f;
13161328
let () =
13171329
match direction with
1318-
| Upto -> P.string f "++"
1319-
| Downto -> P.string f "--" in
1330+
| Upto -> P.string f L.plus_plus
1331+
| Downto -> P.string f L.minus_minus in
13201332
ident cxt f id
13211333
in
13221334
block cxt f s in
@@ -1357,21 +1369,23 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
13571369
_enclose action inner_cxt lexical
13581370

13591371
| Continue s ->
1360-
P.string f "continue "; (* ASI becareful...*)
1372+
P.string f L.continue;
1373+
P.space f ;
13611374
P.string f s;
13621375
semi f;
13631376
P.newline f;
13641377
cxt
13651378
| Debugger
13661379
->
13671380
P.newline f ;
1368-
P.string f "debugger";
1381+
P.string f L.debugger;
13691382
semi f ;
13701383
P.newline f;
13711384
cxt
13721385
| Break
13731386
->
1374-
P.string f "break ";
1387+
P.string f L.break;
1388+
P.space f ;
13751389
semi f;
13761390
P.newline f;
13771391
cxt
@@ -1394,7 +1408,7 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
13941408
argument. A line return will not work *)
13951409
end
13961410
| Int_switch (e, cc, def) ->
1397-
P.string f "switch";
1411+
P.string f L.switch;
13981412
P.space f;
13991413
let cxt = P.paren_group f 1 @@ fun _ -> expression 0 cxt f e
14001414
in
@@ -1412,7 +1426,7 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
14121426
)
14131427

14141428
| String_switch (e, cc, def) ->
1415-
P.string f "switch";
1429+
P.string f L.switch;
14161430
P.space f;
14171431
let cxt = P.paren_group f 1 @@ fun _ -> expression 0 cxt f e
14181432
in

jscomp/lib/bench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Curry._3(suite.add.bind(suite), "second", function () {
2323
});
2424

2525
Curry._2(suite.on.bind(suite), "complete", function () {
26-
for(var i = 0 ,i_finish = suite.length - 1 | 0; i<= i_finish; ++i){
26+
for(var i = 0 ,i_finish = suite.length - 1 | 0; i <= i_finish; ++i){
2727
console.log(suite[i]);
2828
}
2929
return /* () */0;

jscomp/runtime/caml_array.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ function caml_array_concat(l) {
6464

6565
function caml_make_vect(len, init) {
6666
var b = new Array(len);
67-
for(var i = 0 ,i_finish = len - 1 | 0; i<= i_finish; ++i){
67+
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
6868
b[i] = init;
6969
}
7070
return b;
7171
}
7272

7373
function caml_array_blit(a1, i1, a2, i2, len) {
7474
if (i2 <= i1) {
75-
for(var j = 0 ,j_finish = len - 1 | 0; j<= j_finish; ++j){
75+
for(var j = 0 ,j_finish = len - 1 | 0; j <= j_finish; ++j){
7676
a2[j + i2 | 0] = a1[j + i1 | 0];
7777
}
7878
return /* () */0;
7979
}
8080
else {
81-
for(var j$1 = len - 1 | 0; j$1>= 0; --j$1){
81+
for(var j$1 = len - 1 | 0; j$1 >= 0; --j$1){
8282
a2[j$1 + i2 | 0] = a1[j$1 + i1 | 0];
8383
}
8484
return /* () */0;

jscomp/runtime/caml_bigarray.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function caml_invalid_argument(s) {
1919

2020
function caml_ba_get_size(dims) {
2121
var size = 1;
22-
for(var i = 0 ,i_finish = dims.length - 1 | 0; i<= i_finish; ++i){
22+
for(var i = 0 ,i_finish = dims.length - 1 | 0; i <= i_finish; ++i){
2323
var v = dims[i];
2424
if (v < 0) {
2525
throw [
@@ -42,7 +42,7 @@ function index_offset_c(n_dims, dims, index) {
4242
"Bigarray.get/set: bad number of dimensions"
4343
];
4444
}
45-
for(var i = 0 ,i_finish = n_dims - 1 | 0; i<= i_finish; ++i){
45+
for(var i = 0 ,i_finish = n_dims - 1 | 0; i <= i_finish; ++i){
4646
var index_j = index[i];
4747
var dim_j = dims[i];
4848
if (index_j < 0 || index_j >= dim_j) {
@@ -66,7 +66,7 @@ function index_offset_fortran(n_dims, dims, index) {
6666
"Bigarray.get/set: bad number of dimensions"
6767
];
6868
}
69-
for(var i = n_dims - 1 | 0; i>= 0; --i){
69+
for(var i = n_dims - 1 | 0; i >= 0; --i){
7070
var index_j = index[i];
7171
var dim_j = dims[i];
7272
if (index_j < 1 || index_j > dim_j) {

jscomp/runtime/caml_format.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ function finish_formatting(param, rawbuffer) {
540540
}
541541
var buffer = "";
542542
if (justify === "+" && filter === " ") {
543-
for(var i = len ,i_finish = width - 1 | 0; i<= i_finish; ++i){
543+
for(var i = len ,i_finish = width - 1 | 0; i <= i_finish; ++i){
544544
buffer = buffer + filter;
545545
}
546546
}
@@ -560,13 +560,13 @@ function finish_formatting(param, rawbuffer) {
560560
buffer = buffer + "0x";
561561
}
562562
if (justify === "+" && filter === "0") {
563-
for(var i$1 = len ,i_finish$1 = width - 1 | 0; i$1<= i_finish$1; ++i$1){
563+
for(var i$1 = len ,i_finish$1 = width - 1 | 0; i$1 <= i_finish$1; ++i$1){
564564
buffer = buffer + filter;
565565
}
566566
}
567567
buffer = uppercase ? buffer + rawbuffer.toUpperCase() : buffer + rawbuffer;
568568
if (justify === "-") {
569-
for(var i$2 = len ,i_finish$2 = width - 1 | 0; i$2<= i_finish$2; ++i$2){
569+
for(var i$2 = len ,i_finish$2 = width - 1 | 0; i$2 <= i_finish$2; ++i$2){
570570
buffer = buffer + " ";
571571
}
572572
}

jscomp/runtime/caml_hash.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function caml_hash_mix_string(h, s) {
3131
var len = s.length;
3232
var block = (len / 4 | 0) - 1 | 0;
3333
var hash = h;
34-
for(var i = 0; i<= block; ++i){
34+
for(var i = 0; i <= block; ++i){
3535
var j = (i << 2);
3636
var w = s.charCodeAt(j) | (s.charCodeAt(j + 1 | 0) << 8) | (s.charCodeAt(j + 2 | 0) << 16) | (s.charCodeAt(j + 3 | 0) << 24);
3737
hash = mix(hash, w);
@@ -101,7 +101,7 @@ function caml_hash(count, _, seed, obj) {
101101
hash = mix(hash, tag);
102102
var v = size - 1 | 0;
103103
var block = v < num ? v : num;
104-
for(var i = 0; i<= block; ++i){
104+
for(var i = 0; i <= block; ++i){
105105
Caml_queue.push(obj$1[i], queue);
106106
}
107107
}

jscomp/runtime/caml_md5.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,30 +132,30 @@ function caml_md5_string(s, start, len) {
132132
state[1] = -271733879;
133133
state[2] = -1732584194;
134134
state[3] = 271733878;
135-
for(var i = 0; i<= 15; ++i){
135+
for(var i = 0; i <= 15; ++i){
136136
md5blk[i] = 0;
137137
}
138138
var i_end = n / 64 | 0;
139-
for(var i$1 = 1; i$1<= i_end; ++i$1){
140-
for(var j = 0; j<= 15; ++j){
139+
for(var i$1 = 1; i$1 <= i_end; ++i$1){
140+
for(var j = 0; j <= 15; ++j){
141141
var k = ((i$1 << 6) - 64 | 0) + (j << 2) | 0;
142142
md5blk[j] = ((s$1.charCodeAt(k) + (s$1.charCodeAt(k + 1 | 0) << 8) | 0) + (s$1.charCodeAt(k + 2 | 0) << 16) | 0) + (s$1.charCodeAt(k + 3 | 0) << 24) | 0;
143143
}
144144
cycle(state, md5blk);
145145
}
146146
var s_tail = s$1.slice((i_end << 6));
147-
for(var kk = 0; kk<= 15; ++kk){
147+
for(var kk = 0; kk <= 15; ++kk){
148148
md5blk[kk] = 0;
149149
}
150150
var i_end$1 = s_tail.length - 1 | 0;
151-
for(var i$2 = 0; i$2<= i_end$1; ++i$2){
151+
for(var i$2 = 0; i$2 <= i_end$1; ++i$2){
152152
md5blk[i$2 / 4 | 0] = md5blk[i$2 / 4 | 0] | (s_tail.charCodeAt(i$2) << (i$2 % 4 << 3));
153153
}
154154
var i$3 = i_end$1 + 1 | 0;
155155
md5blk[i$3 / 4 | 0] = md5blk[i$3 / 4 | 0] | (128 << (i$3 % 4 << 3));
156156
if (i$3 > 55) {
157157
cycle(state, md5blk);
158-
for(var i$4 = 0; i$4<= 15; ++i$4){
158+
for(var i$4 = 0; i$4 <= 15; ++i$4){
159159
md5blk[i$4] = 0;
160160
}
161161
}

jscomp/runtime/caml_obj.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function caml_obj_dup(x) {
99
length: len,
1010
tag: x.tag | 0
1111
};
12-
for(var i = 0 ,i_finish = len - 1 | 0; i<= i_finish; ++i){
12+
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
1313
v[i] = x[i];
1414
}
1515
return v;
@@ -24,7 +24,7 @@ function caml_obj_truncate(x, new_size) {
2424
];
2525
}
2626
else if (len !== new_size) {
27-
for(var i = new_size ,i_finish = len - 1 | 0; i<= i_finish; ++i){
27+
for(var i = new_size ,i_finish = len - 1 | 0; i <= i_finish; ++i){
2828
x[i] = 0;
2929
}
3030
x.length = new_size;
@@ -45,7 +45,7 @@ function caml_lazy_make_forward(x) {
4545

4646
function caml_update_dummy(x, y) {
4747
var len = y.length;
48-
for(var i = 0 ,i_finish = len - 1 | 0; i<= i_finish; ++i){
48+
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
4949
x[i] = y[i];
5050
}
5151
x.tag = y.tag | 0;

jscomp/runtime/caml_string.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function caml_string_compare(s1, s2) {
4949

5050
function caml_fill_string(s, i, l, c) {
5151
if (l > 0) {
52-
for(var k = i ,k_finish = (l + i | 0) - 1 | 0; k<= k_finish; ++k){
52+
for(var k = i ,k_finish = (l + i | 0) - 1 | 0; k <= k_finish; ++k){
5353
s[k] = c;
5454
}
5555
return /* () */0;
@@ -63,16 +63,16 @@ function caml_blit_string(s1, i1, s2, i2, len) {
6363
if (len > 0) {
6464
var off1 = s1.length - i1 | 0;
6565
if (len <= off1) {
66-
for(var i = 0 ,i_finish = len - 1 | 0; i<= i_finish; ++i){
66+
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
6767
s2[i2 + i | 0] = s1.charCodeAt(i1 + i | 0);
6868
}
6969
return /* () */0;
7070
}
7171
else {
72-
for(var i$1 = 0 ,i_finish$1 = off1 - 1 | 0; i$1<= i_finish$1; ++i$1){
72+
for(var i$1 = 0 ,i_finish$1 = off1 - 1 | 0; i$1 <= i_finish$1; ++i$1){
7373
s2[i2 + i$1 | 0] = s1.charCodeAt(i1 + i$1 | 0);
7474
}
75-
for(var i$2 = off1 ,i_finish$2 = len - 1 | 0; i$2<= i_finish$2; ++i$2){
75+
for(var i$2 = off1 ,i_finish$2 = len - 1 | 0; i$2 <= i_finish$2; ++i$2){
7676
s2[i2 + i$2 | 0] = /* "\000" */0;
7777
}
7878
return /* () */0;
@@ -87,16 +87,16 @@ function caml_blit_bytes(s1, i1, s2, i2, len) {
8787
if (len > 0) {
8888
var off1 = s1.length - i1 | 0;
8989
if (len <= off1) {
90-
for(var i = 0 ,i_finish = len - 1 | 0; i<= i_finish; ++i){
90+
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
9191
s2[i2 + i | 0] = s1[i1 + i | 0];
9292
}
9393
return /* () */0;
9494
}
9595
else {
96-
for(var i$1 = 0 ,i_finish$1 = off1 - 1 | 0; i$1<= i_finish$1; ++i$1){
96+
for(var i$1 = 0 ,i_finish$1 = off1 - 1 | 0; i$1 <= i_finish$1; ++i$1){
9797
s2[i2 + i$1 | 0] = s1[i1 + i$1 | 0];
9898
}
99-
for(var i$2 = off1 ,i_finish$2 = len - 1 | 0; i$2<= i_finish$2; ++i$2){
99+
for(var i$2 = off1 ,i_finish$2 = len - 1 | 0; i$2 <= i_finish$2; ++i$2){
100100
s2[i2 + i$2 | 0] = /* "\000" */0;
101101
}
102102
return /* () */0;
@@ -110,7 +110,7 @@ function caml_blit_bytes(s1, i1, s2, i2, len) {
110110
function bytes_of_string(s) {
111111
var len = s.length;
112112
var res = new Array(len);
113-
for(var i = 0 ,i_finish = len - 1 | 0; i<= i_finish; ++i){
113+
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
114114
res[i] = s.charCodeAt(i);
115115
}
116116
return res;
@@ -142,7 +142,7 @@ function bytes_to_string(a) {
142142
function caml_string_of_char_array(chars) {
143143
var len = chars.length;
144144
var bytes = new Array(len);
145-
for(var i = 0 ,i_finish = len - 1 | 0; i<= i_finish; ++i){
145+
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
146146
bytes[i] = chars[i];
147147
}
148148
return bytes_to_string(bytes);

0 commit comments

Comments
 (0)