Skip to content

Commit

Permalink
Merge branch 'main' into update-react-refresh-builtin-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
damianstasik authored Feb 5, 2024
2 parents a498588 + 95ec128 commit 1f2fe14
Show file tree
Hide file tree
Showing 107 changed files with 5,378 additions and 2,926 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contact_links:
- name: 📃 Documentation Issue
url: https://github.com/reactjs/reactjs.org/issues/new
url: https://github.com/reactjs/react.dev/issues/new/choose
about: This issue tracker is not for documentation issues. Please file documentation issues here.
- name: 🤔 Questions and Help
url: https://reactjs.org/community/support.html
Expand Down
4 changes: 2 additions & 2 deletions fixtures/dom/src/__tests__/nested-act-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('unmocked scheduler', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
DOMAct = React.unstable_act;
DOMAct = React.act;
TestRenderer = require('react-test-renderer');
TestAct = TestRenderer.act;
});
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('mocked scheduler', () => {
require.requireActual('scheduler/unstable_mock')
);
React = require('react');
DOMAct = React.unstable_act;
DOMAct = React.act;
TestRenderer = require('react-test-renderer');
TestAct = TestRenderer.act;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7747,6 +7747,33 @@ const testsTypescript = {
}
`,
},
{
code: normalizeIndent`
function App(props) {
React.useEffect(() => {
console.log(props.test);
}, [props.test] as const);
}
`,
},
{
code: normalizeIndent`
function App(props) {
React.useEffect(() => {
console.log(props.test);
}, [props.test] as any);
}
`,
},
{
code: normalizeIndent`
function App(props) {
React.useEffect((() => {
console.log(props.test);
}) as any, [props.test]);
}
`,
},
],
invalid: [
{
Expand Down
22 changes: 20 additions & 2 deletions packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,12 @@ export default {

const declaredDependencies = [];
const externalDependencies = new Set();
if (declaredDependenciesNode.type !== 'ArrayExpression') {
const isArrayExpression =
declaredDependenciesNode.type === 'ArrayExpression';
const isTSAsArrayExpression =
declaredDependenciesNode.type === 'TSAsExpression' &&
declaredDependenciesNode.expression.type === 'ArrayExpression';
if (!isArrayExpression && !isTSAsArrayExpression) {
// If the declared dependencies are not an array expression then we
// can't verify that the user provided the correct dependencies. Tell
// the user this in an error.
Expand All @@ -631,7 +636,11 @@ export default {
'dependencies.',
});
} else {
declaredDependenciesNode.elements.forEach(declaredDependencyNode => {
const arrayExpression = isTSAsArrayExpression
? declaredDependenciesNode.expression
: declaredDependenciesNode;

arrayExpression.elements.forEach(declaredDependencyNode => {
// Skip elided elements.
if (declaredDependencyNode === null) {
return;
Expand Down Expand Up @@ -1214,6 +1223,15 @@ export default {
isEffect,
);
return; // Handled
case 'TSAsExpression':
visitFunctionWithDependencies(
callback.expression,
declaredDependenciesNode,
reactiveHook,
reactiveHookName,
isEffect,
);
return; // Handled
case 'Identifier':
if (!declaredDependenciesNode) {
// No deps, no problems.
Expand Down
Loading

0 comments on commit 1f2fe14

Please sign in to comment.