You cannot access referenced objects in an visibility expression.
If you want to show a widget when a reference is selected, then the this expression will be sufficient;
$currentObject/Module.EntityA_EntityB != empty
Suggesting @Rene answer for this case , along with that if your looking for associated object attributes values in visibility expression either can put a data view of selected entity and give your target input box inside of it or a data view with data source as microflow to get the required object and return.
Note: Microflow suggestion would be use full in less on change events. Entering your values need refresh in client to run our microflow again.
Hope this helps!