I thin it would be easier to follow if it was:

```js
// If widget is hidden it's panel need to anchor different `anchorNode` element,
// there override `domNode` with it.
if (anchorNode) {
  // Hide menu panel if clicked widget is in it.
  let menuPanel = getPanelForNode(domNode);
  if (menuPanel)
    menuPanel.hidePopup(); 

  domNode = anchorNode;
}
```