Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
makeScopeId,
} from './HIR';
import {
BuiltInArrayId,
BuiltInMixedReadonlyId,
DefaultMutatingHook,
DefaultNonmutatingHook,
Expand Down Expand Up @@ -1000,6 +1001,24 @@ export class Environment {
}
} else if (typeof property === 'string' && isHookName(property)) {
return this.#getCustomHookType();
} else if (receiver.kind === 'Type' && typeof property === 'string') {
/*
* For unknown receiver types, try to resolve from the BuiltInArray shape
* but only for methods also present in MixedReadonly (the safe subset).
* If .map() is called on an unknown type, the value must be array-like.
* We use the Array shape (not MixedReadonly) because it has aliasing
* signatures that correctly model data flow without over-extending
* mutable ranges. See ObjectShape.ts BuiltInMixedReadonlyId for details.
*/
const mixedShape = this.#shapes.get(BuiltInMixedReadonlyId);
const arrayShape = this.#shapes.get(BuiltInArrayId);
if (
mixedShape !== undefined &&
arrayShape !== undefined &&
mixedShape.properties.has(property)
) {
return arrayShape.properties.get(property) ?? null;
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

## Input

```javascript
function ExpensiveComponent({data, onClick}) {
const processedData = expensiveProcessing(data);
return (
<ul>
{processedData.map((item) => (
<li key={item.id} onClick={() => onClick(item)}>
{item.name}
</li>
))}
</ul>
);
}

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
function ExpensiveComponent(t0) {
const $ = _c(5);
const {
data,
onClick
} = t0;
let t1;
if ($[0] !== data) {
t1 = expensiveProcessing(data);
$[0] = data;
$[1] = t1;
} else {
t1 = $[1];
}
const processedData = t1;
let t2;
if ($[2] !== onClick || $[3] !== processedData) {
t2 = <ul>{processedData.map(item => <li key={item.id} onClick={() => onClick(item)}>{item.name}</li>)}</ul>;
$[2] = onClick;
$[3] = processedData;
$[4] = t2;
} else {
t2 = $[4];
}
return t2;
}

```

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function ExpensiveComponent({data, onClick}) {
const processedData = expensiveProcessing(data);
return (
<ul>
{processedData.map((item) => (
<li key={item.id} onClick={() => onClick(item)}>
{item.name}
</li>
))}
</ul>
);
}