mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
[hir] Check for globals while lowering UpdateExpression
lowerIdentifierForAssignment does extra checks such as checking if globals are lvalues. UpdateExpression lowers into an assignment and previously we missed out on such checks.
This commit is contained in:
1 parent
8eca031508
commit
4a8b36b8b1
4 files changed
+27
-34
No files matched your search
@@ -1790,10 +1790,15 @@ function lowerExpression(
|
||||
builder,
|
||||
expr.node.loc ?? GeneratedSource
|
||||
);
|
||||
const identifier = lowerIdentifier(
|
||||
const identifier = lowerIdentifierForAssignment(
|
||||
builder,
|
||||
argument.node.loc ?? GeneratedSource,
|
||||
InstructionKind.Reassign,
|
||||
argument as NodePath<t.Identifier>
|
||||
);
|
||||
if (identifier === null) {
|
||||
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
||||
}
|
||||
builder.push({
|
||||
id: makeInstructionId(0),
|
||||
lvalue: { ...temp },
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
let renderCount = 0;
|
||||
|
||||
function NoHooks() {
|
||||
renderCount++;
|
||||
return <div />;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] InvalidReact: This reassigns a variable which was not defined inside of the component. Components should be pure and side-effect free. If this variable is used in rendering, use useState instead. (https://react.dev/learn/keeping-components-pure) (4:4)
|
||||
```
|
||||
|
||||
|
||||
File renamed without changes.
-33
@@ -1,33 +0,0 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
let renderCount = 0;
|
||||
|
||||
function NoHooks() {
|
||||
renderCount++;
|
||||
return <div />;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
let renderCount = 0;
|
||||
|
||||
function NoHooks() {
|
||||
const $ = useMemoCache(1);
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = <div />;
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user