Skip to content

Commit daeca3f

Browse files
wcjohnsonrattrayalex
authored andcommitted
Fix false positive shadowing
- Don’t `registerDeclaration` on functions that aren’t `FunctionDeclaration`s. - Added sibling function fixture
1 parent 8aec21b commit daeca3f

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,12 @@ export default function (babel) {
10781078
addImplicitReturns(path);
10791079
}
10801080

1081-
// somehow this wasn't being done... may signal deeper issues...
1082-
path.getFunctionParent().scope.registerDeclaration(path);
1081+
// As this is an exit visitor, other LSC transforms have reduced
1082+
// arrows to plain FunctionDeclarations by this point.
1083+
if (path.node.type === "FunctionDeclaration") {
1084+
// somehow this wasn't being done... may signal deeper issues...
1085+
path.getFunctionParent().scope.registerDeclaration(path);
1086+
}
10831087
}
10841088
},
10851089

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
f = (x) -> x
2+
3+
g(x) -> x
4+
5+
h() ->
6+
x = 3
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const f = function (x) {
2+
return x;
3+
};
4+
function g(x) {
5+
return x;
6+
}
7+
8+
function h() {
9+
const x = 3;
10+
return x;
11+
}

0 commit comments

Comments
 (0)