Skip to content

Commit 9bb4a25

Browse files
committed
better bs.raw printing
1 parent 9cc96d2 commit 9bb4a25

25 files changed

+108
-69
lines changed

jscomp/all.depend

+3-3
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,9 @@ core/js_dump.cmx : core/js_stmt_make.cmx core/js_runtime_modules.cmx \
671671
core/js_op_util.cmx core/js_op.cmx core/js_number.cmx core/js_fun_env.cmx \
672672
core/js_fold_basic.cmx core/js_exp_make.cmx core/js_dump_string.cmx \
673673
core/js_dump_property.cmx core/js_dump_lit.cmx common/js_config.cmx \
674-
core/js_closure.cmx core/j.cmx ext/ident_set.cmx ext/ext_pp_scope.cmx \
675-
ext/ext_pp.cmx ext/ext_list.cmx ext/ext_ident.cmx ext/ext_array.cmx \
676-
core/js_dump.cmi
674+
core/js_closure.cmx core/j.cmx ext/ident_set.cmx ext/ext_string.cmx \
675+
ext/ext_pp_scope.cmx ext/ext_pp.cmx ext/ext_list.cmx ext/ext_ident.cmx \
676+
ext/ext_array.cmx core/js_dump.cmi
677677
core/js_name_of_module_id.cmx : core/lam_compile_env.cmx \
678678
core/js_packages_state.cmx core/js_packages_info.cmx \
679679
core/js_name_of_module_id.cmi

jscomp/bin/all_ounit_tests.ml

+11-8
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,10 @@ val for_all_from:
19311931
(char -> bool) ->
19321932
bool
19331933

1934-
val for_all : (char -> bool) -> string -> bool
1934+
val for_all :
1935+
string ->
1936+
(char -> bool) ->
1937+
bool
19351938

19361939
val is_empty : string -> bool
19371940

@@ -2177,7 +2180,7 @@ let for_all_from s start p =
21772180
else unsafe_for_all_range s ~start ~finish:(len - 1) p
21782181

21792182

2180-
let for_all (p : char -> bool) s =
2183+
let for_all s (p : char -> bool) =
21812184
unsafe_for_all_range s ~start:0 ~finish:(String.length s - 1) p
21822185

21832186
let is_empty s = String.length s = 0
@@ -13890,12 +13893,12 @@ let suites =
1389013893
Ext_string.(starts_with_and_number "js_fn_run_04" ~offset:6 "run_" = 3) =~ false
1389113894
end; *)
1389213895
__LOC__ >:: begin fun _ ->
13893-
Ext_string.for_all (function '_' -> true | _ -> false)
13894-
"____" =~ true;
13895-
Ext_string.for_all (function '_' -> true | _ -> false)
13896-
"___-" =~ false;
13897-
Ext_string.for_all (function '_' -> true | _ -> false)
13898-
"" =~ true
13896+
Ext_string.for_all "____" (function '_' -> true | _ -> false)
13897+
=~ true;
13898+
Ext_string.for_all "___-" (function '_' -> true | _ -> false)
13899+
=~ false;
13900+
Ext_string.for_all "" (function '_' -> true | _ -> false)
13901+
=~ true
1389913902
end;
1390013903
__LOC__ >:: begin fun _ ->
1390113904
Ext_string.tail_from "ghsogh" 1 =~ "hsogh";

jscomp/core/js_dump.ml

+13-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ let rec iter_lst cxt (f : P.t) ls element inter =
9595
inter f;
9696
iter_lst acxt f r element inter
9797

98-
98+
let raw_snippet_exp_simple_enough (s : string) =
99+
Ext_string.for_all s (fun c ->
100+
match c with
101+
| 'a' .. 'z' | 'A' .. 'Z' | '_' -> true
102+
| _ -> false
103+
)
99104
(* Parentheses are required when the expression
100105
starts syntactically with "{" or "function"
101106
TODO: be more conservative, since Google Closure will handle
@@ -618,9 +623,13 @@ and expression_desc cxt (level:int) f x : cxt =
618623
| Raw_js_code (s,info) ->
619624
(match info with
620625
| Exp ->
621-
P.string f L.lparen;
622-
P.string f s ;
623-
P.string f L.rparen;
626+
if raw_snippet_exp_simple_enough s then
627+
P.string f s
628+
else begin
629+
P.string f L.lparen;
630+
P.string f s ;
631+
P.string f L.rparen;
632+
end;
624633
cxt
625634
| Stmt ->
626635
P.newline f ;

jscomp/ext/ext_string.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ let for_all_from s start p =
162162
else unsafe_for_all_range s ~start ~finish:(len - 1) p
163163

164164

165-
let for_all (p : char -> bool) s =
165+
let for_all s (p : char -> bool) =
166166
unsafe_for_all_range s ~start:0 ~finish:(String.length s - 1) p
167167

168168
let is_empty s = String.length s = 0

jscomp/ext/ext_string.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ val for_all_from:
8383
(char -> bool) ->
8484
bool
8585

86-
val for_all : (char -> bool) -> string -> bool
86+
val for_all :
87+
string ->
88+
(char -> bool) ->
89+
bool
8790

8891
val is_empty : string -> bool
8992

jscomp/ounit_tests/ounit_string_tests.ml

+6-6
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ let suites =
115115
Ext_string.(starts_with_and_number "js_fn_run_04" ~offset:6 "run_" = 3) =~ false
116116
end; *)
117117
__LOC__ >:: begin fun _ ->
118-
Ext_string.for_all (function '_' -> true | _ -> false)
119-
"____" =~ true;
120-
Ext_string.for_all (function '_' -> true | _ -> false)
121-
"___-" =~ false;
122-
Ext_string.for_all (function '_' -> true | _ -> false)
123-
"" =~ true
118+
Ext_string.for_all "____" (function '_' -> true | _ -> false)
119+
=~ true;
120+
Ext_string.for_all "___-" (function '_' -> true | _ -> false)
121+
=~ false;
122+
Ext_string.for_all "" (function '_' -> true | _ -> false)
123+
=~ true
124124
end;
125125
__LOC__ >:: begin fun _ ->
126126
Ext_string.tail_from "ghsogh" 1 =~ "hsogh";

jscomp/test/app_root_finder.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function find_package_json(_dir) {
2323
};
2424
}
2525

26-
var match = typeof (__dirname) === "undefined" ? undefined : (__dirname);
26+
var match = typeof __dirname === "undefined" ? undefined : __dirname;
2727

2828
if (match !== undefined) {
2929
console.log(find_package_json(match));

jscomp/test/flow_parser_reg_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13628,7 +13628,7 @@ var array = (function (x) {return x;});
1362813628

1362913629
var number$1 = (function (x) {return x;});
1363013630

13631-
var $$null = (null);
13631+
var $$null = null;
1363213632

1363313633
function regexp$1(loc, pattern, flags) {
1363413634
try {
@@ -16072,7 +16072,7 @@ function eq(loc, x, y) {
1607216072
return /* () */0;
1607316073
}
1607416074

16075-
var match = typeof (__dirname) === "undefined" ? undefined : (__dirname);
16075+
var match = typeof __dirname === "undefined" ? undefined : __dirname;
1607616076

1607716077
if (match !== undefined) {
1607816078
var f = Path.join(match, "flow_parser_sample.js");

jscomp/test/fs_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ function eq(loc, param) {
2828
return /* () */0;
2929
}
3030

31-
var match = typeof (__filename) === "undefined" ? undefined : (__filename);
31+
var match = typeof __filename === "undefined" ? undefined : __filename;
3232

3333
var current_file = match !== undefined ? match : "<Not Node JS>";
3434

35-
var match$1 = typeof (__dirname) === "undefined" ? undefined : (__dirname);
35+
var match$1 = typeof __dirname === "undefined" ? undefined : __dirname;
3636

3737
var current_dir_name = match$1 !== undefined ? match$1 : "<Not Node Js>";
3838

@@ -42,7 +42,7 @@ Fs.readdirSync(current_dir_name);
4242

4343
var pathobj = Path.parse(current_dir_name);
4444

45-
var match$2 = typeof (module) === "undefined" ? undefined : (module);
45+
var match$2 = typeof module === "undefined" ? undefined : module;
4646

4747
if (match$2 !== undefined) {
4848
console.log(/* tuple */[

jscomp/test/installation_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function eq(loc, x, y) {
2929
return /* () */0;
3030
}
3131

32-
var match = typeof (__dirname) === "undefined" ? undefined : (__dirname);
32+
var match = typeof __dirname === "undefined" ? undefined : __dirname;
3333

3434
if (match !== undefined) {
3535
var root = App_root_finder.find_package_json(match);

jscomp/test/js_bool_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var suites_001 = /* :: */[
5757
(function (param) {
5858
return /* Eq */Block.__(0, [
5959
true,
60-
true === (true)
60+
true === true
6161
]);
6262
})
6363
],

jscomp/test/js_nullable_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ eq("File \"js_nullable_test.ml\", line 26, characters 7-14", false, false);
4343

4444
eq("File \"js_nullable_test.ml\", line 28, characters 7-14", (f(1, 2) == null), false);
4545

46-
eq("File \"js_nullable_test.ml\", line 30, characters 6-13", ((null) == null), true);
46+
eq("File \"js_nullable_test.ml\", line 30, characters 6-13", (null == null), true);
4747

4848
eq("File \"js_nullable_test.ml\", line 34, characters 3-10", false, false);
4949

jscomp/test/node_fs_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var Fs = require("fs");
44

5-
var match = typeof (__filename) === "undefined" ? undefined : (__filename);
5+
var match = typeof __filename === "undefined" ? undefined : __filename;
66

77
if (match !== undefined) {
88
console.log(Fs.readFileSync(match, "utf8"));

jscomp/test/test_require.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

33

4-
var match = typeof (require) === "undefined" ? undefined : (require);
4+
var match = typeof require === "undefined" ? undefined : require;
55

66
if (match !== undefined) {
77
console.log(match.resolve("./test_require.js"));
8-
var match$1 = typeof (module) === "undefined" ? undefined : (module);
8+
var match$1 = typeof module === "undefined" ? undefined : module;
99
var match$2 = match.main;
1010
if (match$1 !== undefined) {
1111
if (match$2 !== undefined && match$1 === match$2) {

jscomp/test/test_zero_nullable.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,17 @@ var Test_null_def = /* module */[
281281

282282
eq("File \"test_zero_nullable.ml\", line 227, characters 7-14", f1$2(0), 1);
283283

284-
eq("File \"test_zero_nullable.ml\", line 228, characters 7-14", f1$2((null)), 3);
284+
eq("File \"test_zero_nullable.ml\", line 228, characters 7-14", f1$2(null), 3);
285285

286-
eq("File \"test_zero_nullable.ml\", line 229, characters 7-14", f1$2((undefined)), 3);
286+
eq("File \"test_zero_nullable.ml\", line 229, characters 7-14", f1$2(undefined), 3);
287287

288288
eq("File \"test_zero_nullable.ml\", line 231, characters 7-14", f1(0), 1);
289289

290-
eq("File \"test_zero_nullable.ml\", line 232, characters 7-14", f1((null)), 3);
290+
eq("File \"test_zero_nullable.ml\", line 232, characters 7-14", f1(null), 3);
291291

292292
eq("File \"test_zero_nullable.ml\", line 234, characters 7-14", f1$1(0), 1);
293293

294-
eq("File \"test_zero_nullable.ml\", line 235, characters 7-14", f1$1((undefined)), 3);
294+
eq("File \"test_zero_nullable.ml\", line 235, characters 7-14", f1$1(undefined), 3);
295295

296296
Mt.from_pair_suites("test_zero_nullable.ml", suites[0]);
297297

jscomp/test/undef_regression2_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ function ok(loc, x) {
3939
return /* () */0;
4040
}
4141

42-
var match = typeof (___undefined_value) === "undefined" ? undefined : (___undefined_value);
42+
var match = typeof ___undefined_value === "undefined" ? undefined : ___undefined_value;
4343

4444
var a = match !== undefined ? 2 : 1;
4545

4646
function test(param) {
47-
var match = typeof (__DEV__) === "undefined" ? undefined : (__DEV__);
47+
var match = typeof __DEV__ === "undefined" ? undefined : __DEV__;
4848
if (match !== undefined) {
4949
console.log("dev mode");
5050
return /* () */0;
@@ -55,7 +55,7 @@ function test(param) {
5555
}
5656

5757
function test2(param) {
58-
var match = typeof (__filename) === "undefined" ? undefined : (__filename);
58+
var match = typeof __filename === "undefined" ? undefined : __filename;
5959
if (match !== undefined) {
6060
console.log(match);
6161
return /* () */0;
@@ -66,7 +66,7 @@ function test2(param) {
6666
}
6767

6868
function test3(param) {
69-
if (Js_primitive.undefined_to_opt(typeof (__DEV__) === "undefined" ? undefined : (__DEV__)) === undefined) {
69+
if (Js_primitive.undefined_to_opt(typeof __DEV__ === "undefined" ? undefined : __DEV__) === undefined) {
7070
console.log("production mode");
7171
return /* () */0;
7272
} else {

jscomp/xwatcher/xwatcher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var events = Xwatcher_util.makeEventObj(/* () */0);
1515

1616
var watchers = /* array */[];
1717

18-
var source_dirname = Js_option.getExn(Js_primitive.undefined_to_opt(typeof (__dirname) === "undefined" ? undefined : (__dirname)));
18+
var source_dirname = Js_option.getExn(Js_primitive.undefined_to_opt(typeof __dirname === "undefined" ? undefined : __dirname));
1919

2020
var bsb = Path.join(source_dirname, "bsb.exe");
2121

jscomp/xwatcher/xwatcher_current.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as Node_process from "../../lib/es6/node_process.js";
1010
import * as Xwatcher_util from "./xwatcher_util.js";
1111
import * as Child_process from "child_process";
1212

13-
Js_option.getExn(Js_primitive.undefined_to_opt(typeof (__dirname) === "undefined" ? undefined : (__dirname)));
13+
Js_option.getExn(Js_primitive.undefined_to_opt(typeof __dirname === "undefined" ? undefined : __dirname));
1414

1515
var cwd = Process.cwd();
1616

lib/bsb.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,10 @@ val for_all_from:
830830
(char -> bool) ->
831831
bool
832832

833-
val for_all : (char -> bool) -> string -> bool
833+
val for_all :
834+
string ->
835+
(char -> bool) ->
836+
bool
834837

835838
val is_empty : string -> bool
836839

@@ -1076,7 +1079,7 @@ let for_all_from s start p =
10761079
else unsafe_for_all_range s ~start ~finish:(len - 1) p
10771080

10781081

1079-
let for_all (p : char -> bool) s =
1082+
let for_all s (p : char -> bool) =
10801083
unsafe_for_all_range s ~start:0 ~finish:(String.length s - 1) p
10811084

10821085
let is_empty s = String.length s = 0

lib/bsb_helper.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,10 @@ val for_all_from:
867867
(char -> bool) ->
868868
bool
869869

870-
val for_all : (char -> bool) -> string -> bool
870+
val for_all :
871+
string ->
872+
(char -> bool) ->
873+
bool
871874

872875
val is_empty : string -> bool
873876

@@ -1113,7 +1116,7 @@ let for_all_from s start p =
11131116
else unsafe_for_all_range s ~start ~finish:(len - 1) p
11141117

11151118

1116-
let for_all (p : char -> bool) s =
1119+
let for_all s (p : char -> bool) =
11171120
unsafe_for_all_range s ~start:0 ~finish:(String.length s - 1) p
11181121

11191122
let is_empty s = String.length s = 0

lib/bsdep.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -23259,7 +23259,10 @@ val for_all_from:
2325923259
(char -> bool) ->
2326023260
bool
2326123261

23262-
val for_all : (char -> bool) -> string -> bool
23262+
val for_all :
23263+
string ->
23264+
(char -> bool) ->
23265+
bool
2326323266

2326423267
val is_empty : string -> bool
2326523268

@@ -23505,7 +23508,7 @@ let for_all_from s start p =
2350523508
else unsafe_for_all_range s ~start ~finish:(len - 1) p
2350623509

2350723510

23508-
let for_all (p : char -> bool) s =
23511+
let for_all s (p : char -> bool) =
2350923512
unsafe_for_all_range s ~start:0 ~finish:(String.length s - 1) p
2351023513

2351123514
let is_empty s = String.length s = 0

lib/bsppx.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -5197,7 +5197,10 @@ val for_all_from:
51975197
(char -> bool) ->
51985198
bool
51995199

5200-
val for_all : (char -> bool) -> string -> bool
5200+
val for_all :
5201+
string ->
5202+
(char -> bool) ->
5203+
bool
52015204

52025205
val is_empty : string -> bool
52035206

@@ -5443,7 +5446,7 @@ let for_all_from s start p =
54435446
else unsafe_for_all_range s ~start ~finish:(len - 1) p
54445447

54455448

5446-
let for_all (p : char -> bool) s =
5449+
let for_all s (p : char -> bool) =
54475450
unsafe_for_all_range s ~start:0 ~finish:(String.length s - 1) p
54485451

54495452
let is_empty s = String.length s = 0

lib/js/caml_obj.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ function caml_equal(_a, _b) {
308308
return true;
309309
} else {
310310
var a_type = typeof a;
311-
if (a_type === "string" || a_type === "number" || a_type === "boolean" || a_type === "undefined" || a === (null)) {
311+
if (a_type === "string" || a_type === "number" || a_type === "boolean" || a_type === "undefined" || a === null) {
312312
return false;
313313
} else {
314314
var b_type = typeof b;
@@ -317,7 +317,7 @@ function caml_equal(_a, _b) {
317317
Caml_builtin_exceptions.invalid_argument,
318318
"equal: functional value"
319319
];
320-
} else if (b_type === "number" || b_type === "undefined" || b === (null)) {
320+
} else if (b_type === "number" || b_type === "undefined" || b === null) {
321321
return false;
322322
} else {
323323
var tag_a = a.tag | 0;

0 commit comments

Comments
 (0)