File tree Expand file tree Collapse file tree 6 files changed +52
-2
lines changed Expand file tree Collapse file tree 6 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -43,3 +43,10 @@ type node_module = <
43
43
children : node_module array ;
44
44
paths : string array ;
45
45
> Js. t
46
+
47
+ type node_require = <
48
+ main : node_module Js .undefined ;
49
+
50
+ resolve : string -> string [@ bs]
51
+ (* @raise exception *)
52
+ > Js. t
Original file line number Diff line number Diff line change @@ -310,7 +310,15 @@ let rec unsafe_mapper : Ast_mapper.mapper =
310
310
(Ast_payload. raw_string_payload loc " module" ))
311
311
(Typ. constr ~loc
312
312
{ txt = Ldot (Lident " Bs_node" , " node_module" ) ;
313
- loc} [] )
313
+ loc} [] )
314
+ | Some {txt = Lident " __require" }
315
+ ->
316
+ Exp. constraint_ ~loc
317
+ (Ast_util. handle_raw loc
318
+ (Ast_payload. raw_string_payload loc " require" ))
319
+ (Typ. constr ~loc
320
+ { txt = Ldot (Lident " Bs_node" , " node_require" ) ;
321
+ loc} [] )
314
322
| Some _ | None -> Location. raise_errorf ~loc " Ilegal payload"
315
323
end
316
324
Original file line number Diff line number Diff line change @@ -690,6 +690,8 @@ test_react_case.cmj :
690
690
test_react_case.cmx :
691
691
test_regex.cmj :
692
692
test_regex.cmx :
693
+ test_require.cmj : ../runtime/js.cmj
694
+ test_require.cmx : ../runtime/js.cmx
693
695
test_runtime_encoding.cmj : ../stdlib/array.cmi
694
696
test_runtime_encoding.cmx : ../stdlib/array.cmx
695
697
test_scope.cmj :
@@ -1448,6 +1450,8 @@ test_react_case.cmo :
1448
1450
test_react_case.cmj :
1449
1451
test_regex.cmo :
1450
1452
test_regex.cmj :
1453
+ test_require.cmo : ../runtime/js.cmo
1454
+ test_require.cmj : ../runtime/js.cmj
1451
1455
test_runtime_encoding.cmo : ../stdlib/array.cmi
1452
1456
test_runtime_encoding.cmj : ../stdlib/array.cmj
1453
1457
test_scope.cmo :
Original file line number Diff line number Diff line change @@ -59,7 +59,8 @@ OTHERS := a test_ari test_export2 test_internalOO test_obj_simple_ffi test_scope
59
59
optional_ffi_test poly_variant_test \
60
60
bs_rest_test infer_type_test fs_test module_as_function\
61
61
test_case_set test_mutliple string_bound_get_test inline_string_test\
62
- ppx_this_obj_test unsafe_obj_external gpr_627_test jsoo_485_test jsoo_400_test
62
+ ppx_this_obj_test unsafe_obj_external gpr_627_test jsoo_485_test jsoo_400_test \
63
+ test_require
63
64
64
65
65
66
SOURCE_LIST := js_dyn $(OTHERS )
Original file line number Diff line number Diff line change
1
+ // GENERATED CODE BY BUCKLESCRIPT VERSION 0.9.3 , PLEASE EDIT WITH CARE
2
+ 'use strict' ;
3
+
4
+
5
+ var u = ( require ) ;
6
+
7
+ console . log ( u . resolve ( "./test_require.js" ) ) ;
8
+
9
+ if ( ( require ) . main === ( module ) ) {
10
+ console . log ( "is main" ) ;
11
+ }
12
+ else {
13
+ console . log ( "not main" ) ;
14
+ }
15
+
16
+ exports . u = u ;
17
+ /* u Not a pure module */
Original file line number Diff line number Diff line change
1
+
2
+
3
+ let u = [% bs.node __require]
4
+
5
+ let () =
6
+ Js. log @@ u#@ resolve " ./test_require.js"
7
+ let () =
8
+ if [% bs.node __require]##main ==
9
+ Js.Undefined. return
10
+ [% bs.node __module] then
11
+ Js. log " is main"
12
+ else
13
+ Js. log " not main"
You can’t perform that action at this time.
0 commit comments