|
23 | 23 | module E = Js_exp_make |
24 | 24 | module S = Js_stmt_make |
25 | 25 |
|
26 | | -type module_id = Lam_module_ident.t |
| 26 | + |
27 | 27 |
|
28 | 28 | open Js_output.Ops |
29 | 29 |
|
30 | | -let string_of_module_id (x : module_id) : string = |
| 30 | +let string_of_module_id (x : Lam_module_ident.t) : string = |
31 | 31 | match x.kind with |
32 | 32 | | Runtime |
33 | 33 | | Ml -> |
34 | 34 | let id = x.id in |
35 | 35 | let file = Printf.sprintf "%s.js" id.name in |
36 | 36 | begin match Js_config.get_env () with |
37 | | - | Browser |
38 | | - (* In browser *) |
39 | | - -> |
40 | | - let target = String.uncapitalize file in |
41 | | - if String_set.mem target Js_config.runtime_set then |
42 | | - "./runtime/" ^ Filename.chop_extension target |
43 | | - else |
44 | | - "./stdlib/" ^ Filename.chop_extension target |
45 | | - | NodeJS -> |
46 | | - if Ext_string.starts_with id.name "Caml_" then |
47 | | - let path = |
48 | | - (* For the runtime, only [JS] files are needed, and |
49 | | - unlike the stdlib, [osc] have some pre-built knowledge |
50 | | - about where it is, since in general, [runtime] |
51 | | - is *transparent* to the user |
52 | | - *) |
53 | | - match Sys.getenv "OCAML_JS_RUNTIME_PATH" with |
54 | | - | exception Not_found -> |
55 | | - Filename.concat |
56 | | - (Filename.dirname (Filename.dirname Sys.executable_name)) |
57 | | - "runtime" |
58 | | - | f -> f in |
59 | | - Ext_filename.node_relative_path !Location.input_name |
60 | | - (Filename.concat path (String.uncapitalize id.name)) |
61 | | - else |
62 | | - begin match Config_util.find file with |
63 | | - (* for some primitive files, no cmj support *) |
64 | | - | exception Not_found -> |
65 | | - Ext_log.warn __LOC__ "@[%s not found in search path - while compiling %s @] " |
66 | | - file !Location.input_name ; |
67 | | - Printf.sprintf "%s" |
68 | | - (String.uncapitalize id.name) |
69 | | - (* maybe from third party library*) |
70 | | - (* Check: be consistent when generating js files |
71 | | - A.ml -> a.js |
72 | | - a.ml -> a.js |
73 | | - check generated [js] file if it's capital or not |
74 | | - Actually, we can not tell its original name just from [id], |
75 | | - so we just always general litte_case.js |
76 | | - *) |
77 | | - | path -> |
78 | | - Ext_filename.node_relative_path !Location.input_name path |
79 | | - |
80 | | - end |
| 37 | + | Goog _ -> |
| 38 | + (*TODO: we should store |
| 39 | + the goog module name in the [cmj] file |
| 40 | + *) |
| 41 | + let base = String.uncapitalize id.name in |
| 42 | + begin match Lam_compile_env.get_goog_package_name x with |
| 43 | + | None |
| 44 | + | Some "" -> |
| 45 | + base |
| 46 | + | Some v -> v ^ "." ^ base |
| 47 | + end |
| 48 | + | Browser |
| 49 | + (* In browser *) |
| 50 | + -> |
| 51 | + let target = String.uncapitalize file in |
| 52 | + if String_set.mem target Js_config.runtime_set then |
| 53 | + "./runtime/" ^ Filename.chop_extension target |
| 54 | + else |
| 55 | + "./stdlib/" ^ Filename.chop_extension target |
| 56 | + | NodeJS -> |
| 57 | + if Ext_string.starts_with id.name "Caml_" then |
| 58 | + let path = |
| 59 | + (* For the runtime, only [JS] files are needed, and |
| 60 | + unlike the stdlib, [osc] have some pre-built knowledge |
| 61 | + about where it is, since in general, [runtime] |
| 62 | + is *transparent* to the user |
| 63 | + *) |
| 64 | + match Sys.getenv "OCAML_JS_RUNTIME_PATH" with |
| 65 | + | exception Not_found -> |
| 66 | + Filename.concat |
| 67 | + (Filename.dirname (Filename.dirname Sys.executable_name)) |
| 68 | + "runtime" |
| 69 | + | f -> f in |
| 70 | + Ext_filename.node_relative_path !Location.input_name |
| 71 | + (Filename.concat path (String.uncapitalize id.name)) |
| 72 | + else |
| 73 | + begin match Config_util.find file with |
| 74 | + (* for some primitive files, no cmj support *) |
| 75 | + | exception Not_found -> |
| 76 | + Ext_log.warn __LOC__ "@[%s not found in search path - while compiling %s @] " |
| 77 | + file !Location.input_name ; |
| 78 | + Printf.sprintf "%s" |
| 79 | + (String.uncapitalize id.name) |
| 80 | + (* maybe from third party library*) |
| 81 | + (* Check: be consistent when generating js files |
| 82 | + A.ml -> a.js |
| 83 | + a.ml -> a.js |
| 84 | + check generated [js] file if it's capital or not |
| 85 | + Actually, we can not tell its original name just from [id], |
| 86 | + so we just always general litte_case.js |
| 87 | + *) |
| 88 | + | path -> |
| 89 | + Ext_filename.node_relative_path !Location.input_name path |
| 90 | + |
| 91 | + end |
81 | 92 | end |
82 | 93 | | External name -> name |
83 | 94 |
|
|
0 commit comments