News for hackers. Stuff that matters.
Re:Hyperscript Tagged Markup: JSX alternative using standard... by magicalist on Thursday November 22, 2018 @03:18PM (#18512253)
> Writing code, not strings, means you can do everything to it that you can do to code.

These are tagged templates, not strings. They work as code at runtime, and it already has support to optimize it, compile it, etc. This is JS all the way down. And spankalee mentioned below they're adding typescript support to type check the very similar lit-html, so that's coming too.

> That's why I like JSX, it's Javascript all the way down. Everything is code. It's a very well designed and thought out DSL.

It's also kind of a weird to highlight all this for a DSL that actually has to be parsed from a string to get it to be Javascript. Everything else you're talking about is tooling that had to be built special for it, not the language itself.

Why not just say "I like the style of jsx embedding and existing tools better" :)

Re:Hyperscript Tagged Markup: JSX alternative using standard... by domenicd on Thursday November 22, 2018 @03:30PM (#18512338)
+1. It's all strings (of source code) in the end. It's just a matter of how well the tools support those strings.

There exists a medium-sized ecosystem of tools which supports static checks on strings inside angle brackets, a la JSX. There is a smaller-but-growing ecosystem of tools that supports static checks on strings inside backticks, a la HTM/lit-html/etc. There's no fundamental difference here.

Re:Hyperscript Tagged Markup: JSX alternative using standard... by dmitriid on Thursday November 22, 2018 @03:52PM (#18512475)
The fundamental difference is what you have in the end. With JSX you have function calls (JSX is a very thin DSL after all).

With tagged literals you end up with runtime string parsing and concatenation.

Re:Hyperscript Tagged Markup: JSX alternative using standard... by magicalist on Thursday November 22, 2018 @04:27PM (#18512688)
> The fundamental difference is what you have in the end. With JSX you have function calls

Check out the output of the Babel plugin mentioned in the readme

> // input:

> html`<div id="foo">hello ${you}</div>`

> // output:

> React.createElement("div", { id: "foo" }, "hello ", you) options

https://www.npmjs.com/package/babel-plugin-htm

Re:Hyperscript Tagged Markup: JSX alternative using standard... by dmitriid on Friday November 23, 2018 @03:31AM (#18515157)
It's (marginally) better than having it at runtime. Poor man's macros. Much like JSX in a sense, though JSX is a much thinner abstraction IMO.
Re:Hyperscript Tagged Markup: JSX alternative using standard... by rickycook on Thursday November 22, 2018 @04:17PM (#18512628)
and i think this is the point; runtime vs compile time! similar reasons that people love the popular new type systems... if it compiles, it probably works or you get an error rather than pushing that later and possibly not catching it
Re:Hyperscript Tagged Markup: JSX alternative using standard... by madeofpalk on Thursday November 22, 2018 @05:34PM (#18512998)
> These are tagged templates, not strings

Tagged templates are strings.

Re:Hyperscript Tagged Markup: JSX alternative using standard... by dmitriid on Thursday November 22, 2018 @03:44PM (#18512428)
> These are tagged templates, not strings. They work as code at runtime, and it already has support to optimize it, compile it, etc.

Optimize, compile etc. what?

f`string` is literally a function call f("string"). What exactly are you "compiling and optimizing"?

Re:Hyperscript Tagged Markup: JSX alternative using standard... by atombender on Thursday November 22, 2018 @04:03PM (#18512545)
No, that's incorrect. Interpolations (${}) are preserved. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re:Hyperscript Tagged Markup: JSX alternative using standard... by dmitriid on Friday November 23, 2018 @03:22AM (#18515127)
Let's return to the original statement, shall we?

> These are tagged templates, not strings. They work as code at runtime, and it already has support to optimize it, compile it, etc.

So. How exactly do they "work as code" and "have support to optimize it, compile it, etc."?

Here's HTM's main function https://github.com/developit/htm/blob/master/src/index.mjs#L...

It: concatenates strings, parses (via regexes), then concatenates again. Can someone enlighten me as to why this is awesome, is code, is optimized and compiled?

Re:Hyperscript Tagged Markup: JSX alternative using standard... by atombender on Friday November 23, 2018 @11:08AM (#18517209)
I was responding to your false assertion that f`s` is the exact equivalent of f("s"), which only holds true without interpolations. f`a${b}c`) becomes f("a", b, "c").

Secondly, the answer is Babel. Since the string's components are part of the AST, it can optimize and compile it as the original poster claimed.

Re:Hyperscript Tagged Markup: JSX alternative using standard... by dmitriid on Sunday November 25, 2018 @08:22AM (#18526767)
> which only holds true without interpolations. f`a${b}c`) becomes f("a", b, "c").

The difference is so subtle as to be irrelevant. You still need to manually parse, process and assemble strings. There’s no magic. There’s no code. It’s just strings (with some values here and there).

It’s enough to see the implementation of HTM (or lit-html or any other library using tagged literals) to see that.

> the answer is Babel

Which is only mentioned once the bullshit claims about tagged literals are refuted.

Babel is not exactly the answer, but as poor man’s macros it will do.

Re:Hyperscript Tagged Markup: JSX alternative using standard... by wild_preference on Friday November 23, 2018 @08:41AM (#18516329)
They're just talking about https://www.npmjs.com/package/babel-plugin-htm.

> A Babel plugin that compiles htm syntax to hyperscript, React.createElement, or just plain objects.