Repository navigation
Conversation
|
I have signed the CLA. |
|
Update: Separated the Babel plugin specific fixes to PR #35. |
|
I'm worried |
|
Yes, In the escaped text the placeholders will be the only appearances of |
|
I forgot to mention: one of the added tests checks that |
|
To make reviewing easier I separated the Babel plugin specific changes to pull request #35 and added a new test file htm.test.js for htm-specific tests that don't depend on the Babel plugin. |
|
Closing this in preparation to #38. |
This pull request addresses some corner cases and adds tests for those cases:
<div>$_h[1]</div>gets transformed toh("div",{},[]);<div id=Hello>gets transformed toh(\"div\",{id:\":::Hello\"},[]);\, which can get transformed into malformed code.These problems were partially caused by the way how e.g. upper-case characters in attributes are escaped before being fed to the browser's HTML parser and how they couldn't be unambigiously unescaped back later. Therefore this patch modifies placeholder handling and escaping:
$_(so e.g.Abecomes$_A).$_[<number>](e.g.$_[1]) instead of$_h[<number>]to separate them from potentially lower-cased$_H.$_instead ofc@so the complete string would be$_=<something>.Cases 2. and 3. are handled as previously, and case 1. gets reversed in the end - the idea being that in the end every substring that matches
/\$_[_A-Z]/ican be safely and unambiguously turned back into an underscore or upper-case character. Attribute names also get escaped withJSON.stringify.These changes do not seem to materially affect the performance in my environment, but of course YMMV. As a bonus the gzipped builds seem to be a tad smaller (671 B for htm.mjs.gz, down from 688 B).
There's also a minor change to preact.test.js, as the new code assumes that the statics that get passed in are always strings. I think this is a valid assumption..?