Skip to content

Commit 157743a

Browse files
author
Brian Vaughn
committed
DevTools: Update named hooks match to use column number also
This prevents edge cases where AST nodes are incorrectly matched.
1 parent 92af60a commit 157743a

24 files changed

+322
-76
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ packages/react-devtools-extensions/chrome/build
2121
packages/react-devtools-extensions/firefox/build
2222
packages/react-devtools-extensions/shared/build
2323
packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/
24+
packages/react-devtools-extensions/src/__tests__/__source__/__untransformed__/
2425
packages/react-devtools-extensions/src/ErrorTesterCompiled.js
2526
packages/react-devtools-inline/dist
2627
packages/react-devtools-shell/dist

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ packages/react-devtools-extensions/chrome/build
33
packages/react-devtools-extensions/firefox/build
44
packages/react-devtools-extensions/shared/build
55
packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/
6+
packages/react-devtools-extensions/src/__tests__/__source__/__untransformed__/
67
packages/react-devtools-extensions/src/ErrorTesterCompiled.js
78
packages/react-devtools-inline/dist
89
packages/react-devtools-shell/dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import {createContext, useContext} from 'react';
11+
12+
const A = createContext(1);
13+
const B = createContext(2);
14+
15+
export function Component() {
16+
const a1 = useContext(A);
17+
const b1 = useContext(B);
18+
19+
// eslint-disable-next-line one-var
20+
const a2 = useContext(A),
21+
b2 = useContext(B);
22+
23+
return a1 + b1 + a2 + b2;
24+
}

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/bundle/index.js

+23-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/bundle/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/ComponentWithMultipleHooksPerLine.js

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/ComponentWithMultipleHooksPerLine.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/index.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/external/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/inline/ComponentWithMultipleHooksPerLine.js

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-devtools-extensions/src/__tests__/__source__/__compiled__/inline/index.js

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
const {useDebugValue, useState} = require('react');
11+
12+
function Component(props) {
13+
const foo = useCustomHookOne();
14+
// This cae is ignored;
15+
// the meaning of a tuple assignment for a custom hook is unclear.
16+
const [bar] = useCustomHookTwo();
17+
return `${foo}-${bar}`;
18+
}
19+
20+
function useCustomHookOne() {
21+
// DebugValue hook should not appear in log.
22+
useDebugValue('example');
23+
return true;
24+
}
25+
26+
function useCustomHookTwo() {
27+
const [baz, setBaz] = useState(true);
28+
return [baz, setBaz];
29+
}
30+
31+
module.exports = {Component};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
const {useDebugValue} = require('react');
11+
12+
function Component(props) {
13+
useCustomHookOne();
14+
const [bar] = useCustomHookTwo();
15+
return bar;
16+
}
17+
18+
function useCustomHookOne() {
19+
// DebugValue hook should not appear in log.
20+
useDebugValue('example');
21+
}
22+
23+
function useCustomHookTwo() {
24+
// DebugValue hook should not appear in log.
25+
useDebugValue('example');
26+
return [true];
27+
}
28+
29+
module.exports = {Component};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
const React = require('react');
11+
const {useEffect} = React;
12+
13+
function Component(props) {
14+
useEffect(() => {});
15+
React.useLayoutEffect(() => () => {});
16+
return null;
17+
}
18+
19+
module.exports = {Component};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
const React = require('react');
11+
const {useReducer} = React;
12+
13+
function Component(props) {
14+
const [foo] = useReducer(true);
15+
const [bar] = useReducer(true);
16+
const [baz] = React.useReducer(true);
17+
return `${foo}-${bar}-${baz}`;
18+
}
19+
20+
module.exports = {Component};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
const React = require('react');
11+
const {useState} = React;
12+
13+
function Component(props) {
14+
const [foo] = useState(true);
15+
const bar = useState(true);
16+
const [baz] = React.useState(true);
17+
return `${foo}-${bar}-${baz}`;
18+
}
19+
20+
module.exports = {Component};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The JavaScript source files in this directory are not linted or pre-processed in any way. This is intentional, since they are used by the `parseHookNames-test` to test the behavior of "uncompiled" JavaScript (without source maps).

packages/react-devtools-extensions/src/__tests__/__source__/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
export {Component as ComponentWithCustomHook} from './ComponentWithCustomHook';
1111
export {Component as ComponentWithExternalCustomHooks} from './ComponentWithExternalCustomHooks';
12+
export {Component as ComponentWithMultipleHooksPerLine} from './ComponentWithMultipleHooksPerLine';
1213
export {Component as Example} from './Example';
1314
export {Component as InlineRequire} from './InlineRequire';
1415
import * as ToDoList from './ToDoList';

0 commit comments

Comments
 (0)