Skip to content

Commit 89c46a5

Browse files
authored
Merge pull request #1193 from bloomberg/non_node_module_resolution_cont
experimental support of es6 global module
2 parents 7b35284 + 1287fb3 commit 89c46a5

14 files changed

+333
-153
lines changed

jscomp/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ BYTE=ocamlc.opt$(EXE)
1010
OCAMLLEX=ocamllex.opt$(EXE)
1111
CAMLP4OF=camlp4of
1212
CAMLDEP=ocamldep.opt$(EXE)
13-
COMPFLAGS= -g -w +6-40-30-23 -warn-error +a-40-30-23
13+
COMPFLAGS=-g -w +6-40-30-23 -warn-error +a-40-30-23
14+
# COMPFLAGS+= -S
1415

1516

1617
.SUFFIXES: .mli .ml .cmi .cmx .mll .c .o .cmo

jscomp/all.depend

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ core/lam_group_pass.cmx : core/lam.cmx
437437
core/lam_compile_env.cmx : core/type_util.cmx ext/string_map.cmx \
438438
core/lam_module_ident.cmx core/lam.cmx core/js_stmt_make.cmx \
439439
core/js_exp_make.cmx common/js_config.cmx core/js_cmj_format.cmx \
440-
ext/ext_ident.cmx core/config_util.cmx core/lam_compile_env.cmi
440+
ext/ext_string.cmx ext/ext_ident.cmx core/config_util.cmx \
441+
core/lam_compile_env.cmi
441442
core/lam_stats_util.cmx : core/lam_stats.cmx core/lam_compile_env.cmx \
442443
core/lam.cmx ext/ident_hashtbl.cmx ext/ext_list.cmx \
443444
core/lam_stats_util.cmi

jscomp/bin/all_ounit_tests.i.ml

Lines changed: 75 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ open OUnitTypes
7575

7676
(** Most simple heuristic, just pick the first test. *)
7777
let simple state =
78-
(* 130 *) List.hd state.tests_planned
78+
(* 132 *) List.hd state.tests_planned
7979

8080
end
8181
module OUnitUtils
@@ -98,22 +98,22 @@ let is_success =
9898
let is_failure =
9999
function
100100
| RFailure _ -> (* 0 *) true
101-
| RSuccess _ | RError _ | RSkip _ | RTodo _ -> (* 260 *) false
101+
| RSuccess _ | RError _ | RSkip _ | RTodo _ -> (* 264 *) false
102102

103103
let is_error =
104104
function
105105
| RError _ -> (* 0 *) true
106-
| RSuccess _ | RFailure _ | RSkip _ | RTodo _ -> (* 260 *) false
106+
| RSuccess _ | RFailure _ | RSkip _ | RTodo _ -> (* 264 *) false
107107

108108
let is_skip =
109109
function
110110
| RSkip _ -> (* 0 *) true
111-
| RSuccess _ | RFailure _ | RError _ | RTodo _ -> (* 260 *) false
111+
| RSuccess _ | RFailure _ | RError _ | RTodo _ -> (* 264 *) false
112112

113113
let is_todo =
114114
function
115115
| RTodo _ -> (* 0 *) true
116-
| RSuccess _ | RFailure _ | RError _ | RSkip _ -> (* 260 *) false
116+
| RSuccess _ | RFailure _ | RError _ | RSkip _ -> (* 264 *) false
117117

118118
let result_flavour =
119119
function
@@ -145,7 +145,7 @@ let rec was_successful =
145145
| [] -> (* 3 *) true
146146
| RSuccess _::t
147147
| RSkip _::t ->
148-
(* 390 *) was_successful t
148+
(* 396 *) was_successful t
149149

150150
| RFailure _::_
151151
| RError _::_
@@ -155,22 +155,22 @@ let rec was_successful =
155155
let string_of_node =
156156
function
157157
| ListItem n ->
158-
(* 520 *) string_of_int n
158+
(* 528 *) string_of_int n
159159
| Label s ->
160-
(* 780 *) s
160+
(* 792 *) s
161161

