diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.expect.md new file mode 100644 index 0000000000..95d7ff68ca --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.expect.md @@ -0,0 +1,28 @@ + +## Input + +```javascript +function useInvalidMutation(options) { + function test() { + foo(options.foo); // error should not point on this line + options.foo = "bar"; + } + return test; +} + +``` + + +## Error + +``` + 1 | function useInvalidMutation(options) { + 2 | function test() { +> 3 | foo(options.foo); // error should not point on this line + | ^^^^^^^^^^^ [ReactForget] InvalidReact: Mutating props or hook arguments is not allowed. Consider using a local variable instead. (3:3) + 4 | options.foo = "bar"; + 5 | } + 6 | return test; +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.js new file mode 100644 index 0000000000..55581fedc3 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.js @@ -0,0 +1,7 @@ +function useInvalidMutation(options) { + function test() { + foo(options.foo); // error should not point on this line + options.foo = "bar"; + } + return test; +}