According to §22.2.4 The RegExp Constructor:
Thus the function call
RegExp(…)is equivalent to the object creation expression
new RegExp(…)with the same arguments.
> r = /a/; /a/ > RegExp(r) === r true > new RegExp(r) === r false
and looking at the steps in §126.96.36.199, it should only be possible for the
RegExp constructor to return its argument unchanged (2.b.ii) when NewTarget is undefined, i.e. it was called as
RegExp(…) rather than
Does the equivalence claim need to be corrected? It seems to have motivated an incorrect optimization in the SWC minifier.