lazd / DOMly

The fast template system that creates and clones DOM nodes
MIT License
53 stars 9 forks source link

Template with script tag produces invalid template code #27

Closed cespare closed 9 years ago

cespare commented 9 years ago

I've got some HTML that domly turns into JS which crashes. Here's a minimal repro (note the leading spaces in front of the <script> tag):

  <script src="a.js"></script>

I'm compiling with domly.precompile(contents, {stripWhitespace: true}).

I get this:

(function() {
  var frag;
function anonymous(data_0) {
    var frag = document.createDocumentFragment();
    var data = data_0;
    var el0 = document.createTextNode(" ");
    frag.appendChild(el0);
    frag.appendChild(el1);
    var el2 = document.createTextNode(" ");
    frag.appendChild(el2);
    return frag;
}
  return function template() {
    if (!frag) {
      frag = anonymous();
    }
    return frag.cloneNode(true);
  };
}())

See that el1 is referenced but never created.

lazd commented 9 years ago

Looks Cheerio gives <script> tags a type = 'script', not type = 'tag', so the compiler completely missed them. The same goes for <style> tags. I've fixed both and added test cases.

Thanks for the report!

cespare commented 9 years ago

Thanks for the quick fix!

lazd commented 9 years ago

You're welcome!

Published as domly@0.0.8.

cespare commented 9 years ago

Awesome!