@samitouri / QOS-React / commits / 530f2c293d

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.

Jan Kassens committed Feb 15, 2024 at 19:00 UTC 530f2c293d6b104c6ada1f2328fa7372be502c5f
2 files changed +35
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.expect.md new
+28
@@ -0,0 +1,28 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function useInvalidMutation(options) {
6 + function test() {
7 + foo(options.foo); // error should not point on this line
8 + options.foo = "bar";
9 + }
10 + return test;
11 +}
12 +
13 +```
14 +
15 +
16 +## Error
17 +
18 +```
19 + 1 | function useInvalidMutation(options) {
20 + 2 | function test() {
21 +> 3 | foo(options.foo); // error should not point on this line
22 + | ^^^^^^^^^^^ [ReactForget] InvalidReact: Mutating props or hook arguments is not allowed. Consider using a local variable instead. (3:3)
23 + 4 | options.foo = "bar";
24 + 5 | }
25 + 6 | return test;
26 +```
27 +
28 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-mutation-in-closure.js new
+7
@@ -0,0 +1,7 @@
1 +function useInvalidMutation(options) {
2 + function test() {
3 + foo(options.foo); // error should not point on this line
4 + options.foo = "bar";
5 + }
6 + return test;
7 +}