You CAN'T exit the limits of the destination language. You could, however, create a compatibility layer that emulates the missing features and provide the functionality somehow.
In your example, if the foo internal function writefile()
is the one that writes files, you could make a library that provides a writefile function that uses ajax to store the files to the server (or a cookie or localstore, etc). The original foo script wouldn't have to be changed for it to work.
And this is precisely one of the main parts about writing a transpiler: You not only have to translate the language, but you also have to emulate the missing features.
(you can also opt to disable the missing features)