3 ms·
> JSX is still a templating language No, it isn't a templating language, it's still just JavaScript - calls to createElement or _jsx or other function with som
by jakubmazanec 2y ago
> JSX is still a templating language
No, it isn't a templating language, it's still just JavaScript - calls to createElement or _jsx or other function with some syntactic sugar to make it look like HTML.
- svachalek 2y ago> with some syntactic sugar isn't that what a templating language is?
- jakubmazanec 2y agoNo. Do you seriously don't understand the difference between JSX, a simple syntax extension that compiles to JavaScript function calls, and a templating language, for example Vue's templating syntax [1] or EJS [2] ? [1] https://vuejs.org/guide/essentials/template-syntax https://vuejs.org/guide/essentials/template-syntax [2] https://ejs.co/ https://ejs.co/
- lolinder 2y agoRather than acting like OP is stupid for not seeing the difference, why don't you enlighten us? From where I'm sitting it looks like maybe you're describing a difference in complexity levels? Vue compiles to a representation that is less obviously related to the template? Or what? I, like OP, am genuinely unsure what distinction you're drawing. It seems like you might just feel that templates are icky and jsx isn't icky.
- jakubmazanec 2y agoIt's trivial. JSX is just syntactic sugar for JavaScript, and templating languages aren't that. They also aren't just syntactic sugar. It's literally apples and oranges. I ask again, what is difficult to understand about this? Or do you think it's not true?
- WorldMaker 2y agoYou may have stricter internal boundaries of what constitutes a "language" than many of us do. Languages are a spectrum and I find there are few hard boundaries in practice. Depending on how you define "syntactic sugar" (and I believe it is a much harder thing to define than you may expect) every language is just "syntactic sugar" for some form of machine code. JSX is a language that takes XML-influenced templates embedded in JS files and compiles that to JS files. EJS is a template language that can embed JS snippets and compiles that to JS files (or interprets it at runtime, though the distinction between compilers and interpreters I think is largely irrelevant here). They both have the same general target compiled language, and they both have similar transformations from an original document to a new process. The biggest difference I mentioned is an "inversion" of what people think of as a template language (the template being the "focus" and scripting it being secondary/embedded), but I don't think that disqualifies it as a template language. Subjective feelings of "syntax sugar" or not, JSX is a language intended to write templates in. That's a "template language" by tautology, if not also by definition.
- jakubmazanec 2y agoNo, JSX is syntactic sugar and nothing more, it requires no context, you can "transpile" it from memory. In my code I sometimes explicitly use React.createElement calls, when using JSX is not that useful, because it's always just writing JavaScript, not writing templates; it's just code. Template languages also add different semantics, e.g. those EJS <% or <%_ tags - you can't express them in some equivalent JavaScript code (don't confuse it with compiling the template to some code, that's something completely different).
- int_19h 2y agoIf JSX was exactly the same feature-wise, but was part of the core JS spec, would JS+JSX suddenly become a "templating language" then?