Skip to content

Commit

Permalink
call global import with path of module
Browse files Browse the repository at this point in the history
  • Loading branch information
mununki committed Oct 5, 2022
1 parent 3c3aced commit 326977a
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 37 deletions.
16 changes: 10 additions & 6 deletions jscomp/core/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,23 @@ let translate ?output_prefix loc (cxt : Lam_compile_context.t)
match args with
| [ e ] -> (
match e.expression_desc with
(* TODO: check if value or unpack *)
| _ -> (
match output_prefix with
| Some output_prefix ->
let output_dir = Filename.dirname output_prefix in
let d = Js_dump.string_of_expression e in
let id = Ident.create d in
(* TODO: construct J.module_id from e *)
let id = Ident.create "Belt_List" in
let path =
Js_name_of_module_id.string_of_module_id
(Lam_module_ident.of_ml id)
~output_dir Js_packages_info.Es6
{ id; kind = Js_op.Ml } ~output_dir
(* TODO: where is Js_package_info.module_system ? *)
Js_packages_info.NodeJS
in
print_endline path;
E.str ("TODO:import " ^ d)
E.call
~info:{ arity = Full; call_info = Call_na }
(E.js_global "import")
[ E.str path ]
| None -> assert false))
| _ -> assert false)
| Pjs_function_length -> E.function_length (Ext_list.singleton_exn args)
Expand Down
4 changes: 3 additions & 1 deletion jscomp/main/builtin_cmi_datasets.ml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion jscomp/main/builtin_cmj_datasets.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* 640a8f7e09c7798341a26633c103d6f4 *)
(* 407f68510a4eaffe1f5cc00fb994c5d4 *)
let module_names : string array = Obj.magic (
"Js" (* 23 *),
"Arg" (* 217 *),
Expand Down Expand Up @@ -89,6 +89,7 @@ let module_names : string array = Obj.magic (
"BytesLabels" (* 878 *),
"Dom_storage" (* 386 *),
"Js_mapperRt" (* 87 *),
"Js_promise2" (* 50 *),
"JsxDOMStyle" (* 23 *),
"Node_buffer" (* 23 *),
"Node_module" (* 23 *),
Expand Down Expand Up @@ -224,6 +225,7 @@ let module_data : string array = Obj.magic (
(* BytesLabels *)"\132\149\166\190\000\000\003Z\000\000\000\231\000\000\003\012\000\000\002\216\160\b\000\000\152\000\176#cat\144\160\160B@@@\176#map\144\160\160B@@@\176#sub\144\160\160C@@@\176$blit\144\160\160E@@@\176$copy\144\160\160A@@@\176$fill\144\160\160D@@@\176$init\144\160\160B@@@\176$iter\144\160\160B@@@\176$make\144\160\160B@@@\176$mapi\144\160\160B@@@\176$trim\144\160\160A@@@\176%equal\144\160\160B@@\144\148\192B\160\176\001\005z!x@\160\176\001\005{!y@@\151\176\1470caml_bytes_equal\160\144\004\011\160\144\004\n@\176\1929stdlib-406/bytesLabels.ml\001\001\171\0011\127\0011\155\192\004\002\001\001\171\0011\127\0011\160@\208B@@@@\176%index\144\160\160B@@@\176%iteri\144\160\160B@@@\176&concat\144\160\160B@@@\176&extend\144\160\160C@@@\176&rindex\144\160\160B@@@\176'compare\144\160\160B@@\144\148\192B\160\176\001\005w!x@\160\176\001\005x!y@@\151\176\1472caml_bytes_compare\160\144\004\011\160\144\004\n@\176\192\0044\001\001\170\0011L\0011h\192\0045\001\001\170\0011L\0011~@\208B@@@@\176'escaped\144\160\160A@@@\176(contains\144\160\160B@@@\176)index_opt\144\160\160B@@@\176)of_string\144\160\160A@@@\176)to_string\144\160\160A@@@\176*index_from\144\160\160C@@@\176*rindex_opt\144\160\160B@@@\176*sub_string\144\160\160C@@@\176+blit_string\144\160\160E@@@\176+rindex_from\144\160\160C@@@\176-contains_from\144\160\160C@@@\176.index_from_opt\144\160\160C@@@\176.rcontains_from\144\160\160C@@@\176/lowercase_ascii\144\160\160A@@@\176/rindex_from_opt\144\160\160C@@@\176/uppercase_ascii\144\160\160A@@@\1760capitalize_ascii\144\160\160A@@@\1760unsafe_of_string\144\004F@\1760unsafe_to_string\144\004D@\1762uncapitalize_ascii\144\160\160A@@@A",
(* Dom_storage *)"\132\149\166\190\000\000\001n\000\000\000k\000\000\001^\000\000\001T\160\192\176#key\144\160\160B@@\144\148\192B\160\176\001\004\004!i@\160\176\001\004\005#obj@@\151\176\000B\160\151\176\180#key\160\160AA\160\004\002@\181#key@@\160\144\004\016\160\144\004\021@\176\1925others/dom_storage.mlR\001\003\022\001\0036\192\004\002R\001\003\022\001\003B@@\004\004\208B@@@@\176'getItem\144\160\160B@@\144\148\192B\160\176\001\003\246!s@\160\176\001\003\247#obj@@\151\176\000B\160\151\176\180'getItem\160\004#\160\004$@\181'getItem@@\160\144\004\015\160\144\004\020@\176\192\004\"D\000x\001\000\140\192\004#D\000x\001\000\156@@\004\003\208B@@@@\176'setItem\144\160\160C@@@\176*removeItem\144\160\160B@@\144\148\192B\160\176\001\003\255!s@\160\176\001\004\000#obj@@\174\151\176\180*removeItem\160\004G\160\004H@\181*removeItem@@\160\144\004\r\160\144\004\018@\176\192\004FL\001\001\208\001\001\238\192\004GL\001\001\208\001\002\001@\146A\208B@@A@A",
(* Js_mapperRt *)"\132\149\166\190\000\000\000C\000\000\000\017\000\000\0009\000\000\0004\160\176\176'fromInt\144\160\160C@@@\176-fromIntAssert\144\160\160C@@@\1761raiseWhenNotFound\144\160\160A@@@A",
(* Js_promise2 *)"\132\149\166\190\000\000\000\030\000\000\000\012\000\000\000$\000\000\000\"\160\160\176$then\144\160\160B@@@\176%catch\144\160\160B@@@A",
(* JsxDOMStyle *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
(* Node_buffer *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
(* Node_module *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
Expand Down
15 changes: 7 additions & 8 deletions jscomp/test/Import.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';

var Curry = require("rescript/lib/js/curry.js");
var Js_promise = require("rescript/lib/js/js_promise.js");
var Curry = require("../../lib/js/curry.js");

var each = "TODO:import Belt_List.forEach";
var each = import("../../lib/js/belt_List.js");

function eachInt(list, f) {
return Js_promise.then_((function (each) {
return Promise.resolve(Curry._2(each, list, f));
}), each);
var arg1 = function (each) {
return Promise.resolve(Curry._2(each, list, f));
};
return each.then(arg1);
}

var beltAsModule = "TODO:import {\n Id: Belt_Id,\n $$Array: Belt_Array,\n SortArray: {\n Int: Belt_SortArrayInt,\n $$String: Belt_SortArrayString,\n strictlySortedLengthU: Belt_SortArray.strictlySortedLengthU,\n strictlySortedLength: Belt_SortArray.strictlySortedLength,\n isSortedU: Belt_SortArray.isSortedU,\n isSorted: Belt_SortArray.isSorted,\n stableSortInPlaceByU: Belt_SortArray.stableSortInPlaceByU,\n stableSortInPlaceBy: Belt_SortArray.stableSortInPlaceBy,\n stableSortByU: Belt_SortArray.stableSortByU,\n stableSortBy: Belt_SortArray.stableSortBy,\n binarySearchByU: Belt_SortArray.binarySearchByU,\n binarySearchBy: Belt_SortArray.binarySearchBy,\n unionU: Belt_SortArray.unionU,\n union: Belt_SortArray.union,\n intersectU: Belt_SortArray.intersectU,\n intersect: Belt_SortArray.intersect,\n diffU: Belt_SortArray.diffU,\n diff: Belt_SortArray.diff\n },\n MutableQueue: Belt_MutableQueue,\n MutableStack: Belt_MutableStack,\n List: Belt_List,\n $$Range: Belt_Range,\n $$Set: {\n Int: Belt_SetInt,\n $$String: Belt_SetString,\n Dict: Belt_SetDict,\n make: Belt_Set.make,\n fromArray: Belt_Set.fromArray,\n fromSortedArrayUnsafe: Belt_Set.fromSortedArrayUnsafe,\n isEmpty: Belt_Set.isEmpty,\n has: Belt_Set.has,\n add: Belt_Set.add,\n mergeMany: Belt_Set.mergeMany,\n remove: Belt_Set.remove,\n removeMany: Belt_Set.removeMany,\n union: Belt_Set.union,\n intersect: Belt_Set.intersect,\n diff: Belt_Set.diff,\n subset: Belt_Set.subset,\n cmp: Belt_Set.cmp,\n eq: Belt_Set.eq,\n forEachU: Belt_Set.forEachU,\n forEach: Belt_Set.forEach,\n reduceU: Belt_Set.reduceU,\n reduce: Belt_Set.reduce,\n everyU: Belt_Set.everyU,\n every: Belt_Set.every,\n someU: Belt_Set.someU,\n some: Belt_Set.some,\n keepU: Belt_Set.keepU,\n keep: Belt_Set.keep,\n partitionU: Belt_Set.partitionU,\n partition: Belt_Set.partition,\n size: Belt_Set.size,\n toArray: Belt_Set.toArray,\n toList: Belt_Set.toList,\n minimum: Belt_Set.minimum,\n minUndefined: Belt_Set.minUndefined,\n maximum: Belt_Set.maximum,\n maxUndefined: Belt_Set.maxUndefined,\n get: Belt_Set.get,\n getUndefined: Belt_Set.getUndefined,\n getExn: Belt_Set.getExn,\n split: Belt_Set.split,\n checkInvariantInternal: Belt_Set.checkInvariantInternal,\n getData: Belt_Set.getData,\n getId: Belt_Set.getId,\n packIdData: Belt_Set.packIdData\n },\n $$Map: {\n Int: Belt_MapInt,\n $$String: Belt_MapString,\n Dict: Belt_MapDict,\n make: Belt_Map.make,\n isEmpty: Belt_Map.isEmpty,\n has: Belt_Map.has,\n cmpU: Belt_Map.cmpU,\n cmp: Belt_Map.cmp,\n eqU: Belt_Map.eqU,\n eq: Belt_Map.eq,\n findFirstByU: Belt_Map.findFirstByU,\n findFirstBy: Belt_Map.findFirstBy,\n forEachU: Belt_Map.forEachU,\n forEach: Belt_Map.forEach,\n reduceU: Belt_Map.reduceU,\n reduce: Belt_Map.reduce,\n everyU: Belt_Map.everyU,\n every: Belt_Map.every,\n someU: Belt_Map.someU,\n some: Belt_Map.some,\n size: Belt_Map.size,\n toArray: Belt_Map.toArray,\n toList: Belt_Map.toList,\n fromArray: Belt_Map.fromArray,\n keysToArray: Belt_Map.keysToArray,\n valuesToArray: Belt_Map.valuesToArray,\n minKey: Belt_Map.minKey,\n minKeyUndefined: Belt_Map.minKeyUndefined,\n maxKey: Belt_Map.maxKey,\n maxKeyUndefined: Belt_Map.maxKeyUndefined,\n minimum: Belt_Map.minimum,\n minUndefined: Belt_Map.minUndefined,\n maximum: Belt_Map.maximum,\n maxUndefined: Belt_Map.maxUndefined,\n get: Belt_Map.get,\n getUndefined: Belt_Map.getUndefined,\n getWithDefault: Belt_Map.getWithDefault,\n getExn: Belt_Map.getExn,\n remove: Belt_Map.remove,\n removeMany: Belt_Map.removeMany,\n set: Belt_Map.set,\n updateU: Belt_Map.updateU,\n update: Belt_Map.update,\n mergeMany: Belt_Map.mergeMany,\n mergeU: Belt_Map.mergeU,\n merge: Belt_Map.merge,\n keepU: Belt_Map.keepU,\n keep: Belt_Map.keep,\n partitionU: Belt_Map.partitionU,\n partition: Belt_Map.partition,\n split: Belt_Map.split,\n mapU: Belt_Map.mapU,\n map: Belt_Map.map,\n mapWithKeyU: Belt_Map.mapWithKeyU,\n mapWithKey: Belt_Map.mapWithKey,\n getData: Belt_Map.getData,\n getId: Belt_Map.getId,\n packIdData: Belt_Map.packIdData,\n checkInvariantInternal: Belt_Map.checkInvariantInternal\n },\n MutableSet: {\n Int: Belt_MutableSetInt,\n $$String: Belt_MutableSetString,\n make: Belt_MutableSet.make,\n fromArray: Belt_MutableSet.fromArray,\n fromSortedArrayUnsafe: Belt_MutableSet.fromSortedArrayUnsafe,\n copy: Belt_MutableSet.copy,\n isEmpty: Belt_MutableSet.isEmpty,\n has: Belt_MutableSet.has,\n add: Belt_MutableSet.add,\n addCheck: Belt_MutableSet.addCheck,\n mergeMany: Belt_MutableSet.mergeMany,\n remove: Belt_MutableSet.remove,\n removeCheck: Belt_MutableSet.removeCheck,\n removeMany: Belt_MutableSet.removeMany,\n union: Belt_MutableSet.union,\n intersect: Belt_MutableSet.intersect,\n diff: Belt_MutableSet.diff,\n subset: Belt_MutableSet.subset,\n cmp: Belt_MutableSet.cmp,\n eq: Belt_MutableSet.eq,\n forEachU: Belt_MutableSet.forEachU,\n forEach: Belt_MutableSet.forEach,\n reduceU: Belt_MutableSet.reduceU,\n reduce: Belt_MutableSet.reduce,\n everyU: Belt_MutableSet.everyU,\n every: Belt_MutableSet.every,\n someU: Belt_MutableSet.someU,\n some: Belt_MutableSet.some,\n keepU: Belt_MutableSet.keepU,\n keep: Belt_MutableSet.keep,\n partitionU: Belt_MutableSet.partitionU,\n partition: Belt_MutableSet.partition,\n size: Belt_MutableSet.size,\n toList: Belt_MutableSet.toList,\n toArray: Belt_MutableSet.toArray,\n minimum: Belt_MutableSet.minimum,\n minUndefined: Belt_MutableSet.minUndefined,\n maximum: Belt_MutableSet.maximum,\n maxUndefined: Belt_MutableSet.maxUndefined,\n get: Belt_MutableSet.get,\n getUndefined: Belt_MutableSet.getUndefined,\n getExn: Belt_MutableSet.getExn,\n split: Belt_MutableSet.split,\n checkInvariantInternal: Belt_MutableSet.checkInvariantInternal\n },\n MutableMap: {\n Int: Belt_MutableMapInt,\n $$String: Belt_MutableMapString,\n make: Belt_MutableMap.make,\n clear: Belt_MutableMap.clear,\n isEmpty: Belt_MutableMap.isEmpty,\n has: Belt_MutableMap.has,\n cmpU: Belt_MutableMap.cmpU,\n cmp: Belt_MutableMap.cmp,\n eqU: Belt_MutableMap.eqU,\n eq: Belt_MutableMap.eq,\n forEachU: Belt_MutableMap.forEachU,\n forEach: Belt_MutableMap.forEach,\n reduceU: Belt_MutableMap.reduceU,\n reduce: Belt_MutableMap.reduce,\n everyU: Belt_MutableMap.everyU,\n every: Belt_MutableMap.every,\n someU: Belt_MutableMap.someU,\n some: Belt_MutableMap.some,\n size: Belt_MutableMap.size,\n toList: Belt_MutableMap.toList,\n toArray: Belt_MutableMap.toArray,\n fromArray: Belt_MutableMap.fromArray,\n keysToArray: Belt_MutableMap.keysToArray,\n valuesToArray: Belt_MutableMap.valuesToArray,\n minKey: Belt_MutableMap.minKey,\n minKeyUndefined: Belt_MutableMap.minKeyUndefined,\n maxKey: Belt_MutableMap.maxKey,\n maxKeyUndefined: Belt_MutableMap.maxKeyUndefined,\n minimum: Belt_MutableMap.minimum,\n minUndefined: Belt_MutableMap.minUndefined,\n maximum: Belt_MutableMap.maximum,\n maxUndefined: Belt_MutableMap.maxUndefined,\n get: Belt_MutableMap.get,\n getUndefined: Belt_MutableMap.getUndefined,\n getWithDefault: Belt_MutableMap.getWithDefault,\n getExn: Belt_MutableMap.getExn,\n checkInvariantInternal: Belt_MutableMap.checkInvariantInternal,\n remove: Belt_MutableMap.remove,\n removeMany: Belt_MutableMap.removeMany,\n set: Belt_MutableMap.set,\n updateU: Belt_MutableMap.updateU,\n update: Belt_MutableMap.update,\n mergeMany: Belt_MutableMap.mergeMany,\n mapU: Belt_MutableMap.mapU,\n map: Belt_MutableMap.map,\n mapWithKeyU: Belt_MutableMap.mapWithKeyU,\n mapWithKey: Belt_MutableMap.mapWithKey\n },\n HashSet: {\n Int: Belt_HashSetInt,\n $$String: Belt_HashSetString,\n make: Belt_HashSet.make,\n clear: Belt_HashSet.clear,\n isEmpty: Belt_HashSet.isEmpty,\n add: Belt_HashSet.add,\n copy: Belt_HashSet.copy,\n has: Belt_HashSet.has,\n remove: Belt_HashSet.remove,\n forEachU: Belt_HashSet.forEachU,\n forEach: Belt_HashSet.forEach,\n reduceU: Belt_HashSet.reduceU,\n reduce: Belt_HashSet.reduce,\n size: Belt_HashSet.size,\n logStats: Belt_HashSet.logStats,\n toArray: Belt_HashSet.toArray,\n fromArray: Belt_HashSet.fromArray,\n mergeMany: Belt_HashSet.mergeMany,\n getBucketHistogram: Belt_HashSet.getBucketHistogram\n },\n HashMap: {\n Int: Belt_HashMapInt,\n $$String: Belt_HashMapString,\n make: Belt_HashMap.make,\n clear: Belt_HashMap.clear,\n isEmpty: Belt_HashMap.isEmpty,\n set: Belt_HashMap.set,\n copy: Belt_HashMap.copy,\n get: Belt_HashMap.get,\n has: Belt_HashMap.has,\n remove: Belt_HashMap.remove,\n forEachU: Belt_HashMap.forEachU,\n forEach: Belt_HashMap.forEach,\n reduceU: Belt_HashMap.reduceU,\n reduce: Belt_HashMap.reduce,\n keepMapInPlaceU: Belt_HashMap.keepMapInPlaceU,\n keepMapInPlace: Belt_HashMap.keepMapInPlace,\n size: Belt_HashMap.size,\n toArray: Belt_HashMap.toArray,\n keysToArray: Belt_HashMap.keysToArray,\n valuesToArray: Belt_HashMap.valuesToArray,\n fromArray: Belt_HashMap.fromArray,\n mergeMany: Belt_HashMap.mergeMany,\n getBucketHistogram: Belt_HashMap.getBucketHistogram,\n logStats: Belt_HashMap.logStats\n },\n $$Option: Belt_Option,\n Result: Belt_Result,\n Int: Belt_Int,\n Float: Belt_Float\n}";
var beltAsModule = import("../../lib/js/belt_List.js");

exports.each = each;
exports.eachInt = eachInt;
Expand Down
Loading

0 comments on commit 326977a

Please sign in to comment.