deno-front-end / eon

8 stars 0 forks source link

TSX/JSX vs Tagged Template Literals #2

Open ghost opened 3 years ago

ghost commented 3 years ago

After reading about TSX/JSX on the official TypeScript website, and a long conversation on the DFF discord channel, I'm now convinced that TSX/JSX (I'll call it XSX from now on) is a better option than tagged template literals (which I'll call TTL) for a templating mechanism. Here's why:

  1. De Facto Standard: TSX is as much of a standard as TS at this point. Deno supports both of these "standards". @timreichen was championing TTLs because of their support in the web platform. In my opinion, Deno extends the web platform to include TS(X), so, because this is a Deno-first framework, and Deno supports these "secondary standards", we should be treating them as part of the "augmented-js-standards"-based platform.
  2. Type Checking Supported Out-of-the-box: Deno already type checks XSX, so doesn't need a custom TTL parser to be able to type check elements/attributes/children.
  3. Parsing the Template Occurs Ahead-of-time: Parsing the template into function calls occurs AOT in XSX and occurs at runtime using native TTL. This runtime parsing incurs a performance cost.
jeroenptrs commented 3 years ago

Parsing the Template Occurs Ahead-of-time: Parsing the template into function calls occurs AOT in XSX and occurs at runtime using native TTL. This runtime parsing incurs a performance cost.

I'd like to note that even if you add a transpiler for TTL in your AOT step, JSX still has more perf real estate since it's baked into tsc/deno

ghost commented 3 years ago

Even if we wrote the AOT TTL transpiler in Rust and used it as a plugin?

jeroenptrs commented 3 years ago

It's still an extra step, thus less benefits as opposed to JSX

littledivy commented 3 years ago

Even if we wrote the AOT TTL transpiler in Rust and used it as a plugin?

@lmnsoftware I won't do a rust plugin and introduce unstable into our code although there is deno_swc that parse source to AST (using wasm so no unstable) (https://github.com/nestdotland/deno_swc/blob/wasm/examples/parse.ts) and then we could visit template literals and implement a js TTL parser for parsing the string.

But, I agree with @jeroenptrs, JSX > TTL in terms of native support & perf