From 530f2c293d6b104c6ada1f2328fa7372be502c5f Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Thu, 15 Feb 2024 19:00:21 -0500 Subject: [PATCH] Add test fixture showing invalid location Add test fixture showing invalid location The error should be on the node mutating the output, not in the read location. --- ...rror.invalid-mutation-in-closure.expect.md | 28 +++++++++++++++++++ .../error.invalid-mutation-in-closure.js | 7 +++++ 2 files changed, 35 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.js 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; +}