Skip to content

Commit

Permalink
Fix issue where emptyArray was reported unused for lowercase compon…
Browse files Browse the repository at this point in the history
…ents without children.

Fixes #85.
  • Loading branch information
cristianoc committed Jan 5, 2021
1 parent 00c840d commit e9ae29a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# master
- Fix issue where `emptyArray` was reported unused for lowercase components without children. (See https://github.com/reason-association/reanalyze/issues/85).

# 2.12.0
- Support OCaml 4.11 and 4.12.
Expand Down
19 changes: 19 additions & 0 deletions examples/deadcode/src/EmptyArray.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/deadcode/src/EmptyArray.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @@config({flags : ["-dsource"]});

module Z = {
@react.component
let make = () => {
<br />
}
}

let _ = <Z />
11 changes: 11 additions & 0 deletions examples/deadcode/src/deadcode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,14 @@
addValueDeclaration +make DynamicallyLoadedComponent.re:2:4 path:+DynamicallyLoadedComponent
addValueReference DynamicallyLoadedComponent.re:2:32 --> DynamicallyLoadedComponent.re:2:13
addValueReference DynamicallyLoadedComponent.re:2:19 --> React.re:7:0
Scanning EmptyArray.cmt Source:EmptyArray.res
addValueDeclaration +make EmptyArray.res:5:6 path:+EmptyArray.Z
DeadOptionalArgs.addReferences ReactDOMRe.createDOMElementVariadic called with optional argNames: argNamesMaybe: EmptyArray.res:6:5
addValueDeclaration +emptyArray EmptyArray.res:6:5 path:+EmptyArray.Z
addDummyReference _none_:1:-1 --> EmptyArray.res:6:5
addValueReference EmptyArray.res:6:5 --> ReactDOMRe.re:114:0
addValueReference EmptyArray.res:10:9 --> EmptyArray.res:5:6
addValueReference EmptyArray.res:10:9 --> React.re:18:0
Scanning ErrorHandler.cmt Source:ErrorHandler.re
addValueDeclaration +notify ErrorHandler.re:7:6 path:+ErrorHandler.Make
addValueDeclaration +x ErrorHandler.re:12:4 path:+ErrorHandler
Expand Down Expand Up @@ -1877,6 +1885,7 @@ File References
DeadValueTest.rei -->> DeadValueTest.re
Docstrings.re -->>
DynamicallyLoadedComponent.re -->> React.re
EmptyArray.res -->> React.re, ReactDOMRe.re
ErrorHandler.re -->>
ErrorHandler.rei -->> ErrorHandler.re
EverythingLiveHere.re -->>
Expand Down Expand Up @@ -2088,6 +2097,8 @@ File References
Live Value +Docstrings.+one: 0 references () [0]
Live Value +Docstrings.+signMessage: 0 references () [0]
Live Value +Docstrings.+flat: 0 references () [0]
Live Value +EmptyArray.Z.+emptyArray: 1 references (_none_:1:-1) [0]
Live Value +EmptyArray.Z.+make: 1 references (EmptyArray.res:10:9) [0]
Dead Value +EverythingLiveHere.+z: 0 references () [0]
Dead Value +EverythingLiveHere.+y: 0 references () [0]
Dead Value +EverythingLiveHere.+x: 0 references () [0]
Expand Down
15 changes: 14 additions & 1 deletion src/DeadValue.re
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,20 @@ let collectExpr = (super, self, e: Typedtree.expression) => {
let locFrom = e.exp_loc;
switch (e.exp_desc) {
| Texp_ident(_path, _, {Types.val_loc: {loc_ghost: false, _} as locTo}) =>
addValueReference(~addFileReference=true, ~locFrom, ~locTo)
if (locFrom == locTo && _path |> Path.name == "emptyArray") {
// Work around lowercase jsx with no children producing an artifact `emptyArray`
// which is called from its own location as many things are generated on the same location.
if (Common.Cli.debug^) {
Log_.item(
"addDummyReference %s --> %s@.",
Location.none.loc_start |> posToString,
locTo.loc_start |> posToString,
);
};
ValueReferences.add(locTo.loc_start, Location.none.loc_start);
} else {
addValueReference(~addFileReference=true, ~locFrom, ~locTo);
}

| Texp_apply(
{
Expand Down

0 comments on commit e9ae29a

Please sign in to comment.