3 ms·
It's a bit disingenuous to say the templates are parsed with regular expressions. The way lit-html generates DOM Templates from strings is by letting the browse
by Ruphin 8y ago
It's a bit disingenuous to say the templates are parsed with regular expressions. The way lit-html generates DOM Templates from strings is by letting the browser parse the string through innerHTML. The purpose of the regexes you are referring to is to find the correct insertion points for dynamic values in the template, and has nothing to do with the HTML parsing process.
There is nothing fundamentally wrong with using innerHTML to parse HTML strings. You use the same parser for the content of index.html, and I don't think anyone is advocating to replace index.html with a single script that creates these nodes using a virtualDOM type rendering system.
- dmitriid 8y ago> It's a bit disingenuous to say the templates are parsed with regular expressions. The way lit-html generates DOM Templates from strings "generates DOM templates from strings" <- this is what I'm talking about. lit-html literally: - parses opaque string blobs [1] - parses them with regexps [2] - concatenates string chunks together [3] - dumps the resulting string blob into DOM via .innerHtml [4] So it does everything that was considered bad programming practices as early as 1999. And does all that at runtime. > and has nothing to do with the HTML parsing process. Yeah, no. This is literally parsing HTML with regexps. Because lit-html has to know whether a value is inside an HTML attribute, or inside a tag, for example. In order to know that it has to... well, parse the string that's passed to it. And what do you pass into lit-html? Oh, HTML. That it parses. > I don't think anyone is advocating to replace index.html with a single script that creates these nodes using a virtualDOM type rendering system. Yeah, you're apparently advocating to replace index.html with a function call that parses strings at runtime and dumps blobs of strings via innerHtml into DOM. [1] Because tagged template literals are just function calls with lists of strings, and some values [2] https://github.com/Polymer/lit-html/blob/master/src/lib/template.ts#L102 https://github.com/Polymer/lit-html/blob/master/src/lib/temp... [3] https://github.com/Polymer/lit-html/blob/master/src/lib/template-result.ts#L85 https://github.com/Polymer/lit-html/blob/master/src/lib/temp... [4] https://github.com/Polymer/lit-html/blob/master/src/lib/template-result.ts#L101 https://github.com/Polymer/lit-html/blob/master/src/lib/temp...