cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.45k stars 160 forks source link

Conditional Code Transpilation Support #586

Closed tomansill closed 3 years ago

tomansill commented 4 years ago

Hi,

First of all, this project looks awesome and I am looking forward to use it in my project. I have a question about JSweet transpilation.

I am wondering if it's possible to have conditional branching on what code to be transpiled to JS.

My issue is that I want to have methods that have 2 versions where one will be run on client-side in browser with javascript and one run on server-side in Java.

I think this feature will benefit us as it can allow us to implement server-side rendering functionality in Java and get 'free' client-side rendering functionality.

Example:

Is this possible in JSweet? If so, can you point or provide examples on how to do so?

Thank you

renaudpawlak commented 4 years ago

JSweet is highly extensible and you can have different configurations or adapters to tune the behavior. Also, an alternative is to have your method to switch at runtime on an environment variable. If you still believe that some feature is missing, please provide a more concrete minimalist example and explain what would be missing exactly.

renaudpawlak commented 4 years ago

BTW, here is a pointer on the documentation to extend JSweet behavior: https://github.com/cincheo/jsweet/blob/master/doc/jsweet-language-specifications.md#extending-the-transpiler

lgrignon commented 4 years ago

Hello @tomansill Did you manage to accomplish what you had in mind?