Skip to content

Commit 2b73512

Browse files
committed
Merge pull request #78 from bloomberg/better_amd
address #75, make amd and commonjs code similar style, yet shorter code
2 parents 11cff6a + bec47e4 commit 2b73512

File tree

2 files changed

+20
-54
lines changed

2 files changed

+20
-54
lines changed

jscomp/js_dump.ml

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,72 +1338,44 @@ let node_program f ( program : J.program) =
13381338
exports cxt f program.exports
13391339

13401340

1341-
let amd_program f ({modules; block = b ; exports = exp ; side_effect } : J.program)
1341+
let amd_program f
1342+
({modules; block = b ; exports = exp ; side_effect } as program : J.program)
13421343
=
1343-
let rec aux cxt f modules =
1344-
match modules with
1345-
| [] -> cxt
1346-
| [(id,_)] -> ident cxt f id
1347-
| (id,_) :: rest ->
1348-
let cxt = ident cxt f id in
1349-
P.string f L.comma;
1350-
aux cxt f rest
1351-
in
13521344
P.newline f ;
13531345
let cxt = Ext_pp_scope.empty in
1354-
let rec list ~pp_sep pp_v ppf = function
1355-
| [] -> ()
1356-
| [v] -> pp_v ppf v
1357-
| v :: vs ->
1358-
pp_v ppf v;
1359-
pp_sep ppf ();
1360-
list ~pp_sep pp_v ppf vs in
1361-
13621346
P.vgroup f 1 @@ fun _ ->
13631347
P.string f L.define;
13641348
P.string f "([";
1365-
list ~pp_sep:(fun f _ -> P.string f L.comma)
1366-
(fun f (_,s) ->
1367-
pp_string f ~utf:true ~quote:(best_string_quote s) s; ) f modules;
1349+
P.string f (Printf.sprintf "%S" L.exports);
1350+
1351+
List.iter (fun (_,s) ->
1352+
P.string f L.comma ;
1353+
P.space f;
1354+
pp_string f ~utf:true ~quote:(best_string_quote s) s;
1355+
) modules ;
13681356
P.string f "]";
13691357
P.string f L.comma;
13701358
P.newline f;
13711359
P.string f L.function_;
13721360
P.string f "(";
1373-
let cxt = aux cxt f modules in
1361+
P.string f L.exports;
1362+
1363+
let cxt =
1364+
List.fold_left (fun cxt (id,_) ->
1365+
P.string f L.comma;
1366+
P.space f ;
1367+
ident cxt f id
1368+
) cxt modules
1369+
in
13741370
P.string f ")";
13751371
P.brace_vgroup f 1 @@ (fun _ ->
13761372
let () = P.string f L.strict_directive in
13771373
let () = P.newline f in
13781374
let cxt = statement_list true cxt f b in
13791375
(* FIXME AMD : use {[ function xx ]} or {[ var x = function ..]} *)
13801376
P.newline f;
1381-
P.string f L.return;
1382-
P.space f;
1383-
P.brace_vgroup f 1 @@ fun _ ->
1384-
let rec aux cxt f (idents : Ident.t list) =
1385-
match idents with
1386-
| [] -> cxt
1387-
| [id] ->
1388-
P.string f (Ext_ident.convert id.name);
1389-
P.space f ;
1390-
P.string f L.colon;
1391-
P.space f ;
1392-
ident cxt f id
1393-
| id :: rest
1394-
->
1395-
P.string f (Ext_ident.convert id.name);
1396-
P.space f ;
1397-
P.string f L.colon;
1398-
P.space f;
1399-
let cxt = ident cxt f id in
1400-
P.string f L.comma;
1401-
P.space f ;
1402-
P.newline f ;
1403-
aux cxt f rest
1404-
1405-
in
1406-
ignore @@ aux cxt f exp);
1377+
P.force_newline f;
1378+
ignore (exports cxt f program.exports));
14071379
P.string f ")";
14081380
;;
14091381

tsconfig.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
{
2-
"compilerOptions": {
3-
"module": "commonjs"
4-
5-
6-
},
7-
82
"exclude": [
93
"node_modules",
104
"jscomp/runtime/caml_marshal.ts",

0 commit comments

Comments
 (0)