Hacker News new | past | comments | ask | show | jobs | submit login

You parse the string literal, just like you parse the string that is the contents of a JavaScript file.



You could definitely do that (Angular recently started doing this too!). I think once there is a way to enforce compile time safety for HTM, it’ll be a lot more appealing for TypeScript/Flow folks.


Yeah, I'll let Javascript engines parse and convert my Javascript to bytecode for me. It's definitely not the same as manually parsing strings at runtime. And equating the two is disingenuous at best


Type-checking happens at compile time, and even the JS is parsed by a user-land library and not the JS engine.

At runtime these templates are parsed by the browser's built-in HTML parser.


> Type-checking happens at compile time, and even the JS is parsed by a user-land library and not the JS engine.

True. Still, it's functions and regular JS, not strings manually processed at runtime

> At runtime these templates are parsed by the browser's built-in HTML parser.

It's not the first time I've seen this ... bullshit (no other word for it). Where does it come from?

The only time it's parsed by browser's built-in HTML parser is when you manually call something like `element.innerHtml = "you string that you manually assembled in your function at runtime"`.

The browser has no idea what is contained in your tagged string. Which is painfully obvious when you actually look at the implementations of HTM: https://github.com/developit/htm/blob/master/src/index.mjs#L... or lit-html: https://github.com/Polymer/lit-html/blob/master/src/lib/temp...




Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: