From f83cde79dc1b8e32f41594b1abfa850750c5c0fc Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Fri, 11 Jul 2025 10:33:13 -0700 Subject: [PATCH] [compiler] Cleanup diagnostic messages Minor sytlistic cleanup --- .../src/HIR/BuildHIR.ts | 13 +++--- .../Inference/InferMutationAliasingEffects.ts | 41 +++++++++---------- .../ValidateLocalsNotReassignedAfterRender.ts | 11 +++-- ...ValidateNoFreezingKnownMutableFunctions.ts | 14 +++++-- .../src/Validation/ValidateUseMemo.ts | 6 +-- .../src/__tests__/Logger-test.ts | 3 +- ...global-in-component-tag-function.expect.md | 4 +- ...or.assign-global-in-jsx-children.expect.md | 4 +- ...ive-ref-validation-in-use-effect.expect.md | 4 +- ...ext-variable-only-chained-assign.expect.md | 6 +-- ...variable-in-function-declaration.expect.md | 6 +-- ...erences-variable-its-assigned-to.expect.md | 6 +-- ...call-freezes-captured-identifier.expect.md | 4 +- ...call-freezes-captured-memberexpr.expect.md | 4 +- ...alid-ReactUseMemo-async-callback.expect.md | 4 +- .../error.invalid-array-push-frozen.expect.md | 4 +- ...d-computed-store-to-frozen-value.expect.md | 4 +- ...omputed-property-of-frozen-value.expect.md | 4 +- ...-delete-property-of-frozen-value.expect.md | 4 +- ...destructure-assignment-to-global.expect.md | 4 +- ...ucture-to-local-global-variables.expect.md | 4 +- ...pression-mutates-immutable-value.expect.md | 2 +- ...lid-global-reassignment-indirect.expect.md | 4 +- .../error.invalid-hoisting-setstate.expect.md | 6 +-- ...-argument-mutates-local-variable.expect.md | 6 +-- ...id-jsx-captures-context-variable.expect.md | 2 +- ...alid-mutate-after-aliased-freeze.expect.md | 4 +- ...rror.invalid-mutate-after-freeze.expect.md | 4 +- ...valid-mutate-context-in-callback.expect.md | 2 +- .../error.invalid-mutate-context.expect.md | 4 +- ...-mutate-props-in-effect-fixpoint.expect.md | 2 +- ...mutate-props-via-for-of-iterator.expect.md | 4 +- ...rror.invalid-mutation-in-closure.expect.md | 2 +- ...n-of-possible-props-phi-indirect.expect.md | 2 +- ...eassign-local-variable-in-effect.expect.md | 6 +-- ...d-reanimated-shared-value-writes.expect.md | 2 +- ...id-pass-mutable-function-as-prop.expect.md | 6 +-- ...r.invalid-prop-mutation-indirect.expect.md | 2 +- ...d-property-store-to-frozen-value.expect.md | 4 +- ...rops-mutation-in-effect-indirect.expect.md | 2 +- ...ssign-local-in-hook-return-value.expect.md | 6 +-- ...eassign-local-variable-in-effect.expect.md | 6 +-- ...-local-variable-in-hook-argument.expect.md | 6 +-- ...n-local-variable-in-jsx-callback.expect.md | 6 +-- ...eturn-mutable-function-from-hook.expect.md | 6 +-- ...es-memoizes-with-captures-values.expect.md | 6 +-- ...r.invalid-useMemo-async-callback.expect.md | 4 +- ...or.invalid-useMemo-callback-args.expect.md | 2 +- .../compiler/error.modify-state-2.expect.md | 4 +- .../compiler/error.modify-state.expect.md | 4 +- .../error.modify-useReducer-state.expect.md | 4 +- ...ange-shared-inner-outer-function.expect.md | 6 +-- .../error.mutate-function-property.expect.md | 4 +- .../error.mutate-hook-argument.expect.md | 8 ++-- ...rror.mutate-property-from-global.expect.md | 4 +- .../compiler/error.mutate-props.expect.md | 4 +- ...or.not-useEffect-external-mutate.expect.md | 8 ++-- .../error.reassign-global-fn-arg.expect.md | 4 +- ....reassignment-to-global-indirect.expect.md | 8 ++-- .../error.reassignment-to-global.expect.md | 8 ++-- .../error.store-property-in-global.expect.md | 4 +- ...ences-later-variable-declaration.expect.md | 6 +-- ...ror.update-global-should-bailout.expect.md | 4 +- ...e-after-useeffect-optional-chain.expect.md | 2 +- ...utate-after-useeffect-ref-access.expect.md | 2 +- .../mutate-after-useeffect.expect.md | 2 +- .../no-emit/retry-no-emit.expect.md | 2 +- ...n-local-variable-in-jsx-callback.expect.md | 6 +-- ...rozen-hoisted-storecontext-const.expect.md | 6 +-- .../error.mutate-frozen-value.expect.md | 4 +- .../error.mutate-hook-argument.expect.md | 8 ++-- ...or.not-useEffect-external-mutate.expect.md | 8 ++-- ....reassignment-to-global-indirect.expect.md | 8 ++-- .../error.reassignment-to-global.expect.md | 8 ++-- ...e-after-useeffect-optional-chain.expect.md | 2 +- ...utate-after-useeffect-ref-access.expect.md | 2 +- .../mutate-after-useeffect.expect.md | 2 +- .../new-mutability/retry-no-emit.expect.md | 2 +- .../__tests__/ReactCompilerRule-test.ts | 4 +- .../ReactCompilerRuleTypescript-test.ts | 2 +- .../__tests__/ReactCompilerRule-test.ts | 4 +- .../ReactCompilerRuleTypescript-test.ts | 2 +- 82 files changed, 212 insertions(+), 206 deletions(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts index 9ea406ef8d..807325a2ab 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts @@ -107,10 +107,9 @@ export function lower( if (binding.kind !== 'Identifier') { builder.errors.pushDiagnostic( CompilerDiagnostic.create({ - category: 'Could not find binding', - description: `[BuildHIR] Could not find binding for param \`${param.node.name}\``, severity: ErrorSeverity.Invariant, - suggestions: null, + category: 'Could not find binding', + description: `[BuildHIR] Could not find binding for param \`${param.node.name}\`.`, }).withDetail({ kind: 'error', loc: param.node.loc ?? null, @@ -172,10 +171,9 @@ export function lower( } else { builder.errors.pushDiagnostic( CompilerDiagnostic.create({ - category: `Handle ${param.node.type} parameters`, - description: `[BuildHIR] Add support for ${param.node.type} parameters`, severity: ErrorSeverity.Todo, - suggestions: null, + category: `Handle ${param.node.type} parameters`, + description: `[BuildHIR] Add support for ${param.node.type} parameters.`, }).withDetail({ kind: 'error', loc: param.node.loc ?? null, @@ -205,8 +203,7 @@ export function lower( CompilerDiagnostic.create({ severity: ErrorSeverity.InvalidJS, category: `Unexpected function body kind`, - description: `Expected function body to be an expression or a block statement, got \`${body.type}\``, - suggestions: null, + description: `Expected function body to be an expression or a block statement, got \`${body.type}\`.`, }).withDetail({ kind: 'error', loc: body.node.loc ?? null, diff --git a/compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts b/compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts index dfee0a10fb..c7913fbb46 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts @@ -447,23 +447,22 @@ function applySignature( reason: value.reason, context: new Set(), }); - const message = + const variable = effect.value.identifier.name !== null && effect.value.identifier.name.kind === 'named' - ? `\`${effect.value.identifier.name.value}\` cannot be modified` - : 'This value cannot be modified'; + ? `\`${effect.value.identifier.name.value}\`` + : 'value'; effects.push({ kind: 'MutateFrozen', place: effect.value, error: CompilerDiagnostic.create({ severity: ErrorSeverity.InvalidReact, category: 'This value cannot be modified', - description: reason, - suggestions: null, + description: `${reason}.`, }).withDetail({ kind: 'error', loc: effect.value.loc, - message, + message: `${variable} cannot be modified`, }), }); } @@ -1018,30 +1017,30 @@ function applyEffect( effect.value.identifier.declarationId, ) ) { - const description = + const variable = effect.value.identifier.name !== null && effect.value.identifier.name.kind === 'named' - ? `Variable \`${effect.value.identifier.name.value}\`` - : 'This variable'; + ? `\`${effect.value.identifier.name.value}\`` + : null; const hoistedAccess = context.hoistedContextDeclarations.get( effect.value.identifier.declarationId, ); const diagnostic = CompilerDiagnostic.create({ severity: ErrorSeverity.InvalidReact, category: 'Cannot access variable before it is declared', - description: `${description} is accessed before it is declared, which prevents the earlier access from updating when this value changes over time`, + description: `${variable ?? 'This variable'} is accessed before it is declared, which prevents the earlier access from updating when this value changes over time.`, }); if (hoistedAccess != null && hoistedAccess.loc != effect.value.loc) { diagnostic.withDetail({ kind: 'error', loc: hoistedAccess.loc, - message: 'Variable accessed before it is declared', + message: `${variable ?? 'variable'} accessed before it is declared`, }); } diagnostic.withDetail({ kind: 'error', loc: effect.value.loc, - message: 'The variable is declared here', + message: `${variable ?? 'variable'} is declared here`, }); applyEffect( @@ -1061,11 +1060,11 @@ function applyEffect( reason: value.reason, context: new Set(), }); - const message = + const variable = effect.value.identifier.name !== null && effect.value.identifier.name.kind === 'named' - ? `\`${effect.value.identifier.name.value}\` cannot be modified` - : 'This value cannot be modified'; + ? `\`${effect.value.identifier.name.value}\`` + : 'value'; applyEffect( context, state, @@ -1078,11 +1077,11 @@ function applyEffect( error: CompilerDiagnostic.create({ severity: ErrorSeverity.InvalidReact, category: 'This value cannot be modified', - description: reason, + description: `${reason}.`, }).withDetail({ kind: 'error', loc: effect.value.loc, - message, + message: `${variable} cannot be modified`, }), }, initialized, @@ -1987,6 +1986,7 @@ function computeSignatureForInstruction( break; } case 'StoreGlobal': { + const variable = `\`${value.name}\``; effects.push({ kind: 'MutateGlobal', place: value.value, @@ -1994,13 +1994,11 @@ function computeSignatureForInstruction( severity: ErrorSeverity.InvalidReact, category: 'Cannot reassign variables declared outside of the component/hook', - description: - 'Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)', - suggestions: null, + description: `Variable ${variable} is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)`, }).withDetail({ kind: 'error', loc: instr.loc, - message: 'Cannot reassign variable', + message: `${variable} cannot be reassigned`, }), }); effects.push({kind: 'Assign', from: value.value, into: lvalue}); @@ -2099,7 +2097,6 @@ function computeEffectsForLegacySignature( ? `\`${signature.canonicalName}\` is an impure function. ` : '') + 'Calling an impure function can produce unstable results that update unpredictably when the component happens to re-render. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)', - suggestions: null, }).withDetail({ kind: 'error', loc, diff --git a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateLocalsNotReassignedAfterRender.ts b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateLocalsNotReassignedAfterRender.ts index 569bbbdc2d..a44770e180 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateLocalsNotReassignedAfterRender.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateLocalsNotReassignedAfterRender.ts @@ -29,15 +29,20 @@ export function validateLocalsNotReassignedAfterRender(fn: HIRFunction): void { ); if (reassignment !== null) { const errors = new CompilerError(); + const variable = + reassignment.identifier.name != null && + reassignment.identifier.name.kind === 'named' + ? `\`${reassignment.identifier.name.value}\`` + : 'variable'; errors.pushDiagnostic( CompilerDiagnostic.create({ severity: ErrorSeverity.InvalidReact, - category: 'Cannot reassign a variable after render completes', - description: `Reassigning ${reassignment.identifier.name != null && reassignment.identifier.name.kind === 'named' ? `variable \`${reassignment.identifier.name.value}\`` : 'a variable'} after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead`, + category: 'Cannot reassign variable after render completes', + description: `Reassigning ${variable} after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead.`, }).withDetail({ kind: 'error', loc: reassignment.loc, - message: 'Cannot reassign variable after render completes', + message: `Cannot reassign ${variable} after render completes`, }), ); throw errors; diff --git a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoFreezingKnownMutableFunctions.ts b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoFreezingKnownMutableFunctions.ts index b988183530..7a79c74780 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoFreezingKnownMutableFunctions.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoFreezingKnownMutableFunctions.ts @@ -57,22 +57,28 @@ export function validateNoFreezingKnownMutableFunctions( if (operand.effect === Effect.Freeze) { const effect = contextMutationEffects.get(operand.identifier.id); if (effect != null) { + const place = [...effect.places][0]; + const variable = + place != null && + place.identifier.name != null && + place.identifier.name.kind === 'named' + ? `\`${place.identifier.name.value}\`` + : 'a local variable'; errors.pushDiagnostic( CompilerDiagnostic.create({ severity: ErrorSeverity.InvalidReact, category: 'Cannot modify local variables after render completes', - description: `This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead`, + description: `This argument is a function which may reassign or mutate ${variable} after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead.`, }) .withDetail({ kind: 'error', loc: operand.loc, - message: - 'This function may (indirectly) reassign or modify local variables after render', + message: `This function may (indirectly) reassign or modify ${variable} after render`, }) .withDetail({ kind: 'error', loc: effect.loc, - message: 'This modifies a local variable', + message: `This modifies ${variable}`, }), ); } diff --git a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts index 7c83e65dff..69ab401c89 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts @@ -82,7 +82,7 @@ export function validateUseMemo(fn: HIRFunction): Result { }).withDetail({ kind: 'error', loc, - message: '', + message: 'Callbacks with parameters are not supported', }), ); } @@ -92,9 +92,9 @@ export function validateUseMemo(fn: HIRFunction): Result { CompilerDiagnostic.create({ severity: ErrorSeverity.InvalidReact, category: - 'useMemo callbacks may not be async or generator functions', + 'useMemo() callbacks may not be async or generator functions', description: - 'useMemo() callbacks are called once and must synchronously return a value', + 'useMemo() callbacks are called once and must synchronously return a value.', suggestions: null, }).withDetail({ kind: 'error', diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/Logger-test.ts b/compiler/packages/babel-plugin-react-compiler/src/__tests__/Logger-test.ts index 4b41068f4e..096b723554 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/Logger-test.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/Logger-test.ts @@ -58,7 +58,8 @@ it('logs failed compilation', () => { expect(event.detail.severity).toEqual('InvalidReact'); //@ts-ignore - const {start, end, identifierName} = event.detail.loc as t.SourceLocation; + const {start, end, identifierName} = + event.detail.primaryLocation() as t.SourceLocation; expect(start).toEqual({column: 28, index: 28, line: 1}); expect(end).toEqual({column: 33, index: 33, line: 1}); expect(identifierName).toEqual('props'); diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.assign-global-in-component-tag-function.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.assign-global-in-component-tag-function.expect.md index daf0071d25..242a1a8b7d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.assign-global-in-component-tag-function.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.assign-global-in-component-tag-function.expect.md @@ -18,13 +18,13 @@ function Component() { Found 1 error: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `someGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.assign-global-in-component-tag-function.ts:3:4 1 | function Component() { 2 | const Foo = () => { > 3 | someGlobal = true; - | ^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^ `someGlobal` cannot be reassigned 4 | }; 5 | return ; 6 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.assign-global-in-jsx-children.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.assign-global-in-jsx-children.expect.md index 81c7be61ac..cf9d9de298 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.assign-global-in-jsx-children.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.assign-global-in-jsx-children.expect.md @@ -21,13 +21,13 @@ function Component() { Found 1 error: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `someGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.assign-global-in-jsx-children.ts:3:4 1 | function Component() { 2 | const foo = () => { > 3 | someGlobal = true; - | ^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^ `someGlobal` cannot be reassigned 4 | }; 5 | // Children are generally access/called during render, so 6 | // modifying a global in a children function is almost diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-old-inference-false-positive-ref-validation-in-use-effect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-old-inference-false-positive-ref-validation-in-use-effect.expect.md index a33ff7ce76..7227c71737 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-old-inference-false-positive-ref-validation-in-use-effect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-old-inference-false-positive-ref-validation-in-use-effect.expect.md @@ -39,7 +39,7 @@ function Component() { Found 1 error: Error: Cannot modify local variables after render completes -This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead +This argument is a function which may reassign or mutate a local variable after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead. error.bug-old-inference-false-positive-ref-validation-in-use-effect.ts:20:12 18 | ); @@ -53,7 +53,7 @@ error.bug-old-inference-false-positive-ref-validation-in-use-effect.ts:20:12 > 23 | } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 24 | }, [update]); - | ^^^^ This function may (indirectly) reassign or modify local variables after render + | ^^^^ This function may (indirectly) reassign or modify a local variable after render 25 | 26 | return 'ok'; 27 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.context-variable-only-chained-assign.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.context-variable-only-chained-assign.expect.md index 408537c5b8..a35b059579 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.context-variable-only-chained-assign.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.context-variable-only-chained-assign.expect.md @@ -29,15 +29,15 @@ export const FIXTURE_ENTRYPOINT = { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.context-variable-only-chained-assign.ts:10:19 8 | }; 9 | const fn2 = () => { > 10 | const copy2 = (x = 4); - | ^ Cannot reassign variable after render completes + | ^ Cannot reassign `x` after render completes 11 | return [invoke(fn1), copy2, identity(copy2)]; 12 | }; 13 | return invoke(fn2); diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.declare-reassign-variable-in-function-declaration.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.declare-reassign-variable-in-function-declaration.expect.md index 2c1c7657f7..df1e63517b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.declare-reassign-variable-in-function-declaration.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.declare-reassign-variable-in-function-declaration.expect.md @@ -18,15 +18,15 @@ function Component() { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.declare-reassign-variable-in-function-declaration.ts:4:4 2 | let x = null; 3 | function foo() { > 4 | x = 9; - | ^ Cannot reassign variable after render completes + | ^ Cannot reassign `x` after render completes 5 | } 6 | const y = bar(foo); 7 | return ; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.function-expression-references-variable-its-assigned-to.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.function-expression-references-variable-its-assigned-to.expect.md index fba4e272ee..1cabbb8651 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.function-expression-references-variable-its-assigned-to.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.function-expression-references-variable-its-assigned-to.expect.md @@ -16,15 +16,15 @@ function Component() { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `callback` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `callback` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.function-expression-references-variable-its-assigned-to.ts:3:4 1 | function Component() { 2 | let callback = () => { > 3 | callback = null; - | ^^^^^^^^ Cannot reassign variable after render completes + | ^^^^^^^^ Cannot reassign `callback` after render completes 4 | }; 5 | return
; 6 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-call-freezes-captured-identifier.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-call-freezes-captured-identifier.expect.md index aaccfe84d8..9b54803ba5 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-call-freezes-captured-identifier.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-call-freezes-captured-identifier.expect.md @@ -32,13 +32,13 @@ export const FIXTURE_ENTRYPOINT = { Found 1 error: Error: This value cannot be modified -Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook +Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook. error.hook-call-freezes-captured-identifier.ts:13:2 11 | }); 12 | > 13 | x.value += count; - | ^ This value cannot be modified + | ^ value cannot be modified 14 | return ; 15 | } 16 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-call-freezes-captured-memberexpr.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-call-freezes-captured-memberexpr.expect.md index 755aa6d68f..7e03b75639 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-call-freezes-captured-memberexpr.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.hook-call-freezes-captured-memberexpr.expect.md @@ -32,13 +32,13 @@ export const FIXTURE_ENTRYPOINT = { Found 1 error: Error: This value cannot be modified -Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook +Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook. error.hook-call-freezes-captured-memberexpr.ts:13:2 11 | }); 12 | > 13 | x.value += count; - | ^ This value cannot be modified + | ^ value cannot be modified 14 | return ; 15 | } 16 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-ReactUseMemo-async-callback.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-ReactUseMemo-async-callback.expect.md index 2f8fd0e671..ac72e061a7 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-ReactUseMemo-async-callback.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-ReactUseMemo-async-callback.expect.md @@ -16,9 +16,9 @@ function component(a, b) { ``` Found 1 error: -Error: useMemo callbacks may not be async or generator functions +Error: useMemo() callbacks may not be async or generator functions -useMemo() callbacks are called once and must synchronously return a value +useMemo() callbacks are called once and must synchronously return a value. error.invalid-ReactUseMemo-async-callback.ts:2:24 1 | function component(a, b) { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-array-push-frozen.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-array-push-frozen.expect.md index 356b3b7c10..d23015728f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-array-push-frozen.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-array-push-frozen.expect.md @@ -18,13 +18,13 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX +Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX. error.invalid-array-push-frozen.ts:4:2 2 | const x = []; 3 |
{x}
; > 4 | x.push(props.value); - | ^ This value cannot be modified + | ^ value cannot be modified 5 | return x; 6 | } 7 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-computed-store-to-frozen-value.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-computed-store-to-frozen-value.expect.md index 585680500b..70c6e6313f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-computed-store-to-frozen-value.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-computed-store-to-frozen-value.expect.md @@ -19,13 +19,13 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX +Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX. error.invalid-computed-store-to-frozen-value.ts:5:2 3 | // freeze 4 |
{x}
; > 5 | x[0] = true; - | ^ This value cannot be modified + | ^ value cannot be modified 6 | return x; 7 | } 8 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-delete-computed-property-of-frozen-value.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-delete-computed-property-of-frozen-value.expect.md index 27c04ffc5e..25923b6c38 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-delete-computed-property-of-frozen-value.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-delete-computed-property-of-frozen-value.expect.md @@ -19,13 +19,13 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX +Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX. error.invalid-delete-computed-property-of-frozen-value.ts:5:9 3 | // freeze 4 |
{x}
; > 5 | delete x[y]; - | ^ This value cannot be modified + | ^ value cannot be modified 6 | return x; 7 | } 8 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-delete-property-of-frozen-value.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-delete-property-of-frozen-value.expect.md index bd3269326c..455e70de0b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-delete-property-of-frozen-value.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-delete-property-of-frozen-value.expect.md @@ -19,13 +19,13 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX +Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX. error.invalid-delete-property-of-frozen-value.ts:5:9 3 | // freeze 4 |
{x}
; > 5 | delete x.y; - | ^ This value cannot be modified + | ^ value cannot be modified 6 | return x; 7 | } 8 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-destructure-assignment-to-global.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-destructure-assignment-to-global.expect.md index 2dd40f203e..9ee511af36 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-destructure-assignment-to-global.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-destructure-assignment-to-global.expect.md @@ -16,12 +16,12 @@ function useFoo(props) { Found 1 error: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `x` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.invalid-destructure-assignment-to-global.ts:2:3 1 | function useFoo(props) { > 2 | [x] = props; - | ^ Cannot reassign variable + | ^ `x` cannot be reassigned 3 | return {x}; 4 | } 5 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-destructure-to-local-global-variables.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-destructure-to-local-global-variables.expect.md index 81dd728b85..62d47cbd3e 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-destructure-to-local-global-variables.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-destructure-to-local-global-variables.expect.md @@ -18,13 +18,13 @@ function Component(props) { Found 1 error: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `b` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.invalid-destructure-to-local-global-variables.ts:3:6 1 | function Component(props) { 2 | let a; > 3 | [a, b] = props.value; - | ^ Cannot reassign variable + | ^ `b` cannot be reassigned 4 | 5 | return [a, b]; 6 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-function-expression-mutates-immutable-value.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-function-expression-mutates-immutable-value.expect.md index 6de3c555e9..f22a56722b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-function-expression-mutates-immutable-value.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-function-expression-mutates-immutable-value.expect.md @@ -21,7 +21,7 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead +Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead. error.invalid-function-expression-mutates-immutable-value.ts:5:4 3 | const onChange = e => { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-global-reassignment-indirect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-global-reassignment-indirect.expect.md index a6579893b0..4223b49f9d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-global-reassignment-indirect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-global-reassignment-indirect.expect.md @@ -38,13 +38,13 @@ export const FIXTURE_ENTRYPOINT = { Found 1 error: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `someGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.invalid-global-reassignment-indirect.ts:9:4 7 | 8 | const setGlobal = () => { > 9 | someGlobal = true; - | ^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^ `someGlobal` cannot be reassigned 10 | }; 11 | const indirectSetGlobal = () => { 12 | setGlobal(); diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-hoisting-setstate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-hoisting-setstate.expect.md index 6573418aee..38077a8dd4 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-hoisting-setstate.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-hoisting-setstate.expect.md @@ -41,13 +41,13 @@ export const FIXTURE_ENTRYPOINT = { Found 1 error: Error: Cannot access variable before it is declared -Variable `setState` is accessed before it is declared, which prevents the earlier access from updating when this value changes over time +`setState` is accessed before it is declared, which prevents the earlier access from updating when this value changes over time. error.invalid-hoisting-setstate.ts:19:18 17 | * $2 = Function context=setState 18 | */ > 19 | useEffect(() => setState(2), []); - | ^^^^^^^^ Variable accessed before it is declared + | ^^^^^^^^ `setState` accessed before it is declared 20 | 21 | const [state, setState] = useState(0); 22 | return ; @@ -56,7 +56,7 @@ error.invalid-hoisting-setstate.ts:21:16 19 | useEffect(() => setState(2), []); 20 | > 21 | const [state, setState] = useState(0); - | ^^^^^^^^ The variable is declared here + | ^^^^^^^^ `setState` is declared here 22 | return ; 23 | } 24 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-hook-function-argument-mutates-local-variable.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-hook-function-argument-mutates-local-variable.expect.md index 8d9be03b42..0d02cab29f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-hook-function-argument-mutates-local-variable.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-hook-function-argument-mutates-local-variable.expect.md @@ -20,7 +20,7 @@ function useFoo() { Found 1 error: Error: Cannot modify local variables after render completes -This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead +This argument is a function which may reassign or mutate `cache` after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead. error.invalid-hook-function-argument-mutates-local-variable.ts:5:10 3 | function useFoo() { @@ -30,7 +30,7 @@ error.invalid-hook-function-argument-mutates-local-variable.ts:5:10 > 6 | cache.set('key', 'value'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 7 | }); - | ^^^^ This function may (indirectly) reassign or modify local variables after render + | ^^^^ This function may (indirectly) reassign or modify `cache` after render 8 | } 9 | @@ -38,7 +38,7 @@ error.invalid-hook-function-argument-mutates-local-variable.ts:6:4 4 | const cache = new Map(); 5 | useHook(() => { > 6 | cache.set('key', 'value'); - | ^^^^^ This modifies a local variable + | ^^^^^ This modifies `cache` 7 | }); 8 | } 9 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-jsx-captures-context-variable.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-jsx-captures-context-variable.expect.md index b4a4d2df42..0faf1d8613 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-jsx-captures-context-variable.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-jsx-captures-context-variable.expect.md @@ -53,7 +53,7 @@ export const FIXTURE_ENTRYPOINT = { Found 1 error: Error: This value cannot be modified -Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX +Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX. error.invalid-jsx-captures-context-variable.ts:22:2 20 | /> diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-after-aliased-freeze.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-after-aliased-freeze.expect.md index 591f3fb53e..32c5191036 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-after-aliased-freeze.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-after-aliased-freeze.expect.md @@ -28,13 +28,13 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX +Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX. error.invalid-mutate-after-aliased-freeze.ts:13:2 11 | // y is MaybeFrozen at this point, since it may alias to x 12 | // (which is the above line freezes) > 13 | y.push(props.p2); - | ^ This value cannot be modified + | ^ value cannot be modified 14 | 15 | return ; 16 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-after-freeze.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-after-freeze.expect.md index 4636b3432d..5507ad3c44 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-after-freeze.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-after-freeze.expect.md @@ -22,13 +22,13 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX +Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX. error.invalid-mutate-after-freeze.ts:7:2 5 | 6 | // x is Frozen at this point > 7 | x.push(props.p2); - | ^ This value cannot be modified + | ^ value cannot be modified 8 | 9 | return
{_}
; 10 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-context-in-callback.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-context-in-callback.expect.md index e97eb19123..a4bde44ed8 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-context-in-callback.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-context-in-callback.expect.md @@ -27,7 +27,7 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value returned from 'useContext()' is not allowed. +Modifying a value returned from 'useContext()' is not allowed.. error.invalid-mutate-context-in-callback.ts:12:4 10 | // independently diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-context.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-context.expect.md index de4c69512f..60058c16ad 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-context.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-context.expect.md @@ -17,13 +17,13 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value returned from 'useContext()' is not allowed. +Modifying a value returned from 'useContext()' is not allowed.. error.invalid-mutate-context.ts:3:2 1 | function Component(props) { 2 | const context = useContext(FooContext); > 3 | context.value = props.value; - | ^^^^^^^ This value cannot be modified + | ^^^^^^^ value cannot be modified 4 | return context.value; 5 | } 6 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-props-in-effect-fixpoint.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-props-in-effect-fixpoint.expect.md index 795af4b75f..8aa82917db 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-props-in-effect-fixpoint.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-props-in-effect-fixpoint.expect.md @@ -28,7 +28,7 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.invalid-mutate-props-in-effect-fixpoint.ts:10:4 8 | let y = x; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-props-via-for-of-iterator.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-props-via-for-of-iterator.expect.md index 2a363a7dac..63d5178b25 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-props-via-for-of-iterator.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutate-props-via-for-of-iterator.expect.md @@ -20,13 +20,13 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.invalid-mutate-props-via-for-of-iterator.ts:4:4 2 | const items = []; 3 | for (const x of props.items) { > 4 | x.modified = true; - | ^ This value cannot be modified + | ^ value cannot be modified 5 | items.push(x); 6 | } 7 | return items; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.expect.md index 83fb1972af..9055b5ccda 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.expect.md @@ -19,7 +19,7 @@ function useInvalidMutation(options) { Found 1 error: Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.invalid-mutation-in-closure.ts:4:4 2 | function test() { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutation-of-possible-props-phi-indirect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutation-of-possible-props-phi-indirect.expect.md index 53926d8260..7d07f40e12 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutation-of-possible-props-phi-indirect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-mutation-of-possible-props-phi-indirect.expect.md @@ -22,7 +22,7 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a variable defined outside a component or hook is not allowed. Consider using an effect +Modifying a variable defined outside a component or hook is not allowed. Consider using an effect. error.invalid-mutation-of-possible-props-phi-indirect.ts:4:4 2 | let x = cond ? someGlobal : props.foo; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-nested-function-reassign-local-variable-in-effect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-nested-function-reassign-local-variable-in-effect.expect.md index 073a15b7f5..4d19c26714 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-nested-function-reassign-local-variable-in-effect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-nested-function-reassign-local-variable-in-effect.expect.md @@ -47,15 +47,15 @@ function Component() { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.invalid-nested-function-reassign-local-variable-in-effect.ts:7:6 5 | // Create the reassignment function inside another function, then return it 6 | const reassignLocal = newValue => { > 7 | local = newValue; - | ^^^^^ Cannot reassign variable after render completes + | ^^^^^ Cannot reassign `local` after render completes 8 | }; 9 | return reassignLocal; 10 | }; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-non-imported-reanimated-shared-value-writes.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-non-imported-reanimated-shared-value-writes.expect.md index 9aef48428f..dfb518e871 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-non-imported-reanimated-shared-value-writes.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-non-imported-reanimated-shared-value-writes.expect.md @@ -27,7 +27,7 @@ function SomeComponent() { Found 1 error: Error: This value cannot be modified -Modifying a value returned from a hook is not allowed. Consider moving the modification into the hook where the value is constructed +Modifying a value returned from a hook is not allowed. Consider moving the modification into the hook where the value is constructed. error.invalid-non-imported-reanimated-shared-value-writes.ts:11:22 9 | return ( diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-pass-mutable-function-as-prop.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-pass-mutable-function-as-prop.expect.md index 50d3a9e668..7e55d8429a 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-pass-mutable-function-as-prop.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-pass-mutable-function-as-prop.expect.md @@ -20,13 +20,13 @@ function Component() { Found 1 error: Error: Cannot modify local variables after render completes -This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead +This argument is a function which may reassign or mutate `cache` after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead. error.invalid-pass-mutable-function-as-prop.ts:7:18 5 | cache.set('key', 'value'); 6 | }; > 7 | return ; - | ^^ This function may (indirectly) reassign or modify local variables after render + | ^^ This function may (indirectly) reassign or modify `cache` after render 8 | } 9 | @@ -34,7 +34,7 @@ error.invalid-pass-mutable-function-as-prop.ts:5:4 3 | const cache = new Map(); 4 | const fn = () => { > 5 | cache.set('key', 'value'); - | ^^^^^ This modifies a local variable + | ^^^^^ This modifies `cache` 6 | }; 7 | return ; 8 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-prop-mutation-indirect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-prop-mutation-indirect.expect.md index dbae5f55b6..9a17f3dbff 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-prop-mutation-indirect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-prop-mutation-indirect.expect.md @@ -21,7 +21,7 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.invalid-prop-mutation-indirect.ts:3:4 1 | function Component(props) { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-property-store-to-frozen-value.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-property-store-to-frozen-value.expect.md index 0b03288db0..e9545f5bf2 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-property-store-to-frozen-value.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-property-store-to-frozen-value.expect.md @@ -19,13 +19,13 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX +Modifying a value used previously in JSX is not allowed. Consider moving the modification before the JSX. error.invalid-property-store-to-frozen-value.ts:5:2 3 | // freeze 4 |
{x}
; > 5 | x.y = true; - | ^ This value cannot be modified + | ^ value cannot be modified 6 | return x; 7 | } 8 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-props-mutation-in-effect-indirect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-props-mutation-in-effect-indirect.expect.md index b6abe7b8a1..67479eaa14 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-props-mutation-in-effect-indirect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-props-mutation-in-effect-indirect.expect.md @@ -21,7 +21,7 @@ function Component(props) { Found 1 error: Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.invalid-props-mutation-in-effect-indirect.ts:3:4 1 | function Component(props) { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-in-hook-return-value.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-in-hook-return-value.expect.md index 02750e4472..90c6698a65 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-in-hook-return-value.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-in-hook-return-value.expect.md @@ -16,15 +16,15 @@ function useFoo() { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `x` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.invalid-reassign-local-in-hook-return-value.ts:4:4 2 | let x = 0; 3 | return value => { > 4 | x = value; - | ^ Cannot reassign variable after render completes + | ^ Cannot reassign `x` after render completes 5 | }; 6 | } 7 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-effect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-effect.expect.md index 3f8a81c106..3bf7be031e 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-effect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-effect.expect.md @@ -48,15 +48,15 @@ function Component() { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.invalid-reassign-local-variable-in-effect.ts:7:4 5 | 6 | const reassignLocal = newValue => { > 7 | local = newValue; - | ^^^^^ Cannot reassign variable after render completes + | ^^^^^ Cannot reassign `local` after render completes 8 | }; 9 | 10 | const onMount = newValue => { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-hook-argument.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-hook-argument.expect.md index 8bf6cd1ccc..7b8ba28e70 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-hook-argument.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-hook-argument.expect.md @@ -49,15 +49,15 @@ function Component() { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.invalid-reassign-local-variable-in-hook-argument.ts:8:4 6 | 7 | const reassignLocal = newValue => { > 8 | local = newValue; - | ^^^^^ Cannot reassign variable after render completes + | ^^^^^ Cannot reassign `local` after render completes 9 | }; 10 | 11 | const callback = newValue => { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-jsx-callback.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-jsx-callback.expect.md index ea7fd3d1d7..4c6f8aec42 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-jsx-callback.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-jsx-callback.expect.md @@ -42,15 +42,15 @@ function Component() { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.invalid-reassign-local-variable-in-jsx-callback.ts:5:4 3 | 4 | const reassignLocal = newValue => { > 5 | local = newValue; - | ^^^^^ Cannot reassign variable after render completes + | ^^^^^ Cannot reassign `local` after render completes 6 | }; 7 | 8 | const onClick = newValue => { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-return-mutable-function-from-hook.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-return-mutable-function-from-hook.expect.md index 767c05ec73..16098dddca 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-return-mutable-function-from-hook.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-return-mutable-function-from-hook.expect.md @@ -22,7 +22,7 @@ function useFoo() { Found 1 error: Error: Cannot modify local variables after render completes -This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead +This argument is a function which may reassign or mutate `cache` after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead. error.invalid-return-mutable-function-from-hook.ts:7:9 5 | useHook(); // for inference to kick in @@ -32,7 +32,7 @@ error.invalid-return-mutable-function-from-hook.ts:7:9 > 8 | cache.set('key', 'value'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 9 | }; - | ^^^^ This function may (indirectly) reassign or modify local variables after render + | ^^^^ This function may (indirectly) reassign or modify `cache` after render 10 | } 11 | @@ -40,7 +40,7 @@ error.invalid-return-mutable-function-from-hook.ts:8:4 6 | const cache = new Map(); 7 | return () => { > 8 | cache.set('key', 'value'); - | ^^^^^ This modifies a local variable + | ^^^^^ This modifies `cache` 9 | }; 10 | } 11 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-uncalled-function-capturing-mutable-values-memoizes-with-captures-values.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-uncalled-function-capturing-mutable-values-memoizes-with-captures-values.expect.md index 88788bbfee..006d9dfcf4 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-uncalled-function-capturing-mutable-values-memoizes-with-captures-values.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-uncalled-function-capturing-mutable-values-memoizes-with-captures-values.expect.md @@ -50,7 +50,7 @@ hook useMemoMap( Found 1 error: Error: Cannot modify local variables after render completes -This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead +This argument is a function which may reassign or mutate `cache` after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead. undefined:21:9 19 | map: TInput => TOutput @@ -88,7 +88,7 @@ undefined:21:9 > 36 | }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 37 | }, [map]); - | ^^^^^^^^^^^^ This function may (indirectly) reassign or modify local variables after render + | ^^^^^^^^^^^^ This function may (indirectly) reassign or modify `cache` after render 38 | } 39 | @@ -96,7 +96,7 @@ undefined:33:8 31 | if (output == null) { 32 | output = map(input); > 33 | cache.set(input, output); - | ^^^^^ This modifies a local variable + | ^^^^^ This modifies `cache` 34 | } 35 | return output; 36 | }; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-useMemo-async-callback.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-useMemo-async-callback.expect.md index 7fc99985f1..c111427d42 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-useMemo-async-callback.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-useMemo-async-callback.expect.md @@ -16,9 +16,9 @@ function component(a, b) { ``` Found 1 error: -Error: useMemo callbacks may not be async or generator functions +Error: useMemo() callbacks may not be async or generator functions -useMemo() callbacks are called once and must synchronously return a value +useMemo() callbacks are called once and must synchronously return a value. error.invalid-useMemo-async-callback.ts:2:18 1 | function component(a, b) { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-useMemo-callback-args.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-useMemo-callback-args.expect.md index 97996884b2..dbb80c67b0 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-useMemo-callback-args.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-useMemo-callback-args.expect.md @@ -21,7 +21,7 @@ useMemo() callbacks are called by React to cache calculations across re-renders. error.invalid-useMemo-callback-args.ts:2:18 1 | function component(a, b) { > 2 | let x = useMemo(c => a, []); - | ^ + | ^ Callbacks with parameters are not supported 3 | return x; 4 | } 5 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-state-2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-state-2.expect.md index 52b6cd67c9..90cffafe00 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-state-2.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-state-2.expect.md @@ -20,13 +20,13 @@ function Foo() { Found 1 error: Error: This value cannot be modified -Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead +Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead. error.modify-state-2.ts:6:2 4 | const [state, setState] = useState({foo: {bar: 3}}); 5 | const foo = state.foo; > 6 | foo.bar = 1; - | ^^^ This value cannot be modified + | ^^^ value cannot be modified 7 | return state; 8 | } 9 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-state.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-state.expect.md index 82066a1930..41ce3af1cc 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-state.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-state.expect.md @@ -19,13 +19,13 @@ function Foo() { Found 1 error: Error: This value cannot be modified -Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead +Modifying a value returned from 'useState()', which should not be modified directly. Use the setter function to update instead. error.modify-state.ts:5:2 3 | function Foo() { 4 | let [state, setState] = useState({}); > 5 | state.foo = 1; - | ^^^^^ This value cannot be modified + | ^^^^^ value cannot be modified 6 | return state; 7 | } 8 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-useReducer-state.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-useReducer-state.expect.md index 25f1fee7f9..d2be8b908c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-useReducer-state.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.modify-useReducer-state.expect.md @@ -19,13 +19,13 @@ function Foo() { Found 1 error: Error: This value cannot be modified -Modifying a value returned from 'useReducer()', which should not be modified directly. Use the dispatch function to update instead +Modifying a value returned from 'useReducer()', which should not be modified directly. Use the dispatch function to update instead. error.modify-useReducer-state.ts:5:2 3 | function Foo() { 4 | let [state, setState] = useReducer({foo: 1}); > 5 | state.foo = 1; - | ^^^^^ This value cannot be modified + | ^^^^^ value cannot be modified 6 | return state; 7 | } 8 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutable-range-shared-inner-outer-function.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutable-range-shared-inner-outer-function.expect.md index e284cb7814..22857a067f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutable-range-shared-inner-outer-function.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutable-range-shared-inner-outer-function.expect.md @@ -33,15 +33,15 @@ export const FIXTURE_ENTRYPOINT = { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `a` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `a` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.mutable-range-shared-inner-outer-function.ts:8:6 6 | const f = () => { 7 | if (cond) { > 8 | a = {}; - | ^ Cannot reassign variable after render completes + | ^ Cannot reassign `a` after render completes 9 | b = []; 10 | } else { 11 | a = {}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-function-property.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-function-property.expect.md index 8e2c210bc1..6e2196513c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-function-property.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-function-property.expect.md @@ -18,13 +18,13 @@ export function ViewModeSelector(props) { Found 1 error: Error: This value cannot be modified -This modifies a variable that React considers immutable +This modifies a variable that React considers immutable. error.mutate-function-property.ts:3:2 1 | export function ViewModeSelector(props) { 2 | const renderIcon = () => ; > 3 | renderIcon.displayName = 'AcceptIcon'; - | ^^^^^^^^^^ This value cannot be modified + | ^^^^^^^^^^ value cannot be modified 4 | 5 | return ; 6 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-hook-argument.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-hook-argument.expect.md index 154f03c6a5..2cce8c401b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-hook-argument.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-hook-argument.expect.md @@ -16,24 +16,24 @@ function useHook(a, b) { Found 2 errors: Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.mutate-hook-argument.ts:2:2 1 | function useHook(a, b) { > 2 | b.test = 1; - | ^ This value cannot be modified + | ^ value cannot be modified 3 | a.test = 2; 4 | } 5 | Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.mutate-hook-argument.ts:3:2 1 | function useHook(a, b) { 2 | b.test = 1; > 3 | a.test = 2; - | ^ This value cannot be modified + | ^ value cannot be modified 4 | } 5 | ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-property-from-global.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-property-from-global.expect.md index b4db493807..d69050c026 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-property-from-global.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-property-from-global.expect.md @@ -18,13 +18,13 @@ function Foo() { Found 1 error: Error: This value cannot be modified -Modifying a variable defined outside a component or hook is not allowed. Consider using an effect +Modifying a variable defined outside a component or hook is not allowed. Consider using an effect. error.mutate-property-from-global.ts:4:9 2 | 3 | function Foo() { > 4 | delete wat.foo; - | ^^^ This value cannot be modified + | ^^^ value cannot be modified 5 | return wat; 6 | } 7 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-props.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-props.expect.md index 221de60bd4..e398ef5619 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-props.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-props.expect.md @@ -16,12 +16,12 @@ function Foo(props) { Found 1 error: Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.mutate-props.ts:2:2 1 | function Foo(props) { > 2 | props.test = 1; - | ^^^^^ This value cannot be modified + | ^^^^^ value cannot be modified 3 | return null; 4 | } 5 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.not-useEffect-external-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.not-useEffect-external-mutate.expect.md index d3ca285dc4..4e912f53b7 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.not-useEffect-external-mutate.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.not-useEffect-external-mutate.expect.md @@ -20,25 +20,25 @@ function Component(props) { Found 2 errors: Error: This value cannot be modified -Modifying a variable defined outside a component or hook is not allowed. Consider using an effect +Modifying a variable defined outside a component or hook is not allowed. Consider using an effect. error.not-useEffect-external-mutate.ts:5:4 3 | function Component(props) { 4 | foo(() => { > 5 | x.a = 10; - | ^ This value cannot be modified + | ^ value cannot be modified 6 | x.a = 20; 7 | }); 8 | } Error: This value cannot be modified -Modifying a variable defined outside a component or hook is not allowed. Consider using an effect +Modifying a variable defined outside a component or hook is not allowed. Consider using an effect. error.not-useEffect-external-mutate.ts:6:4 4 | foo(() => { 5 | x.a = 10; > 6 | x.a = 20; - | ^ This value cannot be modified + | ^ value cannot be modified 7 | }); 8 | } 9 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassign-global-fn-arg.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassign-global-fn-arg.expect.md index fea0311325..7fee14f6ba 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassign-global-fn-arg.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassign-global-fn-arg.expect.md @@ -27,13 +27,13 @@ export const FIXTURE_ENTRYPOINT = { Found 1 error: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `b` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.reassign-global-fn-arg.ts:5:4 3 | export default function MyApp() { 4 | const fn = () => { > 5 | b = 2; - | ^ Cannot reassign variable + | ^ `b` cannot be reassigned 6 | }; 7 | return foo(fn); 8 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassignment-to-global-indirect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassignment-to-global-indirect.expect.md index bb6000deeb..52bc679a66 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassignment-to-global-indirect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassignment-to-global-indirect.expect.md @@ -20,25 +20,25 @@ function Component() { Found 2 errors: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `someUnknownGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.reassignment-to-global-indirect.ts:4:4 2 | const foo = () => { 3 | // Cannot assign to globals > 4 | someUnknownGlobal = true; - | ^^^^^^^^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^^^^^^^^ `someUnknownGlobal` cannot be reassigned 5 | moduleLocal = true; 6 | }; 7 | foo(); Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `moduleLocal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.reassignment-to-global-indirect.ts:5:4 3 | // Cannot assign to globals 4 | someUnknownGlobal = true; > 5 | moduleLocal = true; - | ^^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^^ `moduleLocal` cannot be reassigned 6 | }; 7 | foo(); 8 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassignment-to-global.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassignment-to-global.expect.md index eeb83df78b..e7fc4b5545 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassignment-to-global.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.reassignment-to-global.expect.md @@ -17,25 +17,25 @@ function Component() { Found 2 errors: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `someUnknownGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.reassignment-to-global.ts:3:2 1 | function Component() { 2 | // Cannot assign to globals > 3 | someUnknownGlobal = true; - | ^^^^^^^^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^^^^^^^^ `someUnknownGlobal` cannot be reassigned 4 | moduleLocal = true; 5 | } 6 | Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `moduleLocal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.reassignment-to-global.ts:4:2 2 | // Cannot assign to globals 3 | someUnknownGlobal = true; > 4 | moduleLocal = true; - | ^^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^^ `moduleLocal` cannot be reassigned 5 | } 6 | ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.store-property-in-global.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.store-property-in-global.expect.md index 97d8a3925a..37b7675766 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.store-property-in-global.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.store-property-in-global.expect.md @@ -18,13 +18,13 @@ function Foo() { Found 1 error: Error: This value cannot be modified -Modifying a variable defined outside a component or hook is not allowed. Consider using an effect +Modifying a variable defined outside a component or hook is not allowed. Consider using an effect. error.store-property-in-global.ts:4:2 2 | 3 | function Foo() { > 4 | wat.test = 1; - | ^^^ This value cannot be modified + | ^^^ value cannot be modified 5 | return wat; 6 | } 7 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-function-expression-references-later-variable-declaration.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-function-expression-references-later-variable-declaration.expect.md index f151b624e9..791c70d669 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-function-expression-references-later-variable-declaration.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-function-expression-references-later-variable-declaration.expect.md @@ -18,15 +18,15 @@ function Component() { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `onClick` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `onClick` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.todo-function-expression-references-later-variable-declaration.ts:3:4 1 | function Component() { 2 | let callback = () => { > 3 | onClick = () => {}; - | ^^^^^^^ Cannot reassign variable after render completes + | ^^^^^^^ Cannot reassign `onClick` after render completes 4 | }; 5 | let onClick; 6 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.update-global-should-bailout.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.update-global-should-bailout.expect.md index 44a3b96946..ff45918398 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.update-global-should-bailout.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.update-global-should-bailout.expect.md @@ -22,13 +22,13 @@ export const FIXTURE_ENTRYPOINT = { Found 1 error: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `renderCount` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.update-global-should-bailout.ts:3:2 1 | let renderCount = 0; 2 | function useFoo() { > 3 | renderCount += 1; - | ^^^^^^^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^^^^^^^ `renderCount` cannot be reassigned 4 | return renderCount; 5 | } 6 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect-optional-chain.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect-optional-chain.expect.md index f7e00d6018..4eaeeb2124 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect-optional-chain.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect-optional-chain.expect.md @@ -48,7 +48,7 @@ export const FIXTURE_ENTRYPOINT = { ## Logs ``` -{"kind":"CompileError","fnLoc":{"start":{"line":5,"column":0,"index":139},"end":{"line":12,"column":1,"index":384},"filename":"mutate-after-useeffect-optional-chain.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the modification before calling useEffect()","details":[{"kind":"error","loc":{"start":{"line":10,"column":2,"index":345},"end":{"line":10,"column":5,"index":348},"filename":"mutate-after-useeffect-optional-chain.ts","identifierName":"arr"},"message":"This value cannot be modified"}]}}} +{"kind":"CompileError","fnLoc":{"start":{"line":5,"column":0,"index":139},"end":{"line":12,"column":1,"index":384},"filename":"mutate-after-useeffect-optional-chain.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the modification before calling useEffect().","details":[{"kind":"error","loc":{"start":{"line":10,"column":2,"index":345},"end":{"line":10,"column":5,"index":348},"filename":"mutate-after-useeffect-optional-chain.ts","identifierName":"arr"},"message":"value cannot be modified"}]}}} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":9,"column":2,"index":304},"end":{"line":9,"column":39,"index":341},"filename":"mutate-after-useeffect-optional-chain.ts"},"decorations":[{"start":{"line":9,"column":24,"index":326},"end":{"line":9,"column":27,"index":329},"filename":"mutate-after-useeffect-optional-chain.ts","identifierName":"arr"}]} {"kind":"CompileSuccess","fnLoc":{"start":{"line":5,"column":0,"index":139},"end":{"line":12,"column":1,"index":384},"filename":"mutate-after-useeffect-optional-chain.ts"},"fnName":"Component","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0} ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect-ref-access.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect-ref-access.expect.md index f69fe10fc5..44c0afa685 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect-ref-access.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect-ref-access.expect.md @@ -47,7 +47,7 @@ export const FIXTURE_ENTRYPOINT = { ## Logs ``` -{"kind":"CompileError","fnLoc":{"start":{"line":6,"column":0,"index":148},"end":{"line":11,"column":1,"index":311},"filename":"mutate-after-useeffect-ref-access.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying component props or hook arguments is not allowed. Consider using a local variable instead","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":269},"end":{"line":9,"column":16,"index":283},"filename":"mutate-after-useeffect-ref-access.ts"},"message":"This value cannot be modified"}]}}} +{"kind":"CompileError","fnLoc":{"start":{"line":6,"column":0,"index":148},"end":{"line":11,"column":1,"index":311},"filename":"mutate-after-useeffect-ref-access.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying component props or hook arguments is not allowed. Consider using a local variable instead.","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":269},"end":{"line":9,"column":16,"index":283},"filename":"mutate-after-useeffect-ref-access.ts"},"message":"value cannot be modified"}]}}} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":8,"column":2,"index":227},"end":{"line":8,"column":40,"index":265},"filename":"mutate-after-useeffect-ref-access.ts"},"decorations":[{"start":{"line":8,"column":24,"index":249},"end":{"line":8,"column":30,"index":255},"filename":"mutate-after-useeffect-ref-access.ts","identifierName":"arrRef"}]} {"kind":"CompileSuccess","fnLoc":{"start":{"line":6,"column":0,"index":148},"end":{"line":11,"column":1,"index":311},"filename":"mutate-after-useeffect-ref-access.ts"},"fnName":"Component","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0} ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect.expect.md index 20d7aef8a9..b3d1e5a398 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/bailout-retry/mutate-after-useeffect.expect.md @@ -47,7 +47,7 @@ export const FIXTURE_ENTRYPOINT = { ## Logs ``` -{"kind":"CompileError","fnLoc":{"start":{"line":4,"column":0,"index":101},"end":{"line":11,"column":1,"index":222},"filename":"mutate-after-useeffect.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the modification before calling useEffect()","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":194},"end":{"line":9,"column":5,"index":197},"filename":"mutate-after-useeffect.ts","identifierName":"arr"},"message":"This value cannot be modified"}]}}} +{"kind":"CompileError","fnLoc":{"start":{"line":4,"column":0,"index":101},"end":{"line":11,"column":1,"index":222},"filename":"mutate-after-useeffect.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the modification before calling useEffect().","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":194},"end":{"line":9,"column":5,"index":197},"filename":"mutate-after-useeffect.ts","identifierName":"arr"},"message":"value cannot be modified"}]}}} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":6,"column":2,"index":149},"end":{"line":8,"column":4,"index":190},"filename":"mutate-after-useeffect.ts"},"decorations":[{"start":{"line":7,"column":4,"index":171},"end":{"line":7,"column":7,"index":174},"filename":"mutate-after-useeffect.ts","identifierName":"arr"},{"start":{"line":7,"column":4,"index":171},"end":{"line":7,"column":7,"index":174},"filename":"mutate-after-useeffect.ts","identifierName":"arr"},{"start":{"line":7,"column":13,"index":180},"end":{"line":7,"column":16,"index":183},"filename":"mutate-after-useeffect.ts","identifierName":"foo"}]} {"kind":"CompileSuccess","fnLoc":{"start":{"line":4,"column":0,"index":101},"end":{"line":11,"column":1,"index":222},"filename":"mutate-after-useeffect.ts"},"fnName":"Component","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0} ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/no-emit/retry-no-emit.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/no-emit/retry-no-emit.expect.md index 344b996702..4f7377e00d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/no-emit/retry-no-emit.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies/no-emit/retry-no-emit.expect.md @@ -52,7 +52,7 @@ export const FIXTURE_ENTRYPOINT = { ## Logs ``` -{"kind":"CompileError","fnLoc":{"start":{"line":5,"column":0,"index":163},"end":{"line":13,"column":1,"index":357},"filename":"retry-no-emit.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook","details":[{"kind":"error","loc":{"start":{"line":11,"column":2,"index":320},"end":{"line":11,"column":6,"index":324},"filename":"retry-no-emit.ts","identifierName":"arr2"},"message":"This value cannot be modified"}]}}} +{"kind":"CompileError","fnLoc":{"start":{"line":5,"column":0,"index":163},"end":{"line":13,"column":1,"index":357},"filename":"retry-no-emit.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook.","details":[{"kind":"error","loc":{"start":{"line":11,"column":2,"index":320},"end":{"line":11,"column":6,"index":324},"filename":"retry-no-emit.ts","identifierName":"arr2"},"message":"value cannot be modified"}]}}} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":7,"column":2,"index":216},"end":{"line":7,"column":36,"index":250},"filename":"retry-no-emit.ts"},"decorations":[{"start":{"line":7,"column":31,"index":245},"end":{"line":7,"column":34,"index":248},"filename":"retry-no-emit.ts","identifierName":"arr"}]} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":10,"column":2,"index":274},"end":{"line":10,"column":44,"index":316},"filename":"retry-no-emit.ts"},"decorations":[{"start":{"line":10,"column":25,"index":297},"end":{"line":10,"column":29,"index":301},"filename":"retry-no-emit.ts","identifierName":"arr2"},{"start":{"line":10,"column":25,"index":297},"end":{"line":10,"column":29,"index":301},"filename":"retry-no-emit.ts","identifierName":"arr2"},{"start":{"line":10,"column":35,"index":307},"end":{"line":10,"column":42,"index":314},"filename":"retry-no-emit.ts","identifierName":"propVal"}]} {"kind":"CompileSuccess","fnLoc":{"start":{"line":5,"column":0,"index":163},"end":{"line":13,"column":1,"index":357},"filename":"retry-no-emit.ts"},"fnName":"Foo","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0} diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.invalid-reassign-local-variable-in-jsx-callback.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.invalid-reassign-local-variable-in-jsx-callback.expect.md index 2050ea107c..8ca8f18d90 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.invalid-reassign-local-variable-in-jsx-callback.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.invalid-reassign-local-variable-in-jsx-callback.expect.md @@ -43,15 +43,15 @@ function Component() { ``` Found 1 error: -Error: Cannot reassign a variable after render completes +Error: Cannot reassign variable after render completes -Reassigning variable `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead +Reassigning `local` after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead. error.invalid-reassign-local-variable-in-jsx-callback.ts:6:4 4 | 5 | const reassignLocal = newValue => { > 6 | local = newValue; - | ^^^^^ Cannot reassign variable after render completes + | ^^^^^ Cannot reassign `local` after render completes 7 | }; 8 | 9 | const onClick = newValue => { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.invalid-referencing-frozen-hoisted-storecontext-const.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.invalid-referencing-frozen-hoisted-storecontext-const.expect.md index 9a6593cc2a..d81d62f92c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.invalid-referencing-frozen-hoisted-storecontext-const.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.invalid-referencing-frozen-hoisted-storecontext-const.expect.md @@ -34,13 +34,13 @@ function Component({content, refetch}) { Found 1 error: Error: Cannot access variable before it is declared -Variable `data` is accessed before it is declared, which prevents the earlier access from updating when this value changes over time +`data` is accessed before it is declared, which prevents the earlier access from updating when this value changes over time. undefined:11:12 9 | // TDZ violation! 10 | const onRefetch = useCallback(() => { > 11 | refetch(data); - | ^^^^ Variable accessed before it is declared + | ^^^^ `data` accessed before it is declared 12 | }, [refetch]); 13 | 14 | // The context variable gets frozen here since it's passed to a hook @@ -49,7 +49,7 @@ undefined:19:9 17 | // This has to error: onRefetch needs to memoize with `content` as a 18 | // dependency, but the dependency comes later > 19 | const {data = null} = content; - | ^^^^^^^^^^^ The variable is declared here + | ^^^^^^^^^^^ `data` is declared here 20 | 21 | return ; 22 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.mutate-frozen-value.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.mutate-frozen-value.expect.md index e71470c999..e28e9bb4de 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.mutate-frozen-value.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.mutate-frozen-value.expect.md @@ -19,13 +19,13 @@ function Component({a, b}) { Found 1 error: Error: This value cannot be modified -Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook +Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook. error.mutate-frozen-value.ts:5:2 3 | const x = {a}; 4 | useFreeze(x); > 5 | x.y = true; - | ^ This value cannot be modified + | ^ value cannot be modified 6 | return
error
; 7 | } 8 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.mutate-hook-argument.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.mutate-hook-argument.expect.md index 757483304f..269eeae102 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.mutate-hook-argument.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.mutate-hook-argument.expect.md @@ -17,25 +17,25 @@ function useHook(a, b) { Found 2 errors: Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.mutate-hook-argument.ts:3:2 1 | // @enableNewMutationAliasingModel 2 | function useHook(a, b) { > 3 | b.test = 1; - | ^ This value cannot be modified + | ^ value cannot be modified 4 | a.test = 2; 5 | } 6 | Error: This value cannot be modified -Modifying component props or hook arguments is not allowed. Consider using a local variable instead +Modifying component props or hook arguments is not allowed. Consider using a local variable instead. error.mutate-hook-argument.ts:4:2 2 | function useHook(a, b) { 3 | b.test = 1; > 4 | a.test = 2; - | ^ This value cannot be modified + | ^ value cannot be modified 5 | } 6 | ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.not-useEffect-external-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.not-useEffect-external-mutate.expect.md index f6ba6dd8f7..09180da4f2 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.not-useEffect-external-mutate.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.not-useEffect-external-mutate.expect.md @@ -21,25 +21,25 @@ function Component(props) { Found 2 errors: Error: This value cannot be modified -Modifying a variable defined outside a component or hook is not allowed. Consider using an effect +Modifying a variable defined outside a component or hook is not allowed. Consider using an effect. error.not-useEffect-external-mutate.ts:6:4 4 | function Component(props) { 5 | foo(() => { > 6 | x.a = 10; - | ^ This value cannot be modified + | ^ value cannot be modified 7 | x.a = 20; 8 | }); 9 | } Error: This value cannot be modified -Modifying a variable defined outside a component or hook is not allowed. Consider using an effect +Modifying a variable defined outside a component or hook is not allowed. Consider using an effect. error.not-useEffect-external-mutate.ts:7:4 5 | foo(() => { 6 | x.a = 10; > 7 | x.a = 20; - | ^ This value cannot be modified + | ^ value cannot be modified 8 | }); 9 | } 10 | diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.reassignment-to-global-indirect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.reassignment-to-global-indirect.expect.md index 26016f282a..16947bb644 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.reassignment-to-global-indirect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.reassignment-to-global-indirect.expect.md @@ -21,25 +21,25 @@ function Component() { Found 2 errors: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `someUnknownGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.reassignment-to-global-indirect.ts:5:4 3 | const foo = () => { 4 | // Cannot assign to globals > 5 | someUnknownGlobal = true; - | ^^^^^^^^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^^^^^^^^ `someUnknownGlobal` cannot be reassigned 6 | moduleLocal = true; 7 | }; 8 | foo(); Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `moduleLocal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.reassignment-to-global-indirect.ts:6:4 4 | // Cannot assign to globals 5 | someUnknownGlobal = true; > 6 | moduleLocal = true; - | ^^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^^ `moduleLocal` cannot be reassigned 7 | }; 8 | foo(); 9 | } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.reassignment-to-global.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.reassignment-to-global.expect.md index c6d8d7349a..288dce9cbf 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.reassignment-to-global.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/error.reassignment-to-global.expect.md @@ -18,25 +18,25 @@ function Component() { Found 2 errors: Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `someUnknownGlobal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.reassignment-to-global.ts:4:2 2 | function Component() { 3 | // Cannot assign to globals > 4 | someUnknownGlobal = true; - | ^^^^^^^^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^^^^^^^^ `someUnknownGlobal` cannot be reassigned 5 | moduleLocal = true; 6 | } 7 | Error: Cannot reassign variables declared outside of the component/hook -Reassigning a variable declared outside of the component/hook is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) +Variable `moduleLocal` is declared outside of the component/hook. Reassigning this value during render is a form of side effect, which can cause unpredictable behavior depending on when the component happens to re-render. If this variable is used in rendering, use useState instead. Otherwise, consider updating it in an effect. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render) error.reassignment-to-global.ts:5:2 3 | // Cannot assign to globals 4 | someUnknownGlobal = true; > 5 | moduleLocal = true; - | ^^^^^^^^^^^ Cannot reassign variable + | ^^^^^^^^^^^ `moduleLocal` cannot be reassigned 6 | } 7 | ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect-optional-chain.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect-optional-chain.expect.md index 0f0c1b14cb..b1b1b670ed 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect-optional-chain.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect-optional-chain.expect.md @@ -48,7 +48,7 @@ export const FIXTURE_ENTRYPOINT = { ## Logs ``` -{"kind":"CompileError","fnLoc":{"start":{"line":5,"column":0,"index":171},"end":{"line":12,"column":1,"index":416},"filename":"mutate-after-useeffect-optional-chain.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the modification before calling useEffect()","details":[{"kind":"error","loc":{"start":{"line":10,"column":2,"index":377},"end":{"line":10,"column":5,"index":380},"filename":"mutate-after-useeffect-optional-chain.ts","identifierName":"arr"},"message":"This value cannot be modified"}]}}} +{"kind":"CompileError","fnLoc":{"start":{"line":5,"column":0,"index":171},"end":{"line":12,"column":1,"index":416},"filename":"mutate-after-useeffect-optional-chain.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the modification before calling useEffect().","details":[{"kind":"error","loc":{"start":{"line":10,"column":2,"index":377},"end":{"line":10,"column":5,"index":380},"filename":"mutate-after-useeffect-optional-chain.ts","identifierName":"arr"},"message":"value cannot be modified"}]}}} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":9,"column":2,"index":336},"end":{"line":9,"column":39,"index":373},"filename":"mutate-after-useeffect-optional-chain.ts"},"decorations":[{"start":{"line":9,"column":24,"index":358},"end":{"line":9,"column":27,"index":361},"filename":"mutate-after-useeffect-optional-chain.ts","identifierName":"arr"}]} {"kind":"CompileSuccess","fnLoc":{"start":{"line":5,"column":0,"index":171},"end":{"line":12,"column":1,"index":416},"filename":"mutate-after-useeffect-optional-chain.ts"},"fnName":"Component","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0} ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect-ref-access.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect-ref-access.expect.md index 6cb1ff73ee..2d152f13c5 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect-ref-access.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect-ref-access.expect.md @@ -47,7 +47,7 @@ export const FIXTURE_ENTRYPOINT = { ## Logs ``` -{"kind":"CompileError","fnLoc":{"start":{"line":6,"column":0,"index":180},"end":{"line":11,"column":1,"index":343},"filename":"mutate-after-useeffect-ref-access.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying component props or hook arguments is not allowed. Consider using a local variable instead","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":301},"end":{"line":9,"column":16,"index":315},"filename":"mutate-after-useeffect-ref-access.ts"},"message":"This value cannot be modified"}]}}} +{"kind":"CompileError","fnLoc":{"start":{"line":6,"column":0,"index":180},"end":{"line":11,"column":1,"index":343},"filename":"mutate-after-useeffect-ref-access.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying component props or hook arguments is not allowed. Consider using a local variable instead.","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":301},"end":{"line":9,"column":16,"index":315},"filename":"mutate-after-useeffect-ref-access.ts"},"message":"value cannot be modified"}]}}} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":8,"column":2,"index":259},"end":{"line":8,"column":40,"index":297},"filename":"mutate-after-useeffect-ref-access.ts"},"decorations":[{"start":{"line":8,"column":24,"index":281},"end":{"line":8,"column":30,"index":287},"filename":"mutate-after-useeffect-ref-access.ts","identifierName":"arrRef"}]} {"kind":"CompileSuccess","fnLoc":{"start":{"line":6,"column":0,"index":180},"end":{"line":11,"column":1,"index":343},"filename":"mutate-after-useeffect-ref-access.ts"},"fnName":"Component","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0} ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect.expect.md index 8d10ab1b69..cbe15c25bd 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-after-useeffect.expect.md @@ -47,7 +47,7 @@ export const FIXTURE_ENTRYPOINT = { ## Logs ``` -{"kind":"CompileError","fnLoc":{"start":{"line":4,"column":0,"index":133},"end":{"line":11,"column":1,"index":254},"filename":"mutate-after-useeffect.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the modification before calling useEffect()","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":226},"end":{"line":9,"column":5,"index":229},"filename":"mutate-after-useeffect.ts","identifierName":"arr"},"message":"This value cannot be modified"}]}}} +{"kind":"CompileError","fnLoc":{"start":{"line":4,"column":0,"index":133},"end":{"line":11,"column":1,"index":254},"filename":"mutate-after-useeffect.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the modification before calling useEffect().","details":[{"kind":"error","loc":{"start":{"line":9,"column":2,"index":226},"end":{"line":9,"column":5,"index":229},"filename":"mutate-after-useeffect.ts","identifierName":"arr"},"message":"value cannot be modified"}]}}} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":6,"column":2,"index":181},"end":{"line":8,"column":4,"index":222},"filename":"mutate-after-useeffect.ts"},"decorations":[{"start":{"line":7,"column":4,"index":203},"end":{"line":7,"column":7,"index":206},"filename":"mutate-after-useeffect.ts","identifierName":"arr"},{"start":{"line":7,"column":4,"index":203},"end":{"line":7,"column":7,"index":206},"filename":"mutate-after-useeffect.ts","identifierName":"arr"},{"start":{"line":7,"column":13,"index":212},"end":{"line":7,"column":16,"index":215},"filename":"mutate-after-useeffect.ts","identifierName":"foo"}]} {"kind":"CompileSuccess","fnLoc":{"start":{"line":4,"column":0,"index":133},"end":{"line":11,"column":1,"index":254},"filename":"mutate-after-useeffect.ts"},"fnName":"Component","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0} ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/retry-no-emit.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/retry-no-emit.expect.md index c1ae2da4ef..c300012455 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/retry-no-emit.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/retry-no-emit.expect.md @@ -52,7 +52,7 @@ export const FIXTURE_ENTRYPOINT = { ## Logs ``` -{"kind":"CompileError","fnLoc":{"start":{"line":5,"column":0,"index":195},"end":{"line":13,"column":1,"index":389},"filename":"retry-no-emit.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook","details":[{"kind":"error","loc":{"start":{"line":11,"column":2,"index":352},"end":{"line":11,"column":6,"index":356},"filename":"retry-no-emit.ts","identifierName":"arr2"},"message":"This value cannot be modified"}]}}} +{"kind":"CompileError","fnLoc":{"start":{"line":5,"column":0,"index":195},"end":{"line":13,"column":1,"index":389},"filename":"retry-no-emit.ts"},"detail":{"options":{"severity":"InvalidReact","category":"This value cannot be modified","description":"Modifying a value previously passed as an argument to a hook is not allowed. Consider moving the modification before calling the hook.","details":[{"kind":"error","loc":{"start":{"line":11,"column":2,"index":352},"end":{"line":11,"column":6,"index":356},"filename":"retry-no-emit.ts","identifierName":"arr2"},"message":"value cannot be modified"}]}}} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":7,"column":2,"index":248},"end":{"line":7,"column":36,"index":282},"filename":"retry-no-emit.ts"},"decorations":[{"start":{"line":7,"column":31,"index":277},"end":{"line":7,"column":34,"index":280},"filename":"retry-no-emit.ts","identifierName":"arr"}]} {"kind":"AutoDepsDecorations","fnLoc":{"start":{"line":10,"column":2,"index":306},"end":{"line":10,"column":44,"index":348},"filename":"retry-no-emit.ts"},"decorations":[{"start":{"line":10,"column":25,"index":329},"end":{"line":10,"column":29,"index":333},"filename":"retry-no-emit.ts","identifierName":"arr2"},{"start":{"line":10,"column":25,"index":329},"end":{"line":10,"column":29,"index":333},"filename":"retry-no-emit.ts","identifierName":"arr2"},{"start":{"line":10,"column":35,"index":339},"end":{"line":10,"column":42,"index":346},"filename":"retry-no-emit.ts","identifierName":"propVal"}]} {"kind":"CompileSuccess","fnLoc":{"start":{"line":5,"column":0,"index":195},"end":{"line":13,"column":1,"index":389},"filename":"retry-no-emit.ts"},"fnName":"Foo","memoSlots":0,"memoBlocks":0,"memoValues":0,"prunedMemoBlocks":0,"prunedMemoValues":0} diff --git a/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts b/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts index 887e218dda..e18398337b 100644 --- a/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts +++ b/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts @@ -159,7 +159,7 @@ const tests: CompilerTestCases = { message: /Handle var kinds in VariableDeclaration/, }, { - message: /Mutating component props or hook arguments is not allowed/, + message: /Modifying component props or hook arguments is not allowed/, }, ], }, @@ -195,7 +195,7 @@ const tests: CompilerTestCases = { errors: [ { message: - /Unexpected reassignment of a variable which was defined outside of the component/, + /Cannot reassign variables declared outside of the component\/hook/, }, ], }, diff --git a/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRuleTypescript-test.ts b/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRuleTypescript-test.ts index 071bfb2e7b..5a2bea6852 100644 --- a/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRuleTypescript-test.ts +++ b/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRuleTypescript-test.ts @@ -61,7 +61,7 @@ const tests: CompilerTestCases = { `, errors: [ { - message: /Mutating a value returned from 'useState\(\)'/, + message: /Modifying a value returned from 'useState\(\)'/, line: 7, }, ], diff --git a/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRule-test.ts b/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRule-test.ts index 1da7d8f57f..a636c59375 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRule-test.ts +++ b/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRule-test.ts @@ -161,7 +161,7 @@ const tests: CompilerTestCases = { message: /Handle var kinds in VariableDeclaration/, }, { - message: /Mutating component props or hook arguments is not allowed/, + message: /Modifying component props or hook arguments is not allowed/, }, ], }, @@ -197,7 +197,7 @@ const tests: CompilerTestCases = { errors: [ { message: - /Unexpected reassignment of a variable which was defined outside of the component/, + /Cannot reassign variables declared outside of the component\/hook/, }, ], }, diff --git a/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleTypescript-test.ts b/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleTypescript-test.ts index 28133aee7b..9d05cd1871 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleTypescript-test.ts +++ b/packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleTypescript-test.ts @@ -63,7 +63,7 @@ const tests: CompilerTestCases = { `, errors: [ { - message: /Mutating a value returned from 'useState\(\)'/, + message: /Modifying a value returned from 'useState\(\)'/, line: 7, }, ],