Skip to content

Commit

Permalink
feat: add pexp_ident to @browser_only
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobslisboa committed Dec 30, 2024
1 parent e81cd90 commit 18c2fd6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/browser-ppx/ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,13 @@ module Preprocess = struct
method! expression expr =
let expr = super#expression expr in
match expr.pexp_desc with
| Pexp_apply _ | Pexp_constant _ ->
| Pexp_let (_, [ { pvb_attributes = attrs; _ } ], body) ->
let loc = expr.pexp_loc in
if should_keep expr.pexp_attributes = `keep then if should_keep attrs = `keep then expr else body
else [%expr ()]
| Pexp_apply _ | Pexp_constant _ | Pexp_ident _ ->
let loc = expr.pexp_loc in
if should_keep expr.pexp_attributes = `keep then expr else [%expr ()]
| Pexp_let (_, [ { pvb_attributes = attrs; _ } ], body) -> if should_keep attrs = `keep then expr else body
| Pexp_fun _ ->
if should_keep expr.pexp_attributes = `keep then expr
else
Expand Down
8 changes: 5 additions & 3 deletions packages/browser-ppx/tests/at_browser_only.t
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,19 @@ Ppat_tuple
Pexp_apply

$ cat > input_apply.ml << EOF
> foo (42 [@browser_only]) ((fun () -> ())[@browser_only]) 24
> foo ((pexp_ident_var) [@browser_only]) ((42) [@browser_only]) ((fun () -> ())[@browser_only]) 24
> EOF

$ ./standalone.exe -impl input_apply.ml | ocamlformat - --enable-outside-detected-project --impl
foo ()
foo () ()
(fun _ ->
Runtime.fail_impossible_action_in_ssr "((fun () -> ())[@browser_only ])")
24

$ ./standalone.exe -impl input_apply.ml -js | ocamlformat - --enable-outside-detected-project --impl
foo (42 [@browser_only]) (fun [@browser_only] () -> ()) 24
foo (pexp_ident_var [@browser_only]) (42 [@browser_only])
(fun [@browser_only] () -> ())
24

Ppat_var

Expand Down

0 comments on commit 18c2fd6

Please sign in to comment.