mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[hir] Traverse function to capture deps, not just body node
Technically there is a body node created for implicit return expression in a arrow function, so the existing logic should've worked fine. But there seems to be a Babel bug, so let's work around it by traversing the function. Added a test case that captures a dep as a param -- this is currently unsupported and also something that would've been ignored before this PR. Added a failing test to make sure we think about this case when we add support for default params.
This commit is contained in:
@@ -3058,7 +3058,7 @@ function gatherCapturedDeps(
|
||||
}
|
||||
}
|
||||
|
||||
fn.get("body").traverse({
|
||||
fn.traverse({
|
||||
Expression(path) {
|
||||
visit(path);
|
||||
},
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Foo() {
|
||||
(function t() {
|
||||
let x = {};
|
||||
return function a(x = () => {}) {
|
||||
return x;
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Foo,
|
||||
params: [],
|
||||
isComponent: false,
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] Todo: (BuildHIR::node.lowerReorderableExpression) Expression type 'ArrowFunctionExpression' cannot be safely reordered (4:4)
|
||||
```
|
||||
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
function Foo() {
|
||||
(function t() {
|
||||
let x = {};
|
||||
return function a(x = () => {}) {
|
||||
return x;
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Foo,
|
||||
params: [],
|
||||
isComponent: false,
|
||||
};
|
||||
+15
-4
@@ -18,11 +18,22 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
## Error
|
||||
```javascript
|
||||
import { invoke } from "shared-runtime";
|
||||
|
||||
function useFoo() {
|
||||
const x = {};
|
||||
const result = invoke(() => x);
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [],
|
||||
isComponent: false,
|
||||
};
|
||||
|
||||
```
|
||||
[ReactForget] Invariant: Expected value for identifier `16` to be initialized. (5:5)
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user