This is because JavaScript interprets
return { bar: "hello" };
like return , followed by the creation of a block (which is ignored at runtime). Not how to "return an object." And I really don't know why JavaScript developers made this decision.
In any case, ASI inserts ; after return , which leads to the equivalent code:
return; { bar: "hello" };
The new line after return is the culprit. Do not use it if you want to return something.
source share