Compare commits
1 Commits
asserts-st
...
pr35184
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12d3951727 |
@@ -400,7 +400,15 @@ export function compileProgram(
|
|||||||
*/
|
*/
|
||||||
const suppressions = findProgramSuppressions(
|
const suppressions = findProgramSuppressions(
|
||||||
pass.comments,
|
pass.comments,
|
||||||
pass.opts.eslintSuppressionRules ?? DEFAULT_ESLINT_SUPPRESSIONS,
|
/*
|
||||||
|
* If the compiler is validating hooks rules and exhaustive memo dependencies, we don't need to check
|
||||||
|
* for React ESLint suppressions
|
||||||
|
*/
|
||||||
|
pass.opts.environment.validateExhaustiveMemoizationDependencies &&
|
||||||
|
pass.opts.environment.validateHooksUsage
|
||||||
|
? null
|
||||||
|
: (pass.opts.eslintSuppressionRules ?? DEFAULT_ESLINT_SUPPRESSIONS),
|
||||||
|
// Always bail on Flow suppressions
|
||||||
pass.opts.flowSuppressions,
|
pass.opts.flowSuppressions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export function filterSuppressionsThatAffectFunction(
|
|||||||
|
|
||||||
export function findProgramSuppressions(
|
export function findProgramSuppressions(
|
||||||
programComments: Array<t.Comment>,
|
programComments: Array<t.Comment>,
|
||||||
ruleNames: Array<string>,
|
ruleNames: Array<string> | null,
|
||||||
flowSuppressions: boolean,
|
flowSuppressions: boolean,
|
||||||
): Array<SuppressionRange> {
|
): Array<SuppressionRange> {
|
||||||
const suppressionRanges: Array<SuppressionRange> = [];
|
const suppressionRanges: Array<SuppressionRange> = [];
|
||||||
@@ -89,7 +89,7 @@ export function findProgramSuppressions(
|
|||||||
let disableNextLinePattern: RegExp | null = null;
|
let disableNextLinePattern: RegExp | null = null;
|
||||||
let disablePattern: RegExp | null = null;
|
let disablePattern: RegExp | null = null;
|
||||||
let enablePattern: RegExp | null = null;
|
let enablePattern: RegExp | null = null;
|
||||||
if (ruleNames.length !== 0) {
|
if (ruleNames != null && ruleNames.length !== 0) {
|
||||||
const rulePattern = `(${ruleNames.join('|')})`;
|
const rulePattern = `(${ruleNames.join('|')})`;
|
||||||
disableNextLinePattern = new RegExp(
|
disableNextLinePattern = new RegExp(
|
||||||
`eslint-disable-next-line ${rulePattern}`,
|
`eslint-disable-next-line ${rulePattern}`,
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// @validateExhaustiveMemoizationDependencies
|
||||||
|
|
||||||
|
import {useMemo} from 'react';
|
||||||
|
import {ValidateMemoization} from 'shared-runtime';
|
||||||
|
|
||||||
|
function Component({x}) {
|
||||||
|
useEffect(
|
||||||
|
() => {
|
||||||
|
console.log(x);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
},
|
||||||
|
[
|
||||||
|
/* intentionally missing deps */
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
const memo = useMemo(() => {
|
||||||
|
return [x];
|
||||||
|
}, [x]);
|
||||||
|
|
||||||
|
return <ValidateMemoization inputs={[x]} output={memo} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Code
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { c as _c } from "react/compiler-runtime"; // @validateExhaustiveMemoizationDependencies
|
||||||
|
|
||||||
|
import { useMemo } from "react";
|
||||||
|
import { ValidateMemoization } from "shared-runtime";
|
||||||
|
|
||||||
|
function Component(t0) {
|
||||||
|
const $ = _c(10);
|
||||||
|
const { x } = t0;
|
||||||
|
let t1;
|
||||||
|
if ($[0] !== x) {
|
||||||
|
t1 = () => {
|
||||||
|
console.log(x);
|
||||||
|
};
|
||||||
|
$[0] = x;
|
||||||
|
$[1] = t1;
|
||||||
|
} else {
|
||||||
|
t1 = $[1];
|
||||||
|
}
|
||||||
|
let t2;
|
||||||
|
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
||||||
|
t2 = [];
|
||||||
|
$[2] = t2;
|
||||||
|
} else {
|
||||||
|
t2 = $[2];
|
||||||
|
}
|
||||||
|
useEffect(t1, t2);
|
||||||
|
let t3;
|
||||||
|
if ($[3] !== x) {
|
||||||
|
t3 = [x];
|
||||||
|
$[3] = x;
|
||||||
|
$[4] = t3;
|
||||||
|
} else {
|
||||||
|
t3 = $[4];
|
||||||
|
}
|
||||||
|
const memo = t3;
|
||||||
|
let t4;
|
||||||
|
if ($[5] !== x) {
|
||||||
|
t4 = [x];
|
||||||
|
$[5] = x;
|
||||||
|
$[6] = t4;
|
||||||
|
} else {
|
||||||
|
t4 = $[6];
|
||||||
|
}
|
||||||
|
let t5;
|
||||||
|
if ($[7] !== memo || $[8] !== t4) {
|
||||||
|
t5 = <ValidateMemoization inputs={t4} output={memo} />;
|
||||||
|
$[7] = memo;
|
||||||
|
$[8] = t4;
|
||||||
|
$[9] = t5;
|
||||||
|
} else {
|
||||||
|
t5 = $[9];
|
||||||
|
}
|
||||||
|
return t5;
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Eval output
|
||||||
|
(kind: exception) Fixture not implemented
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// @validateExhaustiveMemoizationDependencies
|
||||||
|
|
||||||
|
import {useMemo} from 'react';
|
||||||
|
import {ValidateMemoization} from 'shared-runtime';
|
||||||
|
|
||||||
|
function Component({x}) {
|
||||||
|
useEffect(
|
||||||
|
() => {
|
||||||
|
console.log(x);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
},
|
||||||
|
[
|
||||||
|
/* intentionally missing deps */
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
const memo = useMemo(() => {
|
||||||
|
return [x];
|
||||||
|
}, [x]);
|
||||||
|
|
||||||
|
return <ValidateMemoization inputs={[x]} output={memo} />;
|
||||||
|
}
|
||||||
@@ -53,8 +53,10 @@ const opts: RunnerOptions = yargs
|
|||||||
.default('worker-threads', true)
|
.default('worker-threads', true)
|
||||||
.boolean('watch')
|
.boolean('watch')
|
||||||
.describe('watch', 'Run compiler in watch mode, re-running after changes')
|
.describe('watch', 'Run compiler in watch mode, re-running after changes')
|
||||||
|
.alias('w', 'watch')
|
||||||
.default('watch', false)
|
.default('watch', false)
|
||||||
.boolean('update')
|
.boolean('update')
|
||||||
|
.alias('u', 'update')
|
||||||
.describe('update', 'Update fixtures')
|
.describe('update', 'Update fixtures')
|
||||||
.default('update', false)
|
.default('update', false)
|
||||||
.boolean('filter')
|
.boolean('filter')
|
||||||
|
|||||||
Reference in New Issue
Block a user