Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48b52d896e |
@@ -184,25 +184,28 @@ function validateNoContextVariableAssignment(
|
|||||||
fn: HIRFunction,
|
fn: HIRFunction,
|
||||||
errors: CompilerError,
|
errors: CompilerError,
|
||||||
): void {
|
): void {
|
||||||
|
const context = new Set(fn.context.map(place => place.identifier.id));
|
||||||
for (const block of fn.body.blocks.values()) {
|
for (const block of fn.body.blocks.values()) {
|
||||||
for (const instr of block.instructions) {
|
for (const instr of block.instructions) {
|
||||||
const value = instr.value;
|
const value = instr.value;
|
||||||
switch (value.kind) {
|
switch (value.kind) {
|
||||||
case 'StoreContext': {
|
case 'StoreContext': {
|
||||||
errors.pushDiagnostic(
|
if (context.has(value.lvalue.place.identifier.id)) {
|
||||||
CompilerDiagnostic.create({
|
errors.pushDiagnostic(
|
||||||
category: ErrorCategory.UseMemo,
|
CompilerDiagnostic.create({
|
||||||
reason:
|
category: ErrorCategory.UseMemo,
|
||||||
'useMemo() callbacks may not reassign variables declared outside of the callback',
|
reason:
|
||||||
description:
|
'useMemo() callbacks may not reassign variables declared outside of the callback',
|
||||||
'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
|
description:
|
||||||
suggestions: null,
|
'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
|
||||||
}).withDetails({
|
suggestions: null,
|
||||||
kind: 'error',
|
}).withDetails({
|
||||||
loc: value.lvalue.place.loc,
|
kind: 'error',
|
||||||
message: 'Cannot reassign variable',
|
loc: value.lvalue.place.loc,
|
||||||
}),
|
message: 'Cannot reassign variable',
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// @flow
|
||||||
|
export hook useItemLanguage(items) {
|
||||||
|
return useMemo(() => {
|
||||||
|
let language: ?string = null;
|
||||||
|
items.forEach(item => {
|
||||||
|
if (item.language != null) {
|
||||||
|
language = item.language;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return language;
|
||||||
|
}, [items]);
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Code
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { c as _c } from "react/compiler-runtime";
|
||||||
|
export function useItemLanguage(items) {
|
||||||
|
const $ = _c(2);
|
||||||
|
let language;
|
||||||
|
if ($[0] !== items) {
|
||||||
|
language = null;
|
||||||
|
items.forEach((item) => {
|
||||||
|
if (item.language != null) {
|
||||||
|
language = item.language;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$[0] = items;
|
||||||
|
$[1] = language;
|
||||||
|
} else {
|
||||||
|
language = $[1];
|
||||||
|
}
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Eval output
|
||||||
|
(kind: exception) Fixture not implemented
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// @flow
|
||||||
|
export hook useItemLanguage(items) {
|
||||||
|
return useMemo(() => {
|
||||||
|
let language: ?string = null;
|
||||||
|
items.forEach(item => {
|
||||||
|
if (item.language != null) {
|
||||||
|
language = item.language;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return language;
|
||||||
|
}, [items]);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user