Skip to content

Commit

Permalink
fix: don't record signatures of local hooks, fixes #1412
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Jan 22, 2020
1 parent 9ab2571 commit f07612f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2,483 deletions.
1 change: 1 addition & 0 deletions src/fresh/babel.js
Expand Up @@ -211,6 +211,7 @@ export default function (babel) {
key: fnHookCalls.map(call => call.name + '{' + call.key + '}').join('\n'),
customHooks: fnHookCalls
.filter(call => !isBuiltinHook(call.name))
.filter(call => scope.parent.hasBinding(call.name))
.map(call => t.cloneDeep(call.callee)),
};
}
Expand Down
36 changes: 36 additions & 0 deletions test/__babel_fixtures__/local-hooks.js
@@ -0,0 +1,36 @@
import {useState} from "react";

function Component1() {
function useRippleHandler() {}
useRippleHandler();
useRippleHandler();
}

function Component2() {
const useRippleHandler = () => {};
useRippleHandler();
useRippleHandler();
}

function Component3() {
const useRippleHandler = function () {};
useRippleHandler();
useRippleHandler();
}

const useInnerHook = ({useHookFromProps}) => {
const useHookBase = () => useState();
const useHook = () => useState(useHookFromProps(useHookBase()));
useHookFromProps();
{
// sub scope
useHook();
}
};

const OnlyThisOneUsesExternalHook = () => {
useInnerHook();
useState();
};

// check for "return ["

0 comments on commit f07612f

Please sign in to comment.