2 ms·
JSX makes your eyes bleed? Perhaps you would love E4X as well! Pretty much same concept: var someXML = <text>Why not?</text>; Sadly, it's no longer suppor
by jchw 8y ago
JSX makes your eyes bleed? Perhaps you would love E4X as well! Pretty much same concept:
var someXML = <text>Why not?</text>;
Sadly, it's no longer supported in Firefox, but there are some ECMAScript variants still supporting E4X syntax, probably most notably ActionScript 3 as used in Adobe Flash.
Personally I love JSX, since it gives you all of the same power as template-based languages with virtually turing complete DSLs, but with JavaScript instead of a DSL. Not always as elegant, but almost always easier to understand.
My only real complaint is what JSX compiles down to. I think that it should either compile down to some data (like JSON data) or JSX should just be an alternative function call syntax. Instead, it compiles down to calls to React in most implementations (though usually, like with TypeScript for example, you can customize what it calls exactly.) The calls also vary depending on if the tag is lowercase or uppercase, since that's how React tells primitive tags apart from components. Frankly, a little ugly.
- sephoric 8y agoI actually like how it compiles down. In a native macOS app I just released this morning, I wrote originally in Preact, converting JSX to function calls to avoid a build phase, and eventually replaced the Preact function with a custom function that creates DOM elements directly. Not only was it a fun learning experience, but it took a relatively tiny amount of time to do, precisely because translating JSX to equivalent DOM node creation code is so predictable and transparent.
- thangngoc89 8y agobabel-plugin-transform-react-jsx accepts several options that allows you to configure what JSX is compiled to. You can see it in details in the docs here https://babeljs.io/docs/en/babel-plugin-transform-react-jsx https://babeljs.io/docs/en/babel-plugin-transform-react-jsx