Skip to content

Commit 5d9ed76

Browse files
author
Juan Tejada
committed
[DevTools] Using array destructuring without assigning first variable does not error
1 parent 6abda7f commit 5d9ed76

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
@@ -270,7 +270,7 @@ function getHookVariableName(
270270
const nodeType = hook.node.id.type;
271271
switch (nodeType) {
272272
case AST_NODE_TYPES.ARRAY_PATTERN:
273-
return !isCustomHook ? hook.node.id.elements[0].name : null;
273+
return !isCustomHook ? hook.node.id.elements[0]?.name ?? null : null;
274274

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

0 commit comments

Comments
 (0)