JSTQL-JS-Transform/output_testing/1100useMemo-mabye-modified-free-variable-preserve-memoization-guarantees.js

31 lines
965 B
JavaScript
Raw Normal View History

// @enablePreserveExistingMemoizationGuarantees
import { useMemo } from "react";
import { identity, makeObject_Primitives, mutate, useHook } from "shared-runtime";
function Component(props) {
// With the feature enabled these variables are inferred as frozen as of
// the useMemo call
const free = makeObject_Primitives();
const free2 = makeObject_Primitives();
const part = free2.part;
// Thus their mutable range ends prior to this hook call, and both the above
// values and the useMemo block value can be memoized
useHook();
const object = (() => {
const x = makeObject_Primitives();
x.value = props.value;
mutate(x, free, part);
return x;
}) |> useMemo(%, [props.value, free, part]);
// These calls should be inferred as non-mutating due to the above freeze inference
free |> identity(%);
part |> identity(%);
return object;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{
value: 42
}]
};