Skip to content

Commit 78781b4

Browse files
committed
add -as-pp flag
1 parent d5d5e57 commit 78781b4

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
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/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

0 commit comments

Comments
 (0)