@samitouri / QOS-React / commits / 8c8bd00c04

[dx] Update error messages for manual memo validation

ghstack-source-id: 1a88145049d7f7acb01748ad6ec4dd1500781766 Pull Request resolved: https://github.com/facebook/react-forget/pull/2861

Joe Savona committed Apr 18, 2024 at 09:21 UTC 8c8bd00c04177eedebf31b3284f9c2a2b4958d66
4 files changed +9 -9
compiler/packages/babel-plugin-react-forget/src/Inference/DropManualMemoization.ts
+6 -6
@@ -282,14 +282,14 @@ function extractManualMemoizationArgs(
282 >;
283 if (fnPlace == null) {
284 CompilerError.throwInvalidReact({
285 - reason: `Expected ${kind} call to pass a callback function`,
285 + reason: `Expected a callback function to be passed to ${kind}`,
286 loc: instr.value.loc,
287 suggestions: null,
288 });
289 }
290 - if (fnPlace?.kind !== "Identifier" || depsListPlace?.kind === "Spread") {
290 + if (fnPlace.kind === "Spread" || depsListPlace?.kind === "Spread") {
291 CompilerError.throwInvalidReact({
292 - reason: `Unexpected arguments to ${kind} call`,
292 + reason: `Unexpected spread argument to ${kind}`,
293 loc: instr.value.loc,
294 suggestions: null,
295 });
@@ -301,7 +301,7 @@ function extractManualMemoizationArgs(
301 );
302 if (maybeDepsList == null) {
303 CompilerError.throwInvalidReact({
304 - reason: `Expected the dependency list for ${kind} to be an array literal without rest spreads`,
304 + reason: `Expected the dependency list to be an array literal without rest spreads`,
305 suggestions: null,
306 loc: depsListPlace.loc,
307 });
@@ -310,7 +310,7 @@ function extractManualMemoizationArgs(
310 const maybeDep = sidemap.maybeDeps.get(dep.identifier.id);
311 if (maybeDep == null) {
312 CompilerError.throwInvalidReact({
313 - reason: `Expected the dependency list for ${kind} to be an array of simple expressions`,
313 + reason: `Expected the dependency list to be an array of simple expressions (e.g. \`x\`, \`x.y.z\`, \`x?.y?.z\`)`,
314 suggestions: null,
315 loc: dep.loc,
316 });
@@ -398,7 +398,7 @@ export function dropManualMemoization(func: HIRFunction): void {
398 */
399 if (!sidemap.functions.has(fnPlace.identifier.id)) {
400 CompilerError.throwInvalidReact({
401 - reason: `Expected the first argument of ${manualMemo.kind} to be an inline function expression`,
401 + reason: `Expected the first argument to be an inline function expression`,
402 suggestions: [],
403 loc: fnPlace.loc,
404 });
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.useMemo-non-literal-depslist.expect.md
+1 -1
@@ -31,7 +31,7 @@ export const FIXTURE_ENTRYPOINT = {
31 8 | return text.toUpperCase();
32 9 | },
33 > 10 | hasDeps ? null : [text] // should be DCE'd
34 - | ^^^^^^^^^^^^^^^^^^^^^^^ InvalidReact: Expected the dependency list for useMemo to be an array literal without rest spreads (10:10)
34 + | ^^^^^^^^^^^^^^^^^^^^^^^ InvalidReact: Expected the dependency list to be an array literal without rest spreads (10:10)
35 11 | );
36 12 | return resolvedText;
37 13 | }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/preserve-memo-validation/error.useMemo-dep-not-recognized.expect.md
+1 -1
@@ -31,7 +31,7 @@ export const FIXTURE_ENTRYPOINT = {
31 11 | const x = makeArray(props);
32 12 | // react-hooks-deps lint would already fail here
33 > 13 | return useMemo(() => [x[0]], [x[0]]);
34 - | ^^^^ InvalidReact: Expected the dependency list for useMemo to be an array of simple expressions (13:13)
34 + | ^^^^ InvalidReact: Expected the dependency list to be an array of simple expressions (e.g. `x`, `x.y.z`, `x?.y?.z`) (13:13)
35 14 | }
36 15 |
37 16 | export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/preserve-memo-validation/error.validate-useMemo-named-function.expect.md
+1 -1
@@ -23,7 +23,7 @@ function Component(props) {
23 7 | // for now.
24 8 | function Component(props) {
25 > 9 | const x = useMemo(someHelper, []);
26 - | ^^^^^^^^^^ InvalidReact: Expected the first argument of useMemo to be an inline function expression (9:9)
26 + | ^^^^^^^^^^ InvalidReact: Expected the first argument to be an inline function expression (9:9)
27 10 | return x;
28 11 | }
29 12 |