Skip to content

Commit 84888be

Browse files
committed
Fix issue where emptyArray was reported unused for lowercase components without children.
Fixes #85.
1 parent 00c840d commit 84888be

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# master
2+
- Fix issue where `emptyArray` was reported unused for lowercase components without children. (See https://github.com/reason-association/reanalyze/issues/85).
23

34
# 2.12.0
45
- Support OCaml 4.11 and 4.12.

examples/deadcode/src/EmptyArray.bs.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @@config({flags : ["-dsource"]});
2+
3+
module Z = {
4+
@react.component
5+
let make = () => {
6+
<br />
7+
}
8+
}
9+
10+
let _ = <Z />

examples/deadcode/src/deadcode.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@
401401
addValueDeclaration +make DynamicallyLoadedComponent.re:2:4 path:+DynamicallyLoadedComponent
402402
addValueReference DynamicallyLoadedComponent.re:2:32 --> DynamicallyLoadedComponent.re:2:13
403403
addValueReference DynamicallyLoadedComponent.re:2:19 --> React.re:7:0
404+
Scanning EmptyArray.cmt Source:EmptyArray.res
405+
addValueDeclaration +make EmptyArray.res:5:6 path:+EmptyArray.Z
406+
DeadOptionalArgs.addReferences ReactDOMRe.createDOMElementVariadic called with optional argNames: argNamesMaybe: EmptyArray.res:6:5
407+
addValueDeclaration +emptyArray EmptyArray.res:6:5 path:+EmptyArray.Z
408+
addDummyReference _none_:1:-1 --> EmptyArray.res:6:5
409+
addValueReference EmptyArray.res:6:5 --> ReactDOMRe.re:114:0
410+
addValueReference EmptyArray.res:10:9 --> EmptyArray.res:5:6
411+
addValueReference EmptyArray.res:10:9 --> React.re:18:0
404412
Scanning ErrorHandler.cmt Source:ErrorHandler.re
405413
addValueDeclaration +notify ErrorHandler.re:7:6 path:+ErrorHandler.Make
406414
addValueDeclaration +x ErrorHandler.re:12:4 path:+ErrorHandler
@@ -1877,6 +1885,7 @@ File References
18771885
DeadValueTest.rei -->> DeadValueTest.re
18781886
Docstrings.re -->>
18791887
DynamicallyLoadedComponent.re -->> React.re
1888+
EmptyArray.res -->> React.re, ReactDOMRe.re
18801889
ErrorHandler.re -->>
18811890
ErrorHandler.rei -->> ErrorHandler.re
18821891
EverythingLiveHere.re -->>
@@ -2088,6 +2097,8 @@ File References
20882097
Live Value +Docstrings.+one: 0 references () [0]
20892098
Live Value +Docstrings.+signMessage: 0 references () [0]
20902099
Live Value +Docstrings.+flat: 0 references () [0]
2100+
Live Value +EmptyArray.Z.+emptyArray: 1 references (_none_:1:-1) [0]
2101+
Live Value +EmptyArray.Z.+make: 1 references (EmptyArray.res:10:9) [0]
20912102
Dead Value +EverythingLiveHere.+z: 0 references () [0]
20922103
Dead Value +EverythingLiveHere.+y: 0 references () [0]
20932104
Dead Value +EverythingLiveHere.+x: 0 references () [0]

src/DeadValue.re

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,20 @@ let collectExpr = (super, self, e: Typedtree.expression) => {
138138
let locFrom = e.exp_loc;
139139
switch (e.exp_desc) {
140140
| Texp_ident(_path, _, {Types.val_loc: {loc_ghost: false, _} as locTo}) =>
141-
addValueReference(~addFileReference=true, ~locFrom, ~locTo)
141+
if (locFrom == locTo && _path |> Path.name == "emptyArray") {
142+
// Work around lowercase jsx with no children producing an artifact `emptyArray`
143+
// which is called from its own location as many things are generated on the same location.
144+
if (Common.Cli.debug^) {
145+
Log_.item(
146+
"addDummyReference %s --> %s@.",
147+
Location.none.loc_start |> posToString,
148+
locTo.loc_start |> posToString,
149+
);
150+
};
151+
ValueReferences.add(locTo.loc_start, Location.none.loc_start);
152+
} else {
153+
addValueReference(~addFileReference=true, ~locFrom, ~locTo);
154+
}
142155

143156
| Texp_apply(
144157
{

0 commit comments

Comments
 (0)