Skip to content

Commit f923e44

Browse files
author
Juan Tejada
committed
[DevTools] Using array destructuring without assigning first variable does not error
1 parent f1db9c3 commit f923e44

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

packages/react-devtools-extensions/src/__tests__/__source__/__untransformed__/ComponentWithUseState.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function Component(props) {
1414
const [foo] = useState(true);
1515
const bar = useState(true);
1616
const [baz] = React.useState(true);
17+
const [, forceUpdate] = useState();
1718
return `${foo}-${bar}-${baz}`;
1819
}
1920

20-
module.exports = {Component};
21+
module.exports = {Component};

packages/react-devtools-extensions/src/__tests__/parseHookNames-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('parseHookNames', () => {
9595
const Component = require('./__source__/__untransformed__/ComponentWithUseState')
9696
.Component;
9797
const hookNames = await getHookNamesForComponent(Component);
98-
expectHookNamesToEqual(hookNames, ['foo', 'bar', 'baz']);
98+
expectHookNamesToEqual(hookNames, ['foo', 'bar', 'baz', null]);
9999
});
100100

101101
it('should parse names for useReducer()', async () => {

packages/react-devtools-extensions/src/astUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function getHookVariableName(
271271
const nodeType = hook.node.id.type;
272272
switch (nodeType) {
273273
case AST_NODE_TYPES.ARRAY_PATTERN:
274-
return !isCustomHook ? hook.node.id.elements[0].name : null;
274+
return !isCustomHook ? hook.node.id.elements[0]?.name ?? null : null;
275275

276276
case AST_NODE_TYPES.IDENTIFIER:
277277
return hook.node.id.name;

0 commit comments

Comments
 (0)