2 ms·
What if you're compiling to JavaScript from another language, like e.g. Kotlin/JS? Does the Svelte compiler rely on some very particular JavaScript syntax, or c
by ptx 6y ago
What if you're compiling to JavaScript from another language, like e.g. Kotlin/JS? Does the Svelte compiler rely on some very particular JavaScript syntax, or could you run it on the JavaScript output from another compiler?
- lhorie 6y agoSvelte source code is not Javascript; it's a mix of JS, HTML, CSS and mustache-like syntax, so you wouldn't necessarily be able to compile to Svelte using out-of-box tooling from other ecosystems. I suppose you could compile to Svelte output, but then you'd just be reimplementing it in a different language.
- ptx 6y agoAh, that's unfortunate. At least with React (and Mithril) you can use it from pure JavaScript, which lets you replace JSX with Kotlin's DSL[1] for HTML. [1] https://github.com/Kotlin/kotlinx.html/blob/master/README.md https://github.com/Kotlin/kotlinx.html/blob/master/README.md
- yencabulator 6y agoI find using HTML for HTML much more pleasant.
- ptx 6y agoI do too, for simple things. But what do you do when you have repeating patterns and want to eliminate duplication? Usually a template language would be introduced, and now it's not HTML anymore; tools that work on plain HTML don't work with the special template language; commenting out code gets tricky because the same file has multiple kinds of syntax intermixed. And in addition to your HTML and your template language you still have your programming language. Kotlin solves this by using the programming language for the whole thing, allowing you to extract repeating parts using plain functions as you would with any other code. Of course it's not as well suited as HTML itself for writing HTML, but it might be better than HTML + some template language + some programming language. Another way to go, to avoid having a mysterious mixture of almost-HTML embedded within some other syntax, is to do what Thymeleaf does[1] and have the template language be embedded inside HTML (rather than the other way around) so that the template file is actually valid HTML. [1] https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#support-for-html5-friendly-attribute-and-element-names https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.h...