This is up to the DMYou cannot use class features while polymorphed
For those companions which are calculated based on your own statistics, there is no explicit guidance in the rules how to calculate the attack bonus if your statistics change later on. In such cases the DM needs to make a ruling. Xanathar's Guide to Everything, p. 4:
The DM is key. Many unexpected events can occur in
a D&D campaign, and no set of rules could reasonably
account for every contingency. If the rules tried to do so,
the game would become a s log. An alternative would be
for the rules to severely limit what characters can do,
which would be contrary to the open-endedness of D&D.
Here's the path the game takes: it lays a foundation of
rules that a DM can build on, and it embraces the DM's
role as the bridge between the things the rules address
and the things they don't.
Below are two possible ways for how to do it. If you keep the creatures around, leaving the bonuses unchanged is a much better solution for practical play.
Polymorph says:
Class and class features are a game statistic that get replaced, soand you cannot use class features while polymorphed. The Artificer's steel defender is a class feature, as is the Ranger's companion. Right under Steel Defender, for example it says
Companions as class features
So a literal reading of the rules would be that they would vanish as your statistics get replaced and you are polymorphed into a beast. Maybe, the way to think about it is these companion are really an extension of you, the character, and they get cannot use these companions while polymorphed into the beast, along with youbecause they are class features. This has the side effect that thereThere is no need to worry about what thecalulate an attack bonus would be: there is no companion that could attack.
Companions as their own entities
Let's assume How the DM feels that this is not how it should play;handles that the feature is the abilityagain up to create the companion, and once the companion is there, it sticks around. It seems more natural, also because you might not even think of these creatures as class features when polymorph happens, and thenthem -- either they stick aroundvanish while the character themselves isyou are polymorphed.
In this case, how this is handled, is up to the DM. I would strongly recommend to keep the bonuses as they (they are, if only for practical reasons: you otherwise have to recalculate everything for the new form an extension of choiceyourself, and that will slow down play to a grinding halt, apart from being a boring exercise. There is little play value in doing that.
There is some abmiguity regarding the effecsbecome part of class feature use being overwritten, because for example, the Transmutation Wizard has the Shapechanger class feature that says:
You can cast polymorph without expending a spell slot. When you
do so, you can target only yourself and transform into a
beast whose challenge rating is 1 or lower.
This would not work if the class feature goes away when they are polymorphed, the polymorph would then end.
Likewise, while spellcasting is a class feature, it is not clear if the creatures summoned would count as a class feature, too. Most likely noteffect), because while spells are magicalor they become inert, or they only defend themselves attacks by such creatures are not magical either.
And there even-- it is a Sage Advice Companion Q/A:
Can you concentrate on a spell while transformed
by polymorph? You can’t cast spells while you’re transformed
by polymorph, but nothing in the spell prevents you from concentrating on a sell that you previously cast
before being transformed.
Which also clearly says that the spell once cast (i.e. the result of usingup to the spellcasting feature) is not overwritten or replaced by polymorphDM.