-
-
Notifications
You must be signed in to change notification settings - Fork 59
Hegel and JSX #37
Comments
Currently, Hegel doesn't work with JSX, but it will work |
If Hegel adopts JSX (which would be awesome!), please take a look at these TypeScript issues:
The TLDR of those issue is that JSX is merely a language feature, and various tools and libraries give JSX different meaning. Some tools, for example, compile JSX to DOM expressions. In the statement const div = <div>hello</div>
const div = <p><span>world</span></p> it would be great to be able to configure Hegel (either with types in code or specifying types in a config file, or something) so that the To take the idea further, maybe there could be (for exampe), a type error if a In TypeScript currently, JSX expressions have only one type, If Hegel will add JSX, there's a chance here to do it a better way than with TypeScript, making it more generic and useful for a variety of use cases. cc @ryansolid |
@trusktr. |
Framework-agnostic JSX would be so nice! |
We can make the same assumption with JSX output as with any other JS output from TS: people will write JSX (or JS) with type safety, and then view the result in the browser, without muddling with the output. They will rely on TS type checking the source, without caring about the output. |
Yeah.. although I believe that brings most of the React-isms with it. It's a path. But it feels like TypeScript has been spending the last couple years trying to backtrack from those early only consider React decisions. The JSX spec goes well beyond what React uses and that transformation. Things like attribute namespaces come to mind (which would be really useful for Vue or Svelte like templating). Or even how awkward it has been to add a universal approach to fragments. The quite literally goes on and on. |
@ryansolid if we make plugins used by hegel configurable we can support any number of frameworks/libraries for example with |
Add it to Hegel? Or add it to an app's particular build pipeline? I think it would be neat if a tool like Hegel had Babel support built in (to some degree?), so we could have both type safety and choice of (JSX) output all in one tool. |
@trusktr hegel is using babel parser and babel AST so babel plugins can be used as well |
As far as I understand, Hegel’s model is very close to Flow’s one: it provides the type system only relying on Babel build pipeline to transpile the code for use in browsers and node. Btw, while using Flow I always missed the support for Babel plugins at the type level. This blocked my team from experimenting with cutting edge language features and making our own little tweaks (say for testing). |
@JSMonk I think it's best to let handle JSX to a well established tools like |
Considering Hegel already uses Babel, maybe Hegel can just add a config option that allows the user to specify Babel presets/plugins that are used after Hegel has finished type checking and after Hegel's transform. Or maybe Hegel can only strip types (after type checking), and allow the user to specify all of the Babel transforms (overriding the default). |
How could we accomplish Hegel to work with JSX?
The text was updated successfully, but these errors were encountered: