DEV Community

Discussion on: A Look at Compilation in JavaScript Frameworks

Collapse
hoichi profile image
Sergey Samokhov

One thing that worries me about this development is that compiled frameworks seem to phase more or less general-purpose compiled languages like ReScript or PureScript or ClojureScript. Sure, both Svelte and SolidJS support TypeScript, but that requires effort on the framework maintanters' part, so how likely is it that, say, Solid will ever support ReScript? Sure, you can somehow marry the compiled framework and an AltJs language (I think in ReScript's case you could even add genType to generate TS, but it's still not a perfect setup: Svelte components just consume ReScript functions, so there's no ReScript features in UI: no concise sum types with exhaustive pattern matching, no runtime currying or pipes.

So the whole situation only reinforces the TS monopoly. And it's not that TS is an awful language, but any monopoly leads to stagnation. And also I think there are still better languages than TypeScript, so the whole situation leaves you with the choice between a modern compiled framework with TypeScript and a nice business-logic friendly compiled language that wraps good old React (ReScript, PureScirpt, ClosureScript), or Preact (Mint), or its own VDom-based implementation (Elm). Or, if you're desperate enough, you could try to convince the language maintainers to alter their JSX compilation to support Solid 🤔

Collapse
steakeye profile image
Andrew Keats

Svelte is extensible enough that if you wanted to, you could add support for ResCript via a preprocessor: svelte.dev/docs#svelte_preprocess.

Collapse
steakeye profile image
Andrew Keats • Edited

Or an alternative approach is to import external res files into your svelte components: github.com/sabinbajracharya/Svelte...

Thread Thread
hoichi profile image
Sergey Samokhov • Edited

That's always a possibity. You can even generate TypeScript types from ReScript. I was also thinking of using ReScript for domain logic and TypeScript for (React) JSX, because TypeScript has less ceremony for conditional rendering. But that scenario is not perfect. For one thing, if ReScript is your language of choice, not being able to use it in your views is not much better than just using templates with a DSL for loops and conditions. No big deal, but I'm already spoiled by the flexitibily of JSX. Also, having to compile (or at least typecheck) both ReScript and TypeScript means maintaining more dependencies. Also, TypeScirpt error messages are kinda meh. Also, context switching. So, all things being equal, I think I'd prefer to use less languages.

Collapse
ryansolid profile image
Ryan Carniato Author

Yeah mind you does this work in the rest of the template? I read this as a way to process blocks. I know like Riot and Knockout used to also support setting the language in the template. Like in the expressions but on quick read I didn't see that.

I imagine it is possible for JavaScript based framework to import Rescript files and if they aren't working on custom Single File Component formats then they can get the full power of it without any preprocessor. But getting the syntax inside the template I think is the more interesting challenge. JSX feels like it could be that bridge with the right support.

Collapse
ryansolid profile image
Ryan Carniato Author

The latter is what we've been looking at with Solid. They support React. Honestly if we could just preserve JSX equivalent. Or even HyperScript can be converted back to JSX is something looked at. All that being said still requires some amount of language support. This is the active discussion: github.com/solidjs/solid/discussio....

It's a tricky one though. TS was hard enough to support for language features. It still restricts what we can do with JSX to this day. I think at least in Solid's case the solution is making the JSX types more adaptable. If ReScript had the same sort of flexibility around JSX like TS does there would be no pause to support it.

Collapse
hoichi profile image
Sergey Samokhov

I'm not sure it's possible for ReScript compiler to leave JSX as is, for several reasons. For instance, at least from the typechecking perspective, every rescript-react component has a make function (that takes a props object) and a makeProps function with named arguments. Also bar in <Foo bar /> in ReScript is a shortcut for bar=bar, not for bar=true.

So I guess it all requires a bit of effort on the teams part. Here's hoping they're going to find time for it at some point. There is some interest, and I hope SolidJS gains some traction and the interest will only increase in the coming months and years.