[ez] Patch unsound array destructuring

--- 

Going to hold off on landing until after codefreeze, it's not urgent as we 
already fixed playground in #2404. All other internal pipelines do error 
handling through Entrypoint, which catches and creates UnexpectedErrors as 
needed.
This commit is contained in:
Mofei Zhang
2023-11-28 17:48:22 -05:00
parent 0a6d3b31de
commit 359b9b1589
@@ -5,7 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/
import { Effect, HIRFunction, IdentifierId } from "../HIR";
import { CompilerError } from "..";
import {
Effect,
HIRFunction,
IdentifierId,
Place,
SpreadPattern,
} from "../HIR";
import { HookKind } from "../HIR/ObjectShape";
/*
@@ -53,8 +60,16 @@ export function dropManualMemoization(func: HIRFunction): void {
const hookKind = hooks.get(id);
if (hookKind != null) {
if (hookKind === "useMemo") {
const [fn] = instr.value.args;
const [fn] = instr.value.args as Array<
Place | SpreadPattern | undefined
>;
if (fn == null) {
CompilerError.throwInvalidReact({
reason: "Expected useMemo call to pass a callback function",
loc: instr.loc,
suggestions: null,
});
}
/*
* TODO(gsn): Consider inlining the function passed to useMemo,
* rather than just calling it directly.
@@ -80,7 +95,16 @@ export function dropManualMemoization(func: HIRFunction): void {
};
}
} else if (hookKind === "useCallback") {
const [fn] = instr.value.args;
const [fn] = instr.value.args as Array<
Place | SpreadPattern | undefined
>;
if (fn == null) {
CompilerError.throwInvalidReact({
reason: "Expected useMemo call to pass a callback function",
loc: instr.loc,
suggestions: null,
});
}
/*
* Instead of a Call, just alias the callback directly.