If you control how the code is evaluated, maybe you can just use task_local_storage()[:SOURCE_PATH]? For example, see how Distributed.@everywhere pass around “current file context”:
It’s not enough to make line positions correct, though. For this, I think it’s simpler to parse the code and change the LineNumberNode yourself before eval. Or, maybe even simpler solution to add empty lines in the temp file.