Skip to content

Commit

Permalink
Use function expression for custom Hook signature argument (#15956)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Jun 22, 2019
1 parent 4189f71 commit d271df5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 9 additions & 1 deletion packages/react-refresh/src/ReactFreshBabelPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,15 @@ export default function(babel) {
}
if (customHooksInScope.length > 0) {
args.push(
t.arrowFunctionExpression([], t.arrayExpression(customHooksInScope)),
// TODO: We could use an arrow here to be more compact.
// However, don't do it until AMA can run them natively.
t.functionExpression(
null,
[],
t.blockStatement([
t.returnStatement(t.arrayExpression(customHooksInScope)),
]),
),
);
}
return args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export default function App() {
return <h1>{bar}{baz}</h1>;
}
_s2(App, 'useFancyState{bar}\\nuseThing{baz}\\nuseState{}\\nuseThePlatform{}', true, () => [FancyHook.useThing]);
_s2(App, 'useFancyState{bar}\\nuseThing{baz}\\nuseState{}\\nuseThePlatform{}', true, function () {
return [FancyHook.useThing];
});
_c = App;
Expand Down Expand Up @@ -186,7 +188,9 @@ function useFancyState() {
return foo;
}
_s(useFancyState, "useState{[foo, setFoo](0)}\\nuseFancyEffect{}", false, () => [useFancyEffect]);
_s(useFancyState, "useState{[foo, setFoo](0)}\\nuseFancyEffect{}", false, function () {
return [useFancyEffect];
});
const useFancyEffect = () => {
_s2();
Expand All @@ -203,7 +207,9 @@ export default function App() {
return <h1>{bar}</h1>;
}
_s3(App, "useFancyState{bar}", false, () => [useFancyState]);
_s3(App, "useFancyState{bar}", false, function () {
return [useFancyState];
});
_c = App;
Expand Down

0 comments on commit d271df5

Please sign in to comment.