3 ms·
You parse the string literal, just like you parse the string that is the contents of a JavaScript file.
by spankalee 8y ago
You parse the string literal, just like you parse the string that is the contents of a JavaScript file.
- dmitriid 8y agoYeah, 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
- spankalee 8y agoType-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.
- dmitriid 8y ago> 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#L36 https://github.com/developit/htm/blob/master/src/index.mjs#L... or lit-html: https://github.com/Polymer/lit-html/blob/master/src/lib/template-result.ts#L47 https://github.com/Polymer/lit-html/blob/master/src/lib/temp...
- bcherny 8y agoYou 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.