Skip to content

Commit b4d5cae

Browse files
authored
Merge pull request #4978 from rescript-lang/support_rescript_synatx
[internal] add support for rescript syntax testing, add -as-pp for native, fix #4977
2 parents 29174de + 3005b70 commit b4d5cae

File tree

12 files changed

+135
-22
lines changed

12 files changed

+135
-22
lines changed

jscomp/common/js_config.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,6 @@ let as_ppx = ref false
9292

9393
let mono_empty_array = ref true
9494

95-
let customize_runtime = ref None
95+
let customize_runtime = ref None
96+
97+
let as_pp = ref false

jscomp/common/js_config.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ val no_export: bool ref
100100
val as_ppx : bool ref
101101

102102
val mono_empty_array : bool ref
103-
val customize_runtime : string option ref
103+
val customize_runtime : string option ref
104+
val as_pp: bool ref

jscomp/core/js_implementation.ml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ let after_parsing_sig ppf outputprefix ast =
6767
ast
6868

6969
end;
70-
if !Js_config.syntax_only then
70+
if !Js_config.as_pp then begin
71+
output_string stdout Config.ast_intf_magic_number;
72+
output_value stdout (!Location.input_name : string);
73+
output_value stdout ast;
74+
end;
75+
if !Js_config.syntax_only then
7176
Warnings.check_fatal()
7277
else
7378
begin
@@ -170,6 +175,11 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
170175
Ml ~output:(outputprefix ^ Literals.suffix_ast)
171176
ast
172177
end ;
178+
if !Js_config.as_pp then begin
179+
output_string stdout Config.ast_impl_magic_number;
180+
output_value stdout (!Location.input_name : string);
181+
output_value stdout ast;
182+
end;
173183
if !Js_config.syntax_only then
174184
Warnings.check_fatal ()
175185
else

jscomp/main/js_main.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
287287

288288
"-as-ppx", set Js_config.as_ppx,
289289
"*internal*As ppx for editor integration";
290-
290+
"-as-pp", unit_call(fun _ -> Js_config.as_pp := true ; Js_config.syntax_only := true),
291+
"*internal*As pp to interact with native tools";
291292
"-no-alias-deps", set Clflags.transparent_modules,
292293
"*internal*Do not record dependencies for module aliases";
293294

jscomp/test/build.ninja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ o test/hash_collision_test.cmi test/hash_collision_test.cmj : cc test/hash_colli
338338
o test/hash_test.cmi test/hash_test.cmj : cc test/hash_test.ml | test/mt.cmj test/mt_global.cmj $stdlib
339339
o test/hashtbl_test.cmi test/hashtbl_test.cmj : cc test/hashtbl_test.ml | test/mt.cmj $stdlib
340340
o test/hello.foo.cmi test/hello.foo.cmj : cc test/hello.foo.ml | $stdlib
341+
o test/hello_res.cmj : cc_cmi test/hello_res.res | test/hello_res.cmi $stdlib
342+
o test/hello_res.cmi : cc test/hello_res.resi | $stdlib
341343
o test/http_types.cmi test/http_types.cmj : cc test/http_types.ml | $stdlib
342344
o test/ignore_test.cmi test/ignore_test.cmj : cc test/ignore_test.ml | test/mt.cmj $stdlib
343345
o test/imm_map_bench.cmi test/imm_map_bench.cmj : cc test/imm_map_bench.ml | $stdlib

jscomp/test/hello_res.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
var List = require("../../lib/js/list.js");
4+
5+
var b = List.length({
6+
hd: 1,
7+
tl: {
8+
hd: 2,
9+
tl: {
10+
hd: 3,
11+
tl: /* [] */0
12+
}
13+
}
14+
});
15+
16+
var a = b - 1 | 0;
17+
18+
console.log("hello, res");
19+
20+
exports.a = a;
21+
/* b Not a pure module */

jscomp/test/hello_res.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
let b = List.length(list{1,2,3})
3+
let a = b - 1
4+
Js.log ("hello, res")

jscomp/test/hello_res.resi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a : int

lib/4.06.1/unstable/bspack.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11958,6 +11958,7 @@ val as_ppx : bool ref
1195811958

1195911959
val mono_empty_array : bool ref
1196011960
val customize_runtime : string option ref
11961+
val as_pp: bool ref
1196111962
end = struct
1196211963
#1 "js_config.ml"
1196311964
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -12053,6 +12054,8 @@ let as_ppx = ref false
1205312054
let mono_empty_array = ref true
1205412055

1205512056
let customize_runtime = ref None
12057+
12058+
let as_pp = ref false
1205612059
end
1205712060
module Map_gen : sig
1205812061
#1 "map_gen.mli"

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17802,6 +17802,7 @@ val as_ppx : bool ref
1780217802

1780317803
val mono_empty_array : bool ref
1780417804
val customize_runtime : string option ref
17805+
val as_pp: bool ref
1780517806
end = struct
1780617807
#1 "js_config.ml"
1780717808
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -17897,6 +17898,8 @@ let as_ppx = ref false
1789717898
let mono_empty_array = ref true
1789817899

1789917900
let customize_runtime = ref None
17901+
17902+
let as_pp = ref false
1790017903
end
1790117904
module Bs_cmi_load
1790217905
= struct

0 commit comments

Comments
 (0)