Search code examples
javascriptcode-translation

Transpiler and compiler


I was wondering between the transpiler and compiler.

For example, I have a language('let's call it foo') and it will be transpiled to javascript.

foo -----transpiled-----> javascript

However, is foo limited under javascript?

Such as: "JavaScript cannot write to files on the server without the help of a server side script"

foo ----x----> write to files on the server without the help of a server side script

If so, is it possible to exit from the limit of javascript?

Such as making foo able to write to file itself.

foo ---------> write to files on the server

Note: What i am asking for is explanation and why and so on, NOT THE CODES!

Note again: Is it possible for it to exit the limits with additional libraries?

Edit: So, if i added another library from another language like python, will it help to exit the limits?


Solution

  • 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)