[HN Gopher] Origins of JSX and Why It Exists
___________________________________________________________________
Origins of JSX and Why It Exists
Author : redbell
Score : 24 points
Date : 2023-07-10 13:55 UTC (9 hours ago)
(HTM) web link (dodov.dev)
(TXT) w3m dump (dodov.dev)
| masswerk wrote:
| I think, it's a bit difficult to name a particular origin like
| HyperScript. The idea has been around for a long time. It's
| actually close to the core of what JS is all about. I personally
| remember writing a small library for generating (reactive) page
| UI from hierarchical object definitions in a 2007 project, and I
| was certainly not the first to so. I wouldn't have thought so for
| a moment. I did so in the 1990s using document.write() and even
| then I wouldn't have thought of claiming the idea.
| nashashmi wrote:
| I wish this was out many years ago. Would have saved me a lot of
| time trying to understand what the new syntax was and why it was
| in syntactically valid.
|
| It still doesn't go over why the greater than and less than signs
| somehow still transform into a syntactically valid JS especially
| when none of the jsx is in quotes.
| kazinator wrote:
| The new syntax isn't syntactically valid Javascript. It's valid
| syntax inside a transpiler language like Babel.
|
| It doesn't have to be in quotes because the tool, like Babel,
| has tokenization and parsing rules for it which disambiguate it
| somehow. It basically is a kind of quote. Or, well quasiquote.
| Just like " introduces a textual quote, a token sequence like
| <div> introduces a HTML quasiquote.
|
| You can transform a language into JS that doesn't look like JS
| in any regard. So of course you can transform one that looks
| like JS, but does weird things that would be syntax errors in
| JS.
| kazinator wrote:
| JSX exists because Javascript doesn't have macros. But Javascript
| has some popular code-generating transpilers for it, and those
| are where the community can inject new syntax without having to
| have it EcmaScript and adopted by implementations of JS engines
| in browsers and elsewhere.
| DesertVarnish wrote:
| No mention of E4X?
| https://blog.vjeux.com/2013/javascript/jsx-e4x-the-good-part...
| 4lun wrote:
| This article feels rather incomplete if there's zero mention of
| XHP: https://pusher.com/blog/the-evolution-of-react/
| starkparker wrote:
| Because it's not about React (or about XML, looking at the
| sibling reference to E4X not being mentioned). It's about JSX.
| Just like your article doesn't mention JSX, and the sibling
| article on E4X calls out all the ways JSX fundamentally
| diverges from E4X, and so they "feel rather incomplete" in the
| context of comments on a post about the origins of JSX as
| explored through making a parser for JSX.
| theultdev wrote:
| The JSX syntax was inspired from work on XHP, not E4X.
|
| Seems strange to focus on E4X when discussing the origins vs
| the actual origin.
|
| Just because E4X is somewhat similar doesn't make it the
| origin.
___________________________________________________________________
(page generated 2023-07-10 23:02 UTC)