@samitouri / QOS-React-1 / commits / 359b9b1589

[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.

Mofei Zhang committed Nov 28, 2023 at 17:48 UTC 359b9b1589bcbe7988ff782ae88dcfaa2bdba927
1 file changed +28 -4
compiler/packages/babel-plugin-react-forget/src/Inference/DropManualMemoization.ts
+28 -4
@@ -5,7 +5,14 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import { Effect, HIRFunction, IdentifierId } from "../HIR";
8 +import { CompilerError } from "..";
9 +import {
10 + Effect,
11 + HIRFunction,
12 + IdentifierId,
13 + Place,
14 + SpreadPattern,
15 +} from "../HIR";
16 import { HookKind } from "../HIR/ObjectShape";
17
18 /*
@@ -53,8 +60,16 @@ export function dropManualMemoization(func: HIRFunction): void {
60 const hookKind = hooks.get(id);
61 if (hookKind != null) {
62 if (hookKind === "useMemo") {
56 - const [fn] = instr.value.args;
57 -
63 + const [fn] = instr.value.args as Array<
64 + Place | SpreadPattern | undefined
65 + >;
66 + if (fn == null) {
67 + CompilerError.throwInvalidReact({
68 + reason: "Expected useMemo call to pass a callback function",
69 + loc: instr.loc,
70 + suggestions: null,
71 + });
72 + }
73 /*
74 * TODO(gsn): Consider inlining the function passed to useMemo,
75 * rather than just calling it directly.
@@ -80,7 +95,16 @@ export function dropManualMemoization(func: HIRFunction): void {
95 };
96 }
97 } else if (hookKind === "useCallback") {
83 - const [fn] = instr.value.args;
98 + const [fn] = instr.value.args as Array<
99 + Place | SpreadPattern | undefined
100 + >;
101 + if (fn == null) {
102 + CompilerError.throwInvalidReact({
103 + reason: "Expected useMemo call to pass a callback function",
104 + loc: instr.loc,
105 + suggestions: null,
106 + });
107 + }
108
109 /*
110 * Instead of a Call, just alias the callback directly.