Use function expression for custom Hook signature argument (#15956)
Dan Abramov committed
Jun 22, 2019 at 11:54 UTC
d271df5c993ba54408969fbfc4b5e0f751a4cf0c
2 files changed
+18
-4
packages/react-refresh/src/ReactFreshBabelPlugin.js
+9
-1
@@ -306,7 +306,15 @@ export default function(babel) {
306
}
307
if (customHooksInScope.length > 0) {
308
args.push(
309
- t.arrowFunctionExpression([], t.arrayExpression(customHooksInScope)),
309
+ // TODO: We could use an arrow here to be more compact.
310
+ // However, don't do it until AMA can run them natively.
311
+ t.functionExpression(
312
+ null,
313
+ [],
314
+ t.blockStatement([
315
+ t.returnStatement(t.arrayExpression(customHooksInScope)),
316
+ ]),
317
+ ),
318
);
319
}
320
return args;
packages/react-refresh/src/__tests__/__snapshots__/ReactFreshBabelPlugin-test.js.snap
+9
-3
@@ -113,7 +113,9 @@ export default function App() {
113
return <h1>{bar}{baz}</h1>;
114
}
115
116
-_s2(App, 'useFancyState{bar}\\nuseThing{baz}\\nuseState{}\\nuseThePlatform{}', true, () => [FancyHook.useThing]);
116
+_s2(App, 'useFancyState{bar}\\nuseThing{baz}\\nuseState{}\\nuseThePlatform{}', true, function () {
117
+ return [FancyHook.useThing];
118
+});
119
120
_c = App;
121
@@ -186,7 +188,9 @@ function useFancyState() {
188
return foo;
189
}
190
189
-_s(useFancyState, "useState{[foo, setFoo](0)}\\nuseFancyEffect{}", false, () => [useFancyEffect]);
191
+_s(useFancyState, "useState{[foo, setFoo](0)}\\nuseFancyEffect{}", false, function () {
192
+ return [useFancyEffect];
193
+});
194
195
const useFancyEffect = () => {
196
_s2();
@@ -203,7 +207,9 @@ export default function App() {
207
return <h1>{bar}</h1>;
208
}
209
206
-_s3(App, "useFancyState{bar}", false, () => [useFancyState]);
210
+_s3(App, "useFancyState{bar}", false, function () {
211
+ return [useFancyState];
212
+});
213
214
_c = App;
215