Skip to content

Commit 2bab323

Browse files
committed
Begin exposing %raw arity
Only print to stderr for now? See #6213
1 parent 0aff3a6 commit 2bab323

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

jscomp/frontend/ast_exp_handle_external.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ let handle_debugger loc (payload : Ast_payload.t) =
7272
Location.raise_errorf ~loc "%%debugger extension doesn't accept arguments"
7373

7474
let handle_raw ~kind loc payload =
75-
let is_function = ref false in
75+
let is_function = ref None in
7676
match Ast_payload.raw_as_string_exp_exn ~kind ~is_function payload with
7777
| None -> (
7878
match kind with
@@ -93,9 +93,11 @@ let handle_raw ~kind loc payload =
9393
~pval_type:(Typ.arrow Nolabel (Typ.any ()) (Typ.any ()))
9494
[exp];
9595
pexp_attributes =
96-
(if !is_function then
97-
Ast_attributes.internal_expansive :: exp.pexp_attributes
98-
else exp.pexp_attributes);
96+
(match !is_function with
97+
| None -> exp.pexp_attributes
98+
| Some arity ->
99+
Printf.eprintf "XXX raw arity:%d\n" arity;
100+
Ast_attributes.internal_expansive :: exp.pexp_attributes);
99101
}
100102

101103
let handle_raw_structure loc payload =

jscomp/ml/ast_payload.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ let raw_as_string_exp_exn ~(kind : Js_raw_info.raw_kind) ?is_function (x : t) :
138138
Location.raise_errorf ~loc
139139
"Syntax error: a valid JS regex literal expected");
140140
(match is_function with
141-
| Some is_function -> (
142-
match Classify_function.classify_exp prog with
143-
| Js_function {arity = _; _} -> is_function := true
144-
| _ -> ())
145-
| None -> ());
141+
| Some is_function -> (
142+
match Classify_function.classify_exp prog with
143+
| Js_function {arity; _} -> is_function := Some arity
144+
| _ -> ())
145+
| None -> ());
146146
errors
147147
| Raw_program -> snd (Parser_flow.parse_program false None str));
148148
Some {e with pexp_desc = Pexp_constant (Pconst_string (str, None))}

jscomp/ml/ast_payload.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ val is_single_ident : t -> Longident.t option
4747

4848
val raw_as_string_exp_exn :
4949
kind:Js_raw_info.raw_kind ->
50-
?is_function:bool ref ->
50+
?is_function:int option ref ->
5151
t ->
5252
Parsetree.expression option
5353
(** Convert %raw into expression *)

0 commit comments

Comments
 (0)