Skip to content

Commit

Permalink
[DevTools] Using array destructuring without assigning first variable…
Browse files Browse the repository at this point in the history
… does not error
  • Loading branch information
Juan Tejada committed Aug 18, 2021
1 parent 6abda7f commit 5d9ed76
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function Component(props) {
const [foo] = useState(true);
const bar = useState(true);
const [baz] = React.useState(true);
const [, forceUpdate] = useState();
return `${foo}-${bar}-${baz}`;
}

module.exports = {Component};
module.exports = {Component};
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('parseHookNames', () => {
const Component = require('./__source__/__untransformed__/ComponentWithUseState')
.Component;
const hookNames = await getHookNamesForComponent(Component);
expectHookNamesToEqual(hookNames, ['foo', 'bar', 'baz']);
expectHookNamesToEqual(hookNames, ['foo', 'bar', 'baz', null]);
});

it('should parse names for useReducer()', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-extensions/src/astUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function getHookVariableName(
const nodeType = hook.node.id.type;
switch (nodeType) {
case AST_NODE_TYPES.ARRAY_PATTERN:
return !isCustomHook ? hook.node.id.elements[0].name : null;
return !isCustomHook ? hook.node.id.elements[0]?.name ?? null : null;

case AST_NODE_TYPES.IDENTIFIER:
return hook.node.id.name;
Expand Down

0 comments on commit 5d9ed76

Please sign in to comment.