I would prefer flattening to be explicit, so it's easier to predict what "hello.world.foo" actually means.

Simplest thing is to just make it an external function, so users could call compileExpression('a.b.c')(flatten(somedata)) if that's what they want. It also allows users to plug in their own flattening strategies if they want and doesn't add overhead for users who don't need it.