162162
(* Return the number of available tests *)
163163
let rec test_case_count =
164164
function
165-
| TestCase _ -> (* 130 *) 1
166-
| TestLabel (_, t) -> (* 151 *) test_case_count t
165+
| TestCase _ -> (* 132 *) 1
166+
| TestLabel (_, t) -> (* 153 *) test_case_count t
167167
| TestList l ->
168168
(* 21 *) List.fold_left
169-
(fun c t -> (* 150 *) c + test_case_count t)
169+
(fun c t -> (* 152 *) c + test_case_count t)
170170
0 l
171171

172172
let string_of_path path =
173-
(* 260 *) String.concat ":" (List.rev_map string_of_node path)
173+
(* 264 *) String.concat ":" (List.rev_map string_of_node path)
174174

175175
let buff_format_printf f =
176176
(* 0 *) let buff = Buffer.create 13 in
@@ -194,12 +194,12 @@ let mapi f l =
194194

195195
let fold_lefti f accu l =
196196
(* 21 *) let rec rfold_lefti cnt accup l =
197-
(* 171 *) match l with
197+
(* 173 *) match l with
198198
| [] ->
199199
(* 21 *) accup
200200

201201
| h::t ->
202-
(* 150 *) rfold_lefti (cnt + 1) (f accup h cnt) t
202+
(* 152 *) rfold_lefti (cnt + 1) (f accup h cnt) t
203203
in
204204
rfold_lefti 0 accu l
205205

@@ -217,7 +217,7 @@ open OUnitUtils
217217
type event_type = GlobalEvent of global_event | TestEvent of test_event
218218

219219
let format_event verbose event_type =
220-
(* 782 *) match event_type with
220+
(* 794 *) match event_type with
221221
| GlobalEvent e ->
222222
(* 2 *) begin
223223
match e with
@@ -276,31 +276,31 @@ let format_event verbose event_type =
276276
end
277277

278278
| TestEvent e ->
279-
(* 780 *) begin
279+
(* 792 *) begin
280280
let string_of_result =
281281
if verbose then
282-
(* 390 *) function
283-
| RSuccess _ -> (* 130 *) "ok\n"
282+
(* 396 *) function
283+
| RSuccess _ -> (* 132 *) "ok\n"
284284
| RFailure (_, _) -> (* 0 *) "FAIL\n"
285285
| RError (_, _) -> (* 0 *) "ERROR\n"
286286
| RSkip (_, _) -> (* 0 *) "SKIP\n"
287287
| RTodo (_, _) -> (* 0 *) "TODO\n"
288288
else
289-
(* 390 *) function
290-
| RSuccess _ -> (* 130 *) "."
289+
(* 396 *) function
290+
| RSuccess _ -> (* 132 *) "."
291291
| RFailure (_, _) -> (* 0 *) "F"
292292
| RError (_, _) -> (* 0 *) "E"
293293
| RSkip (_, _) -> (* 0 *) "S"
294294
| RTodo (_, _) -> (* 0 *) "T"
295295
in
296296
if verbose then
297-
(* 390 *) match e with
297+
(* 396 *) match e with
298298
| EStart p ->
299-
(* 130 *) Printf.sprintf "%s start\n" (string_of_path p)
299+
(* 132 *) Printf.sprintf "%s start\n" (string_of_path p)
300300
| EEnd p ->
301-
(* 130 *) Printf.sprintf "%s end\n" (string_of_path p)
301+
(* 132 *) Printf.sprintf "%s end\n" (string_of_path p)
302302
| EResult result ->
303-
(* 130 *) string_of_result result
303+
(* 132 *) string_of_result result
304304
| ELog (lvl, str) ->
305305
(* 0 *) let prefix =
306306
match lvl with
@@ -312,21 +312,21 @@ let format_event verbose event_type =
312312
| ELogRaw str ->
313313
(* 0 *) str
314314
else
315-
(* 390 *) match e with
316-
| EStart _ | EEnd _ | ELog _ | ELogRaw _ -> (* 260 *) ""
317-
| EResult result -> (* 130 *) string_of_result result
315+
(* 396 *) match e with
316+
| EStart _ | EEnd _ | ELog _ | ELogRaw _ -> (* 264 *) ""
317+
| EResult result -> (* 132 *) string_of_result result
318318
end
319319

320320
let file_logger fn =
321321
(* 1 *) let chn = open_out fn in
322322
(fun ev ->
323-
(* 391 *) output_string chn (format_event true ev);
323+
(* 397 *) output_string chn (format_event true ev);
324324
flush chn),
325325
(fun () -> (* 1 *) close_out chn)
326326

327327
let std_logger verbose =
328328
(* 1 *) (fun ev ->
329-
(* 391 *) print_string (format_event verbose ev);
329+
(* 397 *) print_string (format_event verbose ev);
330330
flush stdout),
331331
(fun () -> (* 1 *) ())
332332

@@ -343,7 +343,7 @@ let create output_file_opt verbose (log,close) =
343343
(* 0 *) null_logger
344344
in
345345
(fun ev ->
346-
(* 391 *) std_log ev; file_log ev; log ev),
346+
(* 397 *) std_log ev; file_log ev; log ev),
347347
(fun () ->
348348
(* 1 *) std_close (); file_close (); close ())
349349

@@ -711,7 +711,7 @@ let assert_string str =
711711
(* 0 *) if not (str = "") then (* 0 *) assert_failure str
712712

713713
let assert_equal ?(cmp = ( = )) ?printer ?pp_diff ?msg expected actual =
714-
(* 2001486 *) let get_error_string () =
714+
(* 2001488 *) let get_error_string () =
715715
(* 0 *) let res =
716716
buff_format_printf
717717
(fun fmt ->
@@ -951,7 +951,7 @@ let (@?) = assert_bool
951951

952952
(* Some shorthands which allows easy test construction *)
953953
let (>:) s t = (* 0 *) TestLabel(s, t) (* infix *)
954-
let (>::) s f = (* 130 *) TestLabel(s, TestCase(f)) (* infix *)
954+
let (>::) s f = (* 132 *) TestLabel(s, TestCase(f)) (* infix *)
955955
let (>:::) s l = (* 21 *) TestLabel(s, TestList(l)) (* infix *)
956956

957957
(* Utility function to manipulate test *)
@@ -1087,7 +1087,7 @@ let maybe_backtrace = ""
10871087
(* Run all tests, report starts, errors, failures, and return the results *)
10881088
let perform_test report test =
10891089
(* 1 *) let run_test_case f path =
1090-
(* 130 *) try
1090+
(* 132 *) try
10911091
f ();
10921092
RSuccess path
10931093
with
@@ -1106,22 +1106,22 @@ let perform_test report test =
11061106
let rec flatten_test path acc =
11071107
function
11081108
| TestCase(f) ->
1109-
(* 130 *) (path, f) :: acc
1109+
(* 132 *) (path, f) :: acc
11101110

11111111
| TestList (tests) ->
11121112
(* 21 *) fold_lefti
11131113
(fun acc t cnt ->
1114-
(* 150 *) flatten_test
1114+
(* 152 *) flatten_test
11151115
((ListItem cnt)::path)
11161116
acc t)
11171117
acc tests
11181118

11191119
| TestLabel (label, t) ->
1120-
(* 151 *) flatten_test ((Label label)::path) acc t
1120+
(* 153 *) flatten_test ((Label label)::path) acc t
11211121
in
11221122
let test_cases = List.rev (flatten_test [] [] test) in
11231123
let runner (path, f) =
1124-
(* 130 *) let result =
1124+
(* 132 *) let result =
11251125
report (EStart path);
11261126
run_test_case f path
11271127
in
@@ -1130,18 +1130,18 @@ let perform_test report test =
11301130
result
11311131
in
11321132
let rec iter state =
1133-
(* 131 *) match state.tests_planned with
1133+
(* 133 *) match state.tests_planned with
11341134
| [] ->
11351135
(* 1 *) state.results
11361136
| _ ->
1137-
(* 130 *) let (path, f) = !global_chooser state in
1137+
(* 132 *) let (path, f) = !global_chooser state in
11381138
let result = runner (path, f) in
11391139
iter
11401140
{
11411141
results = result :: state.results;
11421142
tests_planned =
11431143
List.filter
1144-
(fun (path', _) -> (* 8515 *) path <> path') state.tests_planned
1144+
(fun (path', _) -> (* 8778 *) path <> path') state.tests_planned
11451145
}
11461146
in
11471147
iter {results = []; tests_planned = test_cases}
@@ -1171,7 +1171,7 @@ let run_test_tt ?verbose test =
11711171
time_fun
11721172
perform_test
11731173
(fun ev ->
1174-
(* 390 *) log (OUnitLogger.TestEvent ev))
1174+
(* 396 *) log (OUnitLogger.TestEvent ev))
11751175
test
11761176
in
11771177

@@ -1294,6 +1294,12 @@ val map2i : (int -> 'a -> 'b -> 'c ) -> 'a array -> 'b array -> 'c array
12941294

12951295
val to_list_map : ('a -> 'b option) -> 'a array -> 'b list
12961296

1297+
val to_list_map_acc :
1298+
('a -> 'b option) ->
1299+
'a array ->
1300+
'b list ->
1301+
'b list
1302+
12971303
val of_list_map : ('a -> 'b) -> 'a list -> 'b array
12981304

12991305
val rfind_with_index : 'a array -> ('a -> 'b -> bool) -> 'b -> int
@@ -1414,15 +1420,20 @@ let map2i f a b =
14141420
else
14151421
(* 0 *) Array.mapi (fun i a -> (* 0 *) f i a ( Array.unsafe_get b i )) a
14161422

1417-
let to_list_map f a =
1418-
(* 0 *) let rec tolist i res =
1419-
(* 0 *) if i < 0 then (* 0 *) res else
1420-
(* 0 *) let v = Array.unsafe_get a i in
1421-
tolist (i - 1)
1423+
1424+
let rec tolist_aux a f i res =
1425+
(* 14 *) if i < 0 then (* 2 *) res else
1426+
(* 12 *) let v = Array.unsafe_get a i in
1427+
tolist_aux a f (i - 1)
14221428
(match f v with
1423-
| Some v -> (* 0 *) v :: res
1424-
| None -> (* 0 *) res) in
1425-
tolist (Array.length a - 1) []
1429+
| Some v -> (* 6 *) v :: res
1430+
| None -> (* 6 *) res)
1431+
1432+
let to_list_map f a =
1433+
(* 0 *) tolist_aux a f (Array.length a - 1) []
1434+
1435+
let to_list_map_acc f a acc =
1436+
(* 2 *) tolist_aux a f (Array.length a - 1) acc
14261437

14271438

14281439
(* TODO: What would happen if [f] raise, memory leak? *)
@@ -2262,7 +2273,19 @@ let suites =
22622273
(* 1 *) Ext_array.of_list_map succ [] =~ [||];
22632274
Ext_array.of_list_map succ [1] =~ [|2|];
22642275
Ext_array.of_list_map succ [1;2;3] =~ [|2;3;4|];
2265-
end
2276+
end;
2277+
__LOC__ >:: begin fun _ ->
2278+
(* 1 *) Ext_array.to_list_map_acc
2279+
(fun x -> (* 6 *) if x mod 2 = 0 then (* 3 *) Some x else (* 3 *) None )
2280+
[|1;2;3;4;5;6|] [1;2;3]
2281+
=~ [2;4;6;1;2;3]
2282+
end;
2283+
__LOC__ >:: begin fun _ ->
2284+
(* 1 *) Ext_array.to_list_map_acc
2285+
(fun x -> (* 6 *) if x mod 2 = 0 then (* 3 *) Some x else (* 3 *) None )
2286+
[|1;2;3;4;5;6|] []
2287+
=~ [2;4;6]
2288+
end;
22662289
]
22672290
end
22682291
module Ounit_tests_util
@@ -3539,6 +3562,7 @@ val commonjs : string
35393562
val amdjs : string
35403563
val goog : string
35413564
val es6 : string
3565+
val es6_global : string
35423566
val unused_attribute : string
35433567
end = struct
35443568
#1 "literals.ml"
@@ -3639,7 +3663,7 @@ let commonjs = "commonjs"
36393663
let amdjs = "amdjs"
36403664
let goog = "goog"
36413665
let es6 = "es6"
3642-
3666+
let es6_global = "es6-global"
36433667
let unused_attribute = "Unused attribute "
36443668
end
36453669
module Ounit_cmd_util : sig

0 commit comments

Comments
 (0)