Skip to content

Commit

Permalink
Do not instrument React.forwardRef and React.memo
Browse files Browse the repository at this point in the history
Fixes #375.
  • Loading branch information
aantron committed May 4, 2021
1 parent 21b037f commit 6b50f77
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ppx/instrument.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,9 @@ class instrumenter =
| [%expr ignore]
| [%expr Sys.opaque_identity]
| [%expr Obj.magic]
| [%expr (##)] -> true
| [%expr (##)]
| [%expr React.forwardRef]
| [%expr React.memo] -> true
| _ -> false)
in

Expand Down
37 changes: 37 additions & 0 deletions test/instrument/attribute.t
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,40 @@ Non-coverage attributes are preserved uninstrumented.
let _ = () [@@foo print_endline "bar"]
let _ = () [@foo print_endline "bar"]
Let-bindings with [@@react.component] are not instrumented at their top level.
$ bash test.sh <<'EOF'
> module React = struct let forwardRef f = f () end
>
> let make1 = fun () -> ignore ignore
> [@@react.component]
>
> let make2 () = ignore ignore
> [@@react.component]
>
> let make3 = React.forwardRef (fun r -> ignore r)
> [@@react.component]
> EOF
module React = struct
let forwardRef f =
___bisect_visit___ 0;
f ()
end
let make1 () =
___bisect_visit___ 1;
ignore ignore
[@@react.component]
let make2 () =
___bisect_visit___ 2;
ignore ignore
[@@react.component]
let make3 =
React.forwardRef (fun r ->
___bisect_visit___ 3;
ignore r)
[@@react.component]

0 comments on commit 6b50f77

Please sign in to comment.