You could use an explicit interpolation of variable’s definition during your site build, to change the function files on disk. Something like this may work, appended to your usual build command:
&& sed -i s/PLACEHOLDER/${COMMIT_REF}/g function.js
to use the value that is present in the shell that your build is run in. It’s not elegant and you can probably find a better way, but the key is that since we aren’t interpolating for you, you can do so yourself via some mechanism.