[dx] Update error messages for manual memo validation

ghstack-source-id: 1a88145049d7f7acb01748ad6ec4dd1500781766
Pull Request resolved: https://github.com/facebook/react-forget/pull/2861
This commit is contained in:
Joe Savona
2024-04-18 09:21:22 -07:00
parent c84ff16afb
commit 8c8bd00c04
4 changed files with 9 additions and 9 deletions
@@ -282,14 +282,14 @@ function extractManualMemoizationArgs(
>;
if (fnPlace == null) {
CompilerError.throwInvalidReact({
reason: `Expected ${kind} call to pass a callback function`,
reason: `Expected a callback function to be passed to ${kind}`,
loc: instr.value.loc,
suggestions: null,
});
}
if (fnPlace?.kind !== "Identifier" || depsListPlace?.kind === "Spread") {
if (fnPlace.kind === "Spread" || depsListPlace?.kind === "Spread") {
CompilerError.throwInvalidReact({
reason: `Unexpected arguments to ${kind} call`,
reason: `Unexpected spread argument to ${kind}`,
loc: instr.value.loc,
suggestions: null,
});
@@ -301,7 +301,7 @@ function extractManualMemoizationArgs(
);
if (maybeDepsList == null) {
CompilerError.throwInvalidReact({
reason: `Expected the dependency list for ${kind} to be an array literal without rest spreads`,
reason: `Expected the dependency list to be an array literal without rest spreads`,
suggestions: null,
loc: depsListPlace.loc,
});
@@ -310,7 +310,7 @@ function extractManualMemoizationArgs(
const maybeDep = sidemap.maybeDeps.get(dep.identifier.id);
if (maybeDep == null) {
CompilerError.throwInvalidReact({
reason: `Expected the dependency list for ${kind} to be an array of simple expressions`,
reason: `Expected the dependency list to be an array of simple expressions (e.g. \`x\`, \`x.y.z\`, \`x?.y?.z\`)`,
suggestions: null,
loc: dep.loc,
});
@@ -398,7 +398,7 @@ export function dropManualMemoization(func: HIRFunction): void {
*/
if (!sidemap.functions.has(fnPlace.identifier.id)) {
CompilerError.throwInvalidReact({
reason: `Expected the first argument of ${manualMemo.kind} to be an inline function expression`,
reason: `Expected the first argument to be an inline function expression`,
suggestions: [],
loc: fnPlace.loc,
});
@@ -31,7 +31,7 @@ export const FIXTURE_ENTRYPOINT = {
8 | return text.toUpperCase();
9 | },
> 10 | hasDeps ? null : [text] // should be DCE'd
| ^^^^^^^^^^^^^^^^^^^^^^^ InvalidReact: Expected the dependency list for useMemo to be an array literal without rest spreads (10:10)
| ^^^^^^^^^^^^^^^^^^^^^^^ InvalidReact: Expected the dependency list to be an array literal without rest spreads (10:10)
11 | );
12 | return resolvedText;
13 | }
@@ -31,7 +31,7 @@ export const FIXTURE_ENTRYPOINT = {
11 | const x = makeArray(props);
12 | // react-hooks-deps lint would already fail here
> 13 | return useMemo(() => [x[0]], [x[0]]);
| ^^^^ InvalidReact: Expected the dependency list for useMemo to be an array of simple expressions (13:13)
| ^^^^ InvalidReact: Expected the dependency list to be an array of simple expressions (e.g. `x`, `x.y.z`, `x?.y?.z`) (13:13)
14 | }
15 |
16 | export const FIXTURE_ENTRYPOINT = {
@@ -23,7 +23,7 @@ function Component(props) {
7 | // for now.
8 | function Component(props) {
> 9 | const x = useMemo(someHelper, []);
| ^^^^^^^^^^ InvalidReact: Expected the first argument of useMemo to be an inline function expression (9:9)
| ^^^^^^^^^^ InvalidReact: Expected the first argument to be an inline function expression (9:9)
10 | return x;
11 | }
12 |