Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gratuitous string concatenation occurs when escaped curly braces are present #21

Open
lazd opened this issue Nov 4, 2014 · 0 comments

Comments

@lazd
Copy link
Owner

lazd commented Nov 4, 2014

The output is less than ideal when \{ and \} are present -- there is additional string concatenation going on in the compiled function that is pretty ugly:

Template:

\{\{Outer with data\}\} {{data.name}}

<code>
  \{\{Nested\}\}
</code>

<code>
  \{\{Nested with data\}\} {{data.name}}
</code>

Output:

(function anonymous(data_0) {
  var frag = document.createDocumentFragment();
  var data = data_0;
  var el0 = document.createTextNode("{"+"{"+"Outer with data"+"}"+"}"+" "+data_0["name"]+"\n\n");
  frag.appendChild(el0);
  var el1 = document.createElement("code");
  el1.textContent = "\n  "+"{"+"{"+"Nested"+"}"+"}"+"\n";
  frag.appendChild(el1);
  var el2 = document.createTextNode("\n\n");
  frag.appendChild(el2);
  var el3 = document.createElement("code");
  el3.textContent = "\n  "+"{"+"{"+"Nested with data"+"}"+"}"+" "+data_0["name"]+"\n";
  frag.appendChild(el3);
  return frag;
})

The parser could be modified to concatenate the braces into an existing content block instead of creating a new one, or DOMly could be fixed to combine content blocks into a single string instead of concatenating multiple strings.

This is due to the fixes for #7. @cif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